update for pr feedback and add sync login event

fork
Charlie Humphreys 1 year ago committed by mergify[bot]
parent d8e724218f
commit 65a4442d89

@ -659,6 +659,7 @@ dependencies {
testImplementation 'org.apache.maven:maven-ant-tasks:2.1.3'
implementation Deps.mozilla_support_rusthttp
androidTestImplementation Deps.mockk_android
testImplementation Deps.mockk
// For the initial release of Glean 19, we require consumer applications to

@ -5,12 +5,11 @@ import org.mozilla.fenix.ext.components
import org.mozilla.fenix.helpers.TestHelper.appContext
object Experimentation {
private val nimbus =
val experiments =
appContext.components.analytics.experiments
fun withHelper(block: GleanPlumbMessageHelper.() -> Unit) {
val helper = nimbus.createMessageHelper()
val helper = experiments.createMessageHelper()
block(helper)
}
}

@ -3,17 +3,21 @@ package org.mozilla.fenix.ui
import android.content.Intent
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import mozilla.components.concept.sync.*
import okhttp3.mockwebserver.MockWebServer
import org.junit.*
import org.mozilla.fenix.components.TelemetryAccountObserver
import org.mozilla.fenix.helpers.*
import org.mozilla.fenix.helpers.TestHelper.appContext
import org.mozilla.fenix.ui.robots.homeScreen
import io.mockk.mockk
class NimbusEventTest {
private lateinit var mDevice: UiDevice
private lateinit var mockWebServer: MockWebServer
@get:Rule
val activityTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides()
val homeActivityTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides()
.withIntent(Intent().apply {
action = Intent.ACTION_VIEW
})
@ -45,4 +49,14 @@ class NimbusEventTest {
Assert.assertTrue(evalJexl("'app_opened'|eventSum('Days', 28, 0) > 0"))
}
}
@Test
fun telemetryAccountObserverTest() {
val observer = TelemetryAccountObserver(appContext)
observer.onAuthenticated(mockk(), AuthType.Signin)
Experimentation.withHelper {
Assert.assertTrue(evalJexl("'sync_auth_sign_in'|eventSum('Days', 28, 0) > 0"))
}
}
}

@ -278,6 +278,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
?.let(::getIntentSource)
?.also {
Events.appOpened.record(Events.AppOpenedExtra(it))
// This will record an event in Nimbus' internal event store. Used for behavioral targeting
components.analytics.experiments.recordEvent("app_opened")
}
}

@ -46,7 +46,6 @@ import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.perf.StrictModeManager
import org.mozilla.fenix.perf.lazyMonitored
import org.mozilla.fenix.sync.SyncedTabsIntegration
import org.mozilla.fenix.utils.Settings
/**
* Component group for background services. These are the components that need to be accessed from within a
@ -127,7 +126,7 @@ class BackgroundServices(
}
private val telemetryAccountObserver = TelemetryAccountObserver(
context.settings(),
context
)
val accountAbnormalities = AccountAbnormalities(context, crashReporter, strictMode)
@ -219,13 +218,16 @@ private class AccountManagerReadyObserver(
@VisibleForTesting(otherwise = PRIVATE)
internal class TelemetryAccountObserver(
private val settings: Settings,
private val context: Context
) : AccountObserver {
override fun onAuthenticated(account: OAuthAccount, authType: AuthType) {
settings.signedInFxaAccount = true
context.settings().signedInFxaAccount = true
when (authType) {
// User signed-in into an existing FxA account.
AuthType.Signin -> SyncAuth.signIn.record(NoExtras())
AuthType.Signin -> {
SyncAuth.signIn.record(NoExtras())
context.components.analytics.experiments.recordEvent("sync_auth_sign_in")
}
// User created a new FxA account.
AuthType.Signup -> SyncAuth.signUp.record(NoExtras())
@ -254,6 +256,6 @@ internal class TelemetryAccountObserver(
override fun onLoggedOut() {
SyncAuth.signOut.record(NoExtras())
settings.signedInFxaAccount = false
context.settings().signedInFxaAccount = false
}
}

@ -5,6 +5,7 @@ import org.mozilla.fenix.gradle.tasks.GithubDetailsTask
buildscript {
// This logic is duplicated in the allprojects block: I don't know how to fix that.
repositories {
mavenLocal()
maven {
name "Mozilla Nightly"
url "https://nightly.maven.mozilla.org/maven2"
@ -81,6 +82,7 @@ plugins {
allprojects {
// This logic is duplicated in the buildscript block: I don't know how to fix that.
repositories {
mavenLocal()
maven {
name "Mozilla Nightly"
url "https://nightly.maven.mozilla.org/maven2"

@ -227,6 +227,7 @@ object Deps {
const val junit = "junit:junit:${Versions.junit}"
const val mockk = "io.mockk:mockk:${Versions.mockk}"
const val mockk_android = "io.mockk:mockk-android:${Versions.mockk}"
// --- START AndroidX test dependencies --- //
// N.B.: the versions of these dependencies appear to be pinned together. To avoid bugs, they

Loading…
Cancel
Save