2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-11 13:11:01 +00:00

For #24711: Remove wrapper from recent tabs metrics.

This commit is contained in:
mcarare 2022-04-13 11:48:35 +03:00 committed by mergify[bot]
parent 5d72e42e5e
commit b8a59b2602
6 changed files with 74 additions and 57 deletions

View File

@ -48,13 +48,6 @@ sealed class Event {
object StartOnHomeEnterHomeScreen : Event() object StartOnHomeEnterHomeScreen : Event()
object StartOnHomeOpenTabsTray : Event() object StartOnHomeOpenTabsTray : Event()
// Recent tabs
object ShowAllRecentTabs : Event()
object OpenRecentTab : Event()
object OpenInProgressMediaTab : Event()
object RecentTabsSectionIsVisible : Event()
object RecentTabsSectionIsNotVisible : Event()
// Recent bookmarks // Recent bookmarks
object BookmarkClicked : Event() object BookmarkClicked : Event()
object ShowAllBookmarks : Event() object ShowAllBookmarks : Event()

View File

@ -19,7 +19,6 @@ import org.mozilla.fenix.GleanMetrics.Pings
import org.mozilla.fenix.GleanMetrics.ProgressiveWebApp import org.mozilla.fenix.GleanMetrics.ProgressiveWebApp
import org.mozilla.fenix.GleanMetrics.RecentBookmarks import org.mozilla.fenix.GleanMetrics.RecentBookmarks
import org.mozilla.fenix.GleanMetrics.RecentSearches import org.mozilla.fenix.GleanMetrics.RecentSearches
import org.mozilla.fenix.GleanMetrics.RecentTabs
import org.mozilla.fenix.GleanMetrics.RecentlyVisitedHomepage import org.mozilla.fenix.GleanMetrics.RecentlyVisitedHomepage
import org.mozilla.fenix.GleanMetrics.SearchTerms import org.mozilla.fenix.GleanMetrics.SearchTerms
import org.mozilla.fenix.GleanMetrics.StartOnHome import org.mozilla.fenix.GleanMetrics.StartOnHome
@ -160,26 +159,6 @@ private val Event.wrapper: EventWrapper<*>?
{ StartOnHome.openTabsTray.record(it) } { StartOnHome.openTabsTray.record(it) }
) )
is Event.OpenRecentTab -> EventWrapper<NoExtraKeys>(
{ RecentTabs.recentTabOpened.record(it) }
)
is Event.OpenInProgressMediaTab -> EventWrapper<NoExtraKeys>(
{ RecentTabs.inProgressMediaTabOpened.record(it) }
)
is Event.ShowAllRecentTabs -> EventWrapper<NoExtraKeys>(
{ RecentTabs.showAllClicked.record(it) }
)
is Event.RecentTabsSectionIsVisible -> EventWrapper<NoExtraKeys>(
{ RecentTabs.sectionVisible.set(true) }
)
is Event.RecentTabsSectionIsNotVisible -> EventWrapper<NoExtraKeys>(
{ RecentTabs.sectionVisible.set(false) }
)
is Event.BookmarkClicked -> EventWrapper<NoExtraKeys>( is Event.BookmarkClicked -> EventWrapper<NoExtraKeys>(
{ RecentBookmarks.bookmarkClicked.add() } { RecentBookmarks.bookmarkClicked.add() }
) )

View File

@ -9,6 +9,7 @@ import androidx.annotation.VisibleForTesting.PRIVATE
import androidx.navigation.NavController import androidx.navigation.NavController
import mozilla.components.browser.state.store.BrowserStore import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.feature.tabs.TabsUseCases.SelectTabUseCase import mozilla.components.feature.tabs.TabsUseCases.SelectTabUseCase
import mozilla.components.service.glean.private.NoExtras
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.components.AppStore import org.mozilla.fenix.components.AppStore
import org.mozilla.fenix.components.appstate.AppAction import org.mozilla.fenix.components.appstate.AppAction
@ -18,6 +19,7 @@ import org.mozilla.fenix.ext.inProgressMediaTab
import org.mozilla.fenix.home.HomeFragmentDirections import org.mozilla.fenix.home.HomeFragmentDirections
import org.mozilla.fenix.home.recenttabs.RecentTab import org.mozilla.fenix.home.recenttabs.RecentTab
import org.mozilla.fenix.home.recenttabs.interactor.RecentTabInteractor import org.mozilla.fenix.home.recenttabs.interactor.RecentTabInteractor
import org.mozilla.fenix.GleanMetrics.RecentTabs as RecentTabs
/** /**
* An interface that handles the view manipulation of the recent tabs in the Home screen. * An interface that handles the view manipulation of the recent tabs in the Home screen.
@ -61,9 +63,9 @@ class DefaultRecentTabsController(
override fun handleRecentTabClicked(tabId: String) { override fun handleRecentTabClicked(tabId: String) {
if (tabId == store.state.inProgressMediaTab?.id) { if (tabId == store.state.inProgressMediaTab?.id) {
metrics.track(Event.OpenInProgressMediaTab) RecentTabs.inProgressMediaTabOpened.record(NoExtras())
} else { } else {
metrics.track(Event.OpenRecentTab) RecentTabs.recentTabOpened.record(NoExtras())
} }
selectTabUseCase.invoke(tabId) selectTabUseCase.invoke(tabId)
@ -72,7 +74,7 @@ class DefaultRecentTabsController(
override fun handleRecentTabShowAllClicked() { override fun handleRecentTabShowAllClicked() {
dismissSearchDialogIfDisplayed() dismissSearchDialogIfDisplayed()
metrics.track(Event.ShowAllRecentTabs) RecentTabs.showAllClicked.record(NoExtras())
navController.navigate(HomeFragmentDirections.actionGlobalTabsTrayFragment()) navController.navigate(HomeFragmentDirections.actionGlobalTabsTrayFragment())
} }

View File

@ -35,6 +35,7 @@ import org.mozilla.fenix.GleanMetrics.Collections
import org.mozilla.fenix.GleanMetrics.Events import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.GleanMetrics.Pings import org.mozilla.fenix.GleanMetrics.Pings
import org.mozilla.fenix.GleanMetrics.Pocket import org.mozilla.fenix.GleanMetrics.Pocket
import org.mozilla.fenix.GleanMetrics.RecentTabs
import org.mozilla.fenix.GleanMetrics.TopSites import org.mozilla.fenix.GleanMetrics.TopSites
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R import org.mozilla.fenix.R
@ -647,16 +648,12 @@ class DefaultSessionControlController(
} }
override fun handleReportSessionMetrics(state: AppState) { override fun handleReportSessionMetrics(state: AppState) {
with(metrics) { if (state.recentTabs.isEmpty()) {
track( RecentTabs.sectionVisible.set(false)
if (state.recentTabs.isEmpty()) { } else {
Event.RecentTabsSectionIsNotVisible RecentTabs.sectionVisible.set(true)
} else {
Event.RecentTabsSectionIsVisible
}
)
track(Event.RecentBookmarkCount(state.recentBookmarks.size))
} }
metrics.track(Event.RecentBookmarkCount(state.recentBookmarks.size))
} }
} }

View File

@ -51,6 +51,7 @@ import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.GleanMetrics.Collections import org.mozilla.fenix.GleanMetrics.Collections
import org.mozilla.fenix.GleanMetrics.Events import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.GleanMetrics.Pings import org.mozilla.fenix.GleanMetrics.Pings
import org.mozilla.fenix.GleanMetrics.RecentTabs
import org.mozilla.fenix.GleanMetrics.TopSites import org.mozilla.fenix.GleanMetrics.TopSites
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R import org.mozilla.fenix.R
@ -1102,27 +1103,24 @@ class DefaultSessionControlControllerTest {
@Test @Test
fun `WHEN handleReportSessionMetrics is called AND there are zero recent tabs THEN report Event#RecentTabsSectionIsNotVisible`() { fun `WHEN handleReportSessionMetrics is called AND there are zero recent tabs THEN report Event#RecentTabsSectionIsNotVisible`() {
assertFalse(RecentTabs.sectionVisible.testHasValue())
every { appState.recentTabs } returns emptyList() every { appState.recentTabs } returns emptyList()
createController().handleReportSessionMetrics(appState) createController().handleReportSessionMetrics(appState)
verify(exactly = 0) { assertTrue(RecentTabs.sectionVisible.testHasValue())
metrics.track(Event.RecentTabsSectionIsVisible) assertFalse(RecentTabs.sectionVisible.testGetValue())
}
verify {
metrics.track(Event.RecentTabsSectionIsNotVisible)
}
} }
@Test @Test
fun `WHEN handleReportSessionMetrics is called AND there is at least one recent tab THEN report Event#RecentTabsSectionIsVisible`() { fun `WHEN handleReportSessionMetrics is called AND there is at least one recent tab THEN report Event#RecentTabsSectionIsVisible`() {
assertFalse(RecentTabs.sectionVisible.testHasValue())
val recentTab: RecentTab = mockk(relaxed = true) val recentTab: RecentTab = mockk(relaxed = true)
every { appState.recentTabs } returns listOf(recentTab) every { appState.recentTabs } returns listOf(recentTab)
createController().handleReportSessionMetrics(appState) createController().handleReportSessionMetrics(appState)
verify(exactly = 0) {
metrics.track(Event.RecentTabsSectionIsNotVisible) assertTrue(RecentTabs.sectionVisible.testHasValue())
} assertTrue(RecentTabs.sectionVisible.testGetValue())
verify {
metrics.track(Event.RecentTabsSectionIsVisible)
}
} }
@Test @Test

View File

@ -13,25 +13,36 @@ import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.components.browser.state.action.TabListAction import mozilla.components.browser.state.action.TabListAction
import mozilla.components.browser.state.state.BrowserState import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.LastMediaAccessState
import mozilla.components.browser.state.state.createTab import mozilla.components.browser.state.state.createTab
import mozilla.components.browser.state.store.BrowserStore import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.feature.tabs.TabsUseCases import mozilla.components.feature.tabs.TabsUseCases
import mozilla.components.support.test.ext.joinBlocking import mozilla.components.support.test.ext.joinBlocking
import mozilla.components.support.test.robolectric.testContext
import mozilla.components.support.test.rule.MainCoroutineRule import mozilla.components.support.test.rule.MainCoroutineRule
import mozilla.telemetry.glean.testing.GleanTestRule
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.GleanMetrics.RecentTabs
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.components.AppStore import org.mozilla.fenix.components.AppStore
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@OptIn(ExperimentalCoroutinesApi::class) @OptIn(ExperimentalCoroutinesApi::class)
@RunWith(FenixRobolectricTestRunner::class)
class RecentTabControllerTest { class RecentTabControllerTest {
@get:Rule @get:Rule
val coroutinesTestRule = MainCoroutineRule() val coroutinesTestRule = MainCoroutineRule()
@get:Rule
val gleanTestRule = GleanTestRule(testContext)
private val navController: NavController = mockk(relaxed = true) private val navController: NavController = mockk(relaxed = true)
private val selectTabUseCase: TabsUseCases = mockk(relaxed = true) private val selectTabUseCase: TabsUseCases = mockk(relaxed = true)
private val metrics: MetricController = mockk(relaxed = true) private val metrics: MetricController = mockk(relaxed = true)
@ -60,6 +71,9 @@ class RecentTabControllerTest {
@Test @Test
fun handleRecentTabClicked() { fun handleRecentTabClicked() {
assertFalse(RecentTabs.recentTabOpened.testHasValue())
assertFalse(RecentTabs.inProgressMediaTabOpened.testHasValue())
every { navController.currentDestination } returns mockk { every { navController.currentDestination } returns mockk {
every { id } returns R.id.homeFragment every { id } returns R.id.homeFragment
} }
@ -76,12 +90,42 @@ class RecentTabControllerTest {
verify { verify {
selectTabUseCase.selectTab.invoke(tab.id) selectTabUseCase.selectTab.invoke(tab.id)
navController.navigate(R.id.browserFragment) navController.navigate(R.id.browserFragment)
metrics.track(Event.OpenRecentTab)
} }
assertTrue(RecentTabs.recentTabOpened.testHasValue())
assertFalse(RecentTabs.inProgressMediaTabOpened.testHasValue())
}
@Test
fun handleRecentTabClickedForMediaTab() {
assertFalse(RecentTabs.recentTabOpened.testHasValue())
assertFalse(RecentTabs.inProgressMediaTabOpened.testHasValue())
every { navController.currentDestination } returns mockk {
every { id } returns R.id.homeFragment
}
val inProgressMediaTab = createTab(
url = "mediaUrl", id = "2",
lastMediaAccessState = LastMediaAccessState("https://mozilla.com", 123, true)
)
store.dispatch(TabListAction.AddTabAction(inProgressMediaTab)).joinBlocking()
store.dispatch(TabListAction.SelectTabAction(inProgressMediaTab.id)).joinBlocking()
controller.handleRecentTabClicked(inProgressMediaTab.id)
verify {
selectTabUseCase.selectTab.invoke(inProgressMediaTab.id)
navController.navigate(R.id.browserFragment)
}
assertFalse(RecentTabs.recentTabOpened.testHasValue())
assertTrue(RecentTabs.inProgressMediaTabOpened.testHasValue())
} }
@Test @Test
fun handleRecentTabShowAllClickedFromHome() { fun handleRecentTabShowAllClickedFromHome() {
assertFalse(RecentTabs.showAllClicked.testHasValue())
every { navController.currentDestination } returns mockk { every { navController.currentDestination } returns mockk {
every { id } returns R.id.homeFragment every { id } returns R.id.homeFragment
} }
@ -93,15 +137,18 @@ class RecentTabControllerTest {
navController.navigate( navController.navigate(
match<NavDirections> { it.actionId == R.id.action_global_tabsTrayFragment } match<NavDirections> { it.actionId == R.id.action_global_tabsTrayFragment }
) )
metrics.track(Event.ShowAllRecentTabs)
} }
verify(exactly = 0) { verify(exactly = 0) {
navController.navigateUp() navController.navigateUp()
} }
assertTrue(RecentTabs.showAllClicked.testHasValue())
} }
@Test @Test
fun handleRecentTabShowAllClickedFromSearchDialog() { fun handleRecentTabShowAllClickedFromSearchDialog() {
assertFalse(RecentTabs.showAllClicked.testHasValue())
every { navController.currentDestination } returns mockk { every { navController.currentDestination } returns mockk {
every { id } returns R.id.searchDialogFragment every { id } returns R.id.searchDialogFragment
} }
@ -114,7 +161,8 @@ class RecentTabControllerTest {
navController.navigate( navController.navigate(
match<NavDirections> { it.actionId == R.id.action_global_tabsTrayFragment } match<NavDirections> { it.actionId == R.id.action_global_tabsTrayFragment }
) )
metrics.track(Event.ShowAllRecentTabs)
} }
assertTrue(RecentTabs.showAllClicked.testHasValue())
} }
} }