From 661835a35cc858a26ee688e73ad5a3d1597c3e7b Mon Sep 17 00:00:00 2001 From: Aaron Train Date: Tue, 14 Jul 2020 12:30:17 -0400 Subject: [PATCH] No issue: Add a couple Tabs Tray UI tests --- .../mozilla/fenix/ui/TabbedBrowsingTest.kt | 86 ++++++++++++++++++- .../mozilla/fenix/ui/robots/BrowserRobot.kt | 13 ++- .../fenix/ui/robots/NavigationToolbarRobot.kt | 76 +++++++++++++++- .../mozilla/fenix/ui/robots/TabDrawerRobot.kt | 25 ++++++ 4 files changed, 197 insertions(+), 3 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/TabbedBrowsingTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/TabbedBrowsingTest.kt index 3a5656a67..d7c17e76b 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/TabbedBrowsingTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/TabbedBrowsingTest.kt @@ -32,7 +32,9 @@ import org.mozilla.fenix.ui.robots.notificationShade * - Swipe to close tab (temporarily disabled) * - Undo close tab * - Close private tabs persistent notification - * + * - Empty tab tray state + * - Tab tray details + * - Shortcut context menu navigation */ class TabbedBrowsingTest { @@ -224,4 +226,86 @@ class TabbedBrowsingTest { verifyHomeScreen() } } + + @Test + fun verifyEmptyTabTray() { + homeScreen { }.dismissOnboarding() + + navigationToolbar { + }.openTabTray { + verifyNoTabsOpened() + verifyNewTabButton() + verifyTabTrayOverflowMenu(false) + }.toggleToPrivateTabs { + verifyNoTabsOpened() + verifyNewTabButton() + verifyTabTrayOverflowMenu(false) + } + } + + @Test + fun verifyOpenTabDetails() { + homeScreen { }.dismissOnboarding() + + val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) + + navigationToolbar { + }.enterURLAndEnterToBrowser(defaultWebPage.url) { + // verifyPageContent(defaultWebPage.content) + }.openTabDrawer { + verifyExistingTabList() + verifyNewTabButton() + verifyTabTrayOverflowMenu(true) + verifyExistingOpenTabs(defaultWebPage.title) + verifyCloseTabsButton(defaultWebPage.title) + }.openHomeScreen { + } + } + + @Test + fun verifyContextMenuShortcuts() { + homeScreen { }.dismissOnboarding() + + val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) + + navigationToolbar { + }.enterURLAndEnterToBrowser(defaultWebPage.url) { + // verifyPageContent(defaultWebPage.content) + }.openTabDrawer { + verifyExistingTabList() + verifyNewTabButton() + verifyTabTrayOverflowMenu(true) + verifyExistingOpenTabs(defaultWebPage.title) + verifyCloseTabsButton(defaultWebPage.title) + }.closeTabDrawer { + }.openTabButtonShortcutsMenu { + verifyTabButtonShortcutMenuItems() + }.closeTabFromShortcutsMenu { + }.enterURLAndEnterToBrowser(defaultWebPage.url) { + }.openTabButtonShortcutsMenu { + }.openNewPrivateTabFromShortcutsMenu { + verifyHomeScreen() + verifyNavigationToolbar() + verifyHomePrivateBrowsingButton() + verifyHomeMenu() + verifyHomeWordmark() + verifyTabButton() + verifyPrivateSessionMessage() + verifyHomeToolbar() + verifyHomeComponent() + } + navigationToolbar { + }.enterURLAndEnterToBrowser(defaultWebPage.url) { + + }.openTabButtonShortcutsMenu { + }.openTabFromShortcutsMenu { + verifyHomeScreen() + verifyNavigationToolbar() + verifyHomeMenu() + verifyHomeWordmark() + verifyTabButton() + verifyHomeToolbar() + verifyHomeComponent() + } + } } diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt index 02d1d4e67..63e102efb 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt @@ -18,8 +18,8 @@ import androidx.test.espresso.intent.matcher.BundleMatchers import androidx.test.espresso.intent.matcher.IntentMatchers import androidx.test.espresso.matcher.RootMatchers.isDialog import androidx.test.espresso.matcher.ViewMatchers -import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed import androidx.test.espresso.matcher.ViewMatchers.Visibility +import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility import androidx.test.espresso.matcher.ViewMatchers.withId @@ -392,6 +392,17 @@ class BrowserRobot { return TabDrawerRobot.Transition() } + fun openTabButtonShortcutsMenu(interact: NavigationToolbarRobot.() -> Unit): NavigationToolbarRobot.Transition { + mDevice.waitForIdle(waitingTime) + + tabsCounter().perform( + ViewActions.longClick() + ) + + NavigationToolbarRobot().interact() + return NavigationToolbarRobot.Transition() + } + fun openNotificationShade(interact: NotificationRobot.() -> Unit): NotificationRobot.Transition { mDevice.openNotification() diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NavigationToolbarRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NavigationToolbarRobot.kt index 057cc6cf2..556007c8f 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NavigationToolbarRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NavigationToolbarRobot.kt @@ -7,13 +7,16 @@ package org.mozilla.fenix.ui.robots import android.net.Uri +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.action.ViewActions import androidx.test.espresso.action.ViewActions.pressImeActionButton import androidx.test.espresso.action.ViewActions.replaceText 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.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers.hasDescendant import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility @@ -47,6 +50,8 @@ class NavigationToolbarRobot { fun verifyNoHistoryBookmarks() = assertNoHistoryBookmarks() + fun verifyTabButtonShortcutMenuItems() = assertTabButtonShortcutMenuItems() + class Transition { private lateinit var sessionLoadedIdlingResource: SessionLoadedIdlingResource @@ -113,12 +118,25 @@ class NavigationToolbarRobot { return ThreeDotMenuMainRobot.Transition() } + fun openTabTray(interact: TabDrawerRobot.() -> Unit): TabDrawerRobot.Transition { + onView(withId(R.id.tab_button)) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) + + tabTrayButton().click() + + TabDrawerRobot().interact() + return TabDrawerRobot.Transition() + } + fun openNewTabAndEnterToBrowser( url: Uri, interact: BrowserRobot.() -> Unit ): BrowserRobot.Transition { sessionLoadedIdlingResource = SessionLoadedIdlingResource() - mDevice.waitNotNull(Until.findObject(By.res("org.mozilla.fenix.debug:id/toolbar")), waitingTime) + mDevice.waitNotNull( + Until.findObject(By.res("org.mozilla.fenix.debug:id/toolbar")), + waitingTime + ) urlBar().click() awesomeBar().perform(replaceText(url.toString()), pressImeActionButton()) @@ -165,6 +183,54 @@ class NavigationToolbarRobot { HomeScreenRobot().interact() return HomeScreenRobot.Transition() } + + fun closeTabFromShortcutsMenu(interact: NavigationToolbarRobot.() -> Unit): NavigationToolbarRobot.Transition { + mDevice.waitForIdle(waitingTime) + + onView(withId(R.id.mozac_browser_menu_recyclerView)) + .perform( + RecyclerViewActions.actionOnItem( + hasDescendant( + withText("Close tab") + ), ViewActions.click() + ) + ) + + NavigationToolbarRobot().interact() + return NavigationToolbarRobot.Transition() + } + + fun openTabFromShortcutsMenu(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition { + mDevice.waitForIdle(waitingTime) + + onView(withId(R.id.mozac_browser_menu_recyclerView)) + .perform( + RecyclerViewActions.actionOnItem( + hasDescendant( + withText("New tab") + ), ViewActions.click() + ) + ) + + HomeScreenRobot().interact() + return HomeScreenRobot.Transition() + } + + fun openNewPrivateTabFromShortcutsMenu(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition { + mDevice.waitForIdle(waitingTime) + + onView(withId(R.id.mozac_browser_menu_recyclerView)) + .perform( + RecyclerViewActions.actionOnItem( + hasDescendant( + withText("New private tab") + ), ViewActions.click() + ) + ) + + HomeScreenRobot().interact() + return HomeScreenRobot.Transition() + } } } @@ -196,10 +262,18 @@ private fun assertNoHistoryBookmarks() { .check(matches(not(hasDescendant(withText("Test_Page_3"))))) } +private fun assertTabButtonShortcutMenuItems() { + onView(withId(R.id.mozac_browser_menu_recyclerView)) + .check(matches(hasDescendant(withText("Close tab")))) + .check(matches(hasDescendant(withText("New private tab")))) + .check(matches(hasDescendant(withText("New tab")))) +} + private fun dismissOnboardingButton() = onView(withId(R.id.close_onboarding)) private fun urlBar() = onView(withId(R.id.toolbar)) private fun awesomeBar() = onView(withId(R.id.mozac_browser_toolbar_edit_url_view)) private fun threeDotButton() = onView(withId(R.id.mozac_browser_toolbar_menu)) +private fun tabTrayButton() = onView(withId(R.id.tab_button)) private fun fillLinkButton() = onView(withId(R.id.fill_link_from_clipboard)) private fun clearAddressBar() = onView(withId(R.id.mozac_browser_toolbar_clear_view)) private fun goBackButton() = mDevice.pressBack() diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/TabDrawerRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/TabDrawerRobot.kt index 5ac8bf2d4..638674192 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/TabDrawerRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/TabDrawerRobot.kt @@ -47,6 +47,8 @@ class TabDrawerRobot { fun verifyNoTabsOpened() = assertNoTabsOpenedText() fun verifyPrivateModeSelected() = assertPrivateModeSelected() fun verifyNormalModeSelected() = assertNormalModeSelected() + fun verifyNewTabButton() = assertNewTabButton() + fun verifyTabTrayOverflowMenu(visibility: Boolean) = assertTabTrayOverflowButton(visibility) fun closeTab() { closeTabButton().click() @@ -119,6 +121,18 @@ class TabDrawerRobot { return TabDrawerRobot.Transition() } + fun closeTabDrawer(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition { + mDevice.waitForIdle(waitingTime) + + // Dismisses the tab tray bottom sheet with 2 handle clicks + onView(withId(R.id.handle)).perform( + click(), + click() + ) + BrowserRobot().interact() + return BrowserRobot.Transition() + } + fun openHomeScreen(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition { mDevice.waitForIdle() @@ -196,6 +210,10 @@ private fun assertNoTabsOpenedText() = onView(withId(R.id.tab_tray_empty_view)) .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) +private fun assertNewTabButton() = + onView(withId(R.id.new_tab_button)) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) + private fun assertNormalModeSelected() = normalBrowsingButton() .check(matches(ViewMatchers.isSelected())) @@ -204,6 +222,10 @@ private fun assertPrivateModeSelected() = privateBrowsingButton() .check(matches(ViewMatchers.isSelected())) +private fun assertTabTrayOverflowButton(visible: Boolean) = + onView(withId(R.id.tab_tray_overflow)) + .check(matches(withEffectiveVisibility(visibleOrGone(visible)))) + private fun tab(title: String) = onView( allOf( @@ -213,3 +235,6 @@ private fun tab(title: String) = ) private fun tabsCounter() = onView(withId(R.id.tab_button)) + +private fun visibleOrGone(visibility: Boolean) = + if (visibility) ViewMatchers.Visibility.VISIBLE else ViewMatchers.Visibility.GONE