2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-15 18:12:54 +00:00
This commit is contained in:
Roger Yang 2021-01-27 12:46:16 -05:00 committed by GitHub
parent fffc904ad3
commit bca2e3558d
4 changed files with 94 additions and 0 deletions

View File

@ -205,6 +205,9 @@ sealed class Event {
object ContextMenuSelectAllTapped : Event() object ContextMenuSelectAllTapped : Event()
object ContextMenuShareTapped : Event() object ContextMenuShareTapped : Event()
object HaveTopSites : Event()
object HaveNoTopSites : Event()
// Interaction events with extras // Interaction events with extras
data class TopSiteSwipeCarousel(val page: Int) : Event() { data class TopSiteSwipeCarousel(val page: Int) : Event() {

View File

@ -726,6 +726,12 @@ private val Event.wrapper: EventWrapper<*>?
Event.HaveNoOpenTabs -> EventWrapper<NoExtraKeys>( Event.HaveNoOpenTabs -> EventWrapper<NoExtraKeys>(
{ Metrics.hasOpenTabs.set(false) } { 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: // Don't record other events in Glean:
is Event.AddBookmark -> null is Event.AddBookmark -> null

View File

@ -22,6 +22,7 @@ import mozilla.components.feature.findinpage.facts.FindInPageFacts
import mozilla.components.feature.media.facts.MediaFacts import mozilla.components.feature.media.facts.MediaFacts
import mozilla.components.feature.prompts.dialog.LoginDialogFacts import mozilla.components.feature.prompts.dialog.LoginDialogFacts
import mozilla.components.feature.pwa.ProgressiveWebAppFacts 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.Component
import mozilla.components.support.base.facts.Action import mozilla.components.support.base.facts.Action
import mozilla.components.support.base.facts.Fact 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 isInitialized(type: MetricServiceType): Boolean = initialized.contains(type)
private fun isTelemetryEnabled(type: MetricServiceType): Boolean = when (type) { private fun isTelemetryEnabled(type: MetricServiceType): Boolean = when (type) {
@ -242,6 +250,23 @@ internal class ReleaseMetricController(
Component.FEATURE_PWA to ProgressiveWebAppFacts.Items.INSTALL_SHORTCUT -> { Component.FEATURE_PWA to ProgressiveWebAppFacts.Items.INSTALL_SHORTCUT -> {
Event.ProgressiveWebAppInstallAsShortcut 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 else -> null
} }

View File

@ -10,7 +10,12 @@ import io.mockk.impl.annotations.MockK
import io.mockk.mockk import io.mockk.mockk
import io.mockk.verify import io.mockk.verify
import io.mockk.verifyAll 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 mozilla.components.support.base.log.logger.Logger
import org.junit.Assert.assertEquals
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
@ -167,4 +172,59 @@ class MetricControllerTest {
controller.track(Event.TabMediaPause) controller.track(Event.TabMediaPause)
verify { marketingService1.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)
}
} }