|
|
|
@ -23,7 +23,6 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
|
|
|
|
|
import androidx.test.uiautomator.By
|
|
|
|
|
import androidx.test.uiautomator.UiSelector
|
|
|
|
|
import androidx.test.uiautomator.Until
|
|
|
|
|
import org.hamcrest.CoreMatchers
|
|
|
|
|
import org.hamcrest.CoreMatchers.allOf
|
|
|
|
|
import org.junit.Assert.assertTrue
|
|
|
|
|
import org.mozilla.fenix.R
|
|
|
|
@ -32,12 +31,15 @@ import org.mozilla.fenix.helpers.AppAndSystemHelper.getPermissionAllowID
|
|
|
|
|
import org.mozilla.fenix.helpers.Constants.PackageName.GOOGLE_APPS_PHOTOS
|
|
|
|
|
import org.mozilla.fenix.helpers.Constants.TAG
|
|
|
|
|
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
|
|
|
|
|
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
|
|
|
|
|
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndTextExists
|
|
|
|
|
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
|
|
|
|
|
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
|
|
|
|
|
import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription
|
|
|
|
|
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
|
|
|
|
|
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdAndText
|
|
|
|
|
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdContainingText
|
|
|
|
|
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
|
|
|
|
|
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeLong
|
|
|
|
|
import org.mozilla.fenix.helpers.TestHelper.mDevice
|
|
|
|
|
import org.mozilla.fenix.helpers.TestHelper.packageName
|
|
|
|
|
import org.mozilla.fenix.helpers.click
|
|
|
|
@ -55,18 +57,8 @@ class DownloadRobot {
|
|
|
|
|
Log.i(TAG, "verifyDownloadPrompt: While loop currentTries = $currentTries")
|
|
|
|
|
try {
|
|
|
|
|
Log.i(TAG, "verifyDownloadPrompt: Try block")
|
|
|
|
|
assertTrue(
|
|
|
|
|
"Download prompt button not visible",
|
|
|
|
|
mDevice.findObject(UiSelector().resourceId("$packageName:id/download_button"))
|
|
|
|
|
.waitForExists(waitingTimeLong),
|
|
|
|
|
)
|
|
|
|
|
Log.i(TAG, "verifyDownloadPrompt: Verified that the \"DOWNLOAD\" prompt button exists")
|
|
|
|
|
assertTrue(
|
|
|
|
|
"$fileName title doesn't match",
|
|
|
|
|
mDevice.findObject(UiSelector().text(fileName))
|
|
|
|
|
.waitForExists(waitingTimeLong),
|
|
|
|
|
)
|
|
|
|
|
Log.i(TAG, "verifyDownloadPrompt: Verified that the download prompt for $fileName exists")
|
|
|
|
|
assertItemWithResIdExists(itemWithResId("$packageName:id/download_button"))
|
|
|
|
|
assertItemContainingTextExists(itemContainingText(fileName))
|
|
|
|
|
|
|
|
|
|
break
|
|
|
|
|
} catch (e: AssertionError) {
|
|
|
|
@ -81,48 +73,28 @@ class DownloadRobot {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun verifyDownloadCompleteNotificationPopup() {
|
|
|
|
|
assertTrue(
|
|
|
|
|
"Download notification Open button not found",
|
|
|
|
|
mDevice.findObject(UiSelector().text("Open"))
|
|
|
|
|
.waitForExists(waitingTime),
|
|
|
|
|
)
|
|
|
|
|
assertTrue(
|
|
|
|
|
"Download completed notification text doesn't match",
|
|
|
|
|
mDevice.findObject(UiSelector().textContains("Download completed"))
|
|
|
|
|
.waitForExists(waitingTime),
|
|
|
|
|
)
|
|
|
|
|
assertTrue(
|
|
|
|
|
"Downloaded file name not visible",
|
|
|
|
|
mDevice.findObject(UiSelector().resourceId("$packageName:id/download_dialog_filename"))
|
|
|
|
|
.waitForExists(waitingTime),
|
|
|
|
|
assertItemContainingTextExists(
|
|
|
|
|
itemContainingText(getStringResource(R.string.mozac_feature_downloads_button_open)),
|
|
|
|
|
itemContainingText(getStringResource(R.string.mozac_feature_downloads_completed_notification_text2)),
|
|
|
|
|
)
|
|
|
|
|
assertItemWithResIdExists(itemWithResId("$packageName:id/download_dialog_filename"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun verifyDownloadFailedPrompt(fileName: String) {
|
|
|
|
|
assertTrue(
|
|
|
|
|
itemWithResId("$packageName:id/download_dialog_icon")
|
|
|
|
|
.waitForExists(waitingTime),
|
|
|
|
|
)
|
|
|
|
|
assertTrue(
|
|
|
|
|
"Download dialog title not displayed",
|
|
|
|
|
itemWithResIdAndText(
|
|
|
|
|
assertItemWithResIdExists(itemWithResId("$packageName:id/download_dialog_icon"))
|
|
|
|
|
assertItemWithResIdAndTextExists(
|
|
|
|
|
itemWithResIdContainingText(
|
|
|
|
|
"$packageName:id/download_dialog_title",
|
|
|
|
|
"Download failed",
|
|
|
|
|
).waitForExists(waitingTime),
|
|
|
|
|
)
|
|
|
|
|
assertTrue(
|
|
|
|
|
"Download file name not displayed",
|
|
|
|
|
getStringResource(R.string.mozac_feature_downloads_failed_notification_text2),
|
|
|
|
|
),
|
|
|
|
|
itemWithResIdContainingText(
|
|
|
|
|
"$packageName:id/download_dialog_filename",
|
|
|
|
|
fileName,
|
|
|
|
|
).waitForExists(waitingTime),
|
|
|
|
|
)
|
|
|
|
|
assertTrue(
|
|
|
|
|
"Try again button not displayed",
|
|
|
|
|
itemWithResIdAndText(
|
|
|
|
|
),
|
|
|
|
|
itemWithResIdContainingText(
|
|
|
|
|
"$packageName:id/download_dialog_action_button",
|
|
|
|
|
"Try Again",
|
|
|
|
|
).waitForExists(waitingTime),
|
|
|
|
|
getStringResource(R.string.mozac_feature_downloads_button_try_again),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -131,68 +103,78 @@ class DownloadRobot {
|
|
|
|
|
"$packageName:id/download_dialog_action_button",
|
|
|
|
|
"Try Again",
|
|
|
|
|
).click()
|
|
|
|
|
Log.i(TAG, "clickTryAgainButton: Clicked \"TRY AGAIN\" in app prompt button")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun verifyPhotosAppOpens() = assertExternalAppOpens(GOOGLE_APPS_PHOTOS)
|
|
|
|
|
|
|
|
|
|
fun verifyDownloadedFileName(fileName: String) {
|
|
|
|
|
assertTrue(
|
|
|
|
|
"$fileName not found in Downloads list",
|
|
|
|
|
mDevice.findObject(UiSelector().text(fileName))
|
|
|
|
|
.waitForExists(waitingTime),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
fun verifyDownloadedFileName(fileName: String) = assertItemContainingTextExists(itemContainingText(fileName))
|
|
|
|
|
|
|
|
|
|
fun verifyDownloadedFileIcon() = assertDownloadedFileIcon()
|
|
|
|
|
fun verifyDownloadedFileIcon() = assertItemWithResIdExists(itemWithResId("$packageName:id/favicon"))
|
|
|
|
|
|
|
|
|
|
fun verifyEmptyDownloadsList() {
|
|
|
|
|
Log.i(TAG, "verifyEmptyDownloadsList: Looking for empty download list")
|
|
|
|
|
mDevice.findObject(UiSelector().resourceId("$packageName:id/download_empty_view"))
|
|
|
|
|
.waitForExists(waitingTime)
|
|
|
|
|
onView(withText("No downloaded files")).check(matches(isDisplayed()))
|
|
|
|
|
Log.i(TAG, "verifyEmptyDownloadsList: Verified \"No downloaded files\" list message")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun waitForDownloadsListToExist() =
|
|
|
|
|
fun waitForDownloadsListToExist() {
|
|
|
|
|
assertTrue(
|
|
|
|
|
"Downloads list either empty or not displayed",
|
|
|
|
|
mDevice.findObject(UiSelector().resourceId("$packageName:id/download_list"))
|
|
|
|
|
.waitForExists(waitingTime),
|
|
|
|
|
)
|
|
|
|
|
Log.i(TAG, "waitForDownloadsListToExist: Verified that the download list exists")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun openDownloadedFile(fileName: String) {
|
|
|
|
|
downloadedFile(fileName)
|
|
|
|
|
.check(matches(isDisplayed()))
|
|
|
|
|
.click()
|
|
|
|
|
Log.i(TAG, "openDownloadedFile: Clicked downloaded file: $fileName")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun deleteDownloadedItem(fileName: String) =
|
|
|
|
|
fun deleteDownloadedItem(fileName: String) {
|
|
|
|
|
onView(
|
|
|
|
|
allOf(
|
|
|
|
|
withId(R.id.overflow_menu),
|
|
|
|
|
hasSibling(withText(fileName)),
|
|
|
|
|
),
|
|
|
|
|
).click()
|
|
|
|
|
Log.i(TAG, "deleteDownloadedItem: Deleted downloaded file: $fileName using trash bin icon")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun longClickDownloadedItem(title: String) =
|
|
|
|
|
fun longClickDownloadedItem(title: String) {
|
|
|
|
|
onView(
|
|
|
|
|
allOf(
|
|
|
|
|
withId(R.id.title),
|
|
|
|
|
withText(title),
|
|
|
|
|
),
|
|
|
|
|
).perform(longClick())
|
|
|
|
|
Log.i(TAG, "longClickDownloadedItem: Long clicked downloaded file: $title")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun selectDownloadedItem(title: String) =
|
|
|
|
|
fun selectDownloadedItem(title: String) {
|
|
|
|
|
onView(
|
|
|
|
|
allOf(
|
|
|
|
|
withId(R.id.title),
|
|
|
|
|
withText(title),
|
|
|
|
|
),
|
|
|
|
|
).perform(click())
|
|
|
|
|
Log.i(TAG, "selectDownloadedItem: Selected downloaded file: $title")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun openMultiSelectMoreOptionsMenu() =
|
|
|
|
|
fun openMultiSelectMoreOptionsMenu() {
|
|
|
|
|
itemWithDescription(getStringResource(R.string.content_description_menu)).click()
|
|
|
|
|
Log.i(TAG, "openMultiSelectMoreOptionsMenu: Clicked multi-select more options button")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun clickMultiSelectRemoveButton() =
|
|
|
|
|
fun clickMultiSelectRemoveButton() {
|
|
|
|
|
itemWithResIdContainingText("$packageName:id/title", "Remove").click()
|
|
|
|
|
Log.i(TAG, "clickMultiSelectRemoveButton: Clicked multi-select remove button")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun openPageAndDownloadFile(url: Uri, downloadFile: String) {
|
|
|
|
|
navigationToolbar {
|
|
|
|
@ -213,44 +195,42 @@ class DownloadRobot {
|
|
|
|
|
return Transition()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun closeCompletedDownloadPrompt(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
|
|
|
|
closeCompletedDownloadButton().click()
|
|
|
|
|
|
|
|
|
|
BrowserRobot().interact()
|
|
|
|
|
return BrowserRobot.Transition()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun closeDownloadPrompt(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
|
|
|
|
itemWithResId("$packageName:id/download_dialog_close_button").click()
|
|
|
|
|
Log.i(TAG, "closeDownloadPrompt: Dismissed download prompt by clicking close prompt button")
|
|
|
|
|
|
|
|
|
|
BrowserRobot().interact()
|
|
|
|
|
return BrowserRobot.Transition()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun clickOpen(type: String, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
|
|
|
|
Log.i(TAG, "clickOpen: Looking for \"OPEN\" download prompt button")
|
|
|
|
|
openDownloadButton().waitForExists(waitingTime)
|
|
|
|
|
openDownloadButton().click()
|
|
|
|
|
Log.i(TAG, "clickOpen: Clicked \"OPEN\" download prompt button")
|
|
|
|
|
|
|
|
|
|
// verify open intent is matched with associated data type
|
|
|
|
|
Intents.intended(
|
|
|
|
|
CoreMatchers.allOf(
|
|
|
|
|
allOf(
|
|
|
|
|
IntentMatchers.hasAction(Intent.ACTION_VIEW),
|
|
|
|
|
IntentMatchers.hasType(type),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
Log.i(TAG, "clickOpen: Verified that open intent is matched with associated data type")
|
|
|
|
|
|
|
|
|
|
BrowserRobot().interact()
|
|
|
|
|
return BrowserRobot.Transition()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun clickAllowPermission(interact: DownloadRobot.() -> Unit): Transition {
|
|
|
|
|
Log.i(TAG, "clickAllowPermission: Looking for \"ALLOW\" permission button")
|
|
|
|
|
mDevice.waitNotNull(
|
|
|
|
|
Until.findObject(By.res(getPermissionAllowID() + ":id/permission_allow_button")),
|
|
|
|
|
waitingTime,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val allowPermissionButton = mDevice.findObject(By.res(getPermissionAllowID() + ":id/permission_allow_button"))
|
|
|
|
|
allowPermissionButton.click()
|
|
|
|
|
mDevice.findObject(By.res(getPermissionAllowID() + ":id/permission_allow_button")).click()
|
|
|
|
|
Log.i(TAG, "clickAllowPermission: Clicked \"ALLOW\" permission button")
|
|
|
|
|
|
|
|
|
|
DownloadRobot().interact()
|
|
|
|
|
return Transition()
|
|
|
|
@ -258,6 +238,7 @@ class DownloadRobot {
|
|
|
|
|
|
|
|
|
|
fun exitDownloadsManagerToBrowser(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
|
|
|
|
onView(withContentDescription("Navigate up")).click()
|
|
|
|
|
Log.i(TAG, "exitDownloadsManagerToBrowser: Exited download manager to browser by clicking the navigate up toolbar button")
|
|
|
|
|
|
|
|
|
|
BrowserRobot().interact()
|
|
|
|
|
return BrowserRobot.Transition()
|
|
|
|
@ -265,6 +246,7 @@ class DownloadRobot {
|
|
|
|
|
|
|
|
|
|
fun goBack(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition {
|
|
|
|
|
goBackButton().click()
|
|
|
|
|
Log.i(TAG, "exitDownloadsManagerToBrowser: Exited download manager to home screen by clicking the navigate up toolbar button")
|
|
|
|
|
|
|
|
|
|
HomeScreenRobot().interact()
|
|
|
|
|
return HomeScreenRobot.Transition()
|
|
|
|
@ -277,12 +259,6 @@ fun downloadRobot(interact: DownloadRobot.() -> Unit): DownloadRobot.Transition
|
|
|
|
|
return DownloadRobot.Transition()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun closeCompletedDownloadButton() =
|
|
|
|
|
onView(withId(R.id.download_dialog_close_button))
|
|
|
|
|
|
|
|
|
|
private fun closePromptButton() =
|
|
|
|
|
onView(withId(R.id.close_button))
|
|
|
|
|
|
|
|
|
|
private fun downloadButton() =
|
|
|
|
|
onView(withId(R.id.download_button))
|
|
|
|
|
.check(matches(isDisplayed()))
|
|
|
|
@ -292,11 +268,4 @@ private fun openDownloadButton() =
|
|
|
|
|
|
|
|
|
|
private fun downloadedFile(fileName: String) = onView(withText(fileName))
|
|
|
|
|
|
|
|
|
|
private fun assertDownloadedFileIcon() =
|
|
|
|
|
assertTrue(
|
|
|
|
|
"Downloaded file icon not found",
|
|
|
|
|
mDevice.findObject(UiSelector().resourceId("$packageName:id/favicon"))
|
|
|
|
|
.exists(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
private fun goBackButton() = onView(withContentDescription("Navigate up"))
|
|
|
|
|