mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 08:42:13 +00:00
Bug 1461747 - 1. Add more permission tests; r=snorp
Add permission tests for geolocation and notifications. MozReview-Commit-ID: CR8TGxsUyoL
This commit is contained in:
parent
295877e7ea
commit
4763384cf3
@ -114,4 +114,104 @@ class PermissionDelegateTest : BaseSessionTest() {
|
||||
e.reason.asJSMap(), hasEntry("name", "NotAllowedError"))
|
||||
}
|
||||
}
|
||||
|
||||
@WithDevToolsAPI
|
||||
@Test fun geolocation() {
|
||||
assertInAutomationThat("Should have location permission",
|
||||
hasPermission(Manifest.permission.ACCESS_FINE_LOCATION),
|
||||
equalTo(true))
|
||||
|
||||
mainSession.loadTestPath(HELLO_HTML_PATH)
|
||||
mainSession.waitForPageStop()
|
||||
|
||||
mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate {
|
||||
// Ensure the content permission is asked first, before the Android permission.
|
||||
@AssertCalled(count = 1, order = [1])
|
||||
override fun onContentPermissionRequest(session: GeckoSession, uri: String, type: Int, access: String?, callback: GeckoSession.PermissionDelegate.Callback) {
|
||||
assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH))
|
||||
assertThat("Type should match", type,
|
||||
equalTo(GeckoSession.PermissionDelegate.PERMISSION_GEOLOCATION))
|
||||
assertThat("Access should be null", access, nullValue())
|
||||
callback.grant()
|
||||
}
|
||||
|
||||
@AssertCalled(count = 1, order = [2])
|
||||
override fun onAndroidPermissionsRequest(session: GeckoSession, permissions: Array<out String>, callback: GeckoSession.PermissionDelegate.Callback) {
|
||||
assertThat("Permissions list should be correct",
|
||||
listOf(*permissions), hasItems(Manifest.permission.ACCESS_FINE_LOCATION))
|
||||
callback.grant()
|
||||
}
|
||||
})
|
||||
|
||||
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"))))
|
||||
}
|
||||
|
||||
@WithDevToolsAPI
|
||||
@Test fun geolocation_reject() {
|
||||
mainSession.loadTestPath(HELLO_HTML_PATH)
|
||||
mainSession.waitForPageStop()
|
||||
|
||||
mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onContentPermissionRequest(session: GeckoSession, uri: String, type: Int, access: String?, callback: GeckoSession.PermissionDelegate.Callback) {
|
||||
callback.reject()
|
||||
}
|
||||
|
||||
@AssertCalled(count = 0)
|
||||
override fun onAndroidPermissionsRequest(session: GeckoSession, permissions: Array<out String>, callback: GeckoSession.PermissionDelegate.Callback) {
|
||||
}
|
||||
})
|
||||
|
||||
val error = mainSession.waitForJS("""new Promise((resolve, reject) =>
|
||||
window.navigator.geolocation.getCurrentPosition(reject, resolve))""")
|
||||
|
||||
assertThat("Request should fail",
|
||||
error.asJSMap(), hasEntry("code", 1.0)) // Error code 1 means permission denied.
|
||||
}
|
||||
|
||||
@WithDevToolsAPI
|
||||
@Test fun notification() {
|
||||
mainSession.loadTestPath(HELLO_HTML_PATH)
|
||||
mainSession.waitForPageStop()
|
||||
|
||||
mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onContentPermissionRequest(session: GeckoSession, uri: String, type: Int, access: String?, callback: GeckoSession.PermissionDelegate.Callback) {
|
||||
assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH))
|
||||
assertThat("Type should match", type,
|
||||
equalTo(GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION))
|
||||
assertThat("Access should be null", access, nullValue())
|
||||
callback.grant()
|
||||
}
|
||||
})
|
||||
|
||||
val result = mainSession.waitForJS("Notification.requestPermission()")
|
||||
|
||||
assertThat("Permission should be granted",
|
||||
result as String, equalTo("granted"))
|
||||
}
|
||||
|
||||
@WithDevToolsAPI
|
||||
@Test fun notification_reject() {
|
||||
mainSession.loadTestPath(HELLO_HTML_PATH)
|
||||
mainSession.waitForPageStop()
|
||||
|
||||
mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onContentPermissionRequest(session: GeckoSession, uri: String, type: Int, access: String?, callback: GeckoSession.PermissionDelegate.Callback) {
|
||||
callback.reject()
|
||||
}
|
||||
})
|
||||
|
||||
val result = mainSession.waitForJS("Notification.requestPermission()")
|
||||
|
||||
assertThat("Permission should not be granted",
|
||||
result as String, equalTo("default"))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user