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-07-08 20:48:23 +00:00
Родитель 1049cdd19e
Коммит a9366e6af5
1 изменённых файлов: 14 добавлений и 8 удалений

Просмотреть файл

@ -140,7 +140,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 {
@ -149,7 +150,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()
@ -165,13 +166,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