diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt index 7f6593679e54..a8e65e518830 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt @@ -25,11 +25,6 @@ sealed class Event { object TabSettingsOpened : Event() - object ContextMenuCopyTapped : Event() - object ContextMenuSearchTapped : Event() - object ContextMenuSelectAllTapped : Event() - object ContextMenuShareTapped : Event() - object SyncedTabSuggestionClicked : Event() object BookmarkSuggestionClicked : Event() object ClipboardSuggestionClicked : Event() diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt index 978dd4792cda..f8f1a4f202bd 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt @@ -11,7 +11,6 @@ import mozilla.components.support.base.log.logger.Logger import org.mozilla.fenix.GleanMetrics.Autoplay import org.mozilla.fenix.GleanMetrics.Awesomebar import org.mozilla.fenix.GleanMetrics.BrowserSearch -import org.mozilla.fenix.GleanMetrics.ContextualMenu import org.mozilla.fenix.GleanMetrics.HomeMenu import org.mozilla.fenix.GleanMetrics.HomeScreen import org.mozilla.fenix.GleanMetrics.Pings @@ -101,18 +100,6 @@ private val Event.wrapper: EventWrapper<*>? is Event.TabSettingsOpened -> EventWrapper( { Tabs.settingOpened.record(it) } ) - Event.ContextMenuCopyTapped -> EventWrapper( - { ContextualMenu.copyTapped.record(it) } - ) - is Event.ContextMenuSearchTapped -> EventWrapper( - { ContextualMenu.searchTapped.record(it) } - ) - is Event.ContextMenuSelectAllTapped -> EventWrapper( - { ContextualMenu.selectAllTapped.record(it) } - ) - is Event.ContextMenuShareTapped -> EventWrapper( - { ContextualMenu.shareTapped.record(it) } - ) is Event.SyncedTabSuggestionClicked -> EventWrapper( { SyncedTabs.syncedTabsSuggestionClicked.record(it) } ) diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt index 9ef76bbfa575..62d85890f165 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt @@ -38,6 +38,7 @@ import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.GleanMetrics.Addons import org.mozilla.fenix.GleanMetrics.ContextMenu import org.mozilla.fenix.GleanMetrics.AndroidAutofill +import org.mozilla.fenix.GleanMetrics.ContextualMenu import org.mozilla.fenix.GleanMetrics.CreditCards import org.mozilla.fenix.GleanMetrics.CustomTab import org.mozilla.fenix.GleanMetrics.Events @@ -204,6 +205,16 @@ internal class ReleaseMetricController( AndroidAutofill.unlockCancelled.record(NoExtras()) } } + Component.FEATURE_CONTEXTMENU to ContextMenuFacts.Items.TEXT_SELECTION_OPTION -> { + when (metadata?.get("textSelectionOption")?.toString()) { + CONTEXT_MENU_COPY -> ContextualMenu.copyTapped.record(NoExtras()) + CONTEXT_MENU_SEARCH, + CONTEXT_MENU_SEARCH_PRIVATELY -> ContextualMenu.searchTapped.record(NoExtras()) + CONTEXT_MENU_SELECT_ALL -> ContextualMenu.selectAllTapped.record(NoExtras()) + CONTEXT_MENU_SHARE -> ContextualMenu.shareTapped.record(NoExtras()) + else -> Unit + } + } else -> { this.toEvent()?.also { @@ -271,16 +282,6 @@ internal class ReleaseMetricController( @Suppress("LongMethod", "MaxLineLength") private fun Fact.toEvent(): Event? = when { - Component.FEATURE_CONTEXTMENU == component && ContextMenuFacts.Items.TEXT_SELECTION_OPTION == item -> { - when (metadata?.get("textSelectionOption")?.toString()) { - CONTEXT_MENU_COPY -> Event.ContextMenuCopyTapped - CONTEXT_MENU_SEARCH, CONTEXT_MENU_SEARCH_PRIVATELY -> Event.ContextMenuSearchTapped - CONTEXT_MENU_SELECT_ALL -> Event.ContextMenuSelectAllTapped - CONTEXT_MENU_SHARE -> Event.ContextMenuShareTapped - else -> null - } - } - Component.SUPPORT_WEBEXTENSIONS == component && WebExtensionFacts.Items.WEB_EXTENSIONS_INITIALIZED == item -> { metadata?.get("installed")?.let { installedAddons -> if (installedAddons is List<*>) { diff --git a/app/src/test/java/org/mozilla/fenix/components/metrics/MetricControllerTest.kt b/app/src/test/java/org/mozilla/fenix/components/metrics/MetricControllerTest.kt index 9db90a463ecf..d2d3b70f6f83 100644 --- a/app/src/test/java/org/mozilla/fenix/components/metrics/MetricControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/metrics/MetricControllerTest.kt @@ -13,6 +13,7 @@ import io.mockk.verifyAll import mozilla.components.browser.toolbar.facts.ToolbarFacts import mozilla.components.feature.autofill.facts.AutofillFacts import mozilla.components.feature.awesomebar.facts.AwesomeBarFacts +import mozilla.components.feature.contextmenu.facts.ContextMenuFacts import mozilla.components.feature.customtabs.CustomTabsFacts import mozilla.components.feature.media.facts.MediaFacts import mozilla.components.feature.prompts.dialog.LoginDialogFacts @@ -35,10 +36,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mozilla.fenix.GleanMetrics.AndroidAutofill +import org.mozilla.fenix.GleanMetrics.ContextualMenu 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.components.metrics.ReleaseMetricController.Companion import org.mozilla.fenix.helpers.FenixRobolectricTestRunner import org.mozilla.fenix.utils.Settings @@ -469,6 +472,34 @@ class MetricControllerTest { } } + @Test + fun `WHEN processing a ContextualMenu fact THEN the right metric is recorded`() { + val controller = ReleaseMetricController(emptyList(), { true }, { true }, mockk()) + + val longPressItemsToEvents = listOf( + Companion.CONTEXT_MENU_COPY to ContextualMenu.copyTapped, + Companion.CONTEXT_MENU_SEARCH to ContextualMenu.searchTapped, + Companion.CONTEXT_MENU_SELECT_ALL to ContextualMenu.selectAllTapped, + Companion.CONTEXT_MENU_SHARE to ContextualMenu.shareTapped, + ) + + longPressItemsToEvents.forEach { (item, event) -> + val fact = Fact( + Component.FEATURE_CONTEXTMENU, + mockk(), + ContextMenuFacts.Items.TEXT_SELECTION_OPTION, + metadata = mapOf("textSelectionOption" to item) + ) + with(controller) { + fact.process() + } + + assertEquals(true, event.testHasValue()) + assertEquals(1, event.testGetValue().size) + assertEquals(null, event.testGetValue().single().extra) + } + } + @Test fun `WHEN processing a CreditCardAutofillDialog fact THEN the right metric is recorded`() { val controller = ReleaseMetricController(emptyList(), { true }, { true }, mockk())