Compare commits
1 Commits
main
...
oana-permi
Author | SHA1 | Date |
---|---|---|
sv-ohorvath | e70f36e9df |
|
@ -8,12 +8,23 @@ import androidx.test.espresso.IdlingResourceTimeoutException
|
||||||
import androidx.test.espresso.NoMatchingViewException
|
import androidx.test.espresso.NoMatchingViewException
|
||||||
import androidx.test.uiautomator.UiObjectNotFoundException
|
import androidx.test.uiautomator.UiObjectNotFoundException
|
||||||
import junit.framework.AssertionFailedError
|
import junit.framework.AssertionFailedError
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.junit.rules.TestRule
|
import org.junit.rules.TestRule
|
||||||
import org.junit.runner.Description
|
import org.junit.runner.Description
|
||||||
import org.junit.runners.model.Statement
|
import org.junit.runners.model.Statement
|
||||||
|
import org.mozilla.fenix.components.PermissionStorage
|
||||||
import org.mozilla.fenix.helpers.IdlingResourceHelper.unregisterAllIdlingResources
|
import org.mozilla.fenix.helpers.IdlingResourceHelper.unregisterAllIdlingResources
|
||||||
|
import org.mozilla.fenix.helpers.TestHelper.appContext
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rule to retry flaky tests for a given number of times, catching some of the more common exceptions.
|
||||||
|
* The Rule doesn't clear the app state in between retries, so we are doing some cleanup here.
|
||||||
|
* The @Before and @After methods are not called between retries.
|
||||||
|
*
|
||||||
|
*/
|
||||||
class RetryTestRule(private val retryCount: Int = 5) : TestRule {
|
class RetryTestRule(private val retryCount: Int = 5) : TestRule {
|
||||||
|
// Used for clearing all permission data after each test try
|
||||||
|
private val permissionStorage = PermissionStorage(appContext.applicationContext)
|
||||||
|
|
||||||
@Suppress("TooGenericExceptionCaught", "ComplexMethod")
|
@Suppress("TooGenericExceptionCaught", "ComplexMethod")
|
||||||
override fun apply(base: Statement, description: Description): Statement {
|
override fun apply(base: Statement, description: Description): Statement {
|
||||||
|
@ -24,36 +35,57 @@ class RetryTestRule(private val retryCount: Int = 5) : TestRule {
|
||||||
break
|
break
|
||||||
} catch (t: AssertionError) {
|
} catch (t: AssertionError) {
|
||||||
unregisterAllIdlingResources()
|
unregisterAllIdlingResources()
|
||||||
|
runBlocking {
|
||||||
|
permissionStorage.deleteAllSitePermissions()
|
||||||
|
}
|
||||||
if (i == retryCount) {
|
if (i == retryCount) {
|
||||||
throw t
|
throw t
|
||||||
}
|
}
|
||||||
} catch (t: AssertionFailedError) {
|
} catch (t: AssertionFailedError) {
|
||||||
unregisterAllIdlingResources()
|
unregisterAllIdlingResources()
|
||||||
|
runBlocking {
|
||||||
|
permissionStorage.deleteAllSitePermissions()
|
||||||
|
}
|
||||||
if (i == retryCount) {
|
if (i == retryCount) {
|
||||||
throw t
|
throw t
|
||||||
}
|
}
|
||||||
} catch (t: UiObjectNotFoundException) {
|
} catch (t: UiObjectNotFoundException) {
|
||||||
unregisterAllIdlingResources()
|
unregisterAllIdlingResources()
|
||||||
|
runBlocking {
|
||||||
|
permissionStorage.deleteAllSitePermissions()
|
||||||
|
}
|
||||||
if (i == retryCount) {
|
if (i == retryCount) {
|
||||||
throw t
|
throw t
|
||||||
}
|
}
|
||||||
} catch (t: NoMatchingViewException) {
|
} catch (t: NoMatchingViewException) {
|
||||||
unregisterAllIdlingResources()
|
unregisterAllIdlingResources()
|
||||||
|
runBlocking {
|
||||||
|
permissionStorage.deleteAllSitePermissions()
|
||||||
|
}
|
||||||
if (i == retryCount) {
|
if (i == retryCount) {
|
||||||
throw t
|
throw t
|
||||||
}
|
}
|
||||||
} catch (t: IdlingResourceTimeoutException) {
|
} catch (t: IdlingResourceTimeoutException) {
|
||||||
unregisterAllIdlingResources()
|
unregisterAllIdlingResources()
|
||||||
|
runBlocking {
|
||||||
|
permissionStorage.deleteAllSitePermissions()
|
||||||
|
}
|
||||||
if (i == retryCount) {
|
if (i == retryCount) {
|
||||||
throw t
|
throw t
|
||||||
}
|
}
|
||||||
} catch (t: RuntimeException) {
|
} catch (t: RuntimeException) {
|
||||||
unregisterAllIdlingResources()
|
unregisterAllIdlingResources()
|
||||||
|
runBlocking {
|
||||||
|
permissionStorage.deleteAllSitePermissions()
|
||||||
|
}
|
||||||
if (i == retryCount) {
|
if (i == retryCount) {
|
||||||
throw t
|
throw t
|
||||||
}
|
}
|
||||||
} catch (t: NullPointerException) {
|
} catch (t: NullPointerException) {
|
||||||
unregisterAllIdlingResources()
|
unregisterAllIdlingResources()
|
||||||
|
runBlocking {
|
||||||
|
permissionStorage.deleteAllSitePermissions()
|
||||||
|
}
|
||||||
if (i == retryCount) {
|
if (i == retryCount) {
|
||||||
throw t
|
throw t
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,17 +12,16 @@ import android.os.Build
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.test.filters.SdkSuppress
|
import androidx.test.filters.SdkSuppress
|
||||||
import androidx.test.rule.GrantPermissionRule
|
import androidx.test.rule.GrantPermissionRule
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Assume.assumeTrue
|
import org.junit.Assume.assumeTrue
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Ignore
|
import org.junit.Ignore
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.mozilla.fenix.components.PermissionStorage
|
|
||||||
import org.mozilla.fenix.customannotations.SmokeTest
|
import org.mozilla.fenix.customannotations.SmokeTest
|
||||||
import org.mozilla.fenix.helpers.FeatureSettingsHelper
|
import org.mozilla.fenix.helpers.FeatureSettingsHelper
|
||||||
import org.mozilla.fenix.helpers.HomeActivityTestRule
|
import org.mozilla.fenix.helpers.HomeActivityTestRule
|
||||||
|
import org.mozilla.fenix.helpers.RetryTestRule
|
||||||
import org.mozilla.fenix.helpers.TestHelper.appContext
|
import org.mozilla.fenix.helpers.TestHelper.appContext
|
||||||
import org.mozilla.fenix.ui.robots.browserScreen
|
import org.mozilla.fenix.ui.robots.browserScreen
|
||||||
import org.mozilla.fenix.ui.robots.navigationToolbar
|
import org.mozilla.fenix.ui.robots.navigationToolbar
|
||||||
|
@ -48,22 +47,21 @@ class SitePermissionsTest {
|
||||||
Manifest.permission.CAMERA
|
Manifest.permission.CAMERA
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
@JvmField
|
||||||
|
val retryTestRule = RetryTestRule(3)
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
// disabling the new homepage pop-up that interferes with the tests.
|
// disabling the new homepage pop-up that interferes with the tests.
|
||||||
featureSettingsHelper.setJumpBackCFREnabled(false)
|
featureSettingsHelper.setJumpBackCFREnabled(false)
|
||||||
featureSettingsHelper.deleteSitePermissions(true)
|
featureSettingsHelper.deleteSitePermissions(true)
|
||||||
|
featureSettingsHelper.disablePwaCFR(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
fun tearDown() {
|
fun tearDown() {
|
||||||
// Clearing all permission data after each test to avoid overlapping data
|
featureSettingsHelper.resetAllFeatureFlags()
|
||||||
val applicationContext: Context = activityTestRule.activity.applicationContext
|
|
||||||
val permissionStorage = PermissionStorage(applicationContext)
|
|
||||||
|
|
||||||
runBlocking {
|
|
||||||
permissionStorage.deleteAllSitePermissions()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SdkSuppress(maxSdkVersion = Build.VERSION_CODES.P, codeName = "P")
|
@SdkSuppress(maxSdkVersion = Build.VERSION_CODES.P, codeName = "P")
|
||||||
|
|
|
@ -38,12 +38,14 @@ gcloud:
|
||||||
performance-metrics: true
|
performance-metrics: true
|
||||||
|
|
||||||
test-targets:
|
test-targets:
|
||||||
- notPackage org.mozilla.fenix.screenshots
|
# - notPackage org.mozilla.fenix.screenshots
|
||||||
- notPackage org.mozilla.fenix.syncintegration
|
# - notPackage org.mozilla.fenix.syncintegration
|
||||||
|
- class org.mozilla.fenix.ui.SitePermissionsTest#rememberAllowAudioVideoPermissionChoiceTest
|
||||||
|
- class org.mozilla.fenix.ui.SitePermissionsTest#rememberBlockAudioVideoPermissionChoiceTest
|
||||||
|
|
||||||
device:
|
device:
|
||||||
- model: Pixel2
|
- model: Pixel2
|
||||||
version: 30
|
version: 28
|
||||||
locale: en_US
|
locale: en_US
|
||||||
|
|
||||||
flank:
|
flank:
|
||||||
|
@ -53,7 +55,7 @@ flank:
|
||||||
max-test-shards: -1
|
max-test-shards: -1
|
||||||
# num-test-runs: the amount of times to run the tests.
|
# num-test-runs: the amount of times to run the tests.
|
||||||
# 1 runs the tests once. 10 runs all the tests 10x
|
# 1 runs the tests once. 10 runs all the tests 10x
|
||||||
num-test-runs: 1
|
num-test-runs: 50
|
||||||
### Output Style flag
|
### Output Style flag
|
||||||
## Output style of execution status. May be one of [verbose, multi, single, compact].
|
## Output style of execution status. May be one of [verbose, multi, single, compact].
|
||||||
## For runs with only one test execution the default value is 'verbose', in other cases
|
## For runs with only one test execution the default value is 'verbose', in other cases
|
||||||
|
|
Loading…
Reference in New Issue