summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/storage-access-api/requestStorageAccess.sub.https.window.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/storage-access-api/requestStorageAccess.sub.https.window.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/storage-access-api/requestStorageAccess.sub.https.window.js')
-rw-r--r--testing/web-platform/tests/storage-access-api/requestStorageAccess.sub.https.window.js104
1 files changed, 104 insertions, 0 deletions
diff --git a/testing/web-platform/tests/storage-access-api/requestStorageAccess.sub.https.window.js b/testing/web-platform/tests/storage-access-api/requestStorageAccess.sub.https.window.js
new file mode 100644
index 0000000000..21c451ca61
--- /dev/null
+++ b/testing/web-platform/tests/storage-access-api/requestStorageAccess.sub.https.window.js
@@ -0,0 +1,104 @@
+// META: script=helpers.js
+// META: script=/cookies/resources/cookie-helper.sub.js
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+'use strict';
+
+// Document-level test config flags:
+//
+// testPrefix: Prefix each test case with an indicator so we know what context
+// they are run in if they are used in multiple iframes.
+//
+// topLevelDocument: Keep track of if we run these tests in a nested context, we
+// don't want to recurse forever.
+const {testPrefix, topLevelDocument} = processQueryParams();
+
+if (!topLevelDocument) {
+ // WPT synthesizes a top-level HTML test for this JS file, and in that case we
+ // don't want to, or need to, call set_test_context.
+ test_driver.set_test_context(window.top);
+}
+
+// Common tests to run in all frames.
+promise_test(async () => {
+ assert_not_equals(document.requestStorageAccess, undefined);
+}, "[" + testPrefix + "] document.requestStorageAccess() should exist on the document interface");
+
+// Most tests need to start with the feature in "prompt" state.
+async function CommonSetup() {
+ await test_driver.set_permission({ name: 'storage-access' }, 'prompt');
+}
+
+promise_test(
+ async t => {
+ await CommonSetup();
+ if (topLevelDocument || !testPrefix.includes('cross-site') ||
+ testPrefix.includes('ABA')) {
+ await document.requestStorageAccess().catch(t.unreached_func(
+ 'document.requestStorageAccess() call should resolve in top-level frame or same-site iframe.'));
+
+ assert_true(await CanAccessCookiesViaHTTP(), 'After obtaining storage access, subresource requests from the frame should send and set cookies.');
+ assert_true(CanAccessCookiesViaJS(), 'After obtaining storage access, scripts in the frame should be able to access cookies.');
+ } else {
+ return promise_rejects_dom(
+ t, "NotAllowedError", document.requestStorageAccess(),
+ "document.requestStorageAccess() call without user gesture.");
+ }
+ },
+ '[' + testPrefix +
+ '] document.requestStorageAccess() should resolve in top-level frame or same-site iframe, otherwise reject with a NotAllowedError with no user gesture.');
+
+promise_test(
+ async (t) => {
+ await CommonSetup();
+ await MaybeSetStorageAccess("*", "*", "blocked");
+ await test_driver.set_permission({name: 'storage-access'}, 'granted');
+ t.add_cleanup(async () => {
+ await test_driver.delete_all_cookies();
+ });
+
+ await document.requestStorageAccess();
+
+ assert_true(await CanAccessCookiesViaHTTP(), 'After obtaining storage access, subresource requests from the frame should send and set cookies.');
+ assert_true(CanAccessCookiesViaJS(), 'After obtaining storage access, scripts in the frame should be able to access cookies.');
+ },
+ '[' + testPrefix +
+ '] document.requestStorageAccess() should be resolved with no user gesture when a permission grant exists, and ' +
+ 'should allow cookie access');
+
+if (testPrefix.includes('cross-site')) {
+ promise_test(
+ async t => {
+ await test_driver.set_permission(
+ {name: 'storage-access'}, 'denied');
+
+ await RunCallbackWithGesture(() => {
+ return promise_rejects_dom(t, "NotAllowedError", document.requestStorageAccess(),
+ "document.requestStorageAccess() call with denied permission");
+ });
+ },
+ '[' + testPrefix +
+ '] document.requestStorageAccess() should be rejected with a NotAllowedError with denied permission');
+} else {
+ promise_test(
+ async () => {
+ await CommonSetup();
+ await document.requestStorageAccess();
+
+ assert_true(await CanAccessCookiesViaHTTP(), 'After obtaining storage access, subresource requests from the frame should send and set cookies.');
+ assert_true(CanAccessCookiesViaJS(), 'After obtaining storage access, scripts in the frame should be able to access cookies.');
+ },
+ `[${testPrefix}] document.requestStorageAccess() should resolve without permission grant or user gesture`);
+
+ promise_test(
+ async () => {
+ await test_driver.set_permission(
+ {name: 'storage-access'}, 'denied');
+
+ await document.requestStorageAccess();
+
+ assert_true(await CanAccessCookiesViaHTTP(), 'After obtaining storage access, subresource requests from the frame should send and set cookies.');
+ assert_true(CanAccessCookiesViaJS(), 'After obtaining storage access, scripts in the frame should be able to access cookies.');
+ },
+ `[${testPrefix}] document.requestStorageAccess() should resolve with denied permission`);
+}