Bug 1835920 - Adding support for set_permission for storage-access-api wpt. r=webdriver-reviewers,bvandersloot,jdescottes,whimboo

Differential Revision: https://phabricator.services.mozilla.com/D183890
This commit is contained in:
Harshit Sohaney 2023-09-20 16:14:37 +00:00
Родитель 208a2c1331
Коммит 2e46ed10a3
13 изменённых файлов: 99 добавлений и 50 удалений

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

@ -3350,7 +3350,13 @@ GeckoDriver.prototype.setPermission = async function (cmd) {
`state is ${state}, expected "granted", "denied", or "prompt"`
)(state);
lazy.permissions.set(descriptor, state, oneRealm);
lazy.permissions.set(
descriptor,
state,
oneRealm,
this.getBrowsingContext(),
this.getBrowsingContext({ top: true })
);
};
/**

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

@ -5,6 +5,7 @@
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
assert: "chrome://remote/content/shared/webdriver/Assert.sys.mjs",
error: "chrome://remote/content/shared/webdriver/Errors.sys.mjs",
MarionettePrefs: "chrome://remote/content/marionette/prefs.sys.mjs",
});
@ -22,29 +23,38 @@ export const permissions = {};
* State of the permission. It can be `granted`, `denied` or `prompt`.
* @param {boolean} oneRealm
* Currently ignored
*
* @param {browsingContext=} thirdPartyBrowsingContext
* 3rd party browsing context object
* @param {browsingContext=} topLevelBrowsingContext
* Top level browsing context object
* @throws {UnsupportedOperationError}
* If `marionette.setpermission.enabled` is not set or
* an unsupported permission is used.
*/
permissions.set = function (descriptor, state, oneRealm) {
permissions.set = function (
descriptor,
state,
oneRealm,
thirdPartyBrowsingContext,
topLevelBrowsingContext
) {
if (!lazy.MarionettePrefs.setPermissionEnabled) {
throw new lazy.error.UnsupportedOperationError(
"'Set Permission' is not available"
);
}
if (state === "prompt") {
throw new lazy.error.UnsupportedOperationError(
"'Set Permission' doesn't support prompt"
);
}
// This is not a real implementation of the permissions API.
// Instead the purpose of this implementation is to have web-platform-tests
// that use `set_permission()` not fail.
// Each test needs the corresponding testing pref to make it actually work.
const { name } = descriptor;
if (state === "prompt" && name !== "storage-access") {
throw new lazy.error.UnsupportedOperationError(
"'Set Permission' doesn't support prompt"
);
}
if (["clipboard-write", "clipboard-read"].includes(name)) {
if (
Services.prefs.getBoolPref("dom.events.testing.asyncClipboard", false)
@ -61,6 +71,49 @@ permissions.set = function (descriptor, state, oneRealm) {
throw new lazy.error.UnsupportedOperationError(
"'Set Permission' expected notification.prompt.testing to be set"
);
} else if (name === "storage-access") {
// Check if browsing context has a window global object
lazy.assert.open(thirdPartyBrowsingContext);
lazy.assert.open(topLevelBrowsingContext);
const thirdPartyURI =
thirdPartyBrowsingContext.currentWindowGlobal.documentURI;
const topLevelURI = topLevelBrowsingContext.currentWindowGlobal.documentURI;
const thirdPartyPrincipalSite = Services.eTLD.getSite(thirdPartyURI);
const topLevelPrincipal =
Services.scriptSecurityManager.createContentPrincipal(topLevelURI, {});
switch (state) {
case "granted": {
Services.perms.addFromPrincipal(
topLevelPrincipal,
"3rdPartyFrameStorage^" + thirdPartyPrincipalSite,
Services.perms.ALLOW_ACTION
);
return;
}
case "denied": {
Services.perms.addFromPrincipal(
topLevelPrincipal,
"3rdPartyFrameStorage^" + thirdPartyPrincipalSite,
Services.perms.DENY_ACTION
);
return;
}
case "prompt": {
Services.perms.removeFromPrincipal(
topLevelPrincipal,
"3rdPartyFrameStorage^" + thirdPartyPrincipalSite
);
return;
}
default:
throw new lazy.error.UnsupportedOperationError(
`'Set Permission' did not work for storage-access'`
);
}
}
throw new lazy.error.UnsupportedOperationError(

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

@ -0,0 +1 @@
prefs: [marionette.setpermission.enabled:true]

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

@ -1,7 +1,6 @@
[requestStorageAccess-ABA.tentative.sub.https.window.html]
expected:
if (os == "android") and swgl: [OK, TIMEOUT]
if (os == "android") and not swgl: [OK, TIMEOUT]
[OK, TIMEOUT, ERROR]
[[ABA\] document.requestStorageAccess() should resolve in top-level frame or same-site iframe, otherwise reject with a NotAllowedError with no user gesture.]
expected: FAIL

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

@ -1,13 +1,13 @@
[requestStorageAccess-cross-origin-iframe-navigation.sub.https.window.html]
expected: TIMEOUT
expected: OK
[Self-initiated same-origin navigations preserve storage access]
expected: NOTRUN
expected: FAIL
[Self-initiated reloads preserve storage access]
expected: TIMEOUT
expected: FAIL
[Non-self-initiated same-origin navigations do not preserve storage access]
expected: NOTRUN
expected: FAIL
[Self-initiated cross-origin navigations do not preserve storage access]
expected: NOTRUN
expected: FAIL

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

@ -3,14 +3,12 @@
if (os == "android") and debug and swgl: [TIMEOUT, OK]
if (os == "android") and debug and not swgl: [OK, TIMEOUT]
if (os == "android") and not debug: [OK, TIMEOUT]
[OK, TIMEOUT]
[[cross-site-frame\] document.requestStorageAccess() should be rejected with a NotAllowedError without permission grant]
expected: FAIL
expected: [TIMEOUT, FAIL]
[[cross-site-frame\] document.requestStorageAccess() should be rejected with a NotAllowedError with denied permission]
expected: FAIL
expected: [NOTRUN, FAIL]
[[cross-site-frame\] document.requestStorageAccess() should be resolved with no user gesture when a permission grant exists, and should allow cookie access]
expected: FAIL
[[cross-site-frame\] document.requestStorageAccess() should resolve in top-level frame or same-site iframe, otherwise reject with a NotAllowedError with no user gesture.]
expected: FAIL

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

@ -1,7 +1,7 @@
[requestStorageAccess-cross-site-sibling-iframes.sub.https.window.html]
expected: TIMEOUT
expected: OK
[Grants have per-frame scope]
expected: TIMEOUT
expected: FAIL
[Cross-site sibling iframes should not be able to take advantage of the existing permission grant requested by others.]
expected: NOTRUN
expected: FAIL

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

@ -1,9 +1,9 @@
[requestStorageAccess-nested-cross-origin-iframe.sub.https.window.html]
expected:
if (os == "android") and not swgl and not debug: [OK, TIMEOUT, ERROR]
if (os == "mac") and not debug: [OK, TIMEOUT]
if (os == "mac") and not debug: [OK, TIMEOUT, ERROR]
if (os == "android") and swgl: [OK, TIMEOUT, ERROR]
if (os == "win") and not debug: [TIMEOUT, OK]
if (os == "win") and not debug: [TIMEOUT, OK, ERROR]
[OK, ERROR, TIMEOUT]
[[nested-cross-origin-frame\] document.requestStorageAccess() should be resolved with no user gesture when a permission grant exists, and should allow cookie access]
expected: FAIL

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

@ -1,16 +1,13 @@
[requestStorageAccess-nested-cross-site-iframe.sub.https.window.html]
expected:
if os == "mac": OK
if os == "win": OK
if os == "mac": [OK, TIMEOUT]
if os == "win": [OK, TIMEOUT]
[OK, TIMEOUT]
[[nested-cross-site-frame\] document.requestStorageAccess() should be rejected with a NotAllowedError without permission grant]
expected: FAIL
expected: [TIMEOUT, FAIL]
[[nested-cross-site-frame\] document.requestStorageAccess() should be rejected with a NotAllowedError with denied permission]
expected: FAIL
expected: [NOTRUN, FAIL]
[[nested-cross-site-frame\] document.requestStorageAccess() should be resolved with no user gesture when a permission grant exists, and should allow cookie access]
expected: FAIL
[[nested-cross-site-frame\] document.requestStorageAccess() should resolve in top-level frame or same-site iframe, otherwise reject with a NotAllowedError with no user gesture.]
expected: FAIL

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

@ -1,15 +1,5 @@
[requestStorageAccess-nested-same-origin-iframe.sub.https.window.html]
expected:
if (os == "win") and debug and (processor == "x86_64") and not swgl: [TIMEOUT, OK, ERROR]
if (os == "win") and debug and (processor == "x86_64") and swgl: [TIMEOUT, OK, ERROR]
if (os == "linux") and debug and not fission and swgl: OK
if (os == "android") and not swgl and not debug: [OK, TIMEOUT, ERROR]
if (os == "win") and not debug and (processor == "x86"): [TIMEOUT, OK]
if (os == "win") and not debug and (processor == "x86_64"): [OK, TIMEOUT]
if (os == "linux") and debug and fission: OK
if (os == "mac") and debug: [TIMEOUT, OK, ERROR]
if (os == "mac") and not debug: [TIMEOUT, OK]
if (os == "android") and swgl: [TIMEOUT, OK]
[OK, ERROR, TIMEOUT]
[[nested-same-origin-frame\] document.requestStorageAccess() should resolve without permission grant or user gesture]
expected: FAIL

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

@ -1,7 +1,7 @@
[requestStorageAccess-same-site-iframe.sub.https.window.html]
expected:
if (os == "mac") and debug: [TIMEOUT, OK]
[OK, TIMEOUT]
[OK, TIMEOUT, ERROR]
[[same-site-frame\] document.requestStorageAccess() should resolve in top-level frame or same-site iframe, otherwise reject with a NotAllowedError with no user gesture.]
expected: FAIL

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

@ -1,4 +1,5 @@
[requestStorageAccess.sub.https.window.html]
expected: ERROR
[[top-level-context\] document.requestStorageAccess() should be resolved with no user gesture when a permission grant exists, and should allow cookie access]
expected: FAIL

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

@ -1,10 +1,14 @@
[storage-access-permission.sub.https.window.html]
expected: TIMEOUT
expected:
[OK, TIMEOUT]
[Permissions grants are observable across same-origin iframes]
expected: TIMEOUT
[IFrame tests]
expected: NOTRUN
expected: [TIMEOUT, FAIL]
[Permissions grants are observable across same-site iframes]
expected: NOTRUN
expected: [NOTRUN, FAIL, TIMEOUT]
[Permission state can be observed]
expected: FAIL
[IFrame tests]
expected: [PASS, NOTRUN]