tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit a0e2e0d839b1ce76addb7d8705d03e54f0bdbd03
parent 37b8ea4eceeaa7d0337fdeab895cdbbe9b55eaf3
Author: sarah541 <sarahkhan1107@hotmail.com>
Date:   Fri, 21 Nov 2025 18:52:43 +0000

Bug 2000490 - Add Toolbar CFR. r=android-reviewers,android-l10n-reviewers,petru,flod,tthibaud

Differential Revision: https://phabricator.services.mozilla.com/D272886

Diffstat:
Mmobile/android/android-components/.buildconfig.yml | 3+++
Mmobile/android/android-components/components/compose/browser-toolbar/build.gradle | 1+
Mmobile/android/android-components/components/compose/browser-toolbar/src/main/java/mozilla/components/compose/browser/toolbar/BrowserToolbar.kt | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
Mmobile/android/android-components/components/compose/browser-toolbar/src/main/res/values/strings.xml | 4++++
Mmobile/android/android-components/components/compose/cfr/src/main/java/mozilla/components/compose/cfr/CFRPopup.kt | 2+-
Mmobile/android/fenix/app/metrics.yaml | 26++++++++++++++++++++++++++
Mmobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/helpers/FeatureSettingsHelper.kt | 5+++++
Mmobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/helpers/FeatureSettingsHelperDelegate.kt | 4++++
Mmobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/helpers/HomeActivityTestRule.kt | 5+++++
Mmobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarComposable.kt | 57++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mmobile/android/fenix/app/src/main/java/org/mozilla/fenix/utils/Settings.kt | 8++++++++
Mmobile/android/fenix/app/src/main/res/values/preference_keys.xml | 3++-
Mmobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/BaselineProfileBrowserPageScrollBenchmark.kt | 6++++++
Mmobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/BaselineProfilesHomepageScrollBenchmark.kt | 6++++++
Mmobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/BaselineProfilesNormalBrowsingBenchmark.kt | 6++++++
Mmobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/BaselineProfilesPrivateBrowsingBenchmark.kt | 6++++++
Mmobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/baselineprofile/BrowserPageScrollBaselineProfileGenerator.kt | 6++++++
Mmobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/baselineprofile/HomepageScrollBaselineProfileGenerator.kt | 6++++++
Mmobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/baselineprofile/NormalBrowsingBaselineProfileGenerator.kt | 6++++++
Mmobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/baselineprofile/PrivateBrowsingBaselineProfileGenerator.kt | 6++++++
Mmobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/utils/UiDevice.kt | 7+++++++
21 files changed, 258 insertions(+), 14 deletions(-)

diff --git a/mobile/android/android-components/.buildconfig.yml b/mobile/android/android-components/.buildconfig.yml @@ -324,6 +324,7 @@ projects: - components:browser-menu2 - components:browser-state - components:compose-base + - components:compose-cfr - components:concept-awesomebar - components:concept-base - components:concept-engine @@ -1826,6 +1827,7 @@ projects: - components:compose-awesomebar - components:compose-base - components:compose-browser-toolbar + - components:compose-cfr - components:compose-engine - components:compose-tabstray - components:concept-awesomebar @@ -2000,6 +2002,7 @@ projects: - components:browser-toolbar - components:compose-base - components:compose-browser-toolbar + - components:compose-cfr - components:concept-awesomebar - components:concept-base - components:concept-engine diff --git a/mobile/android/android-components/components/compose/browser-toolbar/build.gradle b/mobile/android/android-components/components/compose/browser-toolbar/build.gradle @@ -25,6 +25,7 @@ dependencies { implementation project(":components:browser-menu2") implementation project(":components:browser-state") implementation project(":components:compose-base") + implementation project(":components:compose-cfr") implementation project(":components:concept-engine") implementation project(":components:concept-menu") implementation project(":components:feature-session") diff --git a/mobile/android/android-components/components/compose/browser-toolbar/src/main/java/mozilla/components/compose/browser/toolbar/BrowserToolbar.kt b/mobile/android/android-components/components/compose/browser-toolbar/src/main/java/mozilla/components/compose/browser/toolbar/BrowserToolbar.kt @@ -4,10 +4,14 @@ package mozilla.components.compose.browser.toolbar +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.PreviewLightDark +import androidx.compose.ui.unit.dp import mozilla.components.compose.base.theme.AcornTheme import mozilla.components.compose.browser.toolbar.concept.PageOrigin import mozilla.components.compose.browser.toolbar.store.BrowserEditToolbarAction.SearchQueryUpdated @@ -18,9 +22,33 @@ import mozilla.components.compose.browser.toolbar.store.BrowserToolbarStore import mozilla.components.compose.browser.toolbar.store.DisplayState import mozilla.components.compose.browser.toolbar.store.EditState import mozilla.components.compose.browser.toolbar.store.Mode +import mozilla.components.compose.browser.toolbar.store.ToolbarGravity import mozilla.components.compose.browser.toolbar.ui.BrowserToolbarQuery +import mozilla.components.compose.cfr.CFRPopup +import mozilla.components.compose.cfr.CFRPopupLayout +import mozilla.components.compose.cfr.CFRPopupProperties import mozilla.components.lib.state.ext.observeAsComposableState +private const val CFR_HORIZONTAL_OFFSET = 160 +private const val CFR_VERTICAL_OFFSET = 0 + +/** + * Represents the state and behavior of a CFR shown in the browser toolbar. + * + * @property enabled Whether the CFR is currently active and should be displayed. + * @property title The headline text displayed in the CFR banner. + * @property description A short descriptive message explaining the feature or action. + * @property onShown Callback invoked when the CFR is first shown to the user. + * @property onDismiss Callback invoked when the CFR is dismissed. + */ +data class BrowserToolbarCFR( + val enabled: Boolean, + val title: String, + val description: String, + val onShown: () -> Unit = {}, + val onDismiss: (Boolean) -> Unit = {}, +) + /** * A customizable toolbar for browsers. * @@ -29,12 +57,15 @@ import mozilla.components.lib.state.ext.observeAsComposableState * implemented by the [BrowserDisplayToolbar] and [BrowserEditToolbar] composables. * * @param store The [BrowserToolbarStore] to observe the UI state from. + * @param cfr The [BrowserToolbarCFR] to hold properties of Toolbar's CFR. */ @Composable fun BrowserToolbar( store: BrowserToolbarStore, + cfr: BrowserToolbarCFR? = null, ) { val uiState by store.observeAsComposableState { it } + val cfrProperties = browserToolbarCFRProperties(uiState.gravity) if (uiState.isEditMode()) { BrowserEditToolbar( @@ -51,15 +82,65 @@ fun BrowserToolbar( onInteraction = { store.dispatch(it) }, ) } else { - BrowserDisplayToolbar( - pageOrigin = uiState.displayState.pageOrigin, - progressBarConfig = uiState.displayState.progressBarConfig, - gravity = uiState.gravity, - browserActionsStart = uiState.displayState.browserActionsStart, - pageActionsStart = uiState.displayState.pageActionsStart, - pageActionsEnd = uiState.displayState.pageActionsEnd, - browserActionsEnd = uiState.displayState.browserActionsEnd, - onInteraction = { store.dispatch(it) }, + CFRPopupLayout( + showCFR = cfr?.enabled == true, + properties = cfrProperties, + onCFRShown = { cfr?.onShown?.invoke() }, + onDismiss = { explicit -> cfr?.onDismiss?.invoke(explicit) }, + title = { + cfr?.title?.let { + Text( + text = it, + color = AcornTheme.colors.textOnColorPrimary, + style = AcornTheme.typography.subtitle2, + ) + } + }, + text = { + cfr?.description?.let { + Text( + text = it, + color = AcornTheme.colors.textOnColorPrimary, + style = AcornTheme.typography.body2, + ) + } + }, + ) { + BrowserDisplayToolbar( + pageOrigin = uiState.displayState.pageOrigin, + progressBarConfig = uiState.displayState.progressBarConfig, + gravity = uiState.gravity, + browserActionsStart = uiState.displayState.browserActionsStart, + pageActionsStart = uiState.displayState.pageActionsStart, + pageActionsEnd = uiState.displayState.pageActionsEnd, + browserActionsEnd = uiState.displayState.browserActionsEnd, + onInteraction = { store.dispatch(it) }, + ) + } + } +} + +@Composable +private fun browserToolbarCFRProperties( + gravity: ToolbarGravity, +): CFRPopupProperties { + val isBottom = gravity == ToolbarGravity.Bottom + val indicatorDir = + if (isBottom) CFRPopup.IndicatorDirection.DOWN else CFRPopup.IndicatorDirection.UP + + val colors = AcornTheme.colors + + return remember(isBottom) { + CFRPopupProperties( + popupAlignment = CFRPopup.PopupAlignment.INDICATOR_CENTERED_IN_ANCHOR, + popupBodyColors = listOf( + colors.layerGradientEnd.toArgb(), + colors.layerGradientStart.toArgb(), + ), + dismissButtonColor = colors.iconOnColor.toArgb(), + indicatorDirection = indicatorDir, + popupVerticalOffset = CFR_VERTICAL_OFFSET.dp, + indicatorArrowStartOffset = CFR_HORIZONTAL_OFFSET.dp, ) } } diff --git a/mobile/android/android-components/components/compose/browser-toolbar/src/main/res/values/strings.xml b/mobile/android/android-components/components/compose/browser-toolbar/src/main/res/values/strings.xml @@ -13,4 +13,8 @@ <string name="mozac_browser_toolbar_long_press_popup_paste">Paste</string> <!-- Contextual menu option for long pressing on the toolbar URL. Clicking it will paste the text from clipboard and search for or load it as an URL. '&amp;' is replaced with the ampersand symbol: & --> <string name="mozac_browser_toolbar_long_press_popup_paste_and_go">Paste &amp; Go</string> + <!-- Text for the title displayed in the contextual feature recommendation popup promoting the new toolbar redesign. --> + <string name="mozac_toolbar_cfr_title">Designed for Android. Refined for You</string> + <!-- Text for the description displayed in the contextual feature recommendation popup promoting the new toolbar redesign. --> + <string name="mozac_toolbar_cfr_description">We’ve refreshed the design with a sleek, modern feel</string> </resources> diff --git a/mobile/android/android-components/components/compose/cfr/src/main/java/mozilla/components/compose/cfr/CFRPopup.kt b/mobile/android/android-components/components/compose/cfr/src/main/java/mozilla/components/compose/cfr/CFRPopup.kt @@ -40,7 +40,7 @@ import java.lang.ref.WeakReference * the indicator arrow will be pointing to the middle of the anchor. * @property popupStartOffset Maximum distance between the popup and anchor start. */ -data class CFRPopupProperties( +class CFRPopupProperties( val popupWidth: Dp = CFRPopup.DEFAULT_WIDTH.dp, val popupAlignment: PopupAlignment = PopupAlignment.BODY_TO_ANCHOR_CENTER, val popupBodyColors: List<Int> = listOf(Color.Blue.toArgb()), diff --git a/mobile/android/fenix/app/metrics.yaml b/mobile/android/fenix/app/metrics.yaml @@ -14373,6 +14373,32 @@ client_association: - fx-accounts toolbar: + cfr_shown: + type: event + description: | + Toolbar cfr was shown to the user. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=2000490 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=2000490 + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: never + cfr_dismissed: + type: event + description: | + Toolbar cfr was dismissed by the user. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=2000490 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=2000490 + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: never button_tapped: type: event description: | diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/helpers/FeatureSettingsHelper.kt b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/helpers/FeatureSettingsHelper.kt @@ -135,6 +135,11 @@ interface FeatureSettingsHelper { var tabManagerOpeningAnimationEnabled: Boolean /** + * Indicates if the toolbar CFR was displayed to the user. + */ + var hasSeenBrowserToolbarCFR: Boolean + + /** * Enable or disable the translations prompt after a page that can be translated is loaded. */ fun enableOrDisablePageLoadTranslationsPrompt(enableTranslationsPrompt: Boolean) { diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/helpers/FeatureSettingsHelperDelegate.kt b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/helpers/FeatureSettingsHelperDelegate.kt @@ -51,6 +51,7 @@ class FeatureSettingsHelperDelegate : FeatureSettingsHelper { isComposeLoginsEnabled = settings.enableComposeLogins, openLinksInApp = getOpenLinksInApp(settings), tabManagerOpeningAnimationEnabled = settings.tabManagerOpeningAnimationEnabled, + hasSeenBrowserToolbarCFR = settings.hasSeenBrowserToolbarCFR, ) /** @@ -80,6 +81,7 @@ class FeatureSettingsHelperDelegate : FeatureSettingsHelper { override var isComposeLoginsEnabled: Boolean by updatedFeatureFlags::isComposeLoginsEnabled override var openLinksInExternalApp: OpenLinksInApp by updatedFeatureFlags::openLinksInApp override var tabManagerOpeningAnimationEnabled: Boolean by updatedFeatureFlags::tabManagerOpeningAnimationEnabled + override var hasSeenBrowserToolbarCFR: Boolean by updatedFeatureFlags::hasSeenBrowserToolbarCFR override fun applyFlagUpdates() { Log.i(TAG, "applyFlagUpdates: Trying to apply the updated feature flags: $updatedFeatureFlags") @@ -119,6 +121,7 @@ class FeatureSettingsHelperDelegate : FeatureSettingsHelper { settings.enableComposeLogins = featureFlags.isComposeLoginsEnabled setOpenLinksInApp(featureFlags.openLinksInApp) settings.tabManagerOpeningAnimationEnabled = featureFlags.tabManagerOpeningAnimationEnabled + settings.hasSeenBrowserToolbarCFR = featureFlags.hasSeenBrowserToolbarCFR } } @@ -146,6 +149,7 @@ private data class FeatureFlags( var isComposeLoginsEnabled: Boolean, var openLinksInApp: OpenLinksInApp, var tabManagerOpeningAnimationEnabled: Boolean, + var hasSeenBrowserToolbarCFR: Boolean, ) internal fun getETPPolicy(settings: Settings): ETPPolicy { diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/helpers/HomeActivityTestRule.kt b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/helpers/HomeActivityTestRule.kt @@ -73,6 +73,7 @@ class HomeActivityTestRule( isTermsOfServiceAccepted: Boolean = true, isComposeLoginsEnabled: Boolean = false, openLinksInExternalApp: OpenLinksInApp = getOpenLinksInApp(settings), + hasSeenBrowserToolbarCFR: Boolean = true, ) : this(initialTouchMode, launchActivity, skipOnboarding) { this.isHomepageHeaderEnabled = isHomepageHeaderEnabled this.isPocketEnabled = isPocketEnabled @@ -96,6 +97,7 @@ class HomeActivityTestRule( this.isTermsOfServiceAccepted = isTermsOfServiceAccepted this.isComposeLoginsEnabled = isComposeLoginsEnabled this.openLinksInExternalApp = openLinksInExternalApp + this.hasSeenBrowserToolbarCFR = hasSeenBrowserToolbarCFR } /** @@ -209,6 +211,7 @@ class HomeActivityIntentTestRule internal constructor( isComposeLoginsEnabled: Boolean = false, openLinksInExternalApp: OpenLinksInApp = getOpenLinksInApp(settings), tabManagerOpeningAnimationEnabled: Boolean = false, + hasSeenBrowserToolbarCFR: Boolean = true, ) : this(initialTouchMode, launchActivity, skipOnboarding) { this.isHomepageHeaderEnabled = isHomepageHeaderEnabled this.isPocketEnabled = isPocketEnabled @@ -233,6 +236,7 @@ class HomeActivityIntentTestRule internal constructor( this.isComposeLoginsEnabled = isComposeLoginsEnabled this.openLinksInExternalApp = openLinksInExternalApp this.tabManagerOpeningAnimationEnabled = tabManagerOpeningAnimationEnabled + this.hasSeenBrowserToolbarCFR = hasSeenBrowserToolbarCFR } private val longTapUserPreference = getLongPressTimeout() @@ -309,6 +313,7 @@ class HomeActivityIntentTestRule internal constructor( isComposeLoginsEnabled = settings.enableComposeLogins openLinksInExternalApp = getOpenLinksInApp(settings) tabManagerOpeningAnimationEnabled = settings.tabManagerOpeningAnimationEnabled + hasSeenBrowserToolbarCFR = settings.hasSeenBrowserToolbarCFR } companion object { diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarComposable.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarComposable.kt @@ -16,12 +16,16 @@ import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.stringResource import androidx.coordinatorlayout.widget.CoordinatorLayout.LayoutParams import mozilla.components.browser.state.action.AwesomeBarAction +import mozilla.components.browser.state.selector.selectedTab import mozilla.components.browser.state.state.CustomTabSessionState import mozilla.components.browser.state.store.BrowserStore import mozilla.components.compose.base.utils.BackInvokedHandler import mozilla.components.compose.browser.toolbar.BrowserToolbar +import mozilla.components.compose.browser.toolbar.BrowserToolbarCFR +import mozilla.components.compose.browser.toolbar.R import mozilla.components.compose.browser.toolbar.store.BrowserToolbarAction.ToolbarGravityUpdated import mozilla.components.compose.browser.toolbar.store.BrowserToolbarStore import mozilla.components.compose.browser.toolbar.store.ToolbarGravity @@ -29,6 +33,8 @@ import mozilla.components.compose.browser.toolbar.store.ToolbarGravity.Bottom import mozilla.components.compose.browser.toolbar.store.ToolbarGravity.Top import mozilla.components.feature.toolbar.ToolbarBehaviorController import mozilla.components.lib.state.ext.observeAsComposableState +import mozilla.telemetry.glean.private.NoExtras +import org.mozilla.fenix.GleanMetrics.Toolbar import org.mozilla.fenix.browser.store.BrowserScreenStore import org.mozilla.fenix.components.AppStore import org.mozilla.fenix.components.appstate.AppAction.SearchAction.SearchEnded @@ -88,6 +94,8 @@ class BrowserToolbarComposable( val customColors = browserScreenStore.observeAsComposableState { it.customTabColors } val shouldUseBottomToolbar = remember(settings) { settings.shouldUseBottomToolbar } + var toolbarCFR = toolbarCFRData(browserStore, settings, customTabSession) + DisposableEffect(activity) { val toolbarController = ToolbarBehaviorController( toolbar = this@BrowserToolbarComposable, @@ -132,7 +140,10 @@ class BrowserToolbarComposable( .wrapContentHeight(), ) { tabStripContent() - BrowserToolbar(toolbarStore) + BrowserToolbar( + store = toolbarStore, + cfr = toolbarCFR, + ) if (customTabSession == null) { searchSuggestionsContent(Modifier.weight(1f)) } @@ -147,10 +158,16 @@ class BrowserToolbarComposable( if (customTabSession == null) { searchSuggestionsContent(Modifier.weight(1f)) } - BrowserToolbar(toolbarStore) + BrowserToolbar( + store = toolbarStore, + cfr = toolbarCFR, + ) navigationBarContent?.invoke() } else { - BrowserToolbar(toolbarStore) + BrowserToolbar( + store = toolbarStore, + cfr = toolbarCFR, + ) if (customTabSession == null) { searchSuggestionsContent(Modifier.weight(1f)) } @@ -188,3 +205,37 @@ class BrowserToolbarComposable( false -> Top } } + +@Composable +private fun toolbarCFRData( + browserStore: BrowserStore, + settings: Settings, + customTabSession: CustomTabSessionState?, +): BrowserToolbarCFR? { + if (settings.hasSeenBrowserToolbarCFR || !settings.toolbarRedesignEnabled || customTabSession != null) { + return null + } + + val session = browserStore.observeAsComposableState { it.selectedTab?.content }.value + val shouldShowCFR = session != null && session.progress == 100 && !session.loading + + val title = stringResource(R.string.mozac_toolbar_cfr_title) + val description = stringResource(R.string.mozac_toolbar_cfr_description) + return remember(shouldShowCFR, title, description) { + if (shouldShowCFR) { + BrowserToolbarCFR( + enabled = shouldShowCFR, + title = title, + description = description, + onShown = { Toolbar.cfrShown.record(NoExtras()) }, + onDismiss = { + settings.hasSeenBrowserToolbarCFR = true + settings.lastCfrShownTimeInMillis = System.currentTimeMillis() + Toolbar.cfrDismissed.record(NoExtras()) + }, + ) + } else { + null + } + } +} diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -2188,6 +2188,14 @@ class Settings( ) /** + * Indicates if the toolbar CFR was displayed to the user. + */ + var hasSeenBrowserToolbarCFR by booleanPreference( + key = appContext.getPreferenceKey(R.string.pref_key_toolbar_cfr), + default = false, + ) + + /** * Get the current mode for how https-only is enabled. */ fun getHttpsOnlyMode(): HttpsOnlyMode { diff --git a/mobile/android/fenix/app/src/main/res/values/preference_keys.xml b/mobile/android/fenix/app/src/main/res/values/preference_keys.xml @@ -176,8 +176,9 @@ <string name="pref_key_app_icon">pref_key_app_icon</string> <string name="pref_key_app_icon_selection_enabled" translatable="false">pref_key_app_icon_selection_enabled</string> - <!-- Menu --> + <!-- Cfr --> <string name="pref_key_menu_cfr" translatable="false">pref_key_menu_cfr</string> + <string name="pref_key_toolbar_cfr" translatable="false">pref_key_toolbar_cfr</string> <!-- Privacy Pop Window --> <string name="pref_key_privacy_pop_window" translatable="false">pref_key_privacy_pop_window</string> diff --git a/mobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/BaselineProfileBrowserPageScrollBenchmark.kt b/mobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/BaselineProfileBrowserPageScrollBenchmark.kt @@ -17,8 +17,10 @@ import org.junit.runner.RunWith import org.mozilla.fenix.benchmark.utils.HtmlAsset import org.mozilla.fenix.benchmark.utils.MockWebServerRule import org.mozilla.fenix.benchmark.utils.TARGET_PACKAGE +import org.mozilla.fenix.benchmark.utils.dismissCFR import org.mozilla.fenix.benchmark.utils.flingToBeginning import org.mozilla.fenix.benchmark.utils.flingToEnd +import org.mozilla.fenix.benchmark.utils.isBrowserToolbarCfrShown import org.mozilla.fenix.benchmark.utils.measureRepeatedDefault import org.mozilla.fenix.benchmark.utils.uri @@ -81,6 +83,10 @@ class BaselineProfilesBrowserPageScrollBenchmark { startActivityAndWait(intent = intent) + if (device.isBrowserToolbarCfrShown()) { + device.dismissCFR() + } + device.flingToEnd( scrollableId = "$packageName:id/engineView", maxSwipes = 1, diff --git a/mobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/BaselineProfilesHomepageScrollBenchmark.kt b/mobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/BaselineProfilesHomepageScrollBenchmark.kt @@ -17,8 +17,10 @@ import org.junit.Test import org.junit.runner.RunWith import org.mozilla.fenix.benchmark.utils.FENIX_HOME_DEEP_LINK import org.mozilla.fenix.benchmark.utils.TARGET_PACKAGE +import org.mozilla.fenix.benchmark.utils.dismissCFR import org.mozilla.fenix.benchmark.utils.dismissWallpaperOnboarding import org.mozilla.fenix.benchmark.utils.flingToEnd +import org.mozilla.fenix.benchmark.utils.isBrowserToolbarCfrShown import org.mozilla.fenix.benchmark.utils.isWallpaperOnboardingShown import org.mozilla.fenix.benchmark.utils.measureRepeatedDefault @@ -80,6 +82,10 @@ class BaselineProfilesHomepageScrollBenchmark { device.dismissWallpaperOnboarding() } + if (device.isBrowserToolbarCfrShown()) { + device.dismissCFR() + } + device.flingToEnd( scrollableId = "$packageName:id/rootContainer", maxSwipes = Int.MAX_VALUE, diff --git a/mobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/BaselineProfilesNormalBrowsingBenchmark.kt b/mobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/BaselineProfilesNormalBrowsingBenchmark.kt @@ -21,8 +21,10 @@ import org.mozilla.fenix.benchmark.utils.HtmlAsset import org.mozilla.fenix.benchmark.utils.MockWebServerRule import org.mozilla.fenix.benchmark.utils.ParameterizedToolbarsTest import org.mozilla.fenix.benchmark.utils.TARGET_PACKAGE +import org.mozilla.fenix.benchmark.utils.dismissCFR import org.mozilla.fenix.benchmark.utils.dismissWallpaperOnboarding import org.mozilla.fenix.benchmark.utils.enterSearchMode +import org.mozilla.fenix.benchmark.utils.isBrowserToolbarCfrShown import org.mozilla.fenix.benchmark.utils.isWallpaperOnboardingShown import org.mozilla.fenix.benchmark.utils.loadSite import org.mozilla.fenix.benchmark.utils.measureRepeatedDefault @@ -94,6 +96,10 @@ class BaselineProfilesNormalBrowsingBenchmark( device.dismissWallpaperOnboarding() } + if (device.isBrowserToolbarCfrShown()) { + device.dismissCFR() + } + device.enterSearchMode(useComposableToolbar) device.loadSite(url = mockRule.url(HtmlAsset.SIMPLE), useComposableToolbar) diff --git a/mobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/BaselineProfilesPrivateBrowsingBenchmark.kt b/mobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/BaselineProfilesPrivateBrowsingBenchmark.kt @@ -22,7 +22,9 @@ import org.mozilla.fenix.benchmark.utils.MockWebServerRule import org.mozilla.fenix.benchmark.utils.ParameterizedToolbarsTest import org.mozilla.fenix.benchmark.utils.TARGET_PACKAGE import org.mozilla.fenix.benchmark.utils.closeTab +import org.mozilla.fenix.benchmark.utils.dismissCFR import org.mozilla.fenix.benchmark.utils.dismissWallpaperOnboarding +import org.mozilla.fenix.benchmark.utils.isBrowserToolbarCfrShown import org.mozilla.fenix.benchmark.utils.isWallpaperOnboardingShown import org.mozilla.fenix.benchmark.utils.loadSite import org.mozilla.fenix.benchmark.utils.measureRepeatedDefault @@ -96,6 +98,10 @@ class BaselineProfilesPrivateBrowsingBenchmark( device.dismissWallpaperOnboarding() } + if (device.isBrowserToolbarCfrShown()) { + device.dismissCFR() + } + device.openTabsTray(useComposableToolbar) device.openNewPrivateTabOnTabsTray() val url = mockRule.url(HtmlAsset.SIMPLE) diff --git a/mobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/baselineprofile/BrowserPageScrollBaselineProfileGenerator.kt b/mobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/baselineprofile/BrowserPageScrollBaselineProfileGenerator.kt @@ -19,6 +19,8 @@ import org.mozilla.fenix.benchmark.utils.flingToBeginning import org.mozilla.fenix.benchmark.utils.flingToEnd import androidx.core.net.toUri import org.mozilla.fenix.benchmark.utils.HtmlAsset +import org.mozilla.fenix.benchmark.utils.dismissCFR +import org.mozilla.fenix.benchmark.utils.isBrowserToolbarCfrShown import org.mozilla.fenix.benchmark.utils.uri /** @@ -68,6 +70,10 @@ class BrowserPageScrollBaselineProfileGenerator { startActivityAndWait(intent = intent) + if (device.isBrowserToolbarCfrShown()) { + device.dismissCFR() + } + device.flingToEnd( scrollableId = "$packageName:id/engineView", maxSwipes = 1, diff --git a/mobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/baselineprofile/HomepageScrollBaselineProfileGenerator.kt b/mobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/baselineprofile/HomepageScrollBaselineProfileGenerator.kt @@ -19,6 +19,8 @@ import org.mozilla.fenix.benchmark.utils.flingToEnd import org.mozilla.fenix.benchmark.utils.isWallpaperOnboardingShown import androidx.core.net.toUri import org.mozilla.fenix.benchmark.utils.FENIX_HOME_DEEP_LINK +import org.mozilla.fenix.benchmark.utils.dismissCFR +import org.mozilla.fenix.benchmark.utils.isBrowserToolbarCfrShown /** * This test class generates a baseline profile on a critical user journey, that scrolls down on the @@ -66,6 +68,10 @@ class HomepageScrollBaselineProfileGenerator { device.dismissWallpaperOnboarding() } + if (device.isBrowserToolbarCfrShown()) { + device.dismissCFR() + } + device.flingToEnd( scrollableId = "$packageName:id/rootContainer", maxSwipes = Int.MAX_VALUE, diff --git a/mobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/baselineprofile/NormalBrowsingBaselineProfileGenerator.kt b/mobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/baselineprofile/NormalBrowsingBaselineProfileGenerator.kt @@ -18,8 +18,10 @@ import org.mozilla.fenix.benchmark.utils.HtmlAsset import org.mozilla.fenix.benchmark.utils.MockWebServerRule import org.mozilla.fenix.benchmark.utils.ParameterizedToolbarsTest import org.mozilla.fenix.benchmark.utils.TARGET_PACKAGE +import org.mozilla.fenix.benchmark.utils.dismissCFR import org.mozilla.fenix.benchmark.utils.dismissWallpaperOnboarding import org.mozilla.fenix.benchmark.utils.enterSearchMode +import org.mozilla.fenix.benchmark.utils.isBrowserToolbarCfrShown import org.mozilla.fenix.benchmark.utils.isWallpaperOnboardingShown import org.mozilla.fenix.benchmark.utils.loadSite import org.mozilla.fenix.benchmark.utils.url @@ -76,6 +78,10 @@ class NormalBrowsingBaselineProfileGenerator( device.dismissWallpaperOnboarding() } + if (device.isBrowserToolbarCfrShown()) { + device.dismissCFR() + } + device.enterSearchMode(useComposableToolbar) device.loadSite(url = mockRule.url(HtmlAsset.SIMPLE), useComposableToolbar) } diff --git a/mobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/baselineprofile/PrivateBrowsingBaselineProfileGenerator.kt b/mobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/baselineprofile/PrivateBrowsingBaselineProfileGenerator.kt @@ -19,7 +19,9 @@ import org.mozilla.fenix.benchmark.utils.MockWebServerRule import org.mozilla.fenix.benchmark.utils.ParameterizedToolbarsTest import org.mozilla.fenix.benchmark.utils.TARGET_PACKAGE import org.mozilla.fenix.benchmark.utils.closeTab +import org.mozilla.fenix.benchmark.utils.dismissCFR import org.mozilla.fenix.benchmark.utils.dismissWallpaperOnboarding +import org.mozilla.fenix.benchmark.utils.isBrowserToolbarCfrShown import org.mozilla.fenix.benchmark.utils.isWallpaperOnboardingShown import org.mozilla.fenix.benchmark.utils.loadSite import org.mozilla.fenix.benchmark.utils.openNewPrivateTabOnTabsTray @@ -78,6 +80,10 @@ class PrivateBrowsingBaselineProfileGenerator( device.dismissWallpaperOnboarding() } + if (device.isBrowserToolbarCfrShown()) { + device.dismissCFR() + } + device.openTabsTray(useComposableToolbar) device.openNewPrivateTabOnTabsTray() val url = mockRule.url(HtmlAsset.SIMPLE) diff --git a/mobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/utils/UiDevice.kt b/mobile/android/fenix/benchmark/src/main/java/org/mozilla/fenix/benchmark/utils/UiDevice.kt @@ -32,6 +32,13 @@ fun UiDevice.dismissWallpaperOnboarding() { closeButton.click() } +fun UiDevice.isBrowserToolbarCfrShown() : Boolean { + val browserToolbarCfrText = findObject( + UiSelector().text("Designed for Android. Refined for You") + ) + return browserToolbarCfrText.exists() +} + fun UiDevice.dismissCFR() { val cfrDismiss = findObject( UiSelector().resourceId("cfr.dismiss")