From 8106fb3d15a48a1797101e3c5327a3153f546970 Mon Sep 17 00:00:00 2001 From: Alexandru2909 Date: Fri, 18 Mar 2022 09:49:44 +0200 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/24203 - Remove Event.wrapper for Onboarding telemetry --- app/metrics.yaml | 3 ++ .../mozilla/fenix/components/metrics/Event.kt | 26 ----------- .../components/metrics/GleanMetricsService.kt | 25 ----------- .../onboarding/OnboardingFinishViewHolder.kt | 6 +-- .../OnboardingManualSignInViewHolder.kt | 6 +-- .../OnboardingPrivacyNoticeViewHolder.kt | 6 +-- .../OnboardingThemePickerViewHolder.kt | 45 ++++++++++++++----- ...boardingToolbarPositionPickerViewHolder.kt | 31 +++++++++---- .../OnboardingTrackingProtectionViewHolder.kt | 19 +++++--- .../OnboardingFinishViewHolderTest.kt | 13 ++++++ .../OnboardingManualSignInViewHolderTest.kt | 11 +++++ .../OnboardingPrivacyNoticeViewHolderTest.kt | 13 ++++++ ...dingToolbarPositionPickerViewHolderTest.kt | 37 +++++++++++++++ 13 files changed, 155 insertions(+), 86 deletions(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index 3369c3a9a2..16102e930e 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -507,6 +507,7 @@ onboarding: The toolbar position preference was chosen from the onboarding card. extra_keys: position: + type: string description: | A string that indicates the position of the toolbar TOP or BOTTOM. Default: BOTTOM @@ -534,6 +535,7 @@ onboarding: The tracking protection preference was chosen from the onboarding card. extra_keys: setting: + type: string description: | A string that indicates the Tracking Protection policy STANDARD or STRICT. Default: Toggle ON, STANDARD @@ -561,6 +563,7 @@ onboarding: The device theme was chosen using the theme picker onboarding card. extra_keys: theme: + type: string description: | A string that indicates the theme LIGHT, DARK, or FOLLOW DEVICE. Default: FOLLOW DEVICE 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 6b27612184..4d805f2a8c 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 @@ -17,7 +17,6 @@ import org.mozilla.fenix.GleanMetrics.ErrorPage import org.mozilla.fenix.GleanMetrics.Events import org.mozilla.fenix.GleanMetrics.History import org.mozilla.fenix.GleanMetrics.Logins -import org.mozilla.fenix.GleanMetrics.Onboarding import org.mozilla.fenix.GleanMetrics.Pocket import org.mozilla.fenix.GleanMetrics.SearchShortcuts import org.mozilla.fenix.GleanMetrics.SearchTerms @@ -183,10 +182,6 @@ sealed class Event { object StudiesSettings : Event() object VoiceSearchTapped : Event() object SearchWidgetInstalled : Event() - object OnboardingAutoSignIn : Event() - object OnboardingManualSignIn : Event() - object OnboardingPrivacyNotice : Event() - object OnboardingFinish : Event() object ChangedToDefaultBrowser : Event() object DefaultBrowserNotifTapped : Event() @@ -296,27 +291,6 @@ sealed class Event { enum class Source { NEWTAB } } - data class OnboardingToolbarPosition(val position: Position) : Event() { - enum class Position { TOP, BOTTOM } - - override val extras: Map? - get() = hashMapOf(Onboarding.prefToggledToolbarPositionKeys.position to position.name) - } - - data class OnboardingTrackingProtection(val setting: Setting) : Event() { - enum class Setting { STRICT, STANDARD } - - override val extras: Map? - get() = hashMapOf(Onboarding.prefToggledTrackingProtKeys.setting to setting.name) - } - - data class OnboardingThemePicker(val theme: Theme) : Event() { - enum class Theme { LIGHT, DARK, FOLLOW_DEVICE } - - override val extras: Map? - get() = mapOf(Onboarding.prefToggledThemePickerKeys.theme to theme.name) - } - data class PreferenceToggled( val preferenceKey: String, val enabled: Boolean, 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 33dd17f264..dce2eac6e3 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 @@ -32,7 +32,6 @@ import org.mozilla.fenix.GleanMetrics.Logins import org.mozilla.fenix.GleanMetrics.MediaNotification import org.mozilla.fenix.GleanMetrics.MediaState import org.mozilla.fenix.GleanMetrics.Metrics -import org.mozilla.fenix.GleanMetrics.Onboarding import org.mozilla.fenix.GleanMetrics.Pings import org.mozilla.fenix.GleanMetrics.Pocket import org.mozilla.fenix.GleanMetrics.Preferences @@ -603,30 +602,6 @@ private val Event.wrapper: EventWrapper<*>? is Event.VoiceSearchTapped -> EventWrapper( { VoiceSearch.tapped.record(it) } ) - is Event.OnboardingPrivacyNotice -> EventWrapper( - { Onboarding.privacyNotice.record(it) } - ) - is Event.OnboardingManualSignIn -> EventWrapper( - { Onboarding.fxaManualSignin.record(it) } - ) - is Event.OnboardingAutoSignIn -> EventWrapper( - { Onboarding.fxaAutoSignin.record(it) } - ) - is Event.OnboardingFinish -> EventWrapper( - { Onboarding.finish.record(it) } - ) - is Event.OnboardingTrackingProtection -> EventWrapper( - { Onboarding.prefToggledTrackingProt.record(it) }, - { Onboarding.prefToggledTrackingProtKeys.valueOf(it) } - ) - is Event.OnboardingThemePicker -> EventWrapper( - { Onboarding.prefToggledThemePicker.record(it) }, - { Onboarding.prefToggledThemePickerKeys.valueOf(it) } - ) - is Event.OnboardingToolbarPosition -> EventWrapper( - { Onboarding.prefToggledToolbarPosition.record(it) }, - { Onboarding.prefToggledToolbarPositionKeys.valueOf(it) } - ) is Event.AutoPlaySettingVisited -> EventWrapper( { Autoplay.visitedSetting.record(it) } diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingFinishViewHolder.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingFinishViewHolder.kt index a73c9903dc..abbd5b90c3 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingFinishViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingFinishViewHolder.kt @@ -6,10 +6,10 @@ package org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding import android.view.View import androidx.recyclerview.widget.RecyclerView +import mozilla.components.service.glean.private.NoExtras +import org.mozilla.fenix.GleanMetrics.Onboarding import org.mozilla.fenix.R -import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.databinding.OnboardingFinishBinding -import org.mozilla.fenix.ext.components import org.mozilla.fenix.home.sessioncontrol.OnboardingInteractor class OnboardingFinishViewHolder( @@ -21,7 +21,7 @@ class OnboardingFinishViewHolder( val binding = OnboardingFinishBinding.bind(view) binding.finishButton.setOnClickListener { interactor.onStartBrowsingClicked() - it.context.components.analytics.metrics.track(Event.OnboardingFinish) + Onboarding.finish.record(NoExtras()) } } diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingManualSignInViewHolder.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingManualSignInViewHolder.kt index cfcc86f37c..89f4e8db8e 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingManualSignInViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingManualSignInViewHolder.kt @@ -7,10 +7,10 @@ package org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding import android.view.View import androidx.navigation.Navigation import androidx.recyclerview.widget.RecyclerView +import mozilla.components.service.glean.private.NoExtras +import org.mozilla.fenix.GleanMetrics.Onboarding import org.mozilla.fenix.R -import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.databinding.OnboardingManualSigninBinding -import org.mozilla.fenix.ext.components import org.mozilla.fenix.home.HomeFragmentDirections class OnboardingManualSignInViewHolder(view: View) : RecyclerView.ViewHolder(view) { @@ -18,7 +18,7 @@ class OnboardingManualSignInViewHolder(view: View) : RecyclerView.ViewHolder(vie init { binding.fxaSignInButton.setOnClickListener { - it.context.components.analytics.metrics.track(Event.OnboardingManualSignIn) + Onboarding.fxaManualSignin.record(NoExtras()) val directions = HomeFragmentDirections.actionGlobalTurnOnSync() Navigation.findNavController(view).navigate(directions) diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingPrivacyNoticeViewHolder.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingPrivacyNoticeViewHolder.kt index 75f18eccca..3243adf575 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingPrivacyNoticeViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingPrivacyNoticeViewHolder.kt @@ -6,10 +6,10 @@ package org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding import android.view.View import androidx.recyclerview.widget.RecyclerView +import mozilla.components.service.glean.private.NoExtras +import org.mozilla.fenix.GleanMetrics.Onboarding import org.mozilla.fenix.R -import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.databinding.OnboardingPrivacyNoticeBinding -import org.mozilla.fenix.ext.components import org.mozilla.fenix.home.sessioncontrol.OnboardingInteractor class OnboardingPrivacyNoticeViewHolder( @@ -25,7 +25,7 @@ class OnboardingPrivacyNoticeViewHolder( binding.descriptionText.text = view.context.getString(R.string.onboarding_privacy_notice_description2, appName) binding.readButton.setOnClickListener { - it.context.components.analytics.metrics.track(Event.OnboardingPrivacyNotice) + Onboarding.privacyNotice.record(NoExtras()) interactor.onReadPrivacyNoticeClicked() } } diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingThemePickerViewHolder.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingThemePickerViewHolder.kt index c27632d94c..09f29af89b 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingThemePickerViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingThemePickerViewHolder.kt @@ -9,9 +9,8 @@ import android.os.Build.VERSION.SDK_INT import android.view.View import androidx.appcompat.app.AppCompatDelegate import androidx.recyclerview.widget.RecyclerView +import org.mozilla.fenix.GleanMetrics.Onboarding import org.mozilla.fenix.R -import org.mozilla.fenix.components.metrics.Event -import org.mozilla.fenix.components.metrics.Event.OnboardingThemePicker.Theme import org.mozilla.fenix.databinding.OnboardingThemePickerBinding import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.settings @@ -41,12 +40,20 @@ class OnboardingThemePickerViewHolder(view: View) : RecyclerView.ViewHolder(view radioDarkTheme.addIllustration(binding.themeDarkImage) binding.themeDarkImage.setOnClickListener { - it.context.components.analytics.metrics.track(Event.OnboardingThemePicker(Theme.DARK)) + Onboarding.prefToggledThemePicker.record( + Onboarding.PrefToggledThemePickerExtra( + Theme.DARK.name + ) + ) radioDarkTheme.performClick() } binding.themeLightImage.setOnClickListener { - it.context.components.analytics.metrics.track(Event.OnboardingThemePicker(Theme.LIGHT)) + Onboarding.prefToggledThemePicker.record( + Onboarding.PrefToggledThemePickerExtra( + Theme.LIGHT.name + ) + ) radioLightTheme.performClick() } @@ -55,26 +62,38 @@ class OnboardingThemePickerViewHolder(view: View) : RecyclerView.ViewHolder(view binding.clickableRegionAutomatic.contentDescription = "$automaticTitle $automaticSummary" binding.clickableRegionAutomatic.setOnClickListener { - it.context.components.analytics.metrics - .track(Event.OnboardingThemePicker(Theme.FOLLOW_DEVICE)) + Onboarding.prefToggledThemePicker.record( + Onboarding.PrefToggledThemePickerExtra( + Theme.FOLLOW_DEVICE.name + ) + ) radioFollowDeviceTheme.performClick() } radioLightTheme.onClickListener { - view.context.components.analytics.metrics - .track(Event.OnboardingThemePicker(Theme.LIGHT)) + Onboarding.prefToggledThemePicker.record( + Onboarding.PrefToggledThemePickerExtra( + Theme.LIGHT.name + ) + ) setNewTheme(AppCompatDelegate.MODE_NIGHT_NO) } radioDarkTheme.onClickListener { - view.context.components.analytics.metrics - .track(Event.OnboardingThemePicker(Theme.DARK)) + Onboarding.prefToggledThemePicker.record( + Onboarding.PrefToggledThemePickerExtra( + Theme.DARK.name + ) + ) setNewTheme(AppCompatDelegate.MODE_NIGHT_YES) } radioFollowDeviceTheme.onClickListener { - view.context.components.analytics.metrics - .track(Event.OnboardingThemePicker(Theme.FOLLOW_DEVICE)) + Onboarding.prefToggledThemePicker.record( + Onboarding.PrefToggledThemePickerExtra( + Theme.FOLLOW_DEVICE.name + ) + ) if (SDK_INT >= Build.VERSION_CODES.P) { setNewTheme(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) } else { @@ -109,5 +128,7 @@ class OnboardingThemePickerViewHolder(view: View) : RecyclerView.ViewHolder(view companion object { const val LAYOUT_ID = R.layout.onboarding_theme_picker + // The theme used for telemetry + enum class Theme { LIGHT, DARK, FOLLOW_DEVICE } } } diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingToolbarPositionPickerViewHolder.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingToolbarPositionPickerViewHolder.kt index 1c29bebea9..5285e77902 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingToolbarPositionPickerViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingToolbarPositionPickerViewHolder.kt @@ -6,9 +6,8 @@ package org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding import android.view.View import androidx.recyclerview.widget.RecyclerView +import org.mozilla.fenix.GleanMetrics.Onboarding import org.mozilla.fenix.R -import org.mozilla.fenix.components.metrics.Event -import org.mozilla.fenix.components.metrics.Event.OnboardingToolbarPosition.Position import org.mozilla.fenix.components.toolbar.ToolbarPosition import org.mozilla.fenix.databinding.OnboardingToolbarPositionPickerBinding import org.mozilla.fenix.ext.asActivity @@ -18,8 +17,6 @@ import org.mozilla.fenix.utils.view.addToRadioGroup class OnboardingToolbarPositionPickerViewHolder(view: View) : RecyclerView.ViewHolder(view) { - private val metrics = view.context.components.analytics.metrics - init { val binding = OnboardingToolbarPositionPickerBinding.bind(view) @@ -39,29 +36,47 @@ class OnboardingToolbarPositionPickerViewHolder(view: View) : RecyclerView.ViewH radio.updateRadioValue(true) radioBottomToolbar.onClickListener { - metrics.track(Event.OnboardingToolbarPosition(Position.BOTTOM)) + Onboarding.prefToggledToolbarPosition.record( + Onboarding.PrefToggledToolbarPositionExtra( + Position.BOTTOM.name + ) + ) itemView.context.asActivity()?.recreate() } binding.toolbarBottomImage.setOnClickListener { - metrics.track(Event.OnboardingToolbarPosition(Position.BOTTOM)) + Onboarding.prefToggledToolbarPosition.record( + Onboarding.PrefToggledToolbarPositionExtra( + Position.BOTTOM.name + ) + ) radioBottomToolbar.performClick() } radioTopToolbar.onClickListener { - metrics.track(Event.OnboardingToolbarPosition(Position.TOP)) + Onboarding.prefToggledToolbarPosition.record( + Onboarding.PrefToggledToolbarPositionExtra( + Position.TOP.name + ) + ) itemView.context.asActivity()?.recreate() } binding.toolbarTopImage.setOnClickListener { - metrics.track(Event.OnboardingToolbarPosition(Position.TOP)) + Onboarding.prefToggledToolbarPosition.record( + Onboarding.PrefToggledToolbarPositionExtra( + Position.TOP.name + ) + ) radioTopToolbar.performClick() } } companion object { const val LAYOUT_ID = R.layout.onboarding_toolbar_position_picker + // Position of the toolbar used for telemetry + enum class Position { TOP, BOTTOM } } } diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingTrackingProtectionViewHolder.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingTrackingProtectionViewHolder.kt index 850a778430..767da1c6e5 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingTrackingProtectionViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingTrackingProtectionViewHolder.kt @@ -6,9 +6,8 @@ package org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding import android.view.View import androidx.recyclerview.widget.RecyclerView +import org.mozilla.fenix.GleanMetrics.Onboarding import org.mozilla.fenix.R -import org.mozilla.fenix.components.metrics.Event -import org.mozilla.fenix.components.metrics.Event.OnboardingTrackingProtection.Setting import org.mozilla.fenix.databinding.OnboardingTrackingProtectionBinding import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.settings @@ -50,14 +49,20 @@ class OnboardingTrackingProtectionViewHolder(view: View) : RecyclerView.ViewHold standardTrackingProtection.onClickListener { updateTrackingProtectionPolicy() - itemView.context.components.analytics.metrics - .track(Event.OnboardingTrackingProtection(Setting.STANDARD)) + Onboarding.prefToggledTrackingProt.record( + Onboarding.PrefToggledTrackingProtExtra( + Settings.STANDARD.name + ) + ) } strictTrackingProtection.onClickListener { updateTrackingProtectionPolicy() - itemView.context.components.analytics.metrics - .track(Event.OnboardingTrackingProtection(Setting.STRICT)) + Onboarding.prefToggledTrackingProt.record( + Onboarding.PrefToggledTrackingProtExtra( + Settings.STRICT.name + ) + ) } } @@ -77,5 +82,7 @@ class OnboardingTrackingProtectionViewHolder(view: View) : RecyclerView.ViewHold companion object { const val LAYOUT_ID = R.layout.onboarding_tracking_protection + // Tracking protection policy types used for telemetry + enum class Settings { STRICT, STANDARD } } } diff --git a/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingFinishViewHolderTest.kt b/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingFinishViewHolderTest.kt index 2dac1b5a7b..543befc0bf 100644 --- a/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingFinishViewHolderTest.kt +++ b/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingFinishViewHolderTest.kt @@ -9,9 +9,15 @@ import io.mockk.every import io.mockk.mockk import io.mockk.verify import mozilla.components.support.test.robolectric.testContext +import mozilla.telemetry.glean.testing.GleanTestRule +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import org.mozilla.fenix.GleanMetrics.Onboarding import org.mozilla.fenix.databinding.OnboardingFinishBinding import org.mozilla.fenix.ext.components import org.mozilla.fenix.helpers.FenixRobolectricTestRunner @@ -20,6 +26,9 @@ import org.mozilla.fenix.home.sessioncontrol.OnboardingInteractor @RunWith(FenixRobolectricTestRunner::class) class OnboardingFinishViewHolderTest { + @get:Rule + val gleanTestRule = GleanTestRule(testContext) + private lateinit var binding: OnboardingFinishBinding private lateinit var interactor: OnboardingInteractor @@ -36,5 +45,9 @@ class OnboardingFinishViewHolderTest { binding.finishButton.performClick() verify { interactor.onStartBrowsingClicked() } + // Check if the event was recorded + assertTrue(Onboarding.finish.testHasValue()) + assertEquals(1, Onboarding.finish.testGetValue().size) + assertNull(Onboarding.finish.testGetValue().single().extra) } } diff --git a/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingManualSignInViewHolderTest.kt b/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingManualSignInViewHolderTest.kt index abb66aff05..bfa1b8e21f 100644 --- a/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingManualSignInViewHolderTest.kt +++ b/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingManualSignInViewHolderTest.kt @@ -14,11 +14,15 @@ import io.mockk.mockkStatic import io.mockk.unmockkStatic import io.mockk.verify import mozilla.components.support.test.robolectric.testContext +import mozilla.telemetry.glean.testing.GleanTestRule import org.junit.After +import org.junit.Assert import org.junit.Assert.assertEquals import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import org.mozilla.fenix.GleanMetrics.Onboarding import org.mozilla.fenix.R import org.mozilla.fenix.databinding.OnboardingManualSigninBinding import org.mozilla.fenix.ext.components @@ -28,6 +32,9 @@ import org.mozilla.fenix.home.HomeFragmentDirections @RunWith(FenixRobolectricTestRunner::class) class OnboardingManualSignInViewHolderTest { + @get:Rule + val gleanTestRule = GleanTestRule(testContext) + private lateinit var binding: OnboardingManualSigninBinding private lateinit var navController: NavController private lateinit var itemView: ViewGroup @@ -65,5 +72,9 @@ class OnboardingManualSignInViewHolderTest { binding.fxaSignInButton.performClick() verify { navController.navigate(HomeFragmentDirections.actionGlobalTurnOnSync()) } + // Check if the event was recorded + Assert.assertTrue(Onboarding.fxaManualSignin.testHasValue()) + assertEquals(1, Onboarding.fxaManualSignin.testGetValue().size) + Assert.assertNull(Onboarding.fxaManualSignin.testGetValue().single().extra) } } diff --git a/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingPrivacyNoticeViewHolderTest.kt b/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingPrivacyNoticeViewHolderTest.kt index 4a594e449c..2722550654 100644 --- a/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingPrivacyNoticeViewHolderTest.kt +++ b/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingPrivacyNoticeViewHolderTest.kt @@ -10,9 +10,15 @@ import io.mockk.every import io.mockk.mockk import io.mockk.verify import mozilla.components.support.test.robolectric.testContext +import mozilla.telemetry.glean.testing.GleanTestRule +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import org.mozilla.fenix.GleanMetrics.Onboarding import org.mozilla.fenix.R import org.mozilla.fenix.databinding.OnboardingPrivacyNoticeBinding import org.mozilla.fenix.ext.components @@ -22,6 +28,9 @@ import org.mozilla.fenix.home.sessioncontrol.OnboardingInteractor @RunWith(FenixRobolectricTestRunner::class) class OnboardingPrivacyNoticeViewHolderTest { + @get:Rule + val gleanTestRule = GleanTestRule(testContext) + private lateinit var binding: OnboardingPrivacyNoticeBinding private lateinit var interactor: OnboardingInteractor @@ -39,5 +48,9 @@ class OnboardingPrivacyNoticeViewHolderTest { binding.readButton.performClick() verify { interactor.onReadPrivacyNoticeClicked() } + // Check if the event was recorded + assertTrue(Onboarding.privacyNotice.testHasValue()) + assertEquals(1, Onboarding.privacyNotice.testGetValue().size) + assertNull(Onboarding.privacyNotice.testGetValue().single().extra) } } diff --git a/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingToolbarPositionPickerViewHolderTest.kt b/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingToolbarPositionPickerViewHolderTest.kt index faa25c52ac..e1c3777f2a 100644 --- a/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingToolbarPositionPickerViewHolderTest.kt +++ b/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingToolbarPositionPickerViewHolderTest.kt @@ -8,11 +8,15 @@ import android.view.LayoutInflater import io.mockk.every import io.mockk.mockk import mozilla.components.support.test.robolectric.testContext +import mozilla.telemetry.glean.testing.GleanTestRule +import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import org.mozilla.fenix.GleanMetrics.Onboarding import org.mozilla.fenix.ext.components import org.mozilla.fenix.components.toolbar.ToolbarPosition import org.mozilla.fenix.databinding.OnboardingToolbarPositionPickerBinding @@ -22,6 +26,9 @@ import org.mozilla.fenix.utils.Settings @RunWith(FenixRobolectricTestRunner::class) class OnboardingToolbarPositionPickerViewHolderTest { + @get:Rule + val gleanTestRule = GleanTestRule(testContext) + private lateinit var binding: OnboardingToolbarPositionPickerBinding private lateinit var settings: Settings @@ -56,4 +63,34 @@ class OnboardingToolbarPositionPickerViewHolderTest { assertTrue(binding.toolbarTopRadioButton.isChecked) assertFalse(binding.toolbarBottomRadioButton.isChecked) } + + @Test + fun `WHEN the top radio button is clicked THEN the proper event is recorded`() { + every { settings.toolbarPosition } returns ToolbarPosition.BOTTOM + OnboardingToolbarPositionPickerViewHolder(binding.root) + + binding.toolbarTopImage.performClick() + + assertTrue(Onboarding.prefToggledToolbarPosition.testHasValue()) + assertEquals( + OnboardingToolbarPositionPickerViewHolder.Companion.Position.TOP.name, + Onboarding.prefToggledToolbarPosition.testGetValue() + .last().extra?.get("position") + ) + } + + @Test + fun `WHEN the bottom radio button is clicked THEN the proper event is recorded`() { + every { settings.toolbarPosition } returns ToolbarPosition.TOP + OnboardingToolbarPositionPickerViewHolder(binding.root) + + binding.toolbarBottomImage.performClick() + + assertTrue(Onboarding.prefToggledToolbarPosition.testHasValue()) + assertEquals( + OnboardingToolbarPositionPickerViewHolder.Companion.Position.BOTTOM.name, + Onboarding.prefToggledToolbarPosition.testGetValue() + .last().extra?.get("position") + ) + } }