diff --git a/app/metrics.yaml b/app/metrics.yaml index beb01fb05042..7c2ed47b90b1 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -145,6 +145,7 @@ events: reader_mode_off, reader_mode_on, reload, remove_from_top_sites, save_to_collection, set_default_browser, settings, share, stop, sync_account, and sync_tabs. + type: string bugs: - https://github.com/mozilla-mobile/fenix/issues/1024 - https://github.com/mozilla-mobile/fenix/issues/19923 diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt index dc6aa5430d94..c88291099430 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt @@ -495,19 +495,6 @@ sealed class Event { data class AddonInstalled(val addonId: String) : Event() - data class BrowserMenuItemTapped(val item: Item) : Event() { - enum class Item { - SETTINGS, HELP, DESKTOP_VIEW_ON, DESKTOP_VIEW_OFF, FIND_IN_PAGE, NEW_TAB, - NEW_PRIVATE_TAB, SHARE, BACK, FORWARD, RELOAD, STOP, OPEN_IN_FENIX, - SAVE_TO_COLLECTION, ADD_TO_TOP_SITES, REMOVE_FROM_TOP_SITES, ADD_TO_HOMESCREEN, QUIT, READER_MODE_ON, - READER_MODE_OFF, OPEN_IN_APP, BOOKMARK, READER_MODE_APPEARANCE, ADDONS_MANAGER, - BOOKMARKS, HISTORY, SYNC_TABS, DOWNLOADS, SET_DEFAULT_BROWSER, SYNC_ACCOUNT - } - - override val extras: Map? - get() = mapOf(Events.browserMenuActionKeys.item to item.toString().lowercase(Locale.ROOT)) - } - object AutoPlaySettingVisited : Event() data class AutoPlaySettingChanged(val setting: AutoplaySetting) : Event() { diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt index e12139630deb..ad1a315748e0 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt @@ -122,10 +122,7 @@ private val Event.wrapper: EventWrapper<*>? { ContextMenu.itemTapped.record(it) }, { ContextMenu.itemTappedKeys.valueOf(it) } ) - is Event.BrowserMenuItemTapped -> EventWrapper( - { Events.browserMenuAction.record(it) }, - { Events.browserMenuActionKeys.valueOf(it) } - ) + is Event.SetDefaultBrowserToolbarMenuClicked -> EventWrapper( { ExperimentsDefaultBrowser.toolbarMenuClicked.record(it) } ) diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarMenuController.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarMenuController.kt index 6bf76b9eed54..ae21bdeb5b6f 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarMenuController.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarMenuController.kt @@ -27,6 +27,7 @@ import mozilla.components.feature.top.sites.DefaultTopSitesStorage import mozilla.components.feature.top.sites.PinnedSiteStorage import mozilla.components.feature.top.sites.TopSite import mozilla.components.support.base.feature.ViewBoundFeatureWrapper +import org.mozilla.fenix.GleanMetrics.Events import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.NavGraphDirections import org.mozilla.fenix.R @@ -400,41 +401,62 @@ class DefaultBrowserToolbarMenuController( @Suppress("ComplexMethod") private fun trackToolbarItemInteraction(item: ToolbarMenu.Item) { - val eventItem = when (item) { - is ToolbarMenu.Item.OpenInFenix -> Event.BrowserMenuItemTapped.Item.OPEN_IN_FENIX - is ToolbarMenu.Item.InstallPwaToHomeScreen -> Event.BrowserMenuItemTapped.Item.ADD_TO_HOMESCREEN - is ToolbarMenu.Item.Quit -> Event.BrowserMenuItemTapped.Item.QUIT - is ToolbarMenu.Item.OpenInApp -> Event.BrowserMenuItemTapped.Item.OPEN_IN_APP + when (item) { + is ToolbarMenu.Item.OpenInFenix -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("open_in_fenix")) + is ToolbarMenu.Item.InstallPwaToHomeScreen -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("add_to_homescreen")) + is ToolbarMenu.Item.Quit -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("quit")) + is ToolbarMenu.Item.OpenInApp -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("open_in_app")) is ToolbarMenu.Item.CustomizeReaderView -> - Event.BrowserMenuItemTapped.Item.READER_MODE_APPEARANCE - is ToolbarMenu.Item.Back -> Event.BrowserMenuItemTapped.Item.BACK - is ToolbarMenu.Item.Forward -> Event.BrowserMenuItemTapped.Item.FORWARD - is ToolbarMenu.Item.Reload -> Event.BrowserMenuItemTapped.Item.RELOAD - is ToolbarMenu.Item.Stop -> Event.BrowserMenuItemTapped.Item.STOP - is ToolbarMenu.Item.Share -> Event.BrowserMenuItemTapped.Item.SHARE - is ToolbarMenu.Item.Settings -> Event.BrowserMenuItemTapped.Item.SETTINGS + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("reader_mode_appearance")) + is ToolbarMenu.Item.Back -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("back")) + is ToolbarMenu.Item.Forward -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("forward")) + is ToolbarMenu.Item.Reload -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("reload")) + is ToolbarMenu.Item.Stop -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("stop")) + is ToolbarMenu.Item.Share -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("share")) + is ToolbarMenu.Item.Settings -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("settings")) is ToolbarMenu.Item.RequestDesktop -> if (item.isChecked) { - Event.BrowserMenuItemTapped.Item.DESKTOP_VIEW_ON + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("desktop_view_on")) } else { - Event.BrowserMenuItemTapped.Item.DESKTOP_VIEW_OFF + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("desktop_view_off")) } - is ToolbarMenu.Item.FindInPage -> Event.BrowserMenuItemTapped.Item.FIND_IN_PAGE - is ToolbarMenu.Item.SaveToCollection -> Event.BrowserMenuItemTapped.Item.SAVE_TO_COLLECTION - is ToolbarMenu.Item.AddToTopSites -> Event.BrowserMenuItemTapped.Item.ADD_TO_TOP_SITES - is ToolbarMenu.Item.AddToHomeScreen -> Event.BrowserMenuItemTapped.Item.ADD_TO_HOMESCREEN - is ToolbarMenu.Item.SyncAccount -> Event.BrowserMenuItemTapped.Item.SYNC_ACCOUNT - is ToolbarMenu.Item.Bookmark -> Event.BrowserMenuItemTapped.Item.BOOKMARK - is ToolbarMenu.Item.AddonsManager -> Event.BrowserMenuItemTapped.Item.ADDONS_MANAGER - is ToolbarMenu.Item.Bookmarks -> Event.BrowserMenuItemTapped.Item.BOOKMARKS - is ToolbarMenu.Item.History -> Event.BrowserMenuItemTapped.Item.HISTORY - is ToolbarMenu.Item.Downloads -> Event.BrowserMenuItemTapped.Item.DOWNLOADS - is ToolbarMenu.Item.NewTab -> Event.BrowserMenuItemTapped.Item.NEW_TAB - is ToolbarMenu.Item.SetDefaultBrowser -> Event.BrowserMenuItemTapped.Item.SET_DEFAULT_BROWSER - is ToolbarMenu.Item.RemoveFromTopSites -> Event.BrowserMenuItemTapped.Item.REMOVE_FROM_TOP_SITES + is ToolbarMenu.Item.FindInPage -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("find_in_page")) + is ToolbarMenu.Item.SaveToCollection -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("save_to_collection")) + is ToolbarMenu.Item.AddToTopSites -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("add_to_top_sites")) + is ToolbarMenu.Item.AddToHomeScreen -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("add_to_homescreen")) + is ToolbarMenu.Item.SyncAccount -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("sync_account")) + is ToolbarMenu.Item.Bookmark -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("bookmark")) + is ToolbarMenu.Item.AddonsManager -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("addons_manager")) + is ToolbarMenu.Item.Bookmarks -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("bookmarks")) + is ToolbarMenu.Item.History -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("history")) + is ToolbarMenu.Item.Downloads -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("downloads")) + is ToolbarMenu.Item.NewTab -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("new_tab")) + is ToolbarMenu.Item.SetDefaultBrowser -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("set_default_browser")) + is ToolbarMenu.Item.RemoveFromTopSites -> + Events.browserMenuAction.record(Events.BrowserMenuActionExtra("remove_from_top_sites")) } - - metrics.track(Event.BrowserMenuItemTapped(eventItem)) } companion object { diff --git a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarMenuControllerTest.kt b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarMenuControllerTest.kt index b40d7ef65e2c..2813763c9c12 100644 --- a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarMenuControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarMenuControllerTest.kt @@ -43,16 +43,20 @@ import mozilla.components.feature.top.sites.DefaultTopSitesStorage import mozilla.components.feature.top.sites.PinnedSiteStorage import mozilla.components.feature.top.sites.TopSite import mozilla.components.feature.top.sites.TopSitesUseCases +import mozilla.components.service.glean.testing.GleanTestRule import mozilla.components.support.base.feature.ViewBoundFeatureWrapper import mozilla.components.support.test.ext.joinBlocking +import mozilla.components.support.test.robolectric.testContext import mozilla.components.support.test.rule.MainCoroutineRule import org.junit.After import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import org.mozilla.fenix.GleanMetrics.Events import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.NavGraphDirections import org.mozilla.fenix.R @@ -78,6 +82,9 @@ class DefaultBrowserToolbarMenuControllerTest { @get:Rule val coroutinesTestRule = MainCoroutineRule() + @get:Rule + val gleanTestRule = GleanTestRule(testContext) + @MockK private lateinit var swipeRefreshLayout: SwipeRefreshLayout @RelaxedMockK private lateinit var activity: HomeActivity @RelaxedMockK private lateinit var navController: NavController @@ -163,9 +170,15 @@ class DefaultBrowserToolbarMenuControllerTest { bookmarkTappedInvoked = true } ) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.BOOKMARK)) } + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("bookmark", snapshot.single().extra?.getValue("item")) + assertTrue(bookmarkTappedInvoked) } @@ -191,9 +204,15 @@ class DefaultBrowserToolbarMenuControllerTest { bookmarkTappedInvoked = true } ) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.BOOKMARK)) } + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("bookmark", snapshot.single().extra?.getValue("item")) + assertTrue(bookmarkTappedInvoked) } @@ -247,9 +266,15 @@ class DefaultBrowserToolbarMenuControllerTest { val item = ToolbarMenu.Item.Back(false) val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.BACK)) } + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("back", snapshot.single().extra?.getValue("item")) + verify { sessionUseCases.goBack(browserStore.state.selectedTabId!!) } } @@ -258,11 +283,16 @@ class DefaultBrowserToolbarMenuControllerTest { val item = ToolbarMenu.Item.Back(true) val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("back", snapshot.single().extra?.getValue("item")) val directions = BrowserFragmentDirections.actionGlobalTabHistoryDialogFragment(null) - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.BACK)) } verify { navController.navigate(directions) } } @@ -271,9 +301,15 @@ class DefaultBrowserToolbarMenuControllerTest { val item = ToolbarMenu.Item.Forward(false) val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.FORWARD)) } + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("forward", snapshot.single().extra?.getValue("item")) + verify { sessionUseCases.goForward(selectedTab.id) } } @@ -282,11 +318,17 @@ class DefaultBrowserToolbarMenuControllerTest { val item = ToolbarMenu.Item.Forward(true) val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("forward", snapshot.single().extra?.getValue("item")) + val directions = BrowserFragmentDirections.actionGlobalTabHistoryDialogFragment(null) - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.FORWARD)) } verify { navController.navigate(directions) } } @@ -295,9 +337,15 @@ class DefaultBrowserToolbarMenuControllerTest { val item = ToolbarMenu.Item.Reload(false) val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.RELOAD)) } + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("reload", snapshot.single().extra?.getValue("item")) + verify { sessionUseCases.reload(selectedTab.id) } } @@ -306,9 +354,15 @@ class DefaultBrowserToolbarMenuControllerTest { val item = ToolbarMenu.Item.Reload(true) val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.RELOAD)) } + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("reload", snapshot.single().extra?.getValue("item")) + verify { sessionUseCases.reload( selectedTab.id, @@ -322,9 +376,15 @@ class DefaultBrowserToolbarMenuControllerTest { val item = ToolbarMenu.Item.Stop val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.STOP)) } + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("stop", snapshot.single().extra?.getValue("item")) + verify { sessionUseCases.stopLoading(selectedTab.id) } } @@ -333,11 +393,16 @@ class DefaultBrowserToolbarMenuControllerTest { val item = ToolbarMenu.Item.Settings val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("settings", snapshot.single().extra?.getValue("item")) val directions = BrowserFragmentDirections.actionBrowserFragmentToSettingsFragment() - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.SETTINGS)) } verify { navController.navigate(directions, null) } } @@ -346,11 +411,16 @@ class DefaultBrowserToolbarMenuControllerTest { val item = ToolbarMenu.Item.Bookmarks val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("bookmarks", snapshot.single().extra?.getValue("item")) val directions = BrowserFragmentDirections.actionGlobalBookmarkFragment(BookmarkRoot.Mobile.id) - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.BOOKMARKS)) } verify { navController.navigate(directions, null) } } @@ -359,11 +429,16 @@ class DefaultBrowserToolbarMenuControllerTest { val item = ToolbarMenu.Item.History val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("history", snapshot.single().extra?.getValue("item")) val directions = BrowserFragmentDirections.actionGlobalHistoryFragment() - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.HISTORY)) } verify { navController.navigate(directions, null) } } @@ -376,9 +451,15 @@ class DefaultBrowserToolbarMenuControllerTest { every { sessionUseCases.requestDesktopSite } returns requestDesktopSiteUseCase val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.DESKTOP_VIEW_ON)) } + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("desktop_view_on", snapshot.single().extra?.getValue("item")) + verify { requestDesktopSiteUseCase.invoke( true, @@ -396,9 +477,15 @@ class DefaultBrowserToolbarMenuControllerTest { every { sessionUseCases.requestDesktopSite } returns requestDesktopSiteUseCase val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.DESKTOP_VIEW_OFF)) } + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("desktop_view_off", snapshot.single().extra?.getValue("item")) + verify { requestDesktopSiteUseCase.invoke( false, @@ -418,11 +505,17 @@ class DefaultBrowserToolbarMenuControllerTest { } returns "Added to top sites!" val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("add_to_top_sites", snapshot.single().extra?.getValue("item")) + verify { addPinnedSiteUseCase.invoke(selectedTab.content.title, selectedTab.content.url) } verify { snackbar.setText("Added to top sites!") } - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.ADD_TO_TOP_SITES)) } } @Test @@ -440,10 +533,16 @@ class DefaultBrowserToolbarMenuControllerTest { } returns snackbarMessage val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("remove_from_top_sites", snapshot.single().extra?.getValue("item")) + verify { snackbar.setText(snackbarMessage) } - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.REMOVE_FROM_TOP_SITES)) } verify { removePinnedSiteUseCase.invoke(topSite) } } @@ -452,9 +551,14 @@ class DefaultBrowserToolbarMenuControllerTest { val item = ToolbarMenu.Item.AddonsManager val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.ADDONS_MANAGER)) } + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("addons_manager", snapshot.single().extra?.getValue("item")) } @Test @@ -462,9 +566,14 @@ class DefaultBrowserToolbarMenuControllerTest { val item = ToolbarMenu.Item.AddToHomeScreen val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.ADD_TO_HOMESCREEN)) } + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("add_to_homescreen", snapshot.single().extra?.getValue("item")) } @Test @@ -479,9 +588,15 @@ class DefaultBrowserToolbarMenuControllerTest { ) browserStore = BrowserStore(BrowserState(tabs = listOf(regularTab), selectedTabId = regularTab.id)) val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.SHARE)) } + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("share", snapshot.single().extra?.getValue("item")) + verify { navController.navigate( directionsEq( @@ -506,9 +621,15 @@ class DefaultBrowserToolbarMenuControllerTest { ) browserStore = BrowserStore(BrowserState(tabs = listOf(readerTab), selectedTabId = readerTab.id)) val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.SHARE)) } + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("share", snapshot.single().extra?.getValue("item")) + verify { navController.navigate( directionsEq( @@ -544,13 +665,15 @@ class DefaultBrowserToolbarMenuControllerTest { every { tabCollectionStorage.cachedTabCollections } returns cachedTabCollections val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) - verify { - metrics.track( - Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.SAVE_TO_COLLECTION) - ) - } + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("save_to_collection", snapshot.single().extra?.getValue("item")) + verify { metrics.track( Event.CollectionSaveButtonPressed(DefaultBrowserToolbarController.TELEMETRY_BROWSER_IDENTIFIER) @@ -572,9 +695,15 @@ class DefaultBrowserToolbarMenuControllerTest { every { tabCollectionStorage.cachedTabCollections } returns cachedTabCollectionsEmpty val controller = createController(scope = this, store = browserStore) + assertFalse(Events.browserMenuAction.testHasValue()) + controller.handleToolbarItemInteraction(item) - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.SAVE_TO_COLLECTION)) } + assertTrue(Events.browserMenuAction.testHasValue()) + val snapshot = Events.browserMenuAction.testGetValue() + assertEquals(1, snapshot.size) + assertEquals("save_to_collection", snapshot.single().extra?.getValue("item")) + verify { metrics.track( Event.CollectionSaveButtonPressed(