From 59c94e447c47a71f7378e7e7103e16bf7f697c33 Mon Sep 17 00:00:00 2001 From: Elise Richards Date: Tue, 20 Apr 2021 12:18:19 -0500 Subject: [PATCH] For #19005: new tab three-dot menu sync sign in (#19037) * Show synced tabs or sync account in new tab menu * Sync sign in item navigates to account settings * Check account auth and get sync item title * Look for sync sign in item on home menu for UI test * Sync sign in menu item UI test --- .../java/org/mozilla/fenix/ui/SmokeTest.kt | 19 ++++++-- .../mozilla/fenix/ui/ThreeDotMenuMainTest.kt | 7 ++- .../fenix/ui/robots/SyncSignInRobot.kt | 46 +++++++++++++++++++ .../fenix/ui/robots/ThreeDotMenuMainRobot.kt | 10 ++++ .../org/mozilla/fenix/home/HomeFragment.kt | 7 +++ .../java/org/mozilla/fenix/home/HomeMenu.kt | 41 ++++++++++------- 6 files changed, 108 insertions(+), 22 deletions(-) create mode 100644 app/src/androidTest/java/org/mozilla/fenix/ui/robots/SyncSignInRobot.kt diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt index bdb2e31bb..cf63c7806 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt @@ -17,6 +17,7 @@ import org.junit.Before import org.junit.Ignore import org.junit.Rule import org.junit.Test +import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.R import org.mozilla.fenix.ext.settings import org.mozilla.fenix.helpers.AndroidAssetDispatcher @@ -227,11 +228,19 @@ class SmokeTest { @Test // Verifies the Synced tabs menu opens from a tab's 3 dot menu - fun openMainMenuSyncedTabsItemTest() { - homeScreen { - }.openThreeDotMenu { - }.openSyncedTabs { - verifySyncedTabsMenuHeader() + fun openMainMenuSyncItemTest() { + if (FeatureFlags.tabsTrayRewrite) { + homeScreen { + }.openThreeDotMenu { + }.openSyncSignIn { + verifyAccountSettingsMenuHeader() + } + } else { + homeScreen { + }.openThreeDotMenu { + }.openSyncedTabs { + verifySyncedTabsMenuHeader() + } } } diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/ThreeDotMenuMainTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/ThreeDotMenuMainTest.kt index f4814f2ee..69b2f294a 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/ThreeDotMenuMainTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/ThreeDotMenuMainTest.kt @@ -9,6 +9,7 @@ import org.junit.After import org.junit.Before import org.junit.Rule import org.junit.Test +import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.helpers.AndroidAssetDispatcher import org.mozilla.fenix.helpers.HomeActivityTestRule import org.mozilla.fenix.ui.robots.homeScreen @@ -48,7 +49,11 @@ class ThreeDotMenuMainTest { verifyHistoryButton() verifyDownloadsButton() verifyAddOnsButton() - verifySyncedTabsButton() + if (FeatureFlags.tabsTrayRewrite) { + verifySyncSignInButton() + } else { + verifySyncedTabsButton() + } verifyDesktopSite() verifyWhatsNewButton() verifyHelpButton() diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SyncSignInRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SyncSignInRobot.kt new file mode 100644 index 000000000..e355174a5 --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SyncSignInRobot.kt @@ -0,0 +1,46 @@ +/* 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.fenix.ui.robots + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.withContentDescription +import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.espresso.matcher.ViewMatchers.Visibility +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.uiautomator.UiDevice +import org.hamcrest.CoreMatchers.allOf +import org.mozilla.fenix.R +import org.mozilla.fenix.helpers.click + +/** + * Implementation of Robot Pattern for Sync Sign In sub menu. + */ +class SyncSignInRobot { + + fun verifyAccountSettingsMenuHeader() = assertAccountSettingsMenuHeader() + + class Transition { + val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())!! + + fun goBack(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition { + goBackButton().click() + + BrowserRobot().interact() + return BrowserRobot.Transition() + } + } +} + +private fun goBackButton() = + onView(allOf(withContentDescription("Navigate up"))) + +private fun assertAccountSettingsMenuHeader() { + // Replaced with the new string here, the test is assuming we are NOT signed in + // Sync tests in SettingsSyncTest are still TO-DO, so I'm not sure that we have a test for signing into Sync + onView(withText(R.string.preferences_account_settings)) + .check((matches(withEffectiveVisibility(Visibility.VISIBLE)))) +} diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt index fcfaac7e4..28e212658 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt @@ -51,6 +51,7 @@ class ThreeDotMenuMainRobot { fun verifyHistoryButton() = assertHistoryButton() fun verifyBookmarksButton() = assertBookmarksButton() fun verifySyncedTabsButton() = assertSyncedTabsButton() + fun verifySyncSignInButton() = assertSignInToSyncButton() fun verifyHelpButton() = assertHelpButton() fun verifyThreeDotMenuExists() = threeDotMenuRecyclerViewExists() fun verifyForwardButton() = assertForwardButton() @@ -164,6 +165,15 @@ class ThreeDotMenuMainRobot { return SyncedTabsRobot.Transition() } + fun openSyncSignIn(interact: SyncSignInRobot.() -> Unit): SyncSignInRobot.Transition { + onView(withId(R.id.mozac_browser_menu_recyclerView)).perform(swipeDown()) + mDevice.waitNotNull(Until.findObject(By.text("Sign in to sync")), waitingTime) + signInToSyncButton().click() + + SyncSignInRobot().interact() + return SyncSignInRobot.Transition() + } + fun openBookmarks(interact: BookmarksRobot.() -> Unit): BookmarksRobot.Transition { onView(withId(R.id.mozac_browser_menu_recyclerView)).perform(swipeDown()) mDevice.waitNotNull(Until.findObject(By.text("Bookmarks")), waitingTime) diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt index 693c14444..9df47af02 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -792,6 +792,13 @@ class HomeFragment : Fragment() { HomeFragmentDirections.actionGlobalSyncedTabsFragment() ) } + HomeMenu.Item.SyncAccount -> { + hideOnboardingIfNeeded() + nav( + R.id.homeFragment, + HomeFragmentDirections.actionGlobalAccountSettingsFragment() + ) + } HomeMenu.Item.Bookmarks -> { hideOnboardingIfNeeded() nav( diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt b/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt index 6d2f6f877..2f277aa29 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt @@ -24,6 +24,7 @@ import mozilla.components.concept.sync.AuthType import mozilla.components.concept.sync.OAuthAccount import mozilla.components.support.ktx.android.content.getColorFromAttr import org.mozilla.fenix.FeatureFlags +import org.mozilla.fenix.FeatureFlags.tabsTrayRewrite import org.mozilla.fenix.R import org.mozilla.fenix.experiments.ExperimentBranch import org.mozilla.fenix.experiments.Experiments @@ -47,6 +48,7 @@ class HomeMenu( object Downloads : Item() object Extensions : Item() object SyncTabs : Item() + object SyncAccount : Item() object WhatsNew : Item() object Help : Item() object Settings : Item() @@ -55,8 +57,7 @@ class HomeMenu( data class DesktopMode(val checked: Boolean) : Item() } - private val primaryTextColor = - ThemeManager.resolveAttribute(R.attr.primaryText, context) + private val primaryTextColor = ThemeManager.resolveAttribute(R.attr.primaryText, context) private val syncDisconnectedColor = ThemeManager.resolveAttribute(R.attr.syncDisconnected, context) private val syncDisconnectedBackgroundColor = @@ -92,17 +93,6 @@ class HomeMenu( } } - private fun getSyncItemTitle(): String { - val authenticatedAccount = accountManager.authenticatedAccount() != null - val email = accountManager.accountProfile()?.email - - return if (authenticatedAccount && email != null) { - email - } else { - context.getString(R.string.sync_menu_sign_in) - } - } - private val oldCoreMenuItems by lazy { val whatsNewItem = BrowserMenuHighlightableItem( context.getString(R.string.browser_menu_whats_new), @@ -236,6 +226,17 @@ class HomeMenu( onItemTapped.invoke(Item.DesktopMode(checked)) } + private fun getSyncItemTitle(): String { + val authenticatedAccount = accountManager.authenticatedAccount() != null + val email = accountManager.accountProfile()?.email + + return if (authenticatedAccount && email != null) { + email + } else { + context.getString(R.string.sync_menu_sign_in) + } + } + @Suppress("ComplexMethod") private fun newCoreMenuItems(): List { val experiments = context.components.analytics.experiments @@ -293,14 +294,22 @@ class HomeMenu( onItemTapped.invoke(Item.Extensions) } - val syncSignInItem = BrowserMenuImageText( - context.getString(R.string.library_synced_tabs), + val syncedTabsItem = BrowserMenuImageText( + context.getString(R.string.synced_tabs), R.drawable.ic_synced_tabs, primaryTextColor ) { onItemTapped.invoke(Item.SyncTabs) } + val syncSignInMenuItem = BrowserMenuImageText( + getSyncItemTitle(), + R.drawable.ic_synced_tabs, + primaryTextColor + ) { + onItemTapped.invoke(Item.SyncAccount) + } + val whatsNewItem = BrowserMenuHighlightableItem( context.getString(R.string.browser_menu_whats_new), R.drawable.ic_whats_new, @@ -344,7 +353,7 @@ class HomeMenu( historyItem, downloadsItem, extensionsItem, - syncSignInItem, + if (tabsTrayRewrite) syncSignInMenuItem else syncedTabsItem, accountAuthItem, BrowserMenuDivider(), desktopItem,