1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 package org.mozilla.fenix.ui
7 import androidx.core.net.toUri
8 import org.junit.Ignore
11 import org.mozilla.fenix.customannotations.SmokeTest
12 import org.mozilla.fenix.helpers.AppAndSystemHelper.assertExternalAppOpens
13 import org.mozilla.fenix.helpers.AppAndSystemHelper.deleteDownloadedFileOnStorage
14 import org.mozilla.fenix.helpers.AppAndSystemHelper.setNetworkEnabled
15 import org.mozilla.fenix.helpers.Constants.PackageName.GOOGLE_APPS_PHOTOS
16 import org.mozilla.fenix.helpers.Constants.PackageName.GOOGLE_DOCS
17 import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
18 import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
19 import org.mozilla.fenix.helpers.TestAssetHelper
20 import org.mozilla.fenix.helpers.TestHelper.clickSnackbarButton
21 import org.mozilla.fenix.helpers.TestHelper.exitMenu
22 import org.mozilla.fenix.helpers.TestHelper.mDevice
23 import org.mozilla.fenix.helpers.TestSetup
24 import org.mozilla.fenix.ui.robots.browserScreen
25 import org.mozilla.fenix.ui.robots.clickPageObject
26 import org.mozilla.fenix.ui.robots.downloadRobot
27 import org.mozilla.fenix.ui.robots.homeScreen
28 import org.mozilla.fenix.ui.robots.navigationToolbar
29 import org.mozilla.fenix.ui.robots.notificationShade
32 * Tests for verifying basic functionality of download
34 * - Initiates a download
35 * - Verifies download prompt
36 * - Verifies download notification and actions
37 * - Verifies managing downloads inside the Downloads listing.
39 class DownloadTest : TestSetup() {
40 /* Remote test page managed by Mozilla Mobile QA team at https://github.com/mozilla-mobile/testapp */
41 private val downloadTestPage = "https://storage.googleapis.com/mobile_test_assets/test_app/downloads.html"
42 private var downloadFile: String = ""
45 val activityTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides()
47 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/243844
49 fun verifyTheDownloadPromptsTest() {
51 openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "web_icon.png")
52 verifyDownloadCompleteNotificationPopup()
53 }.clickOpen("image/png") {}
55 verifyPhotosAppOpens()
59 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2299405
61 fun verifyTheDownloadFailedNotificationsTest() {
63 openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "1GB.zip")
64 setNetworkEnabled(enabled = false)
65 verifyDownloadFailedPrompt("1GB.zip")
66 setNetworkEnabled(enabled = true)
69 mDevice.openNotification()
71 verifySystemNotificationDoesNotExist("Download failed")
72 verifySystemNotificationExists("1GB.zip")
73 }.closeNotificationTray {}
76 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2298616
78 fun verifyDownloadCompleteNotificationTest() {
80 openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "web_icon.png")
81 verifyDownloadCompleteNotificationPopup()
83 mDevice.openNotification()
85 verifySystemNotificationExists("Download completed")
86 clickNotification("Download completed")
87 assertExternalAppOpens(GOOGLE_APPS_PHOTOS)
89 mDevice.openNotification()
90 verifySystemNotificationExists("Download completed")
91 swipeDownloadNotification(
93 shouldDismissNotification = true,
94 canExpandNotification = false,
96 verifySystemNotificationDoesNotExist("Firefox Fenix")
97 }.closeNotificationTray {}
100 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/451563
101 @Ignore("Failing: Bug https://bugzilla.mozilla.org/show_bug.cgi?id=1813521")
104 fun pauseResumeCancelDownloadTest() {
106 openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "3GB.zip")
108 mDevice.openNotification()
110 verifySystemNotificationExists("Firefox Fenix")
111 expandNotificationMessage()
112 clickDownloadNotificationControlButton("PAUSE")
113 verifySystemNotificationExists("Download paused")
114 clickDownloadNotificationControlButton("RESUME")
115 clickDownloadNotificationControlButton("CANCEL")
116 verifySystemNotificationDoesNotExist("3GB.zip")
121 }.openDownloadsManager {
122 verifyEmptyDownloadsList()
126 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2301474
128 fun openDownloadedFileFromDownloadsMenuTest() {
130 openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "web_icon.png")
131 verifyDownloadCompleteNotificationPopup()
135 }.openDownloadsManager {
136 verifyDownloadedFileName("web_icon.png")
137 openDownloadedFile("web_icon.png")
138 verifyPhotosAppOpens()
143 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1114970
145 fun deleteDownloadedFileTest() {
147 openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "smallZip.zip")
151 }.openDownloadsManager {
152 verifyDownloadedFileName("smallZip.zip")
153 deleteDownloadedItem("smallZip.zip")
154 clickSnackbarButton("UNDO")
155 verifyDownloadedFileName("smallZip.zip")
156 deleteDownloadedItem("smallZip.zip")
157 verifyEmptyDownloadsList()
161 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2302662
163 fun deleteMultipleDownloadedFilesTest() {
164 val firstDownloadedFile = "smallZip.zip"
165 val secondDownloadedFile = "textfile.txt"
168 openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = firstDownloadedFile)
169 verifyDownloadedFileName(firstDownloadedFile)
170 }.closeDownloadPrompt {
171 }.clickDownloadLink(secondDownloadedFile) {
172 verifyDownloadPrompt(secondDownloadedFile)
174 verifyDownloadedFileName(secondDownloadedFile)
178 }.openDownloadsManager {
179 verifyDownloadedFileName(firstDownloadedFile)
180 verifyDownloadedFileName(secondDownloadedFile)
181 longClickDownloadedItem(firstDownloadedFile)
182 selectDownloadedItem(secondDownloadedFile)
183 openMultiSelectMoreOptionsMenu()
184 clickMultiSelectRemoveButton()
185 clickSnackbarButton("UNDO")
186 verifyDownloadedFileName(firstDownloadedFile)
187 verifyDownloadedFileName(secondDownloadedFile)
188 longClickDownloadedItem(firstDownloadedFile)
189 selectDownloadedItem(secondDownloadedFile)
190 openMultiSelectMoreOptionsMenu()
191 clickMultiSelectRemoveButton()
192 verifyEmptyDownloadsList()
196 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2301537
198 fun fileDeletedFromStorageIsDeletedEverywhereTest() {
200 openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "smallZip.zip")
201 verifyDownloadCompleteNotificationPopup()
205 }.openDownloadsManager {
206 waitForDownloadsListToExist()
207 verifyDownloadedFileName("smallZip.zip")
208 deleteDownloadedFileOnStorage("smallZip.zip")
209 }.exitDownloadsManagerToBrowser {
211 }.openDownloadsManager {
212 verifyEmptyDownloadsList()
217 openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "smallZip.zip")
218 verifyDownloadCompleteNotificationPopup()
222 }.openDownloadsManager {
223 waitForDownloadsListToExist()
224 verifyDownloadedFileName("smallZip.zip")
228 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/457112
230 fun systemNotificationCantBeDismissedWhileInProgressTest() {
232 openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "3GB.zip")
235 }.openNotificationShade {
236 verifySystemNotificationExists("Firefox Fenix")
237 expandNotificationMessage()
238 swipeDownloadNotification(direction = "Left", shouldDismissNotification = false)
239 clickDownloadNotificationControlButton("PAUSE")
240 swipeDownloadNotification(direction = "Right", shouldDismissNotification = false)
241 clickDownloadNotificationControlButton("CANCEL")
245 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2299297
246 @Ignore("Failing, see: https://bugzilla.mozilla.org/show_bug.cgi?id=1842154")
248 fun notificationCanBeDismissedIfDownloadIsInterruptedTest() {
250 openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "1GB.zip")
253 setNetworkEnabled(enabled = false)
256 }.openNotificationShade {
257 expandNotificationMessage()
258 verifySystemNotificationExists("Download failed")
259 swipeDownloadNotification("Left", true)
260 verifySystemNotificationDoesNotExist("Firefox Fenix")
261 }.closeNotificationTray {}
264 }.closeDownloadPrompt {
265 verifyDownloadPromptIsDismissed()
269 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1632384
271 fun warningWhenClosingPrivateTabsWhileDownloadingTest() {
273 }.togglePrivateBrowsingMode()
275 openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "3GB.zip")
282 verifyCancelPrivateDownloadsPrompt("1")
283 clickStayInPrivateBrowsingPromptButton()
284 }.openNotificationShade {
285 verifySystemNotificationExists("Firefox Fenix")
289 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2302663
291 fun cancelActivePrivateBrowsingDownloadsTest() {
293 }.togglePrivateBrowsingMode()
295 openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "3GB.zip")
302 verifyCancelPrivateDownloadsPrompt("1")
303 clickCancelPrivateDownloadsPromptButton()
304 }.openNotificationShade {
305 verifySystemNotificationDoesNotExist("Firefox Fenix")
309 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2048448
310 // Save edited PDF file from the share overlay
313 fun saveAsPdfFunctionalityTest() {
315 TestAssetHelper.getGenericAsset(mockWebServer, 3)
316 downloadFile = "pdfForm.pdf"
319 }.enterURLAndEnterToBrowser(genericURL.url) {
320 clickPageObject(itemWithText("PDF form file"))
322 fillPdfForm("Firefox")
326 verifyDownloadPrompt("pdfForm.pdf")
328 }.clickOpen("application/pdf") {
329 assertExternalAppOpens(GOOGLE_DOCS)
333 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/244125
335 fun restartDownloadFromAppNotificationAfterConnectionIsInterruptedTest() {
336 downloadFile = "3GB.zip"
339 }.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
341 }.clickDownloadLink(downloadFile) {
342 verifyDownloadPrompt(downloadFile)
343 setNetworkEnabled(false)
345 verifyDownloadFailedPrompt(downloadFile)
346 setNetworkEnabled(true)
347 clickTryAgainButton()
350 }.openNotificationShade {
351 verifySystemNotificationExists("Firefox Fenix")
352 expandNotificationMessage()
353 clickDownloadNotificationControlButton("CANCEL")