summaryrefslogtreecommitdiffstats
path: root/dom/tests
diff options
context:
space:
mode:
Diffstat (limited to 'dom/tests')
-rw-r--r--dom/tests/browser/browser.toml1
-rw-r--r--dom/tests/mochitest/chrome/test_focus.xhtml5
-rw-r--r--dom/tests/mochitest/general/frameStoragePrevented.html4
-rw-r--r--dom/tests/mochitest/general/storagePermissionsUtils.js133
-rw-r--r--dom/tests/mochitest/general/test_interfaces.js5
-rw-r--r--dom/tests/mochitest/general/test_storagePermissionsReject.html2
-rw-r--r--dom/tests/mochitest/general/window_storagePermissions.html2
-rw-r--r--dom/tests/mochitest/general/workerStorageAllowed.js131
-rw-r--r--dom/tests/mochitest/general/workerStoragePrevented.js114
-rw-r--r--dom/tests/mochitest/webcomponents/chrome.toml2
-rw-r--r--dom/tests/mochitest/webcomponents/test_custom_element_auto_import.html (renamed from dom/tests/mochitest/webcomponents/test_custom_element_ensure_custom_element.html)34
11 files changed, 321 insertions, 112 deletions
diff --git a/dom/tests/browser/browser.toml b/dom/tests/browser/browser.toml
index dfb7c2c569..1e9f994488 100644
--- a/dom/tests/browser/browser.toml
+++ b/dom/tests/browser/browser.toml
@@ -44,6 +44,7 @@ tags = "geolocation"
skip-if = ["os != 'mac'"]
["browser_bug1238427.js"]
+https_first_disabled = true
["browser_bug1316330.js"]
diff --git a/dom/tests/mochitest/chrome/test_focus.xhtml b/dom/tests/mochitest/chrome/test_focus.xhtml
index 3e30104af4..ab383c4e1e 100644
--- a/dom/tests/mochitest/chrome/test_focus.xhtml
+++ b/dom/tests/mochitest/chrome/test_focus.xhtml
@@ -9,10 +9,7 @@
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script>
-if (navigator.platform.startsWith("Win")) {
- SimpleTest.expectAssertions(0, 1);
-}
-
+SimpleTest.expectAssertions(0, 1);
SimpleTest.waitForExplicitFinish();
async function runTest()
{
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();
});
}
diff --git a/dom/tests/mochitest/webcomponents/chrome.toml b/dom/tests/mochitest/webcomponents/chrome.toml
index b29df619c4..5db7f14a37 100644
--- a/dom/tests/mochitest/webcomponents/chrome.toml
+++ b/dom/tests/mochitest/webcomponents/chrome.toml
@@ -1,7 +1,7 @@
[DEFAULT]
support-files = ["dummy_page.html"]
-["test_custom_element_ensure_custom_element.html"]
+["test_custom_element_auto_import.html"]
["test_custom_element_htmlconstructor_chrome.html"]
support-files = [
diff --git a/dom/tests/mochitest/webcomponents/test_custom_element_ensure_custom_element.html b/dom/tests/mochitest/webcomponents/test_custom_element_auto_import.html
index 03ed2e3815..2371600677 100644
--- a/dom/tests/mochitest/webcomponents/test_custom_element_ensure_custom_element.html
+++ b/dom/tests/mochitest/webcomponents/test_custom_element_auto_import.html
@@ -1,11 +1,8 @@
<!DOCTYPE HTML>
<html lang="en">
- <!--
- https://bugzilla.mozilla.org/show_bug.cgi?id=1813077
- -->
<head>
<meta charset="utf-8">
- <title>Test for customElements.ensureCustomElement</title>
+ <title>Test for custom element auto import behavior</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<script>
@@ -14,36 +11,33 @@
outside of the task that imported them. This can create issues if writing
another test in this file.
*/
- add_task(async function test_ensure_custom_elements() {
+ add_task(async function test_custom_elements_auto_import() {
let registry = SpecialPowers.wrap(customElements);
- ok(window.ensureCustomElements, "should be defined");
// Ensure the custom elements from ESModules are not defined.
is(registry.get("moz-button-group"), undefined, "moz-button-group should be undefined since we have not yet imported it");
is(registry.get("moz-support-link"), undefined, "moz-support-link should be undefined since we have not yet imported it");
is(registry.get("moz-toggle"), undefined, "moz-toggle should be undefined since we have not yet imported it");
- // Import a single custom element and assert it exists in the custom
- // element registry
- let modules = await window.ensureCustomElements("moz-support-link");
- ok(registry.get("moz-support-link"), "moz-support-link should be defined after importing it");
- is(modules, null, "There should not be a return value when using ensureCustomElements");
+ // Create a custom element and assert that it gets imported/defined.
+ document.createElement("moz-support-link");
+ ok(registry.get("moz-support-link"), "moz-support-link should be defined after creation");
- // Import multiple custom elements and assert they exist in the registry
- modules = undefined;
+ // Create multiple custom elements and assert they exist in the registry.
is(registry.get("moz-button-group"), undefined, "moz-button-group should be undefined since we have not yet imported it");
is(registry.get("moz-toggle"), undefined, "moz-toggle should be undefined since we have not yet imported it")
- modules = await window.ensureCustomElements("moz-toggle", "moz-button-group");
- is(modules, null, "There should not be a return value when using ensureCustomElements");
+
+ document.createElement("moz-button-group");
+ document.createElement("moz-toggle");
+
ok(registry.get("moz-toggle"), "moz-toggle should be defined after importing it");
ok(registry.get("moz-button-group"), "moz-button-group should be defined after importing it");
- // Ensure there are no errors if the imported elements are imported
- // again
- modules = undefined;
- modules = await window.ensureCustomElements("moz-support-link", "moz-toggle", "moz-button-group");
+ // Ensure there are no errors if the imported elements are created again.
+ document.createElement("moz-support-link");
+ document.createElement("moz-button-group");
+ document.createElement("moz-toggle");
ok(true, "The custom elements should not throw an error if imported again");
- is(modules, null, "There should not be a return value when using ensureCustomElements");
})
</script>
</head>