Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #16317 UI tests: save longTap preference to restore it
Browse files Browse the repository at this point in the history
  • Loading branch information
Oana Horvath committed Feb 18, 2021
1 parent 7e70ecc commit d7f1117
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package org.mozilla.fenix.helpers

import android.view.ViewConfiguration.getLongPressTimeout
import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.ActivityTestRule
Expand All @@ -25,15 +26,17 @@ class HomeActivityTestRule(
private val skipOnboarding: Boolean = false
) :
ActivityTestRule<HomeActivity>(HomeActivity::class.java, initialTouchMode, launchActivity) {
private val longTapUserPreference = getLongPressTimeout()

override fun beforeActivityLaunched() {
super.beforeActivityLaunched()
setLongTapTimeout("3000")
setLongTapTimeout(3000)
if (skipOnboarding) { skipOnboardingBeforeLaunch() }
}

override fun afterActivityFinished() {
super.afterActivityFinished()
setLongTapTimeout("400")
setLongTapTimeout(longTapUserPreference)
}
}

Expand All @@ -51,20 +54,22 @@ class HomeActivityIntentTestRule(
private val skipOnboarding: Boolean = false
) :
IntentsTestRule<HomeActivity>(HomeActivity::class.java, initialTouchMode, launchActivity) {
private val longTapUserPreference = getLongPressTimeout()

override fun beforeActivityLaunched() {
super.beforeActivityLaunched()
setLongTapTimeout("3000")
setLongTapTimeout(3000)
if (skipOnboarding) { skipOnboardingBeforeLaunch() }
}

override fun afterActivityFinished() {
super.afterActivityFinished()
setLongTapTimeout("400")
setLongTapTimeout(longTapUserPreference)
}
}

// changing the device preference for Touch and Hold delay, to avoid long-clicks instead of a single-click
fun setLongTapTimeout(delay: String) {
fun setLongTapTimeout(delay: Int) {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.executeShellCommand("settings put secure long_press_timeout $delay")
}
Expand Down

0 comments on commit d7f1117

Please sign in to comment.