Bug 1777405 - GeckoView Intermittent in GeolocationTest onPause r=geckoview-reviewers,calu

In some test runs, the `onPause` Android Lifecycle event is not occuring
in the GeckoView test `GeolocationTest`.

Increasing the time between calling an `onPause` event (going Home)
and the `onResume` event (returning to app) will give the device more
time to complete the `onPause` event and return the expected results.

Differential Revision: https://phabricator.services.mozilla.com/D151031
This commit is contained in:
Olivia Hall 2022-07-12 13:01:38 +00:00
parent 5c4c6b84a0
commit fab615eabb

View File

@ -95,6 +95,17 @@ import org.mozilla.geckoview.test.rule.GeckoSessionTestRule
error => reject(error.code))""").value as JSONObject
}
private fun getCurrentPositionJSWithWait(): JSONObject {
return mainSession.evaluatePromiseJS("""
new Promise((resolve, reject) =>
setTimeout(() => {
window.navigator.geolocation.getCurrentPosition(
position => resolve(
{latitude: position.coords.latitude, longitude: position.coords.longitude})),
error => reject(error.code)
}, "750"))""").value as JSONObject
}
@GeckoSessionTestRule.NullDelegate(Autofill.Delegate::class)
// General test that location can be requested from JS and that the mock provider is providing location
@Test fun jsContentRequestForLocation() {
@ -170,13 +181,13 @@ import org.mozilla.geckoview.test.rule.GeckoSessionTestRule
// Ensures a return to the foreground
Handler(Looper.getMainLooper()).postDelayed({
setActivityToForeground()
}, 1000)
}, 1500)
// Will cause onPause event to occur
pressHome()
// After/During onPause Event
val whilePausingPosition = getCurrentPositionJS()
val whilePausingPosition = getCurrentPositionJSWithWait()
assertThat("Longitude after/during onPause matches.", whilePausingPosition["latitude"] as Number, equalTo(afterPauseLat))
assertThat("Longitude after/during onPause matches.", whilePausingPosition["longitude"] as Number, equalTo(afterPauseLon))