Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Add telemetry probes for recent bookmarks on home screen. Tests for c…
Browse files Browse the repository at this point in the history
…ontroller.
  • Loading branch information
Elise Richards committed Jul 29, 2021
1 parent a901341 commit 867c473
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
28 changes: 28 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5961,3 +5961,31 @@ recent_tabs:
notification_emails:
- [email protected]
expires: "2022-06-23"
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:
- [email protected]
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:
- [email protected]
expires: "2022-01-31"
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ sealed class Event {
object OpenRecentTab : Event()
object OpenInProgressMediaTab : Event()

// Recent bookmarks on Home
object RecentBookmarkClicked : Event()
object RecentBookmarkShowAll : Event()

// Interaction events with extras

data class TopSiteSwipeCarousel(val page: Int) : Event() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.RecentTabs
import org.mozilla.fenix.GleanMetrics.SearchShortcuts
import org.mozilla.fenix.GleanMetrics.SearchSuggestions
Expand Down Expand Up @@ -862,6 +863,14 @@ private val Event.wrapper: EventWrapper<*>?
{ RecentTabs.showAllClicked.record(it) }
)

is Event.RecentBookmarkClicked -> EventWrapper<NoExtraKeys>(
{ RecentBookmarks.bookmarkClicked.record(it) }
)

is Event.RecentBookmarkShowAll -> EventWrapper<NoExtraKeys>(
{ RecentBookmarks.showAllClicked.record(it) }
)

// Don't record other events in Glean:
is Event.AddBookmark -> null
is Event.OpenedAppFirstRun -> null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import io.mockk.spyk
import io.mockk.verify
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
Expand All @@ -25,6 +26,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

Expand All @@ -38,11 +42,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
}
Expand Down Expand Up @@ -79,14 +85,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<NavOptions>()) }

verify {
metrics.track(Event.RecentBookmarkShowAll)
navController.navigate(directions, any<NavOptions>())
}
}
}

0 comments on commit 867c473

Please sign in to comment.