Skip to content

Commit

Permalink
No issue: Add a couple Tabs Tray UI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronMT authored and Oana Horvath committed Jul 15, 2020
1 parent 9ed8551 commit 661835a
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,6 +50,8 @@ class NavigationToolbarRobot {

fun verifyNoHistoryBookmarks() = assertNoHistoryBookmarks()

fun verifyTabButtonShortcutMenuItems() = assertTabButtonShortcutMenuItems()

class Transition {

private lateinit var sessionLoadedIdlingResource: SessionLoadedIdlingResource
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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<RecyclerView.ViewHolder>(
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<RecyclerView.ViewHolder>(
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<RecyclerView.ViewHolder>(
hasDescendant(
withText("New private tab")
), ViewActions.click()
)
)

HomeScreenRobot().interact()
return HomeScreenRobot.Transition()
}
}
}

Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()))
Expand All @@ -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(
Expand All @@ -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

0 comments on commit 661835a

Please sign in to comment.