Skip to content

Commit

Permalink
For mozilla-mobile#24789: Remove wrapper from PWA metrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarare committed Apr 15, 2022
1 parent 62b89da commit 6185ed0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ sealed class Event {
object HistorySearchGroupOpened : Event()
object SearchWidgetInstalled : Event()

object ProgressiveWebAppOpenFromHomescreenTap : Event()
object ProgressiveWebAppInstallAsShortcut : Event()

object TabSettingsOpened : Event()

object SyncedTabSuggestionClicked : Event()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.mozilla.fenix.GleanMetrics.BrowserSearch
import org.mozilla.fenix.GleanMetrics.HomeMenu
import org.mozilla.fenix.GleanMetrics.HomeScreen
import org.mozilla.fenix.GleanMetrics.Pings
import org.mozilla.fenix.GleanMetrics.ProgressiveWebApp
import org.mozilla.fenix.GleanMetrics.RecentlyVisitedHomepage
import org.mozilla.fenix.GleanMetrics.StartOnHome
import org.mozilla.fenix.GleanMetrics.SyncedTabs
Expand Down Expand Up @@ -80,13 +79,6 @@ private val Event.wrapper: EventWrapper<*>?
}
)

is Event.ProgressiveWebAppOpenFromHomescreenTap -> EventWrapper<NoExtraKeys>(
{ ProgressiveWebApp.homescreenTap.record(it) }
)
is Event.ProgressiveWebAppInstallAsShortcut -> EventWrapper<NoExtraKeys>(
{ ProgressiveWebApp.installTap.record(it) }
)

is Event.TabSettingsOpened -> EventWrapper<NoExtraKeys>(
{ Tabs.settingOpened.record(it) }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import org.mozilla.fenix.GleanMetrics.LoginDialog
import org.mozilla.fenix.GleanMetrics.MediaNotification
import org.mozilla.fenix.GleanMetrics.MediaState
import org.mozilla.fenix.GleanMetrics.PerfAwesomebar
import org.mozilla.fenix.GleanMetrics.ProgressiveWebApp
import org.mozilla.fenix.search.awesomebar.ShortcutsSuggestionProvider
import org.mozilla.fenix.utils.Settings

Expand Down Expand Up @@ -216,6 +217,13 @@ internal class ReleaseMetricController(
}
}

Component.FEATURE_PWA to ProgressiveWebAppFacts.Items.HOMESCREEN_ICON_TAP -> {
ProgressiveWebApp.homescreenTap.record(NoExtras())
}
Component.FEATURE_PWA to ProgressiveWebAppFacts.Items.INSTALL_SHORTCUT -> {
ProgressiveWebApp.installTap.record(NoExtras())
}

else -> {
this.toEvent()?.also {
track(it)
Expand Down Expand Up @@ -318,12 +326,7 @@ internal class ReleaseMetricController(
}
null
}
Component.FEATURE_PWA == component && ProgressiveWebAppFacts.Items.HOMESCREEN_ICON_TAP == item -> {
Event.ProgressiveWebAppOpenFromHomescreenTap
}
Component.FEATURE_PWA == component && ProgressiveWebAppFacts.Items.INSTALL_SHORTCUT == item -> {
Event.ProgressiveWebAppInstallAsShortcut
}

Component.FEATURE_TOP_SITES == component && TopSitesFacts.Items.COUNT == item -> {
value?.let {
var count = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import org.mozilla.fenix.GleanMetrics.CreditCards
import org.mozilla.fenix.GleanMetrics.CustomTab
import org.mozilla.fenix.GleanMetrics.LoginDialog
import org.mozilla.fenix.GleanMetrics.MediaNotification
import org.mozilla.fenix.GleanMetrics.ProgressiveWebApp
import org.mozilla.fenix.components.metrics.ReleaseMetricController.Companion
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.utils.Settings
Expand Down Expand Up @@ -285,8 +286,6 @@ class MetricControllerTest {

val simpleMappings = listOf(
// CreditCardAutofillDialogFacts.Items is already tested.
Triple(Component.FEATURE_PWA, ProgressiveWebAppFacts.Items.HOMESCREEN_ICON_TAP, Event.ProgressiveWebAppOpenFromHomescreenTap),
Triple(Component.FEATURE_PWA, ProgressiveWebAppFacts.Items.INSTALL_SHORTCUT, Event.ProgressiveWebAppInstallAsShortcut),
Triple(Component.FEATURE_SYNCEDTABS, SyncedTabsFacts.Items.SYNCED_TABS_SUGGESTION_CLICKED, Event.SyncedTabSuggestionClicked),
Triple(Component.FEATURE_AWESOMEBAR, AwesomeBarFacts.Items.BOOKMARK_SUGGESTION_CLICKED, Event.BookmarkSuggestionClicked),
Triple(Component.FEATURE_AWESOMEBAR, AwesomeBarFacts.Items.CLIPBOARD_SUGGESTION_CLICKED, Event.ClipboardSuggestionClicked),
Expand Down Expand Up @@ -500,4 +499,38 @@ class MetricControllerTest {
assertEquals(null, event.testGetValue().single().extra)
}
}

@Test
fun `GIVEN pwa facts WHEN they are processed THEN the right metric is recorded`() {
val controller = ReleaseMetricController(emptyList(), { true }, { true }, mockk())
val action = mockk<Action>(relaxed = true)

// a PWA shortcut from homescreen was opened
val openPWA = Fact(
Component.FEATURE_PWA,
action,
ProgressiveWebAppFacts.Items.HOMESCREEN_ICON_TAP,
)

assertFalse(ProgressiveWebApp.homescreenTap.testHasValue())
controller.run {
openPWA.process()
}
assertTrue(ProgressiveWebApp.homescreenTap.testHasValue())

// a PWA shortcut was installed
val installPWA = Fact(
Component.FEATURE_PWA,
action,
ProgressiveWebAppFacts.Items.INSTALL_SHORTCUT,
)

assertFalse(ProgressiveWebApp.installTap.testHasValue())

controller.run {
installPWA.process()
}

assertTrue(ProgressiveWebApp.installTap.testHasValue())
}
}
2 changes: 0 additions & 2 deletions detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,6 @@
<ID>UndocumentedPublicClass:Event.kt$Event$PocketTopSiteClicked : Event</ID>
<ID>UndocumentedPublicClass:Event.kt$Event$PocketTopSiteRemoved : Event</ID>
<ID>UndocumentedPublicClass:Event.kt$Event$PreferenceToggled : Event</ID>
<ID>UndocumentedPublicClass:Event.kt$Event$ProgressiveWebAppInstallAsShortcut : Event</ID>
<ID>UndocumentedPublicClass:Event.kt$Event$ProgressiveWebAppOpenFromHomescreenTap : Event</ID>
<ID>UndocumentedPublicClass:Event.kt$Event$ReaderModeAppearanceOpened : Event</ID>
<ID>UndocumentedPublicClass:Event.kt$Event$ReaderModeAvailable : Event</ID>
<ID>UndocumentedPublicClass:Event.kt$Event$ReaderModeClosed : Event</ID>
Expand Down

0 comments on commit 6185ed0

Please sign in to comment.