diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/storage-access-api/requestStorageAccess.sub.https.window.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
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.js | 67 |
1 files changed, 67 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..a74866e56b --- /dev/null +++ b/testing/web-platform/tests/storage-access-api/requestStorageAccess.sub.https.window.js @@ -0,0 +1,67 @@ +// META: script=helpers.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. +const {testPrefix} = processQueryParams(); + +if (window !== window.top) { + // 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. +test(() => { + assert_not_equals(document.requestStorageAccess, undefined); +}, "[" + testPrefix + "] document.requestStorageAccess() should exist on the document interface"); + +// Promise tests should all start with the feature in "prompt" state. +promise_setup(async () => { + await test_driver.set_permission( + { name: 'storage-access' }, 'prompt'); +}); + +promise_test(t => { + return promise_rejects_dom(t, "NotAllowedError", document.requestStorageAccess(), + "document.requestStorageAccess() call without user gesture"); +}, "[" + testPrefix + "] document.requestStorageAccess() should be rejected with a NotAllowedError by default with no user gesture"); + +promise_test( + async () => { + await test_driver.set_permission( + {name: 'storage-access'}, 'granted'); + + await RunCallbackWithGesture(() => document.requestStorageAccess()); + }, + '[' + testPrefix + + '] document.requestStorageAccess() should be resolved when called properly with a user gesture'); + +if (testPrefix == 'cross-origin-frame' || testPrefix == 'nested-cross-origin-frame') { + promise_test( + async t => { + await RunCallbackWithGesture(() => { + return promise_rejects_dom(t, "NotAllowedError", document.requestStorageAccess(), + "document.requestStorageAccess() call without permission"); + }); + }, + '[' + testPrefix + + '] document.requestStorageAccess() should be rejected with a NotAllowedError without permission grant'); + + 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 without permission"); + }); + }, + '[' + testPrefix + + '] document.requestStorageAccess() should be rejected with a NotAllowedError with denied permission'); +} |