Bug 1833503 - Test for importScripts. r=dom-worker-reviewers,smaug

Differential Revision: https://phabricator.services.mozilla.com/D181215
This commit is contained in:
Yoshi Cheng-Hao Huang 2023-08-16 07:56:27 +00:00
parent d81e60336d
commit 74429a25c6
3 changed files with 71 additions and 0 deletions

View File

@ -160,6 +160,8 @@ skip-if =
[test_eventDispatch.html]
[test_fibonacci.html]
[test_importScripts.html]
[test_importScripts_1.html]
[test_importScripts_2.html]
[test_importScripts_mixedcontent.html]
tags = mcb
[test_instanceof.html]

View File

@ -0,0 +1,35 @@
<head>
<title>Test for ServiceWorker importScripts</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script id="worker" type="javascript/worker">
onconnect = async function(e) {
e.ports[0].onmessage = async function(msg) {
try {
self.importScripts("N:", "");
} catch (ex) {
e.source.postMessage("done");
}
};
};
</script>
<script>
SimpleTest.waitForExplicitFinish();
document.addEventListener("DOMContentLoaded", async () => {
const blob = new Blob([document.querySelector('#worker').textContent],
{type: "text/javascript"});
const sw = new SharedWorker(window.URL.createObjectURL(blob));
sw.port.postMessage([], []);
sw.port.onmessage = function(e) {
if (e.data == "done") {
ok(true);
SimpleTest.finish();
}
};
});
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,34 @@
<head>
<title>Test for Worker importScripts</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script id="worker" type="javascript/worker">
onmessage = async function(msg) {
try {
self.importScripts("N:", "");
} catch (ex) {
postMessage("done");
}
};
</script>
<script>
SimpleTest.waitForExplicitFinish();
document.addEventListener("DOMContentLoaded", async () => {
const blob = new Blob([document.querySelector('#worker').textContent],
{type: "text/javascript"});
const worker = new Worker(window.URL.createObjectURL(blob));
worker.postMessage([], []);
worker.onmessage = function(e) {
if (e.data == "done") {
ok(true);
SimpleTest.finish();
}
};
});
</script>
</pre>
</body>
</html>