diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
commit | a90a5cba08fdf6c0ceb95101c275108a152a3aed (patch) | |
tree | 532507288f3defd7f4dcf1af49698bcb76034855 /dom/tests/mochitest/general | |
parent | Adding debian version 126.0.1-1. (diff) | |
download | firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/tests/mochitest/general')
7 files changed, 304 insertions, 87 deletions
diff --git a/dom/tests/mochitest/general/frameStoragePrevented.html b/dom/tests/mochitest/general/frameStoragePrevented.html index 693beff5a4..baa74b1773 100644 --- a/dom/tests/mochitest/general/frameStoragePrevented.html +++ b/dom/tests/mochitest/general/frameStoragePrevented.html @@ -17,7 +17,7 @@ return new Promise((resolve, reject) => { var w; try { - w = new Worker("workerStoragePrevented.js"); + w = new Worker("workerStoragePrevented.js#outer"); } catch (e) { ok(true, "Running workers was prevented"); resolve(); @@ -35,7 +35,7 @@ } // Try to run a worker, which shouldn't be able to access storage - await runWorker("workerStoragePrevented.js"); + await runWorker("workerStoragePrevented.js#outer"); }); </script> diff --git a/dom/tests/mochitest/general/storagePermissionsUtils.js b/dom/tests/mochitest/general/storagePermissionsUtils.js index cfab2f0a14..b17adab6b4 100644 --- a/dom/tests/mochitest/general/storagePermissionsUtils.js +++ b/dom/tests/mochitest/general/storagePermissionsUtils.js @@ -38,7 +38,11 @@ function runIFrame(url) { return; } - ok(!e.data.match(/^FAILURE/), e.data + " (IFRAME = " + url + ")"); + const isFail = e.data.match(/^FAILURE/); + ok(!isFail, e.data + " (IFRAME = " + url + ")"); + if (isFail) { + reject(e); + } } window.addEventListener("message", onMessage); @@ -57,6 +61,11 @@ function runWorker(url) { ok(!e.data.match(/^FAILURE/), e.data + " (WORKER = " + url + ")"); }); + + worker.addEventListener("error", function (e) { + ok(false, e.data + " (WORKER = " + url + ")"); + reject(e); + }); }); } @@ -130,24 +139,59 @@ function storageAllowed() { ok(false, "getting indexedDB should not throw"); } + const dbName = "db"; + try { var promise = caches.keys(); ok(true, "getting caches didn't throw"); return new Promise((resolve, reject) => { - promise.then( - function () { - ok(location.protocol == "https:", "The promise was not rejected"); - resolve(); - }, - function () { - ok( - location.protocol !== "https:", - "The promise should not have been rejected" - ); - resolve(); - } - ); + const checkCacheKeys = () => { + promise.then( + () => { + ok(location.protocol == "https:", "The promise was not rejected"); + resolve(); + }, + () => { + ok( + location.protocol !== "https:", + "The promise should not have been rejected" + ); + resolve(); + } + ); + }; + + const checkDeleteDbAndTheRest = dbs => { + ok( + dbs.some(elem => elem.name === dbName), + "Expected database should be found" + ); + + const end = indexedDB.deleteDatabase(dbName); + end.onsuccess = checkCacheKeys; + end.onerror = err => { + ok(false, "querying indexedDB databases should not throw"); + reject(err); + }; + }; + + const checkDatabasesAndTheRest = () => { + indexedDB + .databases() + .then(checkDeleteDbAndTheRest) + .catch(err => { + ok(false, "deleting an indexedDB database should not throw"); + reject(err); + }); + }; + + const begin = indexedDB.open(dbName); + begin.onsuccess = checkDatabasesAndTheRest; + begin.onerror = err => { + ok(false, "opening an indexedDB database should not throw"); + reject(err); + }; }); } catch (e) { ok(location.protocol !== "https:", "getting caches should not have thrown"); @@ -184,9 +228,47 @@ function storagePrevented() { try { indexedDB; - ok(false, "getting indexedDB should have thrown"); + ok(true, "getting indexedDB didn't throw"); } catch (e) { - ok(true, "getting indexedDB threw"); + ok(false, "getting indexedDB should not have thrown"); + } + + const dbName = "album"; + + try { + indexedDB.open(dbName); + ok(false, "opening an indexedDB database didn't throw"); + } catch (e) { + ok(true, "opening an indexedDB database threw"); + ok( + e.name == "SecurityError", + "opening indexedDB database emitted a security error" + ); + } + + // Note: Security error is expected to be thrown synchronously. + indexedDB.databases().then( + () => { + ok(false, "querying indexedDB databases didn't reject"); + }, + e => { + ok(true, "querying indexedDB databases rejected"); + ok( + e.name == "SecurityError", + "querying indexedDB databases emitted a security error" + ); + } + ); + + try { + indexedDB.deleteDatabase(dbName); + ok(false, "deleting an indexedDB database didn't throw"); + } catch (e) { + ok(true, "deleting an indexedDB database threw"); + ok( + e.name == "SecurityError", + "deleting indexedDB database emitted a security error" + ); } try { @@ -260,8 +342,15 @@ async function runTestInWindow(test) { }; }); - await new Promise(resolve => { + return new Promise((resolve, reject) => { onmessage = e => { + if (!e.data.type) { + w.postMessage("FAILURE: " + e.data, document.referrer); + ok(false, "No error data type"); + reject(e); + return; + } + if (e.data.type == "finish") { w.close(); resolve(); @@ -269,7 +358,15 @@ async function runTestInWindow(test) { } if (e.data.type == "check") { - ok(e.data.test, e.data.msg); + const payload = e.data.msg ? e.data.msg : e.data; + ok(e.data.test, payload); + const isFail = payload.match(/^FAILURE/) || !e.data.test; + if (isFail) { + w.postMessage("FAILURE: " + e.data, document.referrer); + ok(false, payload); + w.close(); + reject(e); + } return; } diff --git a/dom/tests/mochitest/general/test_interfaces.js b/dom/tests/mochitest/general/test_interfaces.js index e6ea910e14..93a26b9238 100644 --- a/dom/tests/mochitest/general/test_interfaces.js +++ b/dom/tests/mochitest/general/test_interfaces.js @@ -73,6 +73,7 @@ let wasmGlobalInterfaces = [ { name: "Function", insecureContext: true, nightly: true }, { name: "Exception", insecureContext: true }, { name: "Tag", insecureContext: true }, + { name: "JSTag", insecureContext: true, earlyBetaOrEarlier: true }, { name: "compile", insecureContext: true }, { name: "compileStreaming", insecureContext: true }, { name: "instantiate", insecureContext: true }, @@ -256,7 +257,7 @@ let interfaceNamesInGlobalScope = [ // IMPORTANT: Do not change this list without review from a DOM peer! { name: "ClipboardEvent", insecureContext: true }, // IMPORTANT: Do not change this list without review from a DOM peer! - { name: "ClipboardItem", earlyBetaOrEarlier: true }, + { name: "ClipboardItem" }, // IMPORTANT: Do not change this list without review from a DOM peer! { name: "CloseEvent", insecureContext: true }, // IMPORTANT: Do not change this list without review from a DOM peer! @@ -328,7 +329,7 @@ let interfaceNamesInGlobalScope = [ // IMPORTANT: Do not change this list without review from a DOM peer! { name: "CSSRuleList", insecureContext: true }, // IMPORTANT: Do not change this list without review from a DOM peer! - { name: "CSSStartingStyleRule", insecureContext: true, disabled: true }, + { name: "CSSStartingStyleRule", insecureContext: true, nightly: true }, // IMPORTANT: Do not change this list without review from a DOM peer! { name: "CSSStyleDeclaration", insecureContext: true }, // IMPORTANT: Do not change this list without review from a DOM peer! diff --git a/dom/tests/mochitest/general/test_storagePermissionsReject.html b/dom/tests/mochitest/general/test_storagePermissionsReject.html index 70dbe856d9..62c06a0639 100644 --- a/dom/tests/mochitest/general/test_storagePermissionsReject.html +++ b/dom/tests/mochitest/general/test_storagePermissionsReject.html @@ -35,7 +35,7 @@ task(async function() { await runIFrame(thirdparty + "frameStorageChrome.html?allowed=no&blockSessionStorage=yes"); // Workers should be unable to access storage - await runWorker("workerStoragePrevented.js"); + await runWorker("workerStoragePrevented.js#outer"); }); }); diff --git a/dom/tests/mochitest/general/window_storagePermissions.html b/dom/tests/mochitest/general/window_storagePermissions.html index 3bab23c13b..92078f2fcc 100644 --- a/dom/tests/mochitest/general/window_storagePermissions.html +++ b/dom/tests/mochitest/general/window_storagePermissions.html @@ -25,6 +25,8 @@ onmessage = e => { let runnable = eval(runnableStr); // eslint-disable-line no-eval runnable.call(this).then(_ => { opener.postMessage({ type: "finish" }, "*"); + }).catch(e => { + ok(false, e.data); }); return; diff --git a/dom/tests/mochitest/general/workerStorageAllowed.js b/dom/tests/mochitest/general/workerStorageAllowed.js index 89e0a4b9ce..93c4c94c48 100644 --- a/dom/tests/mochitest/general/workerStorageAllowed.js +++ b/dom/tests/mochitest/general/workerStorageAllowed.js @@ -14,50 +14,88 @@ function finishTest() { self.close(); } -// Workers don't have access to localstorage or sessionstorage -ok(typeof self.localStorage == "undefined", "localStorage should be undefined"); -ok( - typeof self.sessionStorage == "undefined", - "sessionStorage should be undefined" -); - // Make sure that we can access indexedDB -try { - indexedDB; - ok(true, "WORKER getting indexedDB didn't throw"); -} catch (e) { - ok(false, "WORKER getting indexedDB should not throw"); +function idbTest() { + try { + indexedDB; + + const idbcycle = new Promise((resolve, reject) => { + const begin = indexedDB.open("door"); + begin.onerror = e => { + reject(e); + }; + begin.onsuccess = () => { + indexedDB + .databases() + .then(dbs => { + ok( + dbs.some(elem => elem.name === "door"), + "WORKER just created database should be found" + ); + const end = indexedDB.deleteDatabase("door"); + end.onerror = e => { + reject(e); + }; + end.onsuccess = () => { + resolve(); + }; + }) + .catch(err => { + reject(err); + }); + }; + }); + + idbcycle.then( + () => { + ok(true, "WORKER getting indexedDB didn't throw"); + cacheTest(); + }, + e => { + ok(false, "WORKER getting indexedDB threw " + e.message); + cacheTest(); + } + ); + } catch (e) { + ok(false, "WORKER getting indexedDB should not throw"); + cacheTest(); + } } // Make sure that we can access caches -try { - var promise = caches.keys(); - ok(true, "WORKER getting caches didn't throw"); +function cacheTest() { + try { + var promise = caches.keys(); + ok(true, "WORKER getting caches didn't throw"); - promise.then( - function () { - ok(location.protocol == "https:", "WORKER The promise was not rejected"); - workerTest(); - }, - function () { - ok( - location.protocol !== "https:", - "WORKER The promise should not have been rejected" - ); - workerTest(); - } - ); -} catch (e) { - ok( - location.protocol !== "https:", - "WORKER getting caches should not have thrown" - ); - workerTest(); + promise.then( + function () { + ok( + location.protocol == "https:", + "WORKER The promise was not rejected" + ); + workerTest(); + }, + function () { + ok( + location.protocol !== "https:", + "WORKER The promise should not have been rejected" + ); + workerTest(); + } + ); + } catch (e) { + ok( + location.protocol !== "https:", + "WORKER getting caches should not have thrown" + ); + workerTest(); + } } // Try to spawn an inner worker, and make sure that it can also access storage function workerTest() { - if (location.hash == "#inner") { + if (location.hash != "#outer") { // Don't recurse infinitely, if we are the inner worker, don't spawn another finishTest(); return; @@ -75,4 +113,27 @@ function workerTest() { e.data + " (WORKER = workerStorageAllowed.js#inner)" ); }); + + worker.addEventListener("error", function (e) { + ok(false, e.data + " (WORKER = workerStorageAllowed.js#inner)"); + + finishTest(); + }); +} + +try { + // Workers don't have access to localstorage or sessionstorage + ok( + typeof self.localStorage == "undefined", + "localStorage should be undefined" + ); + ok( + typeof self.sessionStorage == "undefined", + "sessionStorage should be undefined" + ); + + idbTest(); +} catch (e) { + ok(false, "WORKER Unwelcome exception received"); + finishTest(); } diff --git a/dom/tests/mochitest/general/workerStoragePrevented.js b/dom/tests/mochitest/general/workerStoragePrevented.js index 467cc09113..7d232d65df 100644 --- a/dom/tests/mochitest/general/workerStoragePrevented.js +++ b/dom/tests/mochitest/general/workerStoragePrevented.js @@ -21,40 +21,94 @@ ok( "sessionStorage should be undefined" ); -// Make sure that we can't access indexedDB +// Make sure that we can access indexedDB handle try { indexedDB; - ok(false, "WORKER getting indexedDB should have thrown"); + ok(true, "WORKER getting indexedDB didn't throw"); } catch (e) { - ok(true, "WORKER getting indexedDB threw"); + ok(false, "WORKER getting indexedDB threw"); +} + +// Make sure that we cannot access indexedDB methods +idbOpenTest(); + +// Make sure that we can't access indexedDB deleteDatabase +function idbDeleteTest() { + try { + indexedDB.deleteDatabase("door"); + ok(false, "WORKER deleting indexedDB database succeeded"); + } catch (e) { + ok(true, "WORKER deleting indexedDB database failed"); + ok( + e.name == "SecurityError", + "WORKER deleting indexedDB database threw a security error" + ); + } finally { + cacheTest(); + } +} + +// Make sure that we can't access indexedDB databases +function idbDatabasesTest() { + indexedDB + .databases() + .then(() => { + ok(false, "WORKER querying indexedDB databases succeeded"); + }) + .catch(e => { + ok(true, "WORKER querying indexedDB databases failed"); + ok( + e.name == "SecurityError", + "WORKER querying indexedDB databases threw a security error" + ); + }) + .finally(idbDeleteTest); +} + +// Make sure that we can't access indexedDB open +function idbOpenTest() { + try { + indexedDB.open("door"); + ok(false, "WORKER opening indexedDB database succeeded"); + } catch (e) { + ok(true, "WORKER opening indexedDB database failed"); + ok( + e.name == "SecurityError", + "WORKER opening indexedDB database threw a security error" + ); + } finally { + idbDatabasesTest(); + } } // Make sure that we can't access caches -try { - var promise = caches.keys(); - ok(true, "WORKER getting caches didn't throw"); +function cacheTest() { + try { + var promise = caches.keys(); + ok(true, "WORKER getting caches didn't throw"); - promise.then( - function () { - ok(false, "WORKER The promise should have rejected"); - workerTest(); - }, - function () { - ok(true, "WORKER The promise was rejected"); - workerTest(); - } - ); -} catch (e) { - ok( - location.protocol !== "https:", - "WORKER getting caches should not have thrown" - ); - workerTest(); + promise.then( + function () { + ok(false, "WORKER The promise should have rejected"); + workerTest(); + }, + function () { + ok(true, "WORKER The promise was rejected"); + workerTest(); + } + ); + } catch (e) { + ok( + location.protocol !== "https:", + "WORKER getting caches should not have thrown" + ); + workerTest(); + } } // Try to spawn an inner worker, and make sure that it also can't access storage function workerTest() { - if (location.hash == "#inner") { + if (location.hash != "#outer") { // Don't recurse infinitely, if we are the inner worker, don't spawn another finishTest(); return; @@ -62,14 +116,16 @@ function workerTest() { // Create the inner worker, and listen for test messages from it var worker = new Worker("workerStoragePrevented.js#inner"); worker.addEventListener("message", function (e) { - if (e.data == "done") { + const isFail = e.data.match(/^FAILURE/); + ok(!isFail, e.data + " (WORKER = workerStoragePrevented.js#inner)"); + + if (e.data == "done" || isFail) { finishTest(); - return; } + }); + worker.addEventListener("error", function (e) { + ok(false, e.data + " (WORKER = workerStoragePrevented.js#inner)"); - ok( - !e.data.match(/^FAILURE/), - e.data + " (WORKER = workerStoragePrevented.js#inner)" - ); + finishTest(); }); } |