2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/14005: fix strict TP tests loading timeout

This commit is contained in:
Oana Horvath 2021-03-15 14:58:18 +02:00
parent d296d0c9c2
commit 8f9a3dc767
4 changed files with 78 additions and 33 deletions

View File

@ -406,7 +406,7 @@ class SmokeTest {
}.goBackToHomeScreen {}
navigationToolbar {
}.enterURLAndEnterToBrowser(trackingPage.url) {}
}.openTrackingProtectionTestPage(trackingPage.url, true) {}
enhancedTrackingProtection {
dismissTrackingOnboarding()
@ -630,7 +630,7 @@ class SmokeTest {
IdlingRegistry.getInstance().unregister(addonsListIdlingResource!!)
}.goBack {
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(trackingProtectionPage.url) {}
}.openTrackingProtectionTestPage(trackingProtectionPage.url, true) {}
enhancedTrackingProtection {
verifyEnhancedTrackingProtectionNotice()
}.closeNotificationPopup {}

View File

@ -83,7 +83,7 @@ class StrictEnhancedTrackingProtectionTest {
TestAssetHelper.getEnhancedTrackingProtectionAsset(mockWebServer)
navigationToolbar {
}.enterURLAndEnterToBrowser(trackingProtectionTest.url) {}
}.openTrackingProtectionTestPage(trackingProtectionTest.url, true) {}
enhancedTrackingProtection {
verifyEnhancedTrackingProtectionNotice()
@ -96,7 +96,7 @@ class StrictEnhancedTrackingProtectionTest {
TestAssetHelper.getEnhancedTrackingProtectionAsset(mockWebServer)
navigationToolbar {
}.enterURLAndEnterToBrowser(trackingProtectionTest.url) {}
}.openTrackingProtectionTestPage(trackingProtectionTest.url, true) {}
enhancedTrackingProtection {
verifyEnhancedTrackingProtectionNotice()
@ -113,7 +113,7 @@ class StrictEnhancedTrackingProtectionTest {
TestAssetHelper.getEnhancedTrackingProtectionAsset(mockWebServer)
navigationToolbar {
}.enterURLAndEnterToBrowser(trackingProtectionTest.url) {}
}.openTrackingProtectionTestPage(trackingProtectionTest.url, true) {}
enhancedTrackingProtection {
verifyEnhancedTrackingProtectionNotice()
@ -133,7 +133,7 @@ class StrictEnhancedTrackingProtectionTest {
TestAssetHelper.getEnhancedTrackingProtectionAsset(mockWebServer)
navigationToolbar {
}.enterURLAndEnterToBrowser(trackingProtectionTest.url) {}
}.openTrackingProtectionTestPage(trackingProtectionTest.url, true) {}
enhancedTrackingProtection {
verifyEnhancedTrackingProtectionNotice()
@ -164,7 +164,7 @@ class StrictEnhancedTrackingProtectionTest {
TestAssetHelper.getEnhancedTrackingProtectionAsset(mockWebServer)
navigationToolbar {
}.enterURLAndEnterToBrowser(trackingProtectionTest.url) {}
}.openTrackingProtectionTestPage(trackingProtectionTest.url, true) {}
enhancedTrackingProtection {
verifyEnhancedTrackingProtectionNotice()
@ -196,7 +196,7 @@ class StrictEnhancedTrackingProtectionTest {
TestAssetHelper.getEnhancedTrackingProtectionAsset(mockWebServer)
navigationToolbar {
}.enterURLAndEnterToBrowser(trackingProtectionTest.url) {}
}.openTrackingProtectionTestPage(trackingProtectionTest.url, true) {}
enhancedTrackingProtection {
verifyEnhancedTrackingProtectionNotice()

View File

@ -11,6 +11,7 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.IdlingResource
import androidx.test.espresso.IdlingResourceTimeoutException
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.pressImeActionButton
import androidx.test.espresso.action.ViewActions.replaceText
@ -20,6 +21,7 @@ import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
@ -81,15 +83,7 @@ class NavigationToolbarRobot {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
fun goBackToWebsite(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
mDevice.waitNotNull(
Until.findObject(By.res("$packageName:id/toolbar")),
waitingTime
)
urlBar().click()
mDevice.waitNotNull(
Until.findObject(By.res("$packageName:id/mozac_browser_toolbar_edit_url_view")),
waitingTime
)
openEditURLView()
clearAddressBar().click()
awesomeBar().check((matches(withText(containsString("")))))
goBackButton()
@ -104,14 +98,7 @@ class NavigationToolbarRobot {
): BrowserRobot.Transition {
sessionLoadedIdlingResource = SessionLoadedIdlingResource()
mDevice.waitNotNull(Until.findObject(By.res("$packageName:id/toolbar")),
waitingTime
)
urlBar().click()
mDevice.waitNotNull(
Until.findObject(By.res("$packageName:id/mozac_browser_toolbar_edit_url_view")),
waitingTime
)
openEditURLView()
awesomeBar().perform(replaceText(url.toString()), pressImeActionButton())
@ -130,19 +117,55 @@ class NavigationToolbarRobot {
return BrowserRobot.Transition()
}
fun openTrackingProtectionTestPage(url: Uri, etpEnabled: Boolean, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
sessionLoadedIdlingResource = SessionLoadedIdlingResource()
openEditURLView()
awesomeBar().perform(replaceText(url.toString()), pressImeActionButton())
runWithIdleRes(sessionLoadedIdlingResource) {
when (etpEnabled) {
true ->
try {
onView(withId(R.id.onboarding_message))
.check(matches(isDisplayed()))
} catch (e: IdlingResourceTimeoutException) {
openThreeDotMenu {
}.stopPageLoad {
val onboardingDisplayed =
mDevice.findObject(UiSelector().resourceId("$packageName:id/onboarding_message"))
.waitForExists(waitingTime)
if (!onboardingDisplayed) {
openThreeDotMenu {
}.refreshPage {}
}
}
}
false ->
try {
onView(withResourceName("browserLayout")).check(matches(isDisplayed()))
} catch (e: IdlingResourceTimeoutException) {
openThreeDotMenu {
}.stopPageLoad {
}.openThreeDotMenu {
}.refreshPage {}
}
}
}
BrowserRobot().interact()
return BrowserRobot.Transition()
}
fun openTabCrashReporter(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
val crashUrl = "about:crashcontent"
sessionLoadedIdlingResource = SessionLoadedIdlingResource()
mDevice.waitNotNull(Until.findObject(By.res("$packageName:id/toolbar")),
waitingTime
)
urlBar().click()
mDevice.waitNotNull(
Until.findObject(By.res("$packageName:id/mozac_browser_toolbar_edit_url_view")),
waitingTime
)
openEditURLView()
awesomeBar().perform(replaceText(crashUrl), pressImeActionButton())
@ -285,6 +308,18 @@ fun clickUrlbar(interact: SearchRobot.() -> Unit): SearchRobot.Transition {
return SearchRobot.Transition()
}
fun openEditURLView() {
mDevice.waitNotNull(
Until.findObject(By.res("$packageName:id/toolbar")),
waitingTime
)
urlBar().click()
mDevice.waitNotNull(
Until.findObject(By.res("$packageName:id/mozac_browser_toolbar_edit_url_view")),
waitingTime
)
}
private fun assertSuggestionsAreEqualTo(suggestionSize: Int) {
mDevice.waitForIdle()
onView(withId(R.id.awesome_bar)).check(suggestionsAreEqualTo(suggestionSize))

View File

@ -280,6 +280,14 @@ class ThreeDotMenuMainRobot {
return BrowserRobot.Transition()
}
fun stopPageLoad(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
mDevice.waitNotNull(Until.findObject(By.desc("Stop")), waitingTime)
stopLoadingButton().click()
BrowserRobot().interact()
return BrowserRobot.Transition()
}
fun closeAllTabs(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition {
closeAllTabsButton().click()
@ -444,6 +452,8 @@ private fun refreshButton() = onView(ViewMatchers.withContentDescription("Refres
private fun assertRefreshButton() = refreshButton()
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun stopLoadingButton() = onView(ViewMatchers.withContentDescription("Stop"))
private fun closeAllTabsButton() = onView(allOf(withText("Close all tabs"))).inRoot(RootMatchers.isPlatformPopup())
private fun assertCloseAllTabsButton() = closeAllTabsButton()
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))