Skip to content

Commit

Permalink
For mozilla-mobile#24759 - Remove Event.wrapper for text selection co…
Browse files Browse the repository at this point in the history
…ntext menu telemetry
  • Loading branch information
Alexandru2909 authored and mergify[bot] committed Apr 14, 2022
1 parent 1051a98 commit dea0145
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -101,18 +100,6 @@ private val Event.wrapper: EventWrapper<*>?
is Event.TabSettingsOpened -> EventWrapper<NoExtraKeys>(
{ Tabs.settingOpened.record(it) }
)
Event.ContextMenuCopyTapped -> EventWrapper<NoExtraKeys>(
{ ContextualMenu.copyTapped.record(it) }
)
is Event.ContextMenuSearchTapped -> EventWrapper<NoExtraKeys>(
{ ContextualMenu.searchTapped.record(it) }
)
is Event.ContextMenuSelectAllTapped -> EventWrapper<NoExtraKeys>(
{ ContextualMenu.selectAllTapped.record(it) }
)
is Event.ContextMenuShareTapped -> EventWrapper<NoExtraKeys>(
{ ContextualMenu.shareTapped.record(it) }
)
is Event.SyncedTabSuggestionClicked -> EventWrapper<NoExtraKeys>(
{ SyncedTabs.syncedTabsSuggestionClicked.record(it) }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<*>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit dea0145

Please sign in to comment.