mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-15 18:12:54 +00:00
[fenix] Closes https://github.com/mozilla-mobile/fenix/issues/17531: Use top sites count fact for top sites telemetry (https://github.com/mozilla-mobile/fenix/pull/17664)
This commit is contained in:
parent
fffc904ad3
commit
bca2e3558d
@ -205,6 +205,9 @@ sealed class Event {
|
||||
object ContextMenuSelectAllTapped : Event()
|
||||
object ContextMenuShareTapped : Event()
|
||||
|
||||
object HaveTopSites : Event()
|
||||
object HaveNoTopSites : Event()
|
||||
|
||||
// Interaction events with extras
|
||||
|
||||
data class TopSiteSwipeCarousel(val page: Int) : Event() {
|
||||
|
@ -726,6 +726,12 @@ private val Event.wrapper: EventWrapper<*>?
|
||||
Event.HaveNoOpenTabs -> EventWrapper<NoExtraKeys>(
|
||||
{ Metrics.hasOpenTabs.set(false) }
|
||||
)
|
||||
Event.HaveTopSites -> EventWrapper<NoExtraKeys>(
|
||||
{ Metrics.hasTopSites.set(true) }
|
||||
)
|
||||
Event.HaveNoTopSites -> EventWrapper<NoExtraKeys>(
|
||||
{ Metrics.hasTopSites.set(false) }
|
||||
)
|
||||
|
||||
// Don't record other events in Glean:
|
||||
is Event.AddBookmark -> null
|
||||
|
@ -22,6 +22,7 @@ import mozilla.components.feature.findinpage.facts.FindInPageFacts
|
||||
import mozilla.components.feature.media.facts.MediaFacts
|
||||
import mozilla.components.feature.prompts.dialog.LoginDialogFacts
|
||||
import mozilla.components.feature.pwa.ProgressiveWebAppFacts
|
||||
import mozilla.components.feature.top.sites.facts.TopSitesFacts
|
||||
import mozilla.components.support.base.Component
|
||||
import mozilla.components.support.base.facts.Action
|
||||
import mozilla.components.support.base.facts.Fact
|
||||
@ -134,6 +135,13 @@ internal class ReleaseMetricController(
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
internal fun factToEvent(
|
||||
fact: Fact
|
||||
): Event? {
|
||||
return fact.toEvent()
|
||||
}
|
||||
|
||||
private fun isInitialized(type: MetricServiceType): Boolean = initialized.contains(type)
|
||||
|
||||
private fun isTelemetryEnabled(type: MetricServiceType): Boolean = when (type) {
|
||||
@ -242,6 +250,23 @@ internal class ReleaseMetricController(
|
||||
Component.FEATURE_PWA to ProgressiveWebAppFacts.Items.INSTALL_SHORTCUT -> {
|
||||
Event.ProgressiveWebAppInstallAsShortcut
|
||||
}
|
||||
Component.FEATURE_TOP_SITES to TopSitesFacts.Items.COUNT -> {
|
||||
value?.let {
|
||||
var count = 0
|
||||
try {
|
||||
count = it.toInt()
|
||||
} catch (e: NumberFormatException) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
return if (count > 0) {
|
||||
Event.HaveTopSites
|
||||
} else {
|
||||
Event.HaveNoTopSites
|
||||
}
|
||||
}
|
||||
null
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,12 @@ import io.mockk.impl.annotations.MockK
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import io.mockk.verifyAll
|
||||
import mozilla.components.feature.top.sites.facts.TopSitesFacts
|
||||
import mozilla.components.support.base.Component
|
||||
import mozilla.components.support.base.facts.Action
|
||||
import mozilla.components.support.base.facts.Fact
|
||||
import mozilla.components.support.base.log.logger.Logger
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
@ -167,4 +172,59 @@ class MetricControllerTest {
|
||||
controller.track(Event.TabMediaPause)
|
||||
verify { marketingService1.track(Event.TabMediaPause) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `topsites fact should convert to the right events`() {
|
||||
var enabled = true
|
||||
val controller = ReleaseMetricController(
|
||||
services = listOf(dataService1),
|
||||
isDataTelemetryEnabled = { enabled },
|
||||
isMarketingDataTelemetryEnabled = { enabled }
|
||||
)
|
||||
|
||||
var fact = Fact(
|
||||
Component.FEATURE_TOP_SITES,
|
||||
Action.INTERACTION,
|
||||
TopSitesFacts.Items.COUNT,
|
||||
"1"
|
||||
)
|
||||
|
||||
assertEquals(controller.factToEvent(fact), Event.HaveTopSites)
|
||||
|
||||
fact = Fact(
|
||||
Component.FEATURE_TOP_SITES,
|
||||
Action.INTERACTION,
|
||||
TopSitesFacts.Items.COUNT,
|
||||
"0"
|
||||
)
|
||||
|
||||
assertEquals(controller.factToEvent(fact), Event.HaveNoTopSites)
|
||||
|
||||
fact = Fact(
|
||||
Component.FEATURE_TOP_SITES,
|
||||
Action.INTERACTION,
|
||||
TopSitesFacts.Items.COUNT,
|
||||
"10"
|
||||
)
|
||||
|
||||
assertEquals(controller.factToEvent(fact), Event.HaveTopSites)
|
||||
|
||||
fact = Fact(
|
||||
Component.FEATURE_TOP_SITES,
|
||||
Action.INTERACTION,
|
||||
TopSitesFacts.Items.COUNT,
|
||||
"-4"
|
||||
)
|
||||
|
||||
assertEquals(controller.factToEvent(fact), Event.HaveNoTopSites)
|
||||
|
||||
fact = Fact(
|
||||
Component.FEATURE_TOP_SITES,
|
||||
Action.INTERACTION,
|
||||
TopSitesFacts.Items.COUNT,
|
||||
"test"
|
||||
)
|
||||
|
||||
assertEquals(controller.factToEvent(fact), Event.HaveNoTopSites)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user