summaryrefslogtreecommitdiffstats
path: root/mobile/android/android-components/samples/browser/src/androidTest
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:50 +0000
commitdef92d1b8e9d373e2f6f27c366d578d97d8960c6 (patch)
tree2ef34b9ad8bb9a9220e05d60352558b15f513894 /mobile/android/android-components/samples/browser/src/androidTest
parentAdding debian version 125.0.3-1. (diff)
downloadfirefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.tar.xz
firefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mobile/android/android-components/samples/browser/src/androidTest')
-rw-r--r--mobile/android/android-components/samples/browser/src/androidTest/assets/index.html5
-rw-r--r--mobile/android/android-components/samples/browser/src/androidTest/java/org/mozilla/samples/browser/SmokeTests.kt139
2 files changed, 144 insertions, 0 deletions
diff --git a/mobile/android/android-components/samples/browser/src/androidTest/assets/index.html b/mobile/android/android-components/samples/browser/src/androidTest/assets/index.html
new file mode 100644
index 0000000000..9f5632c044
--- /dev/null
+++ b/mobile/android/android-components/samples/browser/src/androidTest/assets/index.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+<h1 id="website_title">Hello World!</h1>
+</body>
+</html>
diff --git a/mobile/android/android-components/samples/browser/src/androidTest/java/org/mozilla/samples/browser/SmokeTests.kt b/mobile/android/android-components/samples/browser/src/androidTest/java/org/mozilla/samples/browser/SmokeTests.kt
new file mode 100644
index 0000000000..9c3b3e2247
--- /dev/null
+++ b/mobile/android/android-components/samples/browser/src/androidTest/java/org/mozilla/samples/browser/SmokeTests.kt
@@ -0,0 +1,139 @@
+/* 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/. */
+
+package org.mozilla.samples.browser
+
+import android.os.SystemClock
+import androidx.test.espresso.Espresso.onView
+import androidx.test.espresso.action.ViewActions.click
+import androidx.test.espresso.action.ViewActions.pressImeActionButton
+import androidx.test.espresso.action.ViewActions.replaceText
+import androidx.test.espresso.assertion.ViewAssertions.matches
+import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
+import androidx.test.espresso.matcher.ViewMatchers.withId
+import androidx.test.espresso.matcher.ViewMatchers.withText
+import androidx.test.ext.junit.rules.ActivityScenarioRule
+import androidx.test.filters.LargeTest
+import androidx.test.platform.app.InstrumentationRegistry
+import androidx.test.uiautomator.UiDevice
+import androidx.test.uiautomator.UiSelector
+import mozilla.components.support.android.test.rules.WebserverRule
+import org.junit.Assert.assertTrue
+import org.junit.Ignore
+import org.junit.Rule
+import org.junit.Test
+import java.util.concurrent.TimeUnit
+
+private const val INITIAL_WAIT_SECONDS = 5L
+private const val WAIT_FOR_WEB_CONTENT_SECONDS = 15L
+
+/**
+ * A collection of "smoke tests" to verify that the basic browsing functionality is working.
+ */
+
+@LargeTest
+class SmokeTests {
+ @get:Rule
+ val activityRule: ActivityScenarioRule<BrowserActivity> = ActivityScenarioRule(BrowserActivity::class.java)
+
+ @get:Rule
+ val webserverRule: WebserverRule = WebserverRule()
+
+ /**
+ * This test loads a website from a local webserver by typing into the URL bar. After that it verifies that the
+ * web content is visible.
+ */
+
+ @Test
+ fun loadWebsiteTest() {
+ // Disable on API21 - https://github.com/mozilla-mobile/android-components/issues/6482
+ if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.LOLLIPOP) {
+ waitForIdle()
+
+ enterUrl(webserverRule.url())
+
+ verifyWebsiteContent("Hello World!")
+ verifyUrlInToolbar(webserverRule.url())
+ }
+ }
+
+ @Ignore("Intermittent: https://bugzilla.mozilla.org/show_bug.cgi?id=1794873")
+ @Test
+ fun loadWebsitesInMultipleTabsTest() {
+ // Disable on API21 - https://github.com/mozilla-mobile/android-components/issues/6482
+ if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.LOLLIPOP) {
+ waitForIdle()
+
+ enterUrl(webserverRule.url())
+
+ verifyWebsiteContent("Hello World!")
+ verifyUrlInToolbar(webserverRule.url())
+
+ navigateToTabsTray()
+ openNewTabInTabsTray()
+
+ enterUrl(webserverRule.url())
+
+ verifyWebsiteContent("Hello World!")
+ verifyUrlInToolbar(webserverRule.url())
+
+ navigateToTabsTray()
+ openNewTabInTabsTray()
+
+ enterUrl(webserverRule.url())
+
+ verifyWebsiteContent("Hello World!")
+ verifyUrlInToolbar(webserverRule.url())
+
+ navigateToTabsTray()
+ openNewTabInTabsTray()
+ }
+ }
+}
+
+private fun waitForIdle() {
+ // Meh! We need a better idle strategy here. Because of bug 1441059 our load request gets lost if it happens
+ // to fast and then only "about:blank" gets loaded. So a "quick" fix here is to just wait a bit.
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1441059
+ SystemClock.sleep(TimeUnit.SECONDS.toMillis(INITIAL_WAIT_SECONDS))
+}
+
+private fun navigateToTabsTray() {
+ onView(withContentDescription(mozilla.components.feature.tabs.R.string.mozac_feature_tabs_toolbar_tabs_button))
+ .perform(click())
+}
+
+private fun openNewTabInTabsTray() {
+ onView(withId(R.id.newTab))
+ .perform(click())
+}
+
+private fun enterUrl(url: String) {
+ onView(withId(mozilla.components.browser.toolbar.R.id.mozac_browser_toolbar_url_view))
+ .perform(click())
+
+ onView(withId(mozilla.components.browser.toolbar.R.id.mozac_browser_toolbar_edit_url_view))
+ .perform(replaceText(url), pressImeActionButton())
+}
+
+private fun verifyUrlInToolbar(url: String) {
+ onView(withId(mozilla.components.browser.toolbar.R.id.mozac_browser_toolbar_url_view))
+ .check(matches(withText(url)))
+}
+
+private fun verifyWebsiteContent(text: String) {
+ val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
+ device.waitForIdle()
+
+ val waitingTime: Long = TimeUnit.SECONDS.toMillis(WAIT_FOR_WEB_CONTENT_SECONDS)
+
+ assertTrue(
+ device
+ .findObject(
+ UiSelector()
+ .textContains(text),
+ )
+ .waitForExists(waitingTime),
+ )
+}