diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/workers/interfaces/WorkerUtils | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/workers/interfaces/WorkerUtils')
62 files changed, 690 insertions, 0 deletions
diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/001.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/001.html new file mode 100644 index 0000000000..9fe5e2b1bc --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/001.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>setTimeout</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +async_test(function() { + var worker = new Worker('001.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data, 1); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/001.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/001.js new file mode 100644 index 0000000000..bd5b7c4071 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/001.js @@ -0,0 +1 @@ +setTimeout(function() { postMessage(1) }, 10);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/002.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/002.html new file mode 100644 index 0000000000..1a10b3d0bb --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/002.html @@ -0,0 +1,13 @@ +<!doctype html> +<title>clearTimeout</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +async_test(function() { + var worker = new Worker('002.js'); + var gotMessage = false; + worker.onmessage = function() { gotMessage = true; }; + setTimeout(this.step_func(function() { assert_false(gotMessage); this.done(); }), 100); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/002.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/002.js new file mode 100644 index 0000000000..a96c088442 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/002.js @@ -0,0 +1,2 @@ +var t = setTimeout(function() { postMessage(1); }, 10); +clearTimeout(t);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/003.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/003.html new file mode 100644 index 0000000000..119d109b5f --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/003.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>setInterval</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +async_test(function() { + var worker = new Worker('003.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data, 1); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/003.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/003.js new file mode 100644 index 0000000000..e64e4e2179 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/003.js @@ -0,0 +1 @@ +setInterval(function() { postMessage(1); }, 10);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/004.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/004.html new file mode 100644 index 0000000000..83d7bf915f --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/004.html @@ -0,0 +1,13 @@ +<!doctype html> +<title>clearInterval</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +async_test(function() { + var worker = new Worker('004.js'); + var i = 0; + worker.onmessage = function() { i++; } + setTimeout(this.step_func(function() { assert_equals(i, 0); this.done(); }), 100); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/004.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/004.js new file mode 100644 index 0000000000..e80d79a8e5 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/004.js @@ -0,0 +1,4 @@ +var t = setInterval(function() { + postMessage(1); +}, 10); +clearInterval(t);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/005.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/005.html new file mode 100644 index 0000000000..2a181d55d0 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/005.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>setInterval when closing</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +async_test(function() { + var worker = new Worker('005.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data, 1); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/005.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/005.js new file mode 100644 index 0000000000..125c224e7b --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/WindowTimers/005.js @@ -0,0 +1,3 @@ +self.close(); +var t = setInterval(function() {}, 10); +postMessage(t);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/001.worker.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/001.worker.js new file mode 100644 index 0000000000..aa86c8ef17 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/001.worker.js @@ -0,0 +1,7 @@ +importScripts("/resources/testharness.js"); + +test(function() { + importScripts(); +}); + +done(); diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/002.worker.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/002.worker.js new file mode 100644 index 0000000000..1cacee5ccb --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/002.worker.js @@ -0,0 +1,11 @@ +importScripts("/resources/testharness.js"); + +test(function() { + var ran = false; + assert_throws_dom("SyntaxError", function() { + importScripts('data:text/javascript,ran=true','http://foo bar'); + }); + assert_false(ran, 'first argument to importScripts ran'); +}); + +done(); diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/003.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/003.html new file mode 100644 index 0000000000..5dcd08aa15 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/003.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>importScripts running scripts</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +async_test(function() { + var worker = new Worker('003.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data, "abc"); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/003.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/003.js new file mode 100644 index 0000000000..6e378ef20f --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/003.js @@ -0,0 +1,8 @@ +var x = 'a'; +try { + importScripts('data:text/javascript,x+="b"', + 'data:text/javascript,x+="c"'); +} catch(e) { + x += "d" +} +postMessage(x);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/004.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/004.html new file mode 100644 index 0000000000..62537e0888 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/004.html @@ -0,0 +1,15 @@ +<!doctype html> +<title>importScripts broken script</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +async_test(function() { + var worker = new Worker('004.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data[0], "first script successful. "); + assert_true(e.data[1], 'expected SyntaxError'); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/004.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/004.js new file mode 100644 index 0000000000..98040d0d48 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/004.js @@ -0,0 +1,13 @@ +var x = ''; +var exception; +try { + importScripts('data:text/javascript,x+="first script successful. "', + 'data:text/javascript,x+="FAIL (second script). "; for(;) break;', // doesn't compile + 'data:text/javascript,x+="FAIL (third script)"'); +} catch(ex) { + if (ex instanceof SyntaxError) + exception = true; + else + exception = String(ex); +} +postMessage([x, exception]);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/005.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/005.html new file mode 100644 index 0000000000..7ebbc1be55 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/005.html @@ -0,0 +1,15 @@ +<!doctype html> +<title>importScripts separate scripts</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +async_test(function() { + var worker = new Worker('005.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data[0], undefined); + assert_true(e.data[1]); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/005.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/005.js new file mode 100644 index 0000000000..18c534efa9 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/005.js @@ -0,0 +1,9 @@ +var x; +var y; +try { + importScripts('data:text/javascript,x={', + 'data:text/javascript,}'); +} catch(e) { + y = true; +} +postMessage([x, y]);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/006.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/006.html new file mode 100644 index 0000000000..aec2fb1483 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/006.html @@ -0,0 +1,17 @@ +<!doctype html> +<title>importScripts uncaught exception</title> +<meta name="timeout" content="long"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +async_test(function() { + var worker = new Worker('006.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data[0], 1); + assert_equals(e.data[1], 2); + assert_equals(e.data[2], undefined); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/006.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/006.js new file mode 100644 index 0000000000..fc170f790c --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/006.js @@ -0,0 +1,11 @@ +var x; +var y; +var z; +try { + importScripts('data:text/javascript,x=1', + 'data:text/javascript,throw 2', + 'data:text/javascript,z=3'); +} catch(e) { + y = e; +} +postMessage([x, y, z]);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/007.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/007.html new file mode 100644 index 0000000000..37e888365f --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/007.html @@ -0,0 +1,17 @@ +<!doctype html> +<title>postMessage in importScripts</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +async_test(function() { + var worker = new Worker('007.js'); + var i = 0; + worker.onmessage = this.step_func(function(e) { + i++; + assert_equals(e.data, i); + if (i == 2) + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/007.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/007.js new file mode 100644 index 0000000000..dc85216f3d --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/007.js @@ -0,0 +1,2 @@ +importScripts('data:text/javascript,postMessage(1)'); +postMessage(2);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/008.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/008.html new file mode 100644 index 0000000000..f72b79939c --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/008.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>variables and functions crossing importScripts boundary</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +async_test(function() { + var worker = new Worker('008.js'); + worker.onmessage = this.step_func(function(e) { + assert_true(e.data); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/008.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/008.js new file mode 100644 index 0000000000..c957fcd635 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/008.js @@ -0,0 +1,3 @@ +var log = postMessage; +importScripts('data:text/javascript,function run() { log(true) }'); +run();
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/009.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/009.html new file mode 100644 index 0000000000..e0eb5488c2 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/009.html @@ -0,0 +1,20 @@ +<!doctype html> +<title>variables and functions crossing importScripts boundary, take 2</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +async_test(function() { + var worker = new Worker('009.js'); + var i = 0; + worker.onmessage = this.step_func(function(e) { + i++; + if (i == 1) { + assert_true(e.data); + } else { + assert_equals(e.data, 1); + this.done(); + } + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/009.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/009.js new file mode 100644 index 0000000000..4b86f8c303 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/009.js @@ -0,0 +1,3 @@ +var log = postMessage; +importScripts('data:text/javascript,function run() { for(var i = 0; i < 1000; ++i) { if (i == 500) log(true); } return 1; }'); +postMessage(run());
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/010.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/010.html new file mode 100644 index 0000000000..a6db49c4be --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/010.html @@ -0,0 +1,17 @@ +<!doctype html> +<title>importScripts(undefined)</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +async_test(function() { + var worker = new Worker('010.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data, 'undefined'); + this.done(); + }) + worker.onerror = this.step_func(function(e) { + assert_unreached(e.message); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/010.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/010.js new file mode 100644 index 0000000000..4ec4a3b8c7 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/010.js @@ -0,0 +1,11 @@ +// prevent recursion +if ('beenThere' in self) { + throw 'undefined stringified to the empty string'; +} +beenThere = true; +try { + importScripts(undefined); + postMessage(got); +} catch(ex) { + postMessage(String(ex)); +}
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/011.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/011.html new file mode 100644 index 0000000000..1bfb233497 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/011.html @@ -0,0 +1,17 @@ +<!doctype html> +<title>importScripts(null)</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +async_test(function() { + var worker = new Worker('011.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data, 'null'); + this.done(); + }); + worker.onerror = this.step_func(function(e) { + assert_unreached(e.message); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/011.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/011.js new file mode 100644 index 0000000000..bd6fed5c0a --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/011.js @@ -0,0 +1,11 @@ +// prevent recursion +if ('beenThere' in self) { + throw 'null stringified to the empty string'; +} +beenThere = true; +try { + importScripts(null); + postMessage(got); +} catch(ex) { + postMessage(String(ex)); +}
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/012.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/012.html new file mode 100644 index 0000000000..ab0778d0c7 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/012.html @@ -0,0 +1,17 @@ +<!doctype html> +<title>importScripts(1)</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +async_test(function() { + var worker = new Worker('012.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data, '1'); + this.done(); + }); + worker.onerror = this.step_func(function(e) { + assert_unreached(e.message); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/012.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/012.js new file mode 100644 index 0000000000..f4c887f7df --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/012.js @@ -0,0 +1,11 @@ +// prevent recursion +if ('beenThere' in self) { + throw '1 stringified to the empty string'; +} +beenThere = true; +try { + importScripts(1); + postMessage(got); +} catch(ex) { + postMessage(String(ex)); +}
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/1 b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/1 new file mode 100644 index 0000000000..18cea4ff0f --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/1 @@ -0,0 +1 @@ +var got = '1';
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/1.headers b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/1.headers new file mode 100644 index 0000000000..a17a9a3a12 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/1.headers @@ -0,0 +1 @@ +Content-Type: application/javascript diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/blob-url.worker.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/blob-url.worker.js new file mode 100644 index 0000000000..71603bf314 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/blob-url.worker.js @@ -0,0 +1,40 @@ +importScripts("/resources/testharness.js"); + +function objectUrlFromScript(script) { + const blob = new Blob([script], { type: "text/javascript" }); + return URL.createObjectURL(blob); +} + +test((t) => { + self.run = false; + const blobScriptUrl = objectUrlFromScript(`self.run = true;`); + t.add_cleanup(() => URL.revokeObjectURL(blobScriptUrl)); + + importScripts(blobScriptUrl); + assert_true(self.run); +}, "Blob URLs work on importScripts"); + +test(() => { + self.run = false; + const blobScriptUrl = objectUrlFromScript(`self.run = true;`); + + URL.revokeObjectURL(blobScriptUrl); + + assert_throws_dom("NetworkError", () => { + importScripts(blobScriptUrl); + }); + assert_false(self.run); +}, "A revoked blob URL will fail"); + +test(() => { + self.run = false; + const runScriptUrl = objectUrlFromScript(`self.run = true;`); + const revokeScriptUrl = objectUrlFromScript( + `URL.revokeObjectURL(${JSON.stringify(runScriptUrl)});` + ); + + importScripts(revokeScriptUrl, runScriptUrl); + assert_true(self.run); +}, "Revoking a blob URL in an earlier script will not fail"); + +done(); diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/catch.sub.any.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/catch.sub.any.js new file mode 100644 index 0000000000..52da60be91 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/catch.sub.any.js @@ -0,0 +1,47 @@ +// META: global=worker + +const crossOrigin = "https://{{hosts[alt][]}}:{{ports[https][0]}}"; +const redirectToCrossOrigin = "/common/redirect.py?location=" + crossOrigin; + +test(function() { + assert_throws_js(SyntaxError, function() { + importScripts("/workers/modules/resources/syntax-error.js"); + }); +}, "Same-origin syntax error"); + +test(function() { + assert_throws_js(Error, function() { + importScripts("/workers/modules/resources/throw.js"); + }); +}, "Same-origin throw"); + +// https://html.spec.whatwg.org/C/#run-a-classic-script +// Step 8.2. If rethrow errors is true and script's muted errors is true, then: +// Step 8.2.2. Throw a "NetworkError" DOMException. +test(function() { + assert_throws_dom("NetworkError", function() { + importScripts(crossOrigin + + "/workers/modules/resources/syntax-error.js"); + }); +}, "Cross-origin syntax error"); + +test(function() { + assert_throws_dom("NetworkError", function() { + importScripts(crossOrigin + + "/workers/modules/resources/throw.js"); + }); +}, "Cross-origin throw"); + +test(function() { + assert_throws_dom("NetworkError", function() { + importScripts(redirectToCrossOrigin + + "/workers/modules/resources/syntax-error.js"); + }); +}, "Redirect-to-cross-origin syntax error"); + +test(function() { + assert_throws_dom("NetworkError", function() { + importScripts(redirectToCrossOrigin + + "/workers/modules/resources/throw.js"); + }); +}, "Redirect-to-Cross-origin throw"); diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/null b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/null new file mode 100644 index 0000000000..8e54b66c50 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/null @@ -0,0 +1 @@ +var got = 'null';
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/null.headers b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/null.headers new file mode 100644 index 0000000000..a17a9a3a12 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/null.headers @@ -0,0 +1 @@ +Content-Type: application/javascript diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-cross-origin.sub.any.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-cross-origin.sub.any.js new file mode 100644 index 0000000000..4fd8914856 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-cross-origin.sub.any.js @@ -0,0 +1,8 @@ +// META: global=dedicatedworker,sharedworker +// META: script=report-error-helper.js +const crossOrigin = "https://{{hosts[alt][]}}:{{ports[https][0]}}"; +runTest( + crossOrigin + "/workers/modules/resources/syntax-error.js", + false, + "NetworkError" +); diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-helper.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-helper.js new file mode 100644 index 0000000000..7fc6d0dd64 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-helper.js @@ -0,0 +1,80 @@ +setup({ allow_uncaught_exception:true }); + +// For SyntaxError, the line in doImportScripts() is expected to be reported +// as `e.lineno` etc. below. +// doImportScripts() is introduced here to prevent the line number from being +// affected by changes in runTest(), use of setTimeout(), etc. +function doImportScripts(url) { + importScripts(url); +} + +const t0 = async_test("WorkerGlobalScope error event: error"); +const t1 = async_test("WorkerGlobalScope error event: message"); +const t2 = async_test("WorkerGlobalScope error event: filename"); +const t3 = async_test("WorkerGlobalScope error event: lineno"); + +function runTest(importScriptUrl, shouldUseSetTimeout, expected) { + self.addEventListener("error", e => { + if (expected === "NetworkError") { + t0.step_func_done(() => { + assert_equals(e.error.constructor, DOMException, + "e.error should be a DOMException") + assert_equals(e.error.name, "NetworkError"); + })(); + + t1.step_func_done(() => { + assert_not_equals(e.message, "Script error.", + "e.message should not be muted to 'Script error.'"); + })(); + + // filename, lineno etc. should NOT point to the location within + // `syntax-error.js` (otherwise parse errors to be muted are + // leaked to JavaScript). + // we expect they point to the caller of `importScripts()`, + // while this is not explicitly stated in the spec. + t2.step_func_done(() => { + assert_equals(e.filename, self.location.origin + + '/workers/interfaces/WorkerUtils/importScripts/report-error-helper.js'); + })(); + t3.step_func_done(() => { + assert_equals(e.lineno, 8); + })(); + // We don't check `e.colno` for now, because browsers set different + // `colno` values. + } else if (expected === "SyntaxError") { + t0.step_func_done(() => { + assert_equals(e.error.constructor, SyntaxError); + assert_equals(e.error.name, "SyntaxError"); + })(); + + t1.step_func_done(() => { + assert_not_equals(e.message, "Script error.", + "e.message should not be muted to 'Script error.'"); + })(); + + // filename, lineno etc. are expected to point to the location within + // `syntax-error.js` because it is same-origin, + // while this is not explicitly stated in the spec. + t2.step_func_done(() => { + assert_equals(e.filename, self.location.origin + + '/workers/modules/resources/syntax-error.js'); + })(); + t3.step_func_done(() => { + assert_equals(e.lineno, 1); + })(); + // We don't check `e.colno` for now, because browsers set different + // `colno` values. + } + + // Because importScripts() throws, we call done() here. + done(); + }); + + if (shouldUseSetTimeout) { + setTimeout( + () => doImportScripts(importScriptUrl), + 0); + } else { + doImportScripts(importScriptUrl); + } +} diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-redirect-to-cross-origin.sub.any.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-redirect-to-cross-origin.sub.any.js new file mode 100644 index 0000000000..2b9600973f --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-redirect-to-cross-origin.sub.any.js @@ -0,0 +1,9 @@ +// META: global=dedicatedworker,sharedworker +// META: script=report-error-helper.js +const crossOrigin = "https://{{hosts[alt][]}}:{{ports[https][0]}}"; +runTest( + "/common/redirect.py?location=" + crossOrigin + + "/workers/modules/resources/syntax-error.js", + false, + "NetworkError" +); diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-same-origin.sub.any.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-same-origin.sub.any.js new file mode 100644 index 0000000000..f7de416e11 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-same-origin.sub.any.js @@ -0,0 +1,7 @@ +// META: global=dedicatedworker,sharedworker +// META: script=report-error-helper.js +runTest( + "/workers/modules/resources/syntax-error.js", + false, + "SyntaxError" +); diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-cross-origin.sub.any.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-cross-origin.sub.any.js new file mode 100644 index 0000000000..a1bbef7bc4 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-cross-origin.sub.any.js @@ -0,0 +1,8 @@ +// META: global=dedicatedworker,sharedworker +// META: script=report-error-helper.js +const crossOrigin = "https://{{hosts[alt][]}}:{{ports[https][0]}}"; +runTest( + crossOrigin + "/workers/modules/resources/syntax-error.js", + true, + "NetworkError" +); diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-redirect-to-cross-origin.sub.any.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-redirect-to-cross-origin.sub.any.js new file mode 100644 index 0000000000..2755b337d3 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-redirect-to-cross-origin.sub.any.js @@ -0,0 +1,9 @@ +// META: global=dedicatedworker,sharedworker +// META: script=report-error-helper.js +const crossOrigin = "https://{{hosts[alt][]}}:{{ports[https][0]}}"; +runTest( + "/common/redirect.py?location=" + crossOrigin + + "/workers/modules/resources/syntax-error.js", + true, + "NetworkError" +); diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-same-origin.sub.any.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-same-origin.sub.any.js new file mode 100644 index 0000000000..c4f70ebec9 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-same-origin.sub.any.js @@ -0,0 +1,7 @@ +// META: global=dedicatedworker,sharedworker +// META: script=report-error-helper.js +runTest( + "/workers/modules/resources/syntax-error.js", + true, + "SyntaxError" +); diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/undefined b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/undefined new file mode 100644 index 0000000000..f99ba4be74 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/undefined @@ -0,0 +1 @@ +var got = 'undefined';
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/undefined.headers b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/undefined.headers new file mode 100644 index 0000000000..a17a9a3a12 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/undefined.headers @@ -0,0 +1 @@ +Content-Type: application/javascript diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/002.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/002.html new file mode 100644 index 0000000000..4c76e2b699 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/002.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>navigator.appName</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +async_test(function() { + var worker = new Worker('002.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data, navigator.appName); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/002.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/002.js new file mode 100644 index 0000000000..a5af348ef1 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/002.js @@ -0,0 +1 @@ +postMessage(navigator.appName);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/003.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/003.html new file mode 100644 index 0000000000..86ab5aee48 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/003.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>navigator.appVersion</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +async_test(function() { + var worker = new Worker('003.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data, navigator.appVersion); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/003.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/003.js new file mode 100644 index 0000000000..ff92f8aadb --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/003.js @@ -0,0 +1 @@ +postMessage(navigator.appVersion);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/004.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/004.html new file mode 100644 index 0000000000..93eee00957 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/004.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>navigator.platform</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +async_test(function() { + var worker = new Worker('004.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data, navigator.platform); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/004.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/004.js new file mode 100644 index 0000000000..c1b575e43c --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/004.js @@ -0,0 +1 @@ +postMessage(navigator.platform);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/005.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/005.html new file mode 100644 index 0000000000..ad2899e62e --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/005.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>navigator.userAgent</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +async_test(function() { + var worker = new Worker('005.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data, navigator.userAgent); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/005.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/005.js new file mode 100644 index 0000000000..d62252d39b --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/005.js @@ -0,0 +1 @@ +postMessage(navigator.userAgent);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/006.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/006.html new file mode 100644 index 0000000000..e0f7386af3 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/006.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>navigator.onLine</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +async_test(function() { + var worker = new Worker('006.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data, navigator.onLine); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/006.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/006.js new file mode 100644 index 0000000000..325fd0fbde --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/006.js @@ -0,0 +1 @@ +postMessage(navigator.onLine);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/007.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/007.html new file mode 100644 index 0000000000..8f9d38dd85 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/007.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>readonlyness of members of Navigator</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +async_test(function() { + var worker = new Worker('007.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data, ''); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/007.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/007.js new file mode 100644 index 0000000000..38849bc8ab --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/007.js @@ -0,0 +1,11 @@ +var log = []; +var neverEncounteredValue = "This is not the value you are looking for."; +for (x in navigator) { + // skip functions, as they are writable + if (typeof navigator[x] === 'function') continue; + // this should silently fail and not throw per webidl + navigator[x] = neverEncounteredValue; + if (navigator[x] === neverEncounteredValue) + log.push(x); +} +postMessage(log.join(', '));
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/008.worker.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/008.worker.js new file mode 100644 index 0000000000..e539d85d76 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/008.worker.js @@ -0,0 +1,12 @@ +"use strict"; +importScripts("/resources/testharness.js"); +test(function () { + for (const x in navigator) { + // skip functions, as they are settable + if (typeof navigator[x] === "function") continue; + assert_throws_js(TypeError, () => { + navigator[x] = ""; + }, `navigator.${x} is read-only`); + } +}, "navigator properties are read-only"); +done(); diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/language.html b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/language.html new file mode 100644 index 0000000000..535ab3a7cb --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/language.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>navigator.language</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +async_test(function() { + var worker = new Worker('language.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data, navigator.language); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/language.js b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/language.js new file mode 100644 index 0000000000..e94ba4dfcf --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/navigator/language.js @@ -0,0 +1 @@ +postMessage(navigator.language);
\ No newline at end of file |