summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/storage-access-api/helpers.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/storage-access-api/helpers.js
parentInitial commit. (diff)
downloadfirefox-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/helpers.js')
-rw-r--r--testing/web-platform/tests/storage-access-api/helpers.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/testing/web-platform/tests/storage-access-api/helpers.js b/testing/web-platform/tests/storage-access-api/helpers.js
new file mode 100644
index 0000000000..de9fba2d1c
--- /dev/null
+++ b/testing/web-platform/tests/storage-access-api/helpers.js
@@ -0,0 +1,63 @@
+'use strict';
+
+function processQueryParams() {
+ const queryParams = new URL(window.location).searchParams;
+ return {
+ expectAccessAllowed: queryParams.get("allowed") != "false",
+ topLevelDocument: queryParams.get("rootdocument") != "false",
+ testPrefix: queryParams.get("testCase") || "top-level-context",
+ };
+}
+
+function CreateFrameAndRunTests(setUpFrame) {
+ const frame = document.createElement('iframe');
+ const promise = new Promise((resolve, reject) => {
+ frame.onload = resolve;
+ frame.onerror = reject;
+ });
+
+ setUpFrame(frame);
+
+ fetch_tests_from_window(frame.contentWindow);
+ return promise;
+}
+
+function RunTestsInIFrame(sourceURL) {
+ return CreateFrameAndRunTests((frame) => {
+ frame.src = sourceURL;
+ document.body.appendChild(frame);
+ });
+}
+
+function RunTestsInNestedIFrame(sourceURL) {
+ return CreateFrameAndRunTests((frame) => {
+ document.body.appendChild(frame);
+ frame.contentDocument.write(`
+ <script src="/resources/testharness.js"></script>
+ <script src="helpers.js"></script>
+ <body>
+ <script>
+ RunTestsInIFrame("${sourceURL}");
+ </script>
+ `);
+ frame.contentDocument.close();
+ });
+}
+
+function RunRequestStorageAccessInDetachedFrame() {
+ const frame = document.createElement('iframe');
+ document.body.append(frame);
+ const inner_doc = frame.contentDocument;
+ frame.remove();
+ return inner_doc.requestStorageAccess();
+}
+
+function RunRequestStorageAccessViaDomParser() {
+ const parser = new DOMParser();
+ const doc = parser.parseFromString('<html></html>', 'text/html');
+ return doc.requestStorageAccess();
+}
+
+function RunCallbackWithGesture(callback) {
+ return test_driver.bless('run callback with user gesture', callback);
+}