forked from mozilla-mobile/focus-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomTabTest.kt
149 lines (133 loc) · 4.93 KB
/
CustomTabTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* 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/. */
@file:Suppress("DEPRECATION")
package org.mozilla.focus.activity
import androidx.lifecycle.Lifecycle
import androidx.test.core.app.launchActivity
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import androidx.test.rule.ActivityTestRule
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.focus.activity.robots.browserScreen
import org.mozilla.focus.activity.robots.customTab
import org.mozilla.focus.activity.robots.homeScreen
import org.mozilla.focus.activity.robots.searchScreen
import org.mozilla.focus.helpers.FeatureSettingsHelper
import org.mozilla.focus.helpers.MockWebServerHelper
import org.mozilla.focus.helpers.TestAssetHelper.getGenericAsset
import org.mozilla.focus.helpers.TestAssetHelper.getGenericTabAsset
import org.mozilla.focus.helpers.TestHelper.createCustomTabIntent
import org.mozilla.focus.helpers.TestHelper.mDevice
import org.mozilla.focus.helpers.TestHelper.waitingTime
import org.mozilla.focus.testAnnotations.SmokeTest
import java.io.IOException
@RunWith(AndroidJUnit4ClassRunner::class)
class CustomTabTest {
private lateinit var webServer: MockWebServer
private val MENU_ITEM_LABEL = "TestItem4223"
private val ACTION_BUTTON_DESCRIPTION = "TestButton"
private val featureSettingsHelper = FeatureSettingsHelper()
@get: Rule
val activityTestRule = ActivityTestRule(
IntentReceiverActivity::class.java,
true,
false,
)
@Before
fun setUp() {
featureSettingsHelper.setCfrForTrackingProtectionEnabled(false)
featureSettingsHelper.setShowStartBrowsingCfrEnabled(false)
webServer = MockWebServer().apply {
dispatcher = MockWebServerHelper.AndroidAssetDispatcher()
start()
}
}
@After
fun tearDown() {
try {
webServer.shutdown()
} catch (e: IOException) {
throw AssertionError("Could not stop web server", e)
}
featureSettingsHelper.resetAllFeatureFlags()
}
@SmokeTest
@Test
fun testCustomTabUI() {
val customTabPage = getGenericAsset(webServer)
val customTabActivity =
launchActivity<IntentReceiverActivity>(
createCustomTabIntent(customTabPage.url, MENU_ITEM_LABEL, ACTION_BUTTON_DESCRIPTION),
)
browserScreen {
progressBar.waitUntilGone(waitingTime)
verifyPageContent(customTabPage.content)
verifyPageURL(customTabPage.url)
}
customTab {
verifyCustomTabActionButton(ACTION_BUTTON_DESCRIPTION)
verifyShareButtonIsDisplayed()
openCustomTabMenu()
verifyTheStandardMenuItems()
verifyCustomMenuItem(MENU_ITEM_LABEL)
// Close the menu and close the tab
mDevice.pressBack()
closeCustomTab()
assertEquals(Lifecycle.State.DESTROYED, customTabActivity.state)
}
}
@SmokeTest
@Test
fun openCustomTabInFocusTest() {
val browserPage = getGenericAsset(webServer)
val customTabPage = getGenericTabAsset(webServer, 1)
launchActivity<IntentReceiverActivity>()
homeScreen {
// The new onboarding moved to experiments, remove comment when implemented again in Focus
// clickStartBrowsing()
closeOnboarding()
}
searchScreen {
}.loadPage(browserPage.url) {
verifyPageURL(browserPage.url)
}
launchActivity<IntentReceiverActivity>(createCustomTabIntent(customTabPage.url))
customTab {
progressBar.waitUntilGone(waitingTime)
verifyPageURL(customTabPage.url)
openCustomTabMenu()
}.clickOpenInFocusButton {
verifyPageURL(customTabPage.url)
mDevice.pressBack()
verifyPageURL(browserPage.url)
}
}
@SmokeTest
@Test
fun customTabNavigationButtonsTest() {
val firstPage = getGenericTabAsset(webServer, 1)
val secondPage = getGenericTabAsset(webServer, 2)
launchActivity<IntentReceiverActivity>(createCustomTabIntent(firstPage.url))
customTab {
verifyPageContent(firstPage.content)
clickLinkMatchingText("Tab 2")
verifyPageURL(secondPage.url)
}.openCustomTabMenu {
}.pressBack {
progressBar.waitUntilGone(waitingTime)
verifyPageURL(firstPage.url)
}.openMainMenu {
}.pressForward {
verifyPageURL(secondPage.url)
}.openMainMenu {
}.clickReloadButton {
verifyPageContent(secondPage.content)
}
}
}