Bug 1553515 - Account for errors in PermissionDelegateTest.geolocation. r=snorp

Sometime the geolocation test fails because the position is not retrieved
quickly enough, this is OK as we're just trying to make sure that the
permission is correct.

Differential Revision: https://phabricator.services.mozilla.com/D32576

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Agi Sferro 2019-06-27 19:00:25 +00:00
parent 6724e140bb
commit 1d0f6f0cca

View File

@ -139,7 +139,8 @@ class PermissionDelegateTest : BaseSessionTest() {
hasPermission(Manifest.permission.ACCESS_FINE_LOCATION),
equalTo(true))
mainSession.loadTestPath(HELLO_HTML_PATH)
val url = "https://example.com/"
mainSession.loadUri(url)
mainSession.waitForPageStop()
mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate {
@ -148,7 +149,7 @@ class PermissionDelegateTest : BaseSessionTest() {
override fun onContentPermissionRequest(
session: GeckoSession, uri: String?, type: Int,
callback: GeckoSession.PermissionDelegate.Callback) {
assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH))
assertThat("URI should match", uri, endsWith(url))
assertThat("Type should match", type,
equalTo(GeckoSession.PermissionDelegate.PERMISSION_GEOLOCATION))
callback.grant()
@ -164,13 +165,18 @@ class PermissionDelegateTest : BaseSessionTest() {
}
})
val position = mainSession.waitForJS("""new Promise((resolve, reject) =>
window.navigator.geolocation.getCurrentPosition(resolve, reject))""")
try {
val position = mainSession.waitForJS("""new Promise((resolve, reject) =>
window.navigator.geolocation.getCurrentPosition(resolve, reject))""")
assertThat("Request should succeed",
position.asJSMap(),
hasEntry(equalTo("coords"),
both(hasKey("longitude")).and(hasKey("latitude"))))
assertThat("Request should succeed",
position.asJSMap(),
hasEntry(equalTo("coords"),
both(hasKey("longitude")).and(hasKey("latitude"))))
} catch (ex: RejectedPromiseException) {
assertThat("Error should not because the permission was denied.",
ex.reason.asJSMap(), hasEntry(equalTo("code"), not(1.0)))
}
}
@WithDevToolsAPI