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 @file:Suppress("DEPRECATION")
7 package org.mozilla.fenix.ui
9 import androidx.core.net.toUri
10 import androidx.test.rule.ActivityTestRule
13 import org.mozilla.fenix.IntentReceiverActivity
14 import org.mozilla.fenix.customannotations.SmokeTest
15 import org.mozilla.fenix.helpers.AppAndSystemHelper.openAppFromExternalLink
16 import org.mozilla.fenix.helpers.DataGenerationHelper.createCustomTabIntent
17 import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
18 import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdAndText
19 import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
20 import org.mozilla.fenix.helpers.TestAssetHelper
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.customTabScreen
27 import org.mozilla.fenix.ui.robots.enhancedTrackingProtection
28 import org.mozilla.fenix.ui.robots.homeScreen
29 import org.mozilla.fenix.ui.robots.navigationToolbar
30 import org.mozilla.fenix.ui.robots.notificationShade
31 import org.mozilla.fenix.ui.robots.openEditURLView
32 import org.mozilla.fenix.ui.robots.searchScreen
34 class CustomTabsTest : TestSetup() {
35 private val customMenuItem = "TestMenuItem"
36 private val customTabActionButton = "CustomActionButton"
38 /* Updated externalLinks.html to v2.0,
39 changed the hypertext reference to mozilla-mobile.github.io/testapp/downloads for "External link"
41 private val externalLinksPWAPage = "https://mozilla-mobile.github.io/testapp/v2.0/externalLinks.html"
42 private val loginPage = "https://mozilla-mobile.github.io/testapp/loginForm"
45 val activityTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides()
48 val intentReceiverActivityTestRule = ActivityTestRule(
49 IntentReceiverActivity::class.java,
54 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/249659
57 fun verifyLoginSaveInCustomTabTest() {
58 intentReceiverActivityTestRule.launchActivity(
59 createCustomTabIntent(
60 loginPage.toUri().toString(),
67 fillAndSubmitLoginCredentials("mozilla", "firefox")
71 verifySaveLoginPromptIsDisplayed()
72 clickPageObject(itemWithText("Save"))
75 openAppFromExternalLink(loginPage)
80 }.openLoginsAndPasswordSubMenu {
82 verifySecurityPromptForLogins()
84 verifySavedLoginsSectionUsername("mozilla")
88 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2334762
90 fun copyCustomTabToolbarUrlTest() {
91 val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
93 intentReceiverActivityTestRule.launchActivity(
94 createCustomTabIntent(
95 customTabPage.url.toString(),
101 longCLickAndCopyToolbarUrl()
104 openAppFromExternalLink(customTabPage.url.toString())
114 verifyTypedToolbarText(customTabPage.url.toString())
118 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2334761
121 fun verifyDownloadInACustomTabTest() {
122 val customTabPage = "https://storage.googleapis.com/mobile_test_assets/test_app/downloads.html"
123 val downloadFile = "web_icon.png"
125 intentReceiverActivityTestRule.launchActivity(
126 createCustomTabIntent(
127 customTabPage.toUri().toString(),
137 }.clickDownloadLink(downloadFile) {
138 verifyDownloadPrompt(downloadFile)
140 verifyDownloadCompleteNotificationPopup()
142 mDevice.openNotification()
144 verifySystemNotificationExists("Download completed")
148 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/249644
149 // Verifies the main menu of a custom tab with a custom menu item
152 fun verifyCustomTabMenuItemsTest() {
153 val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
155 intentReceiverActivityTestRule.launchActivity(
156 createCustomTabIntent(
157 customTabPage.url.toString(),
163 verifyCustomTabCloseButton()
165 verifyPoweredByTextIsDisplayed()
166 verifyCustomMenuItem(customMenuItem)
167 verifyDesktopSiteButtonExists()
168 verifyFindInPageButtonExists()
169 verifyOpenInBrowserButtonExists()
170 verifyBackButtonExists()
171 verifyForwardButtonExists()
172 verifyRefreshButtonExists()
176 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/249645
177 // The test opens a link in a custom tab then sends it to the browser
180 fun openCustomTabInFirefoxTest() {
181 val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
183 intentReceiverActivityTestRule.launchActivity(
184 createCustomTabIntent(
185 customTabPage.url.toString(),
190 verifyCustomTabCloseButton()
192 }.clickOpenInBrowserButton {
193 verifyTabCounter("1")
197 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2239548
199 fun shareCustomTabUsingToolbarButtonTest() {
200 val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
202 intentReceiverActivityTestRule.launchActivity(
203 createCustomTabIntent(
204 customTabPage.url.toString(),
210 verifyShareTabLayout()
214 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/249643
216 fun verifyCustomTabViewItemsTest() {
217 val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
219 intentReceiverActivityTestRule.launchActivity(
220 createCustomTabIntent(
221 pageUrl = customTabPage.url.toString(),
222 customActionButtonDescription = customTabActionButton,
227 verifyCustomTabCloseButton()
228 verifyCustomTabsSiteInfoButton()
229 verifyCustomTabToolbarTitle(customTabPage.title)
230 verifyCustomTabUrl(customTabPage.url.toString())
231 verifyCustomTabActionButton(customTabActionButton)
232 verifyCustomTabsShareButton()
233 verifyMainMenuButton()
234 clickCustomTabCloseButton()
237 verifyHomeScreenAppBarItems()
241 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2239544
243 fun verifyPDFViewerInACustomTabTest() {
244 val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 3)
245 val pdfFormResource = TestAssetHelper.getPdfFormAsset(mockWebServer)
247 intentReceiverActivityTestRule.launchActivity(
248 createCustomTabIntent(
249 customTabPage.url.toString(),
254 clickPageObject(itemWithText("PDF form file"))
255 clickPageObject(itemWithResIdAndText("android:id/button2", "CANCEL"))
257 verifyPDFReaderToolbarItems()
258 verifyCustomTabCloseButton()
259 verifyCustomTabsSiteInfoButton()
260 verifyCustomTabToolbarTitle("pdfForm.pdf")
261 verifyCustomTabUrl(pdfFormResource.url.toString())
262 verifyCustomTabsShareButton()
263 verifyMainMenuButton()
264 clickCustomTabCloseButton()
267 verifyHomeScreenAppBarItems()
271 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2239117
273 fun verifyCustomTabETPSheetAndToggleTest() {
274 val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
276 intentReceiverActivityTestRule.launchActivity(
277 createCustomTabIntent(
278 pageUrl = customTabPage.url.toString(),
279 customActionButtonDescription = customTabActionButton,
283 enhancedTrackingProtection {
284 }.openEnhancedTrackingProtectionSheet {
285 verifyEnhancedTrackingProtectionSheetStatus(status = "ON", state = true)
286 }.toggleEnhancedTrackingProtectionFromSheet {
287 verifyEnhancedTrackingProtectionSheetStatus(status = "OFF", state = false)
288 }.closeEnhancedTrackingProtectionSheet {
291 openAppFromExternalLink(customTabPage.url.toString())
296 }.openEnhancedTrackingProtectionSubMenu {
297 switchEnhancedTrackingProtectionToggle()
298 verifyEnhancedTrackingProtectionOptionsEnabled(enabled = false)
305 // Actually exiting to the previously opened custom tab
308 enhancedTrackingProtection {
309 verifyETPSectionIsDisplayedInQuickSettingsSheet(isDisplayed = false)