From d0bf499441123e629b624c96c22fdfe3f2a5e96d Mon Sep 17 00:00:00 2001 From: Elise Richards Date: Thu, 8 Jul 2021 17:15:21 -0500 Subject: [PATCH] Add telemetry probes for recent bookmarks on home screen. Tests for controller. --- app/metrics.yaml | 28 +++++++++++++++++++ .../mozilla/fenix/components/metrics/Event.kt | 4 +++ .../components/metrics/GleanMetricsService.kt | 9 ++++++ .../controller/RecentBookmarksController.kt | 4 +++ .../DefaultRecentBookmarksControllerTest.kt | 17 +++++++++-- 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index 1b9c7d722afd..a06b274a0003 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -5840,3 +5840,31 @@ start_on_home: notification_emails: - android-probes@mozilla.com expires: "2022-06-16" +recent_bookmarks: + bookmark_clicked: + type: event + description: | + A recently saved bookmark was clicked on the home screen. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/19931 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/TBD... + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: "2022-01-31" + show_all_clicked: + type: event + description: | + The show all button was clicked on the recently saved + bookmarks section of the home screen. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/19931 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/TBD... + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: "2022-01-31" 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 261744a36c5f..7bdc5ef93ebd 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 @@ -243,6 +243,10 @@ sealed class Event { object StartOnHomeEnterHomeScreen : Event() object StartOnHomeOpenTabsTray : Event() + // Recent bookmarks on Home + object RecentBookmarkClicked : Event() + object RecentBookmarkShowAll : Event() + // Interaction events with extras data class TopSiteSwipeCarousel(val page: Int) : 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 01d916ea6579..4fe68904f5c3 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 @@ -46,6 +46,7 @@ import org.mozilla.fenix.GleanMetrics.PrivateBrowsingMode import org.mozilla.fenix.GleanMetrics.PrivateBrowsingShortcut import org.mozilla.fenix.GleanMetrics.ProgressiveWebApp import org.mozilla.fenix.GleanMetrics.ReaderMode +import org.mozilla.fenix.GleanMetrics.RecentBookmarks import org.mozilla.fenix.GleanMetrics.SearchShortcuts import org.mozilla.fenix.GleanMetrics.SearchSuggestions import org.mozilla.fenix.GleanMetrics.SearchWidget @@ -850,6 +851,14 @@ private val Event.wrapper: EventWrapper<*>? { StartOnHome.openTabsTray.record(it) } ) + is Event.RecentBookmarkClicked -> EventWrapper( + { RecentBookmarks.bookmarkClicked.record(it) } + ) + + is Event.RecentBookmarkShowAll -> EventWrapper( + { RecentBookmarks.showAllClicked.record(it) } + ) + // Don't record other events in Glean: is Event.AddBookmark -> null is Event.OpenedAppFirstRun -> null diff --git a/app/src/main/java/org/mozilla/fenix/home/recentbookmarks/controller/RecentBookmarksController.kt b/app/src/main/java/org/mozilla/fenix/home/recentbookmarks/controller/RecentBookmarksController.kt index ebb788f73bbd..6eaf45b138d3 100644 --- a/app/src/main/java/org/mozilla/fenix/home/recentbookmarks/controller/RecentBookmarksController.kt +++ b/app/src/main/java/org/mozilla/fenix/home/recentbookmarks/controller/RecentBookmarksController.kt @@ -10,6 +10,8 @@ import mozilla.components.concept.storage.BookmarkNode import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R +import org.mozilla.fenix.components.metrics.Event +import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.nav import org.mozilla.fenix.home.HomeFragmentDirections import org.mozilla.fenix.home.recentbookmarks.interactor.RecentBookmarksInteractor @@ -45,9 +47,11 @@ class DefaultRecentBookmarksController( newTab = true, from = BrowserDirection.FromHome ) + activity.components.core.metrics.track(Event.RecentBookmarkClicked) } override fun handleShowAllBookmarksClicked() { + activity.components.core.metrics.track(Event.RecentBookmarkShowAll) val directions = HomeFragmentDirections.actionGlobalBookmarkFragment(BookmarkRoot.Mobile.id) navController.nav(R.id.homeFragment, directions) } diff --git a/app/src/test/java/org/mozilla/fenix/home/recentbookmarks/DefaultRecentBookmarksControllerTest.kt b/app/src/test/java/org/mozilla/fenix/home/recentbookmarks/DefaultRecentBookmarksControllerTest.kt index 156048532fce..38841afc7108 100644 --- a/app/src/test/java/org/mozilla/fenix/home/recentbookmarks/DefaultRecentBookmarksControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/home/recentbookmarks/DefaultRecentBookmarksControllerTest.kt @@ -8,12 +8,15 @@ import androidx.navigation.NavController import androidx.navigation.NavOptions import io.mockk.Runs import io.mockk.every +import io.mockk.impl.annotations.RelaxedMockK import io.mockk.just import io.mockk.mockk import io.mockk.spyk import io.mockk.verify +import io.mockk.verifyAll import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestCoroutineDispatcher +import kotlinx.coroutines.test.runBlockingTest import mozilla.appservices.places.BookmarkRoot import mozilla.components.concept.storage.BookmarkNode import mozilla.components.concept.storage.BookmarkNodeType @@ -25,6 +28,9 @@ import org.junit.Test import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R +import org.mozilla.fenix.components.metrics.Event +import org.mozilla.fenix.components.metrics.MetricController +import org.mozilla.fenix.ext.components import org.mozilla.fenix.home.HomeFragmentDirections import org.mozilla.fenix.home.recentbookmarks.controller.DefaultRecentBookmarksController @@ -38,11 +44,13 @@ class DefaultRecentBookmarksControllerTest { private val activity: HomeActivity = mockk(relaxed = true) private val navController: NavController = mockk(relaxUnitFun = true) + private val metrics: MetricController = mockk(relaxed = true) private lateinit var controller: DefaultRecentBookmarksController @Before fun setup() { every { activity.openToBrowserAndLoad(any(), any(), any()) } just Runs + every { activity.components.core.metrics } returns metrics every { navController.currentDestination } returns mockk { every { id } returns R.id.homeFragment } @@ -78,14 +86,19 @@ class DefaultRecentBookmarksControllerTest { newTab = true, from = BrowserDirection.FromHome ) + metrics.track(Event.RecentBookmarkClicked) } } @Test - fun `WHEN show all recently saved bookmark is clicked THEN the bookmarks root is opened`() { + fun `WHEN show all recently saved bookmark is clicked THEN the bookmarks root is opened`() = runBlockingTest { controller.handleShowAllBookmarksClicked() val directions = HomeFragmentDirections.actionGlobalBookmarkFragment(BookmarkRoot.Mobile.id) - verify { navController.navigate(directions, any()) } + + verify { + metrics.track(Event.RecentBookmarkShowAll) + navController.navigate(directions, any()) + } } }