зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1714945 - Clean up PermissionDelegateTest. r=owlish
Removes redundant namespaces, adds some static imports, cleans up some java-ism (like .equals and semicolons). Differential Revision: https://phabricator.services.mozilla.com/D126545
This commit is contained in:
Родитель
b84a0603d7
Коммит
486cf25495
|
@ -8,6 +8,9 @@ import org.mozilla.geckoview.GeckoResult
|
|||
import org.mozilla.geckoview.GeckoSession
|
||||
import org.mozilla.geckoview.GeckoSession.NavigationDelegate
|
||||
import org.mozilla.geckoview.GeckoSession.PermissionDelegate
|
||||
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.ContentPermission
|
||||
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.MediaSource
|
||||
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.MediaCallback
|
||||
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled
|
||||
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.RejectedPromiseException
|
||||
|
||||
|
@ -40,9 +43,12 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
}
|
||||
|
||||
private fun isEmulator(): Boolean {
|
||||
return "generic".equals(Build.DEVICE) || Build.DEVICE.startsWith("generic_")
|
||||
return "generic" == Build.DEVICE || Build.DEVICE.startsWith("generic_")
|
||||
}
|
||||
|
||||
private val storageController
|
||||
get() = sessionRule.runtime.storageController
|
||||
|
||||
@Test fun media() {
|
||||
// TODO: needs bug 1700243
|
||||
assumeThat(sessionRule.env.isIsolatedProcess, equalTo(false))
|
||||
|
@ -64,10 +70,10 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
var hasAudio = false
|
||||
for (i in 0 until devices.length()) {
|
||||
if (devices.getJSONObject(i).getString("kind") == "videoinput") {
|
||||
hasVideo = true;
|
||||
hasVideo = true
|
||||
}
|
||||
if (devices.getJSONObject(i).getString("kind") == "audioinput") {
|
||||
hasAudio = true;
|
||||
hasAudio = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,9 +86,9 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
@AssertCalled(count = 1)
|
||||
override fun onMediaPermissionRequest(
|
||||
session: GeckoSession, uri: String,
|
||||
video: Array<out GeckoSession.PermissionDelegate.MediaSource>?,
|
||||
audio: Array<out GeckoSession.PermissionDelegate.MediaSource>?,
|
||||
callback: GeckoSession.PermissionDelegate.MediaCallback) {
|
||||
video: Array<out MediaSource>?,
|
||||
audio: Array<out MediaSource>?,
|
||||
callback: MediaCallback) {
|
||||
assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH))
|
||||
assertThat("Video source should be valid", video, not(emptyArray()))
|
||||
|
||||
|
@ -96,16 +102,15 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
})
|
||||
|
||||
// Start a video stream, with audio if on a real device.
|
||||
var code: String?
|
||||
if (isEmulator()) {
|
||||
code = """this.stream = window.navigator.mediaDevices.getUserMedia({
|
||||
video: { width: 320, height: 240, frameRate: 10 },
|
||||
});"""
|
||||
val code = if (isEmulator()) {
|
||||
"""this.stream = window.navigator.mediaDevices.getUserMedia({
|
||||
video: { width: 320, height: 240, frameRate: 10 },
|
||||
});"""
|
||||
} else {
|
||||
code = """this.stream = window.navigator.mediaDevices.getUserMedia({
|
||||
video: { width: 320, height: 240, frameRate: 10 },
|
||||
audio: true
|
||||
});"""
|
||||
"""this.stream = window.navigator.mediaDevices.getUserMedia({
|
||||
video: { width: 320, height: 240, frameRate: 10 },
|
||||
audio: true
|
||||
});"""
|
||||
}
|
||||
|
||||
// Stop the stream and check active flag and id
|
||||
|
@ -121,16 +126,16 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
})
|
||||
""".trimMargin()) as Boolean
|
||||
|
||||
assertThat("Stream should be active and id should not be empty.", isActive, equalTo(true));
|
||||
assertThat("Stream should be active and id should not be empty.", isActive, equalTo(true))
|
||||
|
||||
// Now test rejecting the request.
|
||||
mainSession.delegateDuringNextWait(object : PermissionDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onMediaPermissionRequest(
|
||||
session: GeckoSession, uri: String,
|
||||
video: Array<out GeckoSession.PermissionDelegate.MediaSource>?,
|
||||
audio: Array<out GeckoSession.PermissionDelegate.MediaSource>?,
|
||||
callback: GeckoSession.PermissionDelegate.MediaCallback) {
|
||||
video: Array<out MediaSource>?,
|
||||
audio: Array<out MediaSource>?,
|
||||
callback: MediaCallback) {
|
||||
callback.reject()
|
||||
}
|
||||
})
|
||||
|
@ -163,18 +168,18 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
// Ensure the content permission is asked first, before the Android permission.
|
||||
@AssertCalled(count = 1, order = [1])
|
||||
override fun onContentPermissionRequest(
|
||||
session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission):
|
||||
GeckoResult<Int>? {
|
||||
session: GeckoSession, perm: ContentPermission):
|
||||
GeckoResult<Int> {
|
||||
assertThat("URI should match", perm.uri, endsWith(url))
|
||||
assertThat("Type should match", perm.permission,
|
||||
equalTo(GeckoSession.PermissionDelegate.PERMISSION_GEOLOCATION))
|
||||
return GeckoResult.fromValue(GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW)
|
||||
equalTo(PermissionDelegate.PERMISSION_GEOLOCATION))
|
||||
return GeckoResult.fromValue(ContentPermission.VALUE_ALLOW)
|
||||
}
|
||||
|
||||
@AssertCalled(count = 1, order = [2])
|
||||
override fun onAndroidPermissionsRequest(
|
||||
session: GeckoSession, permissions: Array<out String>?,
|
||||
callback: GeckoSession.PermissionDelegate.Callback) {
|
||||
callback: PermissionDelegate.Callback) {
|
||||
assertThat("Permissions list should be correct",
|
||||
listOf(*permissions!!), hasItems(Manifest.permission.ACCESS_FINE_LOCATION))
|
||||
callback.grant()
|
||||
|
@ -195,13 +200,13 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
ex.reason as String, not("1"))
|
||||
}
|
||||
|
||||
val perms = sessionRule.waitForResult(sessionRule.runtime.storageController.getPermissions(url))
|
||||
val perms = sessionRule.waitForResult(storageController.getPermissions(url))
|
||||
|
||||
assertThat("Permissions should not be null", perms, notNullValue())
|
||||
var permFound : Boolean = false
|
||||
var permFound = false
|
||||
for (perm in perms) {
|
||||
if (perm.permission == GeckoSession.PermissionDelegate.PERMISSION_GEOLOCATION &&
|
||||
url.startsWith(perm.uri) && perm.value == GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW) {
|
||||
if (perm.permission == PermissionDelegate.PERMISSION_GEOLOCATION &&
|
||||
url.startsWith(perm.uri) && perm.value == ContentPermission.VALUE_ALLOW) {
|
||||
permFound = true
|
||||
}
|
||||
}
|
||||
|
@ -210,11 +215,11 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
|
||||
mainSession.delegateDuringNextWait(object : NavigationDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<GeckoSession.PermissionDelegate.ContentPermission>) {
|
||||
var permFound2 : Boolean = false
|
||||
override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) {
|
||||
var permFound2 = false
|
||||
for (perm in perms) {
|
||||
if (perm.permission == GeckoSession.PermissionDelegate.PERMISSION_GEOLOCATION &&
|
||||
perm.value == GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW) {
|
||||
if (perm.permission == PermissionDelegate.PERMISSION_GEOLOCATION &&
|
||||
perm.value == ContentPermission.VALUE_ALLOW) {
|
||||
permFound2 = true
|
||||
}
|
||||
}
|
||||
|
@ -233,15 +238,15 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
mainSession.delegateDuringNextWait(object : PermissionDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onContentPermissionRequest(
|
||||
session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission):
|
||||
GeckoResult<Int>? {
|
||||
return GeckoResult.fromValue(GeckoSession.PermissionDelegate.ContentPermission.VALUE_DENY)
|
||||
session: GeckoSession, perm: ContentPermission):
|
||||
GeckoResult<Int> {
|
||||
return GeckoResult.fromValue(ContentPermission.VALUE_DENY)
|
||||
}
|
||||
|
||||
@AssertCalled(count = 0)
|
||||
override fun onAndroidPermissionsRequest(
|
||||
session: GeckoSession, permissions: Array<out String>?,
|
||||
callback: GeckoSession.PermissionDelegate.Callback) {
|
||||
callback: PermissionDelegate.Callback) {
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -253,13 +258,13 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
// Error code 1 means permission denied.
|
||||
assertThat("Request should fail", errorCode as Double, equalTo(1.0))
|
||||
|
||||
val perms = sessionRule.waitForResult(sessionRule.runtime.storageController.getPermissions(url))
|
||||
val perms = sessionRule.waitForResult(storageController.getPermissions(url))
|
||||
|
||||
assertThat("Permissions should not be null", perms, notNullValue())
|
||||
var permFound : Boolean = false
|
||||
var permFound = false
|
||||
for (perm in perms) {
|
||||
if (perm.permission == GeckoSession.PermissionDelegate.PERMISSION_GEOLOCATION &&
|
||||
url.startsWith(perm.uri) && perm.value == GeckoSession.PermissionDelegate.ContentPermission.VALUE_DENY) {
|
||||
if (perm.permission == PermissionDelegate.PERMISSION_GEOLOCATION &&
|
||||
url.startsWith(perm.uri) && perm.value == ContentPermission.VALUE_DENY) {
|
||||
permFound = true
|
||||
}
|
||||
}
|
||||
|
@ -268,11 +273,11 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
|
||||
mainSession.delegateDuringNextWait(object : NavigationDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<GeckoSession.PermissionDelegate.ContentPermission>) {
|
||||
var permFound2 : Boolean = false
|
||||
override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) {
|
||||
var permFound2 = false
|
||||
for (perm in perms) {
|
||||
if (perm.permission == GeckoSession.PermissionDelegate.PERMISSION_GEOLOCATION &&
|
||||
perm.value == GeckoSession.PermissionDelegate.ContentPermission.VALUE_DENY) {
|
||||
if (perm.permission == PermissionDelegate.PERMISSION_GEOLOCATION &&
|
||||
perm.value == ContentPermission.VALUE_DENY) {
|
||||
permFound2 = true
|
||||
}
|
||||
}
|
||||
|
@ -292,12 +297,12 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
mainSession.delegateDuringNextWait(object : PermissionDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onContentPermissionRequest(
|
||||
session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission):
|
||||
GeckoResult<Int>? {
|
||||
session: GeckoSession, perm: ContentPermission):
|
||||
GeckoResult<Int> {
|
||||
assertThat("URI should match", perm.uri, endsWith(url))
|
||||
assertThat("Type should match", perm.permission,
|
||||
equalTo(GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION))
|
||||
return GeckoResult.fromValue(GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW)
|
||||
equalTo(PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION))
|
||||
return GeckoResult.fromValue(ContentPermission.VALUE_ALLOW)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -306,13 +311,13 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
assertThat("Permission should be granted",
|
||||
result as String, equalTo("granted"))
|
||||
|
||||
val perms = sessionRule.waitForResult(sessionRule.runtime.storageController.getPermissions(url))
|
||||
val perms = sessionRule.waitForResult(storageController.getPermissions(url))
|
||||
|
||||
assertThat("Permissions should not be null", perms, notNullValue())
|
||||
var permFound : Boolean = false
|
||||
var permFound = false
|
||||
for (perm in perms) {
|
||||
if (perm.permission == GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
url.startsWith(perm.uri) && perm.value == GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW) {
|
||||
if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
url.startsWith(perm.uri) && perm.value == ContentPermission.VALUE_ALLOW) {
|
||||
permFound = true
|
||||
}
|
||||
}
|
||||
|
@ -321,11 +326,11 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
|
||||
mainSession.delegateDuringNextWait(object : NavigationDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<GeckoSession.PermissionDelegate.ContentPermission>) {
|
||||
var permFound2 : Boolean = false
|
||||
override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) {
|
||||
var permFound2 = false
|
||||
for (perm in perms) {
|
||||
if (perm.permission == GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
perm.value == GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW) {
|
||||
if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
perm.value == ContentPermission.VALUE_ALLOW) {
|
||||
permFound2 = true
|
||||
}
|
||||
}
|
||||
|
@ -350,9 +355,9 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
mainSession.delegateDuringNextWait(object : PermissionDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onContentPermissionRequest(
|
||||
session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission):
|
||||
GeckoResult<Int>? {
|
||||
return GeckoResult.fromValue(GeckoSession.PermissionDelegate.ContentPermission.VALUE_DENY)
|
||||
session: GeckoSession, perm: ContentPermission):
|
||||
GeckoResult<Int> {
|
||||
return GeckoResult.fromValue(ContentPermission.VALUE_DENY)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -361,13 +366,13 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
assertThat("Permission should not be granted",
|
||||
result as String, equalTo("denied"))
|
||||
|
||||
val perms = sessionRule.waitForResult(sessionRule.runtime.storageController.getPermissions(url))
|
||||
val perms = sessionRule.waitForResult(storageController.getPermissions(url))
|
||||
|
||||
assertThat("Permissions should not be null", perms, notNullValue())
|
||||
var permFound : Boolean = false
|
||||
var permFound = false
|
||||
for (perm in perms) {
|
||||
if (perm.permission == GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
url.startsWith(perm.uri) && perm.value == GeckoSession.PermissionDelegate.ContentPermission.VALUE_DENY) {
|
||||
if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
url.startsWith(perm.uri) && perm.value == ContentPermission.VALUE_DENY) {
|
||||
permFound = true
|
||||
}
|
||||
}
|
||||
|
@ -376,11 +381,11 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
|
||||
mainSession.delegateDuringNextWait(object : NavigationDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<GeckoSession.PermissionDelegate.ContentPermission>) {
|
||||
var permFound2 : Boolean = false
|
||||
override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) {
|
||||
var permFound2 = false
|
||||
for (perm in perms) {
|
||||
if (perm.permission == GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
perm.value == GeckoSession.PermissionDelegate.ContentPermission.VALUE_DENY) {
|
||||
if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
perm.value == ContentPermission.VALUE_DENY) {
|
||||
permFound2 = true
|
||||
}
|
||||
}
|
||||
|
@ -401,11 +406,11 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
|
||||
mainSession.waitUntilCalled(object : PermissionDelegate {
|
||||
@AssertCalled(count = 2)
|
||||
override fun onContentPermissionRequest(session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission):
|
||||
GeckoResult<Int>? {
|
||||
val expectedType = if (sessionRule.currentCall.counter == 1) GeckoSession.PermissionDelegate.PERMISSION_AUTOPLAY_AUDIBLE else GeckoSession.PermissionDelegate.PERMISSION_AUTOPLAY_INAUDIBLE
|
||||
override fun onContentPermissionRequest(session: GeckoSession, perm: ContentPermission):
|
||||
GeckoResult<Int> {
|
||||
val expectedType = if (sessionRule.currentCall.counter == 1) PermissionDelegate.PERMISSION_AUTOPLAY_AUDIBLE else PermissionDelegate.PERMISSION_AUTOPLAY_INAUDIBLE
|
||||
assertThat("Type should match", perm.permission, equalTo(expectedType))
|
||||
return GeckoResult.fromValue(GeckoSession.PermissionDelegate.ContentPermission.VALUE_DENY)
|
||||
return GeckoResult.fromValue(ContentPermission.VALUE_DENY)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -420,13 +425,13 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
mainSession.delegateDuringNextWait(object : PermissionDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onContentPermissionRequest(
|
||||
session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission):
|
||||
GeckoResult<Int>? {
|
||||
session: GeckoSession, perm: ContentPermission):
|
||||
GeckoResult<Int> {
|
||||
assertThat("URI should match", perm.uri, endsWith(url))
|
||||
assertThat("Type should match", perm.permission,
|
||||
equalTo(GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION))
|
||||
equalTo(PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION))
|
||||
assertThat("Context ID should match", perm.contextId, equalTo(mainSession.settings.contextId))
|
||||
return GeckoResult.fromValue(GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW)
|
||||
return GeckoResult.fromValue(ContentPermission.VALUE_ALLOW)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -435,13 +440,13 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
assertThat("Permission should be granted",
|
||||
result as String, equalTo("granted"))
|
||||
|
||||
val perms = sessionRule.waitForResult(sessionRule.runtime.storageController.getPermissions(url))
|
||||
val perms = sessionRule.waitForResult(storageController.getPermissions(url))
|
||||
|
||||
assertThat("Permissions should not be null", perms, notNullValue())
|
||||
var permFound: Boolean = false
|
||||
var permFound = false
|
||||
for (perm in perms) {
|
||||
if (perm.permission == GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
url.startsWith(perm.uri) && perm.value == GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW) {
|
||||
if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
url.startsWith(perm.uri) && perm.value == ContentPermission.VALUE_ALLOW) {
|
||||
permFound = true
|
||||
}
|
||||
}
|
||||
|
@ -450,11 +455,11 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
|
||||
mainSession.delegateDuringNextWait(object : NavigationDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<GeckoSession.PermissionDelegate.ContentPermission>) {
|
||||
var permFound2: Boolean = false
|
||||
override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) {
|
||||
var permFound2 = false
|
||||
for (perm in perms) {
|
||||
if (perm.permission == GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
perm.value == GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW) {
|
||||
if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
perm.value == ContentPermission.VALUE_ALLOW) {
|
||||
permFound2 = true
|
||||
}
|
||||
}
|
||||
|
@ -475,14 +480,14 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
session2.delegateDuringNextWait(object : PermissionDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onContentPermissionRequest(
|
||||
session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission):
|
||||
GeckoResult<Int>? {
|
||||
session: GeckoSession, perm: ContentPermission):
|
||||
GeckoResult<Int> {
|
||||
assertThat("URI should match", perm.uri, endsWith(url))
|
||||
assertThat("Type should match", perm.permission,
|
||||
equalTo(GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION))
|
||||
equalTo(PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION))
|
||||
assertThat("Context ID should match", perm.contextId,
|
||||
equalTo(session2.settings.contextId))
|
||||
return GeckoResult.fromValue(GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW)
|
||||
return GeckoResult.fromValue(ContentPermission.VALUE_ALLOW)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -491,13 +496,13 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
assertThat("Permission should be granted",
|
||||
result2 as String, equalTo("granted"))
|
||||
|
||||
val perms2 = sessionRule.waitForResult(sessionRule.runtime.storageController.getPermissions(url))
|
||||
val perms2 = sessionRule.waitForResult(storageController.getPermissions(url))
|
||||
|
||||
assertThat("Permissions should not be null", perms, notNullValue())
|
||||
permFound = false
|
||||
for (perm in perms2) {
|
||||
if (perm.permission == GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
url.startsWith(perm.uri) && perm.value == GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW) {
|
||||
if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
url.startsWith(perm.uri) && perm.value == ContentPermission.VALUE_ALLOW) {
|
||||
permFound = true
|
||||
}
|
||||
}
|
||||
|
@ -506,11 +511,11 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
|
||||
session2.delegateDuringNextWait(object : NavigationDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<GeckoSession.PermissionDelegate.ContentPermission>) {
|
||||
var permFound2: Boolean = false
|
||||
override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) {
|
||||
var permFound2 = false
|
||||
for (perm in perms) {
|
||||
if (perm.permission == GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
perm.value == GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW &&
|
||||
if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
perm.value == ContentPermission.VALUE_ALLOW &&
|
||||
perm.contextId == session2.settings.contextId) {
|
||||
permFound2 = true
|
||||
}
|
||||
|
@ -531,24 +536,24 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
mainSession.delegateDuringNextWait(object : PermissionDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onContentPermissionRequest(
|
||||
session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission):
|
||||
GeckoResult<Int>? {
|
||||
session: GeckoSession, perm: ContentPermission):
|
||||
GeckoResult<Int> {
|
||||
assertThat("URI should match", perm.uri, endsWith(url))
|
||||
assertThat("Type should match", perm.permission,
|
||||
equalTo(GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION))
|
||||
return GeckoResult.fromValue(GeckoSession.PermissionDelegate.ContentPermission.VALUE_DENY)
|
||||
equalTo(PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION))
|
||||
return GeckoResult.fromValue(ContentPermission.VALUE_DENY)
|
||||
}
|
||||
})
|
||||
mainSession.waitForJS("Notification.requestPermission()")
|
||||
|
||||
val perms = sessionRule.waitForResult(sessionRule.runtime.storageController.getPermissions(url))
|
||||
val perms = sessionRule.waitForResult(storageController.getPermissions(url))
|
||||
|
||||
assertThat("Permissions should not be null", perms, notNullValue())
|
||||
var permFound : Boolean = false
|
||||
var notificationPerm : GeckoSession.PermissionDelegate.ContentPermission? = null
|
||||
var permFound = false
|
||||
var notificationPerm : ContentPermission? = null
|
||||
for (perm in perms) {
|
||||
if (perm.permission == GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
url.startsWith(perm.uri) && perm.value == GeckoSession.PermissionDelegate.ContentPermission.VALUE_DENY) {
|
||||
if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
url.startsWith(perm.uri) && perm.value == ContentPermission.VALUE_DENY) {
|
||||
notificationPerm = perm
|
||||
permFound = true
|
||||
}
|
||||
|
@ -556,16 +561,16 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
|
||||
assertThat("Notification permission should be set to allow", permFound, equalTo(true))
|
||||
|
||||
sessionRule.runtime.storageController.setPermission(notificationPerm!!,
|
||||
GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW)
|
||||
storageController.setPermission(notificationPerm!!,
|
||||
ContentPermission.VALUE_ALLOW)
|
||||
|
||||
mainSession.delegateDuringNextWait(object : NavigationDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<GeckoSession.PermissionDelegate.ContentPermission>) {
|
||||
var permFound2 : Boolean = false
|
||||
override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) {
|
||||
var permFound2 = false
|
||||
for (perm in perms) {
|
||||
if (perm.permission == GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
perm.value == GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW) {
|
||||
if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
perm.value == ContentPermission.VALUE_ALLOW) {
|
||||
permFound2 = true
|
||||
}
|
||||
}
|
||||
|
@ -590,12 +595,12 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
mainSession.delegateDuringNextWait(object : PermissionDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onContentPermissionRequest(
|
||||
session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission):
|
||||
GeckoResult<Int>? {
|
||||
session: GeckoSession, perm: ContentPermission):
|
||||
GeckoResult<Int> {
|
||||
assertThat("URI should match", perm.uri, endsWith(url))
|
||||
assertThat("Type should match", perm.permission,
|
||||
equalTo(GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION))
|
||||
return GeckoResult.fromValue(GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW)
|
||||
equalTo(PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION))
|
||||
return GeckoResult.fromValue(ContentPermission.VALUE_ALLOW)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -604,14 +609,14 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
assertThat("Permission should be granted",
|
||||
result as String, equalTo("granted"))
|
||||
|
||||
val perms = sessionRule.waitForResult(sessionRule.runtime.storageController.getPermissions(url))
|
||||
val perms = sessionRule.waitForResult(storageController.getPermissions(url))
|
||||
|
||||
assertThat("Permissions should not be null", perms, notNullValue())
|
||||
var permFound : Boolean = false
|
||||
var notificationPerm : GeckoSession.PermissionDelegate.ContentPermission? = null
|
||||
var permFound = false
|
||||
var notificationPerm : ContentPermission? = null
|
||||
for (perm in perms) {
|
||||
if (perm.permission == GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
url.startsWith(perm.uri) && perm.value == GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW) {
|
||||
if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
url.startsWith(perm.uri) && perm.value == ContentPermission.VALUE_ALLOW) {
|
||||
notificationPerm = perm
|
||||
permFound = true
|
||||
}
|
||||
|
@ -619,16 +624,16 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
|
||||
assertThat("Notification permission should be set to allow", permFound, equalTo(true))
|
||||
|
||||
sessionRule.runtime.storageController.setPermission(notificationPerm!!,
|
||||
GeckoSession.PermissionDelegate.ContentPermission.VALUE_DENY)
|
||||
storageController.setPermission(notificationPerm!!,
|
||||
ContentPermission.VALUE_DENY)
|
||||
|
||||
mainSession.delegateDuringNextWait(object : NavigationDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<GeckoSession.PermissionDelegate.ContentPermission>) {
|
||||
var permFound2 : Boolean = false
|
||||
override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) {
|
||||
var permFound2 = false
|
||||
for (perm in perms) {
|
||||
if (perm.permission == GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
perm.value == GeckoSession.PermissionDelegate.ContentPermission.VALUE_DENY) {
|
||||
if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
perm.value == ContentPermission.VALUE_DENY) {
|
||||
permFound2 = true
|
||||
}
|
||||
}
|
||||
|
@ -653,12 +658,12 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
mainSession.delegateDuringNextWait(object : PermissionDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onContentPermissionRequest(
|
||||
session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission):
|
||||
GeckoResult<Int>? {
|
||||
session: GeckoSession, perm: ContentPermission):
|
||||
GeckoResult<Int> {
|
||||
assertThat("URI should match", perm.uri, endsWith(url))
|
||||
assertThat("Type should match", perm.permission,
|
||||
equalTo(GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION))
|
||||
return GeckoResult.fromValue(GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW)
|
||||
equalTo(PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION))
|
||||
return GeckoResult.fromValue(ContentPermission.VALUE_ALLOW)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -667,14 +672,14 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
assertThat("Permission should be granted",
|
||||
result as String, equalTo("granted"))
|
||||
|
||||
val perms = sessionRule.waitForResult(sessionRule.runtime.storageController.getPermissions(url))
|
||||
val perms = sessionRule.waitForResult(storageController.getPermissions(url))
|
||||
|
||||
assertThat("Permissions should not be null", perms, notNullValue())
|
||||
var permFound : Boolean = false
|
||||
var notificationPerm : GeckoSession.PermissionDelegate.ContentPermission? = null
|
||||
var permFound = false
|
||||
var notificationPerm : ContentPermission? = null
|
||||
for (perm in perms) {
|
||||
if (perm.permission == GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
url.startsWith(perm.uri) && perm.value == GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW) {
|
||||
if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
url.startsWith(perm.uri) && perm.value == ContentPermission.VALUE_ALLOW) {
|
||||
notificationPerm = perm
|
||||
permFound = true
|
||||
}
|
||||
|
@ -682,15 +687,15 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
|
||||
assertThat("Notification permission should be set to allow", permFound, equalTo(true))
|
||||
|
||||
sessionRule.runtime.storageController.setPermission(notificationPerm!!,
|
||||
GeckoSession.PermissionDelegate.ContentPermission.VALUE_PROMPT)
|
||||
storageController.setPermission(notificationPerm!!,
|
||||
ContentPermission.VALUE_PROMPT)
|
||||
|
||||
mainSession.delegateDuringNextWait(object : PermissionDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onContentPermissionRequest(
|
||||
session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission):
|
||||
GeckoResult<Int>? {
|
||||
return GeckoResult.fromValue(GeckoSession.PermissionDelegate.ContentPermission.VALUE_PROMPT)
|
||||
session: GeckoSession, perm: ContentPermission):
|
||||
GeckoResult<Int> {
|
||||
return GeckoResult.fromValue(ContentPermission.VALUE_PROMPT)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -709,12 +714,12 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
mainSession.delegateDuringNextWait(object : PermissionDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onContentPermissionRequest(
|
||||
session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission):
|
||||
GeckoResult<Int>? {
|
||||
session: GeckoSession, perm: ContentPermission):
|
||||
GeckoResult<Int> {
|
||||
assertThat("URI should match", perm.uri, endsWith(url))
|
||||
assertThat("Type should match", perm.permission,
|
||||
equalTo(GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION))
|
||||
return GeckoResult.fromValue(GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW)
|
||||
equalTo(PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION))
|
||||
return GeckoResult.fromValue(ContentPermission.VALUE_ALLOW)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -723,14 +728,14 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
assertThat("Permission should be granted",
|
||||
result as String, equalTo("granted"))
|
||||
|
||||
val perms = sessionRule.waitForResult(sessionRule.runtime.storageController.getPermissions(url))
|
||||
val perms = sessionRule.waitForResult(storageController.getPermissions(url))
|
||||
|
||||
assertThat("Permissions should not be null", perms, notNullValue())
|
||||
var permFound : Boolean = false
|
||||
var notificationPerm : GeckoSession.PermissionDelegate.ContentPermission? = null
|
||||
var permFound = false
|
||||
var notificationPerm : ContentPermission? = null
|
||||
for (perm in perms) {
|
||||
if (perm.permission == GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
url.startsWith(perm.uri) && perm.value == GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW) {
|
||||
if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION &&
|
||||
url.startsWith(perm.uri) && perm.value == ContentPermission.VALUE_ALLOW) {
|
||||
notificationPerm = perm
|
||||
permFound = true
|
||||
}
|
||||
|
@ -741,7 +746,7 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
val jsonPerm = notificationPerm?.toJson()
|
||||
assertThat("JSON export should not be null", jsonPerm, notNullValue())
|
||||
|
||||
val importedPerm = GeckoSession.PermissionDelegate.ContentPermission.fromJson(jsonPerm!!)
|
||||
val importedPerm = ContentPermission.fromJson(jsonPerm!!)
|
||||
assertThat("JSON import should not be null", importedPerm, notNullValue())
|
||||
|
||||
assertThat("URIs should match", importedPerm?.uri, equalTo(notificationPerm?.uri))
|
||||
|
@ -760,7 +765,7 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
// @AssertCalled(count = 1)
|
||||
// override fun onContentPermissionRequest(
|
||||
// session: GeckoSession, uri: String?, type: Int,
|
||||
// callback: GeckoSession.PermissionDelegate.Callback) {
|
||||
// callback: PermissionDelegate.Callback) {
|
||||
// callback.reject()
|
||||
// }
|
||||
// })
|
||||
|
@ -776,10 +781,10 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
// @AssertCalled(count = 1, order = [1])
|
||||
// override fun onContentPermissionRequest(
|
||||
// session: GeckoSession, uri: String?, type: Int,
|
||||
// callback: GeckoSession.PermissionDelegate.Callback) {
|
||||
// callback: PermissionDelegate.Callback) {
|
||||
// assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH))
|
||||
// assertThat("Type should match", type,
|
||||
// equalTo(GeckoSession.PermissionDelegate.PERMISSION_PERSISTENT_STORAGE))
|
||||
// equalTo(PermissionDelegate.PERMISSION_PERSISTENT_STORAGE))
|
||||
// callback.grant()
|
||||
// }
|
||||
// })
|
||||
|
@ -795,7 +800,7 @@ class PermissionDelegateTest : BaseSessionTest() {
|
|||
// @AssertCalled(count = 1)
|
||||
// override fun onContentPermissionRequest(
|
||||
// session: GeckoSession, uri: String?, type: Int,
|
||||
// callback: GeckoSession.PermissionDelegate.Callback) {
|
||||
// callback: PermissionDelegate.Callback) {
|
||||
// callback.reject()
|
||||
// }
|
||||
// })
|
||||
|
|
Загрузка…
Ссылка в новой задаче