Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #21002: improve Manage Downloads smoke tests coverage
Browse files Browse the repository at this point in the history
Add parametrized test for downloading various file types
  • Loading branch information
Oana Horvath authored and mergify[bot] committed Jan 18, 2022
1 parent 12a9071 commit 02d62c8
Show file tree
Hide file tree
Showing 11 changed files with 310 additions and 146 deletions.
10 changes: 0 additions & 10 deletions app/src/androidTest/assets/pages/download.html

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class FeatureSettingsHelper {
private var isPocketEnabled: Boolean = settings.showPocketRecommendationsFeature
private var isJumpBackInCFREnabled: Boolean = settings.shouldShowJumpBackInCFR
private var isRecentTabsFeatureEnabled: Boolean = settings.showRecentTabsFeature
private var isUserKnowsAboutPwasTrue: Boolean = settings.userKnowsAboutPwas

fun setPocketEnabled(enabled: Boolean) {
settings.showPocketRecommendationsFeature = enabled
Expand All @@ -33,12 +34,17 @@ class FeatureSettingsHelper {
settings.setStrictETP()
}

fun disablePwaCFR(disable: Boolean) {
settings.userKnowsAboutPwas = disable
}

// Important:
// Use this after each test if you have modified these feature settings
// to make sure the app goes back to the default state
fun resetAllFeatureFlags() {
settings.showPocketRecommendationsFeature = isPocketEnabled
settings.shouldShowJumpBackInCFR = isJumpBackInCFREnabled
settings.showRecentTabsFeature = isRecentTabsFeatureEnabled
settings.userKnowsAboutPwas = isUserKnowsAboutPwasTrue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
package org.mozilla.fenix.helpers

import android.net.Uri

import java.util.concurrent.TimeUnit
import okhttp3.mockwebserver.MockWebServer
import org.mozilla.fenix.helpers.ext.toUri
import java.util.concurrent.TimeUnit

/**
* Helper for hosting web pages locally for testing purposes.
Expand All @@ -17,8 +16,6 @@ object TestAssetHelper {
@Suppress("MagicNumber")
val waitingTime: Long = TimeUnit.SECONDS.toMillis(15)
val waitingTimeShort: Long = TimeUnit.SECONDS.toMillis(1)
// A long enough file name to not fit on a single line in the UI.
const val downloadFileName = "tAJwqaWjJsXS8AhzSninBMCfIZbHBGgcc001lx5DIdDwIcfEgQ6vE5Gb5VgAled17DFZ2A7ZDOHA0NpQPHXXFHPSD4wzCkRWiaOorNI574zLtv4Hjiz6O6T7onmUTGgUQ2YQoiQFyrCrPv8ZB9Kvmt.svg"

data class TestAsset(val url: Uri, val content: String, val title: String)

Expand Down Expand Up @@ -70,13 +67,6 @@ object TestAssetHelper {
return TestAsset(url, content, "")
}

fun getDownloadAsset(server: MockWebServer): TestAsset {
val url = server.url("pages/download.html").toString().toUri()!!
val content = "Page content: $downloadFileName"

return TestAsset(url, content, "")
}

fun getEnhancedTrackingProtectionAsset(server: MockWebServer): TestAsset {
val url = server.url("pages/trackingPage.html").toString().toUri()!!

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.fenix.ui

import androidx.core.net.toUri
import androidx.test.rule.GrantPermissionRule
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.FeatureSettingsHelper
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.RetryTestRule
import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.ui.robots.navigationToolbar

/**
* Test for verifying downloading a list of different file types:
* - Initiates a download
* - Verifies download prompt
* - Verifies downloading of varying file types and the appearance inside the Downloads listing.
**/
@RunWith(Parameterized::class)
class DownloadFileTypesTest(fileName: String) {
/* Remote test page managed by Mozilla Mobile QA team at https://github.com/mozilla-mobile/testapp */
private val downloadTestPage = "https://storage.googleapis.com/mobile_test_assets/test_app/downloads.html"
private var downloadFile: String = fileName
private val featureSettingsHelper = FeatureSettingsHelper()

@get:Rule
val activityTestRule = HomeActivityIntentTestRule()

@Rule
@JvmField
val retryTestRule = RetryTestRule(3)

@get:Rule
var mGrantPermissions = GrantPermissionRule.grant(
android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
android.Manifest.permission.READ_EXTERNAL_STORAGE
)

companion object {
// Creating test data. The test will take each file name as a parameter and run it individually.
@JvmStatic
@Parameterized.Parameters
fun downloadList() = listOf(
"washington.pdf",
"MyDocument.docx",
"audioSample.mp3",
"textfile.txt",
"web_icon.png",
"videoSample.webm",
"CSVfile.csv",
"XMLfile.xml"
)
}

@Before
fun setUp() {
// disabling the jump-back-in pop-up that interferes with the tests.
featureSettingsHelper.setJumpBackCFREnabled(false)
// disabling the PWA CFR on 3rd visit
featureSettingsHelper.disablePwaCFR(true)
}

@After
fun tearDown() {
TestHelper.deleteDownloadFromStorage(downloadFile)
featureSettingsHelper.resetAllFeatureFlags()
}

@SmokeTest
@Test
fun downloadMultipleFileTypesTest() {
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
verifyDownloadNotificationPopup()
}.closePrompt {
}.openThreeDotMenu {
}.openDownloadsManager {
waitForDownloadsListToExist()
verifyDownloadedFileName(downloadFile)
verifyDownloadedFileIcon()
}.exitDownloadsManagerToBrowser { }
}
}
147 changes: 111 additions & 36 deletions app/src/androidTest/java/org/mozilla/fenix/ui/DownloadTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,45 @@

package org.mozilla.fenix.ui

import androidx.core.net.toUri
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule
import androidx.test.uiautomator.UiDevice
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestAssetHelper.downloadFileName
import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.FeatureSettingsHelper
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.RetryTestRule
import org.mozilla.fenix.helpers.TestHelper.deleteDownloadFromStorage
import org.mozilla.fenix.ui.robots.browserScreen
import org.mozilla.fenix.ui.robots.downloadRobot
import org.mozilla.fenix.ui.robots.navigationToolbar
import org.mozilla.fenix.ui.robots.notificationShade

/**
* Tests for verifying basic functionality of download prompt UI
* Tests for verifying basic functionality of download
*
* - Initiates a download
* - Verifies download prompt
* - Verifies download notification
* - Verifies download notification and actions
* - Verifies managing downloads inside the Downloads listing.
**/

class DownloadTest {

private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
private lateinit var mockWebServer: MockWebServer
private val featureSettingsHelper = FeatureSettingsHelper()
/* Remote test page managed by Mozilla Mobile QA team at https://github.com/mozilla-mobile/testapp */
private val downloadTestPage = "https://storage.googleapis.com/mobile_test_assets/test_app/downloads.html"
private var downloadFile: String = ""

/* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping.
@get:Rule
val activityTestRule = HomeActivityTestRule()
val activityTestRule = HomeActivityIntentTestRule()

@Rule
@JvmField
val retryTestRule = RetryTestRule(3)

@get:Rule
var mGrantPermissions = GrantPermissionRule.grant(
Expand All @@ -46,53 +52,122 @@ class DownloadTest {

@Before
fun setUp() {
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
}
// disabling the jump-back-in pop-up that interferes with the tests.
featureSettingsHelper.setJumpBackCFREnabled(false)
// disabling the PWA CFR on 3rd visit
featureSettingsHelper.disablePwaCFR(true)
}

@After
fun tearDown() {
mockWebServer.shutdown()

TestHelper.deleteDownloadFromStorage(downloadFileName)
deleteDownloadFromStorage(downloadFile)
featureSettingsHelper.resetAllFeatureFlags()
}

@Test
fun testDownloadPrompt() {
val defaultWebPage = TestAssetHelper.getDownloadAsset(mockWebServer)
downloadFile = "web_icon.png"

navigationToolbar {
}.enterURLAndEnterToBrowser(defaultWebPage.url) {
mDevice.waitForIdle()
}

}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
verifyDownloadNotificationPopup()
}.clickOpen("image/png") {}
downloadRobot {
verifyDownloadPrompt()
}.closePrompt {}
verifyPhotosAppOpens()
}
}

@Test
fun testDownloadNotification() {
val defaultWebPage = TestAssetHelper.getDownloadAsset(mockWebServer)
fun testCloseDownloadPrompt() {
downloadFile = "smallZip.zip"

navigationToolbar {
}.enterURLAndEnterToBrowser(defaultWebPage.url) {
mDevice.waitForIdle()
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.closePrompt {
}.openThreeDotMenu {
}.openDownloadsManager {
verifyEmptyDownloadsList()
}
}

downloadRobot {
verifyDownloadPrompt()
@Test
fun testDownloadCompleteNotification() {
downloadFile = "smallZip.zip"

navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
verifyDownloadNotificationPopup()
}

mDevice.openNotification()
notificationShade {
verifySystemNotificationExists("Download completed")
}
// close notification shade before the next test
mDevice.pressBack()
}

@SmokeTest
@Test
fun pauseResumeCancelDownloadTest() {
downloadFile = "1GB.zip"

navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {}
mDevice.openNotification()
notificationShade {
expandNotificationMessage()
clickSystemNotificationControlButton("Pause")
clickSystemNotificationControlButton("Resume")
clickSystemNotificationControlButton("Cancel")
mDevice.pressBack()
}
browserScreen {
}.openThreeDotMenu {
}.openDownloadsManager {
verifyEmptyDownloadsList()
}
}

@SmokeTest
@Test
/* Verifies downloads in the Downloads Menu:
- downloads appear in the list
- deleting a download from device storage, removes it from the Downloads Menu too
*/
fun manageDownloadsInDownloadsMenuTest() {
// a long filename to verify it's correctly displayed on the prompt and in the Downloads menu
downloadFile = "tAJwqaWjJsXS8AhzSninBMCfIZbHBGgcc001lx5DIdDwIcfEgQ6vE5Gb5VgAled17DFZ2A7ZDOHA0NpQPHXXFt.svg"

navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
verifyDownloadNotificationPopup()
}
browserScreen {
}.openThreeDotMenu {
}.openDownloadsManager {
waitForDownloadsListToExist()
verifyDownloadedFileName(downloadFile)
verifyDownloadedFileIcon()
openDownloadedFile(downloadFile)
verifyPhotosAppOpens()
mDevice.pressBack()
deleteDownloadFromStorage(downloadFile)
}.exitDownloadsManagerToBrowser {
}.openThreeDotMenu {
}.openDownloadsManager {
verifyEmptyDownloadsList()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MediaNotificationTest {
assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
}.openNotificationShade {
verifySystemNotificationExists(videoTestPage.title)
clickMediaSystemNotificationControlButton("Pause")
clickSystemNotificationControlButton("Pause")
verifyMediaSystemNotificationButtonState("Play")
}

Expand Down Expand Up @@ -101,7 +101,7 @@ class MediaNotificationTest {
assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
}.openNotificationShade {
verifySystemNotificationExists("A site is playing media")
clickMediaSystemNotificationControlButton("Pause")
clickSystemNotificationControlButton("Pause")
verifyMediaSystemNotificationButtonState("Play")
}

Expand Down
Loading

0 comments on commit 02d62c8

Please sign in to comment.