diff --git a/app/src/androidTest/java/org/mozilla/tv/firefox/ui/TooltipTest.kt b/app/src/androidTest/java/org/mozilla/tv/firefox/ui/TooltipTest.kt new file mode 100644 index 0000000000..a8d1924b30 --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/tv/firefox/ui/TooltipTest.kt @@ -0,0 +1,83 @@ +/* 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.tv.firefox.ui + +import org.junit.Rule +import org.junit.Test +import org.mozilla.tv.firefox.helpers.MainActivityTestRule +import org.mozilla.tv.firefox.ui.robots.navigationOverlay + +private const val TURBO_MODE_TEXT = "Turbo Mode" +private const val BACK_TEXT = "Navigate back" +private const val FORWARD_TEXT = "Navigate forward" +private const val RELOAD_TEXT = "Reload website" +private const val PIN_TEXT = "Pin to homescreen" +private const val DESKTOP_MODE_TEXT = "Request desktop version of this site" +private const val EXIT_TEXT = "Exit Firefox" +private const val SETTINGS_TEXT = "Settings" + +/** + * A test for the nav bar tooltips including: + * - Each tooltip shows the correct string + * - The string dynamically updates the ON/OFF state (only applicable to Turbo Mode) + */ +class TooltipTest { + + @get:Rule val activityTestRule = MainActivityTestRule() + + /* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping. + @Test + fun tooltipTest() { + navigationOverlay { + // Url bar is focused on startup and next focus up will be turbo mode button + remoteUp() + assertTooltipText(TURBO_MODE_TEXT) + remoteCenter() + assertTooltipText(TURBO_MODE_TEXT) + }.openTileToBrowser(1) { + }.openOverlay { + }.openTileToBrowser(2) { + }.openOverlay { + // Focus back button + remoteUp() + assertTooltipText(BACK_TEXT) + }.goBack { + }.openOverlay { + // Focus forward button + remoteUp() + assertTooltipText(FORWARD_TEXT) + // Focus reload button + remoteRight() + assertTooltipText(RELOAD_TEXT) + // Focus pin button + remoteRight() + assertTooltipText(PIN_TEXT) + }.unpinSite { + }.openOverlay { + // This sequence focuses the pin button from the url bar + remoteUp() + remoteRight(2) + assertTooltipText(PIN_TEXT) + // Focus turbo mode button + remoteRight() + assertTooltipText(TURBO_MODE_TEXT) + // Focus desktop mode button + remoteRight() + assertTooltipText(DESKTOP_MODE_TEXT) + }.turnDesktopModeOn { + }.openOverlay { + // This sequence focuses the desktop mode button from the url bar + remoteUp() + remoteRight(4) + assertTooltipText(DESKTOP_MODE_TEXT) + // Focus exit button + remoteRight() + assertTooltipText(EXIT_TEXT) + // Focus settings button + remoteRight() + assertTooltipText(SETTINGS_TEXT) + } + } +} diff --git a/app/src/androidTest/java/org/mozilla/tv/firefox/ui/robots/NavigationOverlayRobot.kt b/app/src/androidTest/java/org/mozilla/tv/firefox/ui/robots/NavigationOverlayRobot.kt index aa26c8d32d..90264946bf 100644 --- a/app/src/androidTest/java/org/mozilla/tv/firefox/ui/robots/NavigationOverlayRobot.kt +++ b/app/src/androidTest/java/org/mozilla/tv/firefox/ui/robots/NavigationOverlayRobot.kt @@ -12,6 +12,7 @@ import androidx.test.espresso.action.ViewActions.pressImeActionButton import androidx.test.espresso.action.ViewActions.typeText import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.contrib.RecyclerViewActions +import androidx.test.espresso.matcher.RootMatchers.isPlatformPopup import androidx.test.espresso.matcher.ViewMatchers.hasDescendant import androidx.test.espresso.matcher.ViewMatchers.withHint import androidx.test.espresso.matcher.ViewMatchers.withId @@ -39,11 +40,15 @@ class NavigationOverlayRobot { private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) fun goBack() = backButton().click() - fun remoteBack() = device.pressBack() fun goForward() = forwardButton().click() fun reload() = reloadButton().click() fun toggleTurbo() = turboButton().click() + fun remoteBack() = device.pressBack() + fun remoteUp() = device.pressDPadUp() + fun remoteRight(x: Int = 1) = repeat(x) { device.pressDPadRight() } + fun remoteCenter() = device.pressDPadCenter() + // The implementation of this method is arbitrary. We could run this check // against any of its views fun assertOverlayIsOpen() = urlBar().assertIsDisplayed(true) @@ -97,6 +102,8 @@ class NavigationOverlayRobot { fun disableSessionIdling(activityTestRule: MainActivityTestRule) { activityTestRule.loadingIdlingResource.ignoreLoading = true } fun enableSessionIdling(activityTestRule: MainActivityTestRule) { activityTestRule.loadingIdlingResource.ignoreLoading = false } + fun assertTooltipText(text: String) = tooltip().check(matches(withText(text))) + class Transition { private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) @@ -254,3 +261,4 @@ private fun homeTiles() = onView(withId(R.id.tileContainer)) private fun overlay() = onView(withId(R.layout.fragment_navigation_overlay)) private fun desktopModeButton() = onView(withId(R.id.desktopModeButton)) private fun pocketMegaTile() = onView(withId(R.id.pocketVideosContainer)) +private fun tooltip() = onView(withId(R.id.tooltip)).inRoot(isPlatformPopup())