Fixes #27933: record app opened event and add nimbus event test suite

fork
Charlie Humphreys 2 years ago committed by mergify[bot]
parent 11efaff96c
commit f709036636

@ -6,6 +6,7 @@
package org.mozilla.fenix.helpers package org.mozilla.fenix.helpers
import android.content.Intent
import android.view.ViewConfiguration.getLongPressTimeout import android.view.ViewConfiguration.getLongPressTimeout
import androidx.test.espresso.intent.rule.IntentsTestRule import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.rule.ActivityTestRule import androidx.test.rule.ActivityTestRule
@ -161,6 +162,8 @@ class HomeActivityIntentTestRule internal constructor(
private val longTapUserPreference = getLongPressTimeout() private val longTapUserPreference = getLongPressTimeout()
private lateinit var intent: Intent
/** /**
* Update settings after the activity was created. * Update settings after the activity was created.
*/ */
@ -171,6 +174,19 @@ class HomeActivityIntentTestRule internal constructor(
} }
} }
override fun getActivityIntent(): Intent {
return if(this::intent.isInitialized) {
this.intent
} else {
super.getActivityIntent()
}
}
fun withIntent(intent: Intent): HomeActivityIntentTestRule {
this.intent = intent
return this
}
override fun beforeActivityLaunched() { override fun beforeActivityLaunched() {
super.beforeActivityLaunched() super.beforeActivityLaunched()
setLongTapTimeout(3000) setLongTapTimeout(3000)

@ -0,0 +1,51 @@
package org.mozilla.fenix.ui
import android.content.Intent
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import okhttp3.mockwebserver.MockWebServer
import org.junit.*
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.RetryTestRule
import org.mozilla.fenix.ui.robots.homeScreen
class NimbusEventTest {
private lateinit var mDevice: UiDevice
private lateinit var mockWebServer: MockWebServer
@get:Rule
val activityTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides()
.withIntent(Intent().apply {
action = Intent.ACTION_VIEW
})
@Rule
@JvmField
val retryTestRule = RetryTestRule(3)
@Before
fun setUp() {
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
}
}
@After
fun tearDown() {
mockWebServer.shutdown()
}
@Test
fun homeScreenNimbusEventsTest() {
homeScreen { }.dismissOnboarding()
homeScreen {
verifyHomeScreen()
Assert.assertTrue(evaluateAgainstNimbusTargetingHelper("'app_opened'|eventSum('Days', 28, 0) > 0"))
}
}
}

@ -90,6 +90,7 @@ class HomeScreenRobot {
fun verifyDefaultSearchEngine(searchEngine: String) = verifySearchEngineIcon(searchEngine) fun verifyDefaultSearchEngine(searchEngine: String) = verifySearchEngineIcon(searchEngine)
fun verifyNoTabsOpened() = assertNoTabsOpened() fun verifyNoTabsOpened() = assertNoTabsOpened()
fun verifyKeyboardVisible() = assertKeyboardVisibility(isExpectedToBeVisible = true) fun verifyKeyboardVisible() = assertKeyboardVisibility(isExpectedToBeVisible = true)
fun evaluateAgainstNimbusTargetingHelper(jexl: String): Boolean = evaluateAgainstNimbus(jexl)
fun verifyWallpaperImageApplied(isEnabled: Boolean) { fun verifyWallpaperImageApplied(isEnabled: Boolean) {
if (isEnabled) { if (isEnabled) {
@ -806,6 +807,14 @@ private fun verifySearchEngineIcon(searchEngineName: String) {
verifySearchEngineIcon(defaultSearchEngine.icon, defaultSearchEngine.name) verifySearchEngineIcon(defaultSearchEngine.icon, defaultSearchEngine.name)
} }
private fun getNimbus() =
appContext.components.analytics.experiments
private fun evaluateAgainstNimbus(jexl: String): Boolean {
val helper = getNimbus().createMessageHelper()
return helper.evalJexl(jexl)
}
// First Run elements // First Run elements
private fun assertWelcomeHeader() = private fun assertWelcomeHeader() =
assertTrue( assertTrue(

@ -276,7 +276,10 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
val safeIntent = intent?.toSafeIntent() val safeIntent = intent?.toSafeIntent()
safeIntent safeIntent
?.let(::getIntentSource) ?.let(::getIntentSource)
?.also { Events.appOpened.record(Events.AppOpenedExtra(it)) } ?.also {
Events.appOpened.record(Events.AppOpenedExtra(it))
components.analytics.experiments.recordEvent("app_opened")
}
} }
supportActionBar?.hide() supportActionBar?.hide()

Loading…
Cancel
Save