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

This commit is contained in:
Charlie Humphreys 2022-11-21 15:12:06 -06:00 committed by mergify[bot]
parent 11efaff96c
commit f709036636
4 changed files with 80 additions and 1 deletions

View File

@ -6,6 +6,7 @@
package org.mozilla.fenix.helpers
import android.content.Intent
import android.view.ViewConfiguration.getLongPressTimeout
import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.rule.ActivityTestRule
@ -161,6 +162,8 @@ class HomeActivityIntentTestRule internal constructor(
private val longTapUserPreference = getLongPressTimeout()
private lateinit var intent: Intent
/**
* 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() {
super.beforeActivityLaunched()
setLongTapTimeout(3000)

View File

@ -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"))
}
}
}

View File

@ -90,6 +90,7 @@ class HomeScreenRobot {
fun verifyDefaultSearchEngine(searchEngine: String) = verifySearchEngineIcon(searchEngine)
fun verifyNoTabsOpened() = assertNoTabsOpened()
fun verifyKeyboardVisible() = assertKeyboardVisibility(isExpectedToBeVisible = true)
fun evaluateAgainstNimbusTargetingHelper(jexl: String): Boolean = evaluateAgainstNimbus(jexl)
fun verifyWallpaperImageApplied(isEnabled: Boolean) {
if (isEnabled) {
@ -806,6 +807,14 @@ private fun verifySearchEngineIcon(searchEngineName: String) {
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
private fun assertWelcomeHeader() =
assertTrue(

View File

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