Bug 1807268 - Re-enable verifyShowClipboardSuggestionsToggleTest UI test r=jajohnson
[gecko.git] / mobile / android / fenix / app / src / androidTest / java / org / mozilla / fenix / ui / DownloadTest.kt
blob23c8e2ac3ca6c8ba07b8b0d0ebb11fb749acb80e
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
9 import org.junit.Rule
10 import org.junit.Test
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
31 /**
32  *  Tests for verifying basic functionality of download
33  *
34  *  - Initiates a download
35  *  - Verifies download prompt
36  *  - Verifies download notification and actions
37  *  - Verifies managing downloads inside the Downloads listing.
38  **/
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 = ""
44     @get:Rule
45     val activityTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides()
47     // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/243844
48     @Test
49     fun verifyTheDownloadPromptsTest() {
50         downloadRobot {
51             openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "web_icon.png")
52             verifyDownloadCompleteNotificationPopup()
53         }.clickOpen("image/png") {}
54         downloadRobot {
55             verifyPhotosAppOpens()
56         }
57     }
59     // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2299405
60     @Test
61     fun verifyTheDownloadFailedNotificationsTest() {
62         downloadRobot {
63             openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "1GB.zip")
64             setNetworkEnabled(enabled = false)
65             verifyDownloadFailedPrompt("1GB.zip")
66             setNetworkEnabled(enabled = true)
67             clickTryAgainButton()
68         }
69         mDevice.openNotification()
70         notificationShade {
71             verifySystemNotificationDoesNotExist("Download failed")
72             verifySystemNotificationExists("1GB.zip")
73         }.closeNotificationTray {}
74     }
76     // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2298616
77     @Test
78     fun verifyDownloadCompleteNotificationTest() {
79         downloadRobot {
80             openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "web_icon.png")
81             verifyDownloadCompleteNotificationPopup()
82         }
83         mDevice.openNotification()
84         notificationShade {
85             verifySystemNotificationExists("Download completed")
86             clickNotification("Download completed")
87             assertExternalAppOpens(GOOGLE_APPS_PHOTOS)
88             mDevice.pressBack()
89             mDevice.openNotification()
90             verifySystemNotificationExists("Download completed")
91             swipeDownloadNotification(
92                 direction = "Left",
93                 shouldDismissNotification = true,
94                 canExpandNotification = false,
95             )
96             verifySystemNotificationDoesNotExist("Firefox Fenix")
97         }.closeNotificationTray {}
98     }
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")
102     @SmokeTest
103     @Test
104     fun pauseResumeCancelDownloadTest() {
105         downloadRobot {
106             openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "3GB.zip")
107         }
108         mDevice.openNotification()
109         notificationShade {
110             verifySystemNotificationExists("Firefox Fenix")
111             expandNotificationMessage()
112             clickDownloadNotificationControlButton("PAUSE")
113             verifySystemNotificationExists("Download paused")
114             clickDownloadNotificationControlButton("RESUME")
115             clickDownloadNotificationControlButton("CANCEL")
116             verifySystemNotificationDoesNotExist("3GB.zip")
117             mDevice.pressBack()
118         }
119         browserScreen {
120         }.openThreeDotMenu {
121         }.openDownloadsManager {
122             verifyEmptyDownloadsList()
123         }
124     }
126     // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2301474
127     @Test
128     fun openDownloadedFileFromDownloadsMenuTest() {
129         downloadRobot {
130             openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "web_icon.png")
131             verifyDownloadCompleteNotificationPopup()
132         }
133         browserScreen {
134         }.openThreeDotMenu {
135         }.openDownloadsManager {
136             verifyDownloadedFileName("web_icon.png")
137             openDownloadedFile("web_icon.png")
138             verifyPhotosAppOpens()
139             mDevice.pressBack()
140         }
141     }
143     // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1114970
144     @Test
145     fun deleteDownloadedFileTest() {
146         downloadRobot {
147             openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "smallZip.zip")
148         }
149         browserScreen {
150         }.openThreeDotMenu {
151         }.openDownloadsManager {
152             verifyDownloadedFileName("smallZip.zip")
153             deleteDownloadedItem("smallZip.zip")
154             clickSnackbarButton("UNDO")
155             verifyDownloadedFileName("smallZip.zip")
156             deleteDownloadedItem("smallZip.zip")
157             verifyEmptyDownloadsList()
158         }
159     }
161     // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2302662
162     @Test
163     fun deleteMultipleDownloadedFilesTest() {
164         val firstDownloadedFile = "smallZip.zip"
165         val secondDownloadedFile = "textfile.txt"
167         downloadRobot {
168             openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = firstDownloadedFile)
169             verifyDownloadedFileName(firstDownloadedFile)
170         }.closeDownloadPrompt {
171         }.clickDownloadLink(secondDownloadedFile) {
172             verifyDownloadPrompt(secondDownloadedFile)
173         }.clickDownload {
174             verifyDownloadedFileName(secondDownloadedFile)
175         }
176         browserScreen {
177         }.openThreeDotMenu {
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()
193         }
194     }
196     // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2301537
197     @Test
198     fun fileDeletedFromStorageIsDeletedEverywhereTest() {
199         downloadRobot {
200             openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "smallZip.zip")
201             verifyDownloadCompleteNotificationPopup()
202         }
203         browserScreen {
204         }.openThreeDotMenu {
205         }.openDownloadsManager {
206             waitForDownloadsListToExist()
207             verifyDownloadedFileName("smallZip.zip")
208             deleteDownloadedFileOnStorage("smallZip.zip")
209         }.exitDownloadsManagerToBrowser {
210         }.openThreeDotMenu {
211         }.openDownloadsManager {
212             verifyEmptyDownloadsList()
213             exitMenu()
214         }
216         downloadRobot {
217             openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "smallZip.zip")
218             verifyDownloadCompleteNotificationPopup()
219         }
220         browserScreen {
221         }.openThreeDotMenu {
222         }.openDownloadsManager {
223             waitForDownloadsListToExist()
224             verifyDownloadedFileName("smallZip.zip")
225         }
226     }
228     // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/457112
229     @Test
230     fun systemNotificationCantBeDismissedWhileInProgressTest() {
231         downloadRobot {
232             openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "3GB.zip")
233         }
234         browserScreen {
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")
242         }
243     }
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")
247     @Test
248     fun notificationCanBeDismissedIfDownloadIsInterruptedTest() {
249         downloadRobot {
250             openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "1GB.zip")
251         }
253         setNetworkEnabled(enabled = false)
255         browserScreen {
256         }.openNotificationShade {
257             expandNotificationMessage()
258             verifySystemNotificationExists("Download failed")
259             swipeDownloadNotification("Left", true)
260             verifySystemNotificationDoesNotExist("Firefox Fenix")
261         }.closeNotificationTray {}
263         downloadRobot {
264         }.closeDownloadPrompt {
265             verifyDownloadPromptIsDismissed()
266         }
267     }
269     // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1632384
270     @Test
271     fun warningWhenClosingPrivateTabsWhileDownloadingTest() {
272         homeScreen {
273         }.togglePrivateBrowsingMode()
274         downloadRobot {
275             openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "3GB.zip")
276         }
277         browserScreen {
278         }.openTabDrawer {
279             closeTab()
280         }
281         browserScreen {
282             verifyCancelPrivateDownloadsPrompt("1")
283             clickStayInPrivateBrowsingPromptButton()
284         }.openNotificationShade {
285             verifySystemNotificationExists("Firefox Fenix")
286         }
287     }
289     // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2302663
290     @Test
291     fun cancelActivePrivateBrowsingDownloadsTest() {
292         homeScreen {
293         }.togglePrivateBrowsingMode()
294         downloadRobot {
295             openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "3GB.zip")
296         }
297         browserScreen {
298         }.openTabDrawer {
299             closeTab()
300         }
301         browserScreen {
302             verifyCancelPrivateDownloadsPrompt("1")
303             clickCancelPrivateDownloadsPromptButton()
304         }.openNotificationShade {
305             verifySystemNotificationDoesNotExist("Firefox Fenix")
306         }
307     }
309     // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2048448
310     // Save edited PDF file from the share overlay
311     @SmokeTest
312     @Test
313     fun saveAsPdfFunctionalityTest() {
314         val genericURL =
315             TestAssetHelper.getGenericAsset(mockWebServer, 3)
316         downloadFile = "pdfForm.pdf"
318         navigationToolbar {
319         }.enterURLAndEnterToBrowser(genericURL.url) {
320             clickPageObject(itemWithText("PDF form file"))
321             waitForPageToLoad()
322             fillPdfForm("Firefox")
323         }.openThreeDotMenu {
324         }.clickShareButton {
325         }.clickSaveAsPDF {
326             verifyDownloadPrompt("pdfForm.pdf")
327         }.clickDownload {
328         }.clickOpen("application/pdf") {
329             assertExternalAppOpens(GOOGLE_DOCS)
330         }
331     }
333     // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/244125
334     @Test
335     fun restartDownloadFromAppNotificationAfterConnectionIsInterruptedTest() {
336         downloadFile = "3GB.zip"
338         navigationToolbar {
339         }.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
340             waitForPageToLoad()
341         }.clickDownloadLink(downloadFile) {
342             verifyDownloadPrompt(downloadFile)
343             setNetworkEnabled(false)
344         }.clickDownload {
345             verifyDownloadFailedPrompt(downloadFile)
346             setNetworkEnabled(true)
347             clickTryAgainButton()
348         }
349         browserScreen {
350         }.openNotificationShade {
351             verifySystemNotificationExists("Firefox Fenix")
352             expandNotificationMessage()
353             clickDownloadNotificationControlButton("CANCEL")
354         }
355     }