Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Bug 1885300 - Add logs to HomeActivityTestRule
Browse files Browse the repository at this point in the history
  • Loading branch information
AndiAJ authored and mergify[bot] committed Mar 14, 2024
1 parent 4b64f85 commit 6eb225c
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
package org.mozilla.fenix.helpers

import android.content.Intent
import android.util.Log
import android.view.ViewConfiguration.getLongPressTimeout
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.rule.ActivityTestRule
import androidx.test.uiautomator.UiSelector
import org.junit.rules.TestRule
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.helpers.Constants.TAG
import org.mozilla.fenix.helpers.FeatureSettingsHelper.Companion.settings
import org.mozilla.fenix.helpers.TestHelper.appContext
import org.mozilla.fenix.helpers.TestHelper.mDevice
Expand Down Expand Up @@ -76,25 +78,31 @@ class HomeActivityTestRule(
* Update settings after the activity was created.
*/
fun applySettingsExceptions(settings: (FeatureSettingsHelper) -> Unit) {
Log.i(TAG, "applySettingsExceptions: Trying to update the settings after the activity was created")
FeatureSettingsHelperDelegate().also {
settings(this)
applyFlagUpdates()
}
Log.i(TAG, "applySettingsExceptions: Updated the settings after the activity was created")
}

private val longTapUserPreference = getLongPressTimeout()

override fun beforeActivityLaunched() {
super.beforeActivityLaunched()
setLongTapTimeout(3000)
Log.i(TAG, "beforeActivityLaunched: Trying to apply the feature flags updates")
applyFlagUpdates()
Log.i(TAG, "beforeActivityLaunched: Successfully applied the feature flag updates")
if (skipOnboarding) { skipOnboardingBeforeLaunch() }
}

override fun afterActivityFinished() {
super.afterActivityFinished()
setLongTapTimeout(longTapUserPreference)
Log.i(TAG, "afterActivityFinished: Trying to reset all feature flags")
resetAllFeatureFlags()
Log.i(TAG, "afterActivityFinished: Successfully performed the reset of all feature flags")
closeNotificationShade()
}

Expand Down Expand Up @@ -189,10 +197,12 @@ class HomeActivityIntentTestRule internal constructor(
* Update settings after the activity was created.
*/
fun applySettingsExceptions(settings: (FeatureSettingsHelper) -> Unit) {
Log.i(TAG, "applySettingsExceptions: Trying to update the settings after the activity was created")
FeatureSettingsHelperDelegate().apply {
settings(this)
applyFlagUpdates()
}
Log.i(TAG, "applySettingsExceptions: Updated the settings after the activity was created")
}

override fun getActivityIntent(): Intent? {
Expand All @@ -211,15 +221,19 @@ class HomeActivityIntentTestRule internal constructor(
override fun beforeActivityLaunched() {
super.beforeActivityLaunched()
setLongTapTimeout(3000)
Log.i(TAG, "beforeActivityLaunched: Trying to apply the feature flag updates")
applyFlagUpdates()
Log.i(TAG, "beforeActivityLaunched: Successfully applied the feature flag updates")
if (skipOnboarding) { skipOnboardingBeforeLaunch() }
}

override fun afterActivityFinished() {
super.afterActivityFinished()
setLongTapTimeout(longTapUserPreference)
closeNotificationShade()
Log.i(TAG, "afterActivityFinished: Trying to reset all feature flags")
resetAllFeatureFlags()
Log.i(TAG, "afterActivityFinished: Successfully performed the reset of all feature flags")
}

/**
Expand Down Expand Up @@ -281,9 +295,12 @@ fun setLongTapTimeout(delay: Int) {
var attempts = 0
while (attempts++ < 3) {
try {
Log.i(TAG, "setLongTapTimeout: Trying to set the \"Touch and hold delay\" to: $delay ms")
mDevice.executeShellCommand("settings put secure long_press_timeout $delay")
Log.i(TAG, "setLongTapTimeout: Executed command \"settings put secure long_press_timeout $delay\"")
break
} catch (e: RuntimeException) {
Log.i(TAG, "setLongTapTimeout: RuntimeException caught, executing fallback methods")
e.printStackTrace()
}
}
Expand All @@ -292,14 +309,18 @@ fun setLongTapTimeout(delay: Int) {
private fun skipOnboardingBeforeLaunch() {
// The production code isn't aware that we're using
// this API so it can be fragile.
Log.i(TAG, "skipOnboardingBeforeLaunch: Trying to skip the onboarding before launching the app")
FenixOnboarding(appContext).finish()
Log.i(TAG, "skipOnboardingBeforeLaunch: Successfully skipped the onboarding before launching the app")
}

private fun closeNotificationShade() {
if (mDevice.findObject(
UiSelector().resourceId("com.android.systemui:id/notification_stack_scroller"),
).exists()
) {
Log.i(TAG, "closeNotificationShade: Trying to press device home button")
mDevice.pressHome()
Log.i(TAG, "closeNotificationShade: Pressed the device home button")
}
}

0 comments on commit 6eb225c

Please sign in to comment.