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 9, 2021
1 parent 9bfe9b0 commit d0bf499
Show file tree
Hide file tree
Showing 5 changed files with 60 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 @@ -5840,3 +5840,31 @@ start_on_home:
notification_emails:
- [email protected]
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:
- [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 @@ -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() {
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.SearchShortcuts
import org.mozilla.fenix.GleanMetrics.SearchSuggestions
import org.mozilla.fenix.GleanMetrics.SearchWidget
Expand Down Expand Up @@ -850,6 +851,14 @@ private val Event.wrapper: EventWrapper<*>?
{ StartOnHome.openTabsTray.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 @@ -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
Expand All @@ -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

Expand All @@ -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
}
Expand Down Expand Up @@ -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<NavOptions>()) }

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

0 comments on commit d0bf499

Please sign in to comment.