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 | |
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')
125 files changed, 1673 insertions, 0 deletions
diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/EventTarget.worker.js b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/EventTarget.worker.js new file mode 100644 index 0000000000..954c46c07e --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/EventTarget.worker.js @@ -0,0 +1,23 @@ +importScripts("/resources/testharness.js"); + +test(function(t) { + var i = 0; + addEventListener("message", function listener(evt) { + t.step(function() { + ++i; + removeEventListener("message", listener, true); + }); + }, true); + self.dispatchEvent(new Event("message")); + self.dispatchEvent(new Event("message")); + assert_equals(i, 1); +}, "removeEventListener"); + +test(function() { + addEventListener("message", this.step_func(function(evt) { + assert_equals(evt.target, self); + }), true); + self.dispatchEvent(new Event("message")); +}, "target"); + +done(); diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/onmessage.worker.js b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/onmessage.worker.js new file mode 100644 index 0000000000..6f285caac3 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/onmessage.worker.js @@ -0,0 +1,40 @@ +importScripts("/resources/testharness.js"); + +test(function() { + self.onmessage = 1; + assert_equals(self.onmessage, null, + "attribute should return null after being set to a primitive"); +}, "Setting onmessage to 1"); + +test(function() { + var object = { + handleEvent: this.unreached_func() + }; + self.onmessage = object; + assert_equals(self.onmessage, object, + "attribute should return the object it was set to."); + + self.dispatchEvent(new Event("message")); +}, "Setting onmessage to an object"); + +test(function() { + var triggered = false; + var f = function(e) { triggered = true; }; + self.onmessage = f; + assert_equals(self.onmessage, f, + "attribute should return the function it was set to."); + + self.dispatchEvent(new Event("message")); + assert_true(triggered, "event handler should have been triggered"); +}, "Setting onmessage to a function"); + + +test(function() { + assert_not_equals(self.onmessage, null, + "attribute should not return null after being set to a function"); + self.onmessage = 1; + assert_equals(self.onmessage, null, + "attribute should return null after being set to a primitive"); +}, "Setting onmessage to 1 (again)"); + +done(); diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/event-ports-dedicated.html b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/event-ports-dedicated.html new file mode 100644 index 0000000000..be89478786 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/event-ports-dedicated.html @@ -0,0 +1,15 @@ +<!doctype html> +<title>e.ports in dedicated worker</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +(async_test()).step(function() { + var worker = new Worker('event-ports-dedicated.js'); + worker.postMessage(1); + 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/DedicatedWorkerGlobalScope/postMessage/event-ports-dedicated.js b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/event-ports-dedicated.js new file mode 100644 index 0000000000..c5cc9f8d9f --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/event-ports-dedicated.js @@ -0,0 +1,3 @@ +onmessage = function(e) { + postMessage(e.ports instanceof Array && e.ports.length === 0); +}
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/imagedata-cloned-canvas-in-array.html b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/imagedata-cloned-canvas-in-array.html new file mode 100644 index 0000000000..7c019a9993 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/imagedata-cloned-canvas-in-array.html @@ -0,0 +1,22 @@ +<!doctype html> +<title>posting an imagedata (from a cloned canvas) in an array</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +(async_test()).step(function() { + var worker = new Worker('imagedata-cloned-canvas-in-array.js'); + var canvas = document.createElement('canvas'); + var clone = canvas.cloneNode(true); + var ctx = clone.getContext('2d'); + var imagedata = ctx.getImageData(0, 0, 300, 150); + worker.postMessage([imagedata]); + worker.onmessage = this.step_func(function(e) { + var pixeldata = e.data.data; + for (var i = 0; i < pixeldata.length; i++) { + assert_equals(pixeldata[i], (i % 4 == 0) ? 128 : 0); + } + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/imagedata-cloned-canvas-in-array.js b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/imagedata-cloned-canvas-in-array.js new file mode 100644 index 0000000000..76eaee366c --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/imagedata-cloned-canvas-in-array.js @@ -0,0 +1,10 @@ +onmessage = function(e) { + function processPixels(imagedata) { + var pixeldata = imagedata.data; + for (var i = 0; i < pixeldata.length; i = i+4) { + pixeldata[i] = 128; + } + postMessage(imagedata); + } + processPixels(e.data[0]); +}
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/message-event.html b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/message-event.html new file mode 100644 index 0000000000..91ec632685 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/message-event.html @@ -0,0 +1,23 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>'message' event properties</title> +<link rel=help href="http://www.whatwg.org/html/#dom-dedicatedworkerglobalscope-postmessage"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +async_test("Properties of the 'message' event").step(function() { + var worker = new Worker("message-event.js"); + worker.onmessage = this.step_func_done(function (evt) { + assert_class_string(evt, "MessageEvent"); + assert_equals(evt.type, "message"); + assert_false(evt.bubbles, "bubbles should be false"); + assert_false(evt.cancelable, "cancelable should be false"); + assert_equals(evt.data, "test"); + assert_equals(evt.origin, "", "origin"); + assert_equals(evt.lastEventId, "", "lastEventId"); + assert_equals(evt.source, null, "source"); + assert_array_equals(evt.ports, [], "ports"); + }); +}); +</script> diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/message-event.js b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/message-event.js new file mode 100644 index 0000000000..54a250005e --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/message-event.js @@ -0,0 +1 @@ +postMessage("test"); diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/return-value.worker.js b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/return-value.worker.js new file mode 100644 index 0000000000..521251699a --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/return-value.worker.js @@ -0,0 +1,8 @@ +importScripts("/resources/testharness.js"); + +test(function() { + var rv = postMessage(1); + assert_equals(rv, undefined); +}, "return value of postMessage"); + +done(); diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-dictionary.html b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-dictionary.html new file mode 100644 index 0000000000..1749644908 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-dictionary.html @@ -0,0 +1,16 @@ +<!doctype html> +<title>Using dictionary as postMessage's second argument</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +(async_test()).step(function() { + var worker = new Worker('second-argument-dictionary.js'); + var ab = new ArrayBuffer(1); + worker.postMessage(ab, {transfer: [ab]}); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data.byteLength, 1); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-dictionary.js b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-dictionary.js new file mode 100644 index 0000000000..0cb80f8fae --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-dictionary.js @@ -0,0 +1,7 @@ +onmessage = (event) => { + try { + postMessage(event.data, {transfer: [event.data]}); + } catch(e) { + postMessage(''+e); + } +}
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null-in-array.html b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null-in-array.html new file mode 100644 index 0000000000..8db06b4116 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null-in-array.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>Using [null] in postMessage's second argument</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +(async_test()).step(function() { + var worker = new Worker('second-argument-null-in-array.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/DedicatedWorkerGlobalScope/postMessage/second-argument-null-in-array.js b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null-in-array.js new file mode 100644 index 0000000000..95a094234b --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null-in-array.js @@ -0,0 +1,5 @@ +try { + postMessage(false, [null]); +} catch(e) { + postMessage(e instanceof TypeError); +}
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null.html b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null.html new file mode 100644 index 0000000000..68d9caabc5 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>Using null in postMessage's second argument</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +(async_test()).step(function() { + var worker = new Worker('second-argument-null.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(1, e.data); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null.js b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null.js new file mode 100644 index 0000000000..6f6f9e799f --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null.js @@ -0,0 +1,5 @@ +try { + postMessage(1, null); +} catch(e) { + postMessage(e instanceof TypeError); +}
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-undefined.html b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-undefined.html new file mode 100644 index 0000000000..c7dcb3c5c0 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-undefined.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>Using undefined in postMessage's second argument</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +(async_test()).step(function() { + var worker = new Worker('second-argument-undefined.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/DedicatedWorkerGlobalScope/postMessage/second-argument-undefined.js b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-undefined.js new file mode 100644 index 0000000000..6f11443c4a --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-undefined.js @@ -0,0 +1,5 @@ +try { + postMessage(1, undefined); +} catch(e) { + postMessage(''+e); +}
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/setting-postMessage.html b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/setting-postMessage.html new file mode 100644 index 0000000000..5b3e014e1e --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/setting-postMessage.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>setting postMessage</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +(async_test()).step(function() { + var worker = new Worker('setting-postMessage.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/DedicatedWorkerGlobalScope/postMessage/setting-postMessage.js b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/setting-postMessage.js new file mode 100644 index 0000000000..5426ebde0d --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/setting-postMessage.js @@ -0,0 +1,3 @@ +var x = postMessage; +postMessage = 1; +x(postMessage == 1);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/structured-clone-imagedata.html b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/structured-clone-imagedata.html new file mode 100644 index 0000000000..c7fbb0f956 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/structured-clone-imagedata.html @@ -0,0 +1,18 @@ +<!doctype html> +<title>structured clone of ImageData</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +(async_test()).step(function() { + var worker = new Worker('structured-clone-imagedata.js'); + var ctx = document.createElement('canvas').getContext('2d'); + var imagedata = ctx.getImageData(0, 0, 300, 150); + worker.postMessage(imagedata); + worker.onmessage = this.step_func(function(e) { + assert_equals(''+e.data, '[object ImageData]'); + assert_equals(e.data.data[0], 128); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/structured-clone-imagedata.js b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/structured-clone-imagedata.js new file mode 100644 index 0000000000..04cd7eea5b --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/structured-clone-imagedata.js @@ -0,0 +1,5 @@ +onmessage = function(e) { + var imagedata = e.data; + imagedata.data[0] = 128; + postMessage(imagedata); +}
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/structured-clone-message.html b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/structured-clone-message.html new file mode 100644 index 0000000000..edf4fb7e0e --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/structured-clone-message.html @@ -0,0 +1,38 @@ +<!doctype html> +<title>structured clone of message</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +var wrapper_test = async_test(); +var tests = [ + {test:async_test('undefined'), check:function(e) { assert_equals(e.data, undefined); }}, + {test:async_test('null'), check:function(e) { assert_equals(e.data, null); }}, + {test:async_test('false'), check:function(e) { assert_false(e.data); }}, + {test:async_test('true'), check:function(e) { assert_true(e.data); }}, + {test:async_test('1'), check:function(e) { assert_equals(e.data, 1); }}, + {test:async_test('NaN'), check:function(e) { assert_equals(e.data, NaN); }}, + {test:async_test('Infinity'), check:function(e) { assert_equals(e.data, Infinity); }}, + {test:async_test('string'), check:function(e) { assert_equals(e.data, 'foo'); }}, + {test:async_test('date'), check:function(e) { assert_equals(e.data instanceof Date, true); }}, + {test:async_test('regexp'), check:function(e) { assert_equals('' + e.data, '/foo/'); assert_equals(e.data instanceof RegExp, true, 'e.data instanceof RegExp'); }}, + {test:async_test('self'), check:function(e) { assert_equals(e.data, null); }}, + {test:async_test('array'), check:function(e) { assert_array_equals(e.data, [undefined, null, false, true, 1, NaN, Infinity, 'foo', null, null]); }}, + {test:async_test('object'), check:function(e) { assert_object_equals(e.data, {a:undefined, b:null, c:false, d:true, e:1, f:NaN, g:Infinity, h:'foo', k:null, n:null}); }}, + {test:async_test('error'), check:function(e) { assert_equals(e.data, null, 'new Error()'); }}, + {test:wrapper_test, check:function(e) { assert_unreached(); }} +]; +// make wrapper_test pass after 500ms +setTimeout(tests[tests.length-1].test.step_func(function() { + this.done(); +}), 500); + +wrapper_test.step(function() { + var worker = new Worker('structured-clone-message.js'); + var i = 0; + worker.onmessage = function(e) { + tests[i].test.step(function() { tests[i].check(e); this.done(); }); + i++; + }; +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/structured-clone-message.js b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/structured-clone-message.js new file mode 100644 index 0000000000..db456e1fba --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/structured-clone-message.js @@ -0,0 +1,14 @@ +var err = new Error('foo'); +var date = new Date(); +// commented out bits are either tested elsewhere or not supported yet. or uncloneable. +var tests = [undefined, null, false, true, 1, NaN, Infinity, 'foo', date, /foo/, /* ImageData, File, FileData, FileList,*/ null/*self*/, + [undefined, null, false, true, 1, NaN, Infinity, 'foo', /*date, /foo/,*/ null/*self*/, /*[], {},*/ null/*err*/], + {a:undefined, b:null, c:false, d:true, e:1, f:NaN, g:Infinity, h:'foo', /*i:date, j:/foo/,*/ k:null/*self*/, /*l:[], m:{},*/ n:null/*err*/}, + null/*err*/]; +for (var i = 0; i < tests.length; ++i) { + try { + postMessage(tests[i]); + } catch(e) { + postMessage(''+e); + } +}
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/SharedWorkerGlobalScope/name/getting.html b/testing/web-platform/tests/workers/interfaces/SharedWorkerGlobalScope/name/getting.html new file mode 100644 index 0000000000..c3a52d12e8 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/SharedWorkerGlobalScope/name/getting.html @@ -0,0 +1,17 @@ +<!doctype html> +<title>getting name</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +var tests = [['getting.js#1', ''], ['getting.js#2', 'a'], ['getting.js#3', -0]]; +tests.forEach(function(t) { + async_test(function() { + var w = new SharedWorker(t[0], t[1]); + w.port.onmessage = this.step_func(function(e) { + assert_true(e.data); + this.done(); + }); + }); +}); +</script> diff --git a/testing/web-platform/tests/workers/interfaces/SharedWorkerGlobalScope/name/getting.js b/testing/web-platform/tests/workers/interfaces/SharedWorkerGlobalScope/name/getting.js new file mode 100644 index 0000000000..acf89ca6f6 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/SharedWorkerGlobalScope/name/getting.js @@ -0,0 +1,9 @@ +addEventListener('connect', function(e) { + var passed; + switch (location.hash) { + case '#1': passed = name == ''; break; + case '#2': passed = name == 'a'; break; + case '#3': passed = name == '0'; break; + } + e.ports[0].postMessage(passed); +}, false); diff --git a/testing/web-platform/tests/workers/interfaces/SharedWorkerGlobalScope/name/setting.html b/testing/web-platform/tests/workers/interfaces/SharedWorkerGlobalScope/name/setting.html new file mode 100644 index 0000000000..ddd8569710 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/SharedWorkerGlobalScope/name/setting.html @@ -0,0 +1,15 @@ +<!doctype html> +<title>setting name</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +async_test(function() { + var w1 = new SharedWorker('setting.js#1', 'x'); + w1.port.addEventListener('message', this.step_func(function(e) { + assert_equals(e.data, 1); + this.done(); + }), false); + w1.port.start(); +}); +</script> diff --git a/testing/web-platform/tests/workers/interfaces/SharedWorkerGlobalScope/name/setting.js b/testing/web-platform/tests/workers/interfaces/SharedWorkerGlobalScope/name/setting.js new file mode 100644 index 0000000000..c705e9c40a --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/SharedWorkerGlobalScope/name/setting.js @@ -0,0 +1,4 @@ +addEventListener('connect', function(e) { + name = 1; + e.ports[0].postMessage(name); +}, false); diff --git a/testing/web-platform/tests/workers/interfaces/SharedWorkerGlobalScope/onconnect.html b/testing/web-platform/tests/workers/interfaces/SharedWorkerGlobalScope/onconnect.html new file mode 100644 index 0000000000..8a0f103d40 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/SharedWorkerGlobalScope/onconnect.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>onconnect</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +async_test(function() { + var w1 = new SharedWorker('onconnect.js', ''); + w1.port.addEventListener('message', this.step_func(function(e) { + assert_array_equals(e.data, ['null', 'null', 'function', '']); + }), false); + w1.port.start(); +}); +</script> diff --git a/testing/web-platform/tests/workers/interfaces/SharedWorkerGlobalScope/onconnect.js b/testing/web-platform/tests/workers/interfaces/SharedWorkerGlobalScope/onconnect.js new file mode 100644 index 0000000000..34a2be51fc --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/SharedWorkerGlobalScope/onconnect.js @@ -0,0 +1,19 @@ +var results = []; +try { + self.onconnect = 1; + results.push(String(onconnect)); +} catch(e) { + results.push(''+e); +} +try { + self.onconnect = {handleEvent:function(){}}; + results.push(String(onconnect)); +} catch(e) { + results.push(''+e); +} +var f = function(e) { + results.push(e.data); + e.ports[0].postMessage(results); +}; +onconnect = f; +results.push(typeof onconnect); diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/incoming-message.html b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/incoming-message.html new file mode 100644 index 0000000000..0905d07661 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/incoming-message.html @@ -0,0 +1,18 @@ +<!doctype html> +<title>close() and incoming message</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +setup({ single_test: true }); + +var worker = new Worker('incoming-message.js'); +worker.onmessage = function(e) { + assert_unreached("Got message"); +}; +worker.onerror = function(e) { + assert_unreached("Got error"); +}; +worker.postMessage(1); +setTimeout(done, 2000); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/incoming-message.js b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/incoming-message.js new file mode 100644 index 0000000000..b4f7e7fc05 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/incoming-message.js @@ -0,0 +1,5 @@ +onmessage = function(e) { + postMessage(1); + throw new Error(); +} +close();
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/sending-messages.html b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/sending-messages.html new file mode 100644 index 0000000000..da7da66d25 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/sending-messages.html @@ -0,0 +1,18 @@ +<!doctype html> +<title>close() and sending messages</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('sending-messages.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/WorkerGlobalScope/close/sending-messages.js b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/sending-messages.js new file mode 100644 index 0000000000..2e0a898288 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/sending-messages.js @@ -0,0 +1,3 @@ +postMessage(1); +close(); +postMessage(2);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/setInterval.html b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/setInterval.html new file mode 100644 index 0000000000..2f0ba176d4 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/setInterval.html @@ -0,0 +1,17 @@ +<!doctype html> +<title>close() and setInterval</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +setup({ single_test: true }); + +var worker = new Worker('setInterval.js'); +worker.onmessage = function(e) { + assert_unreached("Got message"); +}; +worker.onerror = function(e) { + assert_unreached("Got error"); +}; +setTimeout(done, 2000); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/setInterval.js b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/setInterval.js new file mode 100644 index 0000000000..d165d20eab --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/setInterval.js @@ -0,0 +1,11 @@ +var interval1 = setInterval(function() { + clearInterval(interval1); + postMessage(1); + throw new Error(); +}, 10); +close(); +var interval2 = setInterval(function() { + clearInterval(interval2); + postMessage(1); + throw new Error(); +}, 10);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/setTimeout.html b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/setTimeout.html new file mode 100644 index 0000000000..2bddc0947f --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/setTimeout.html @@ -0,0 +1,17 @@ +<!doctype html> +<title>close() and setTimeout</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +setup({ single_test: true }); + +var worker = new Worker('setTimeout.js'); +worker.onmessage = function(e) { + assert_unreached("Got message"); +}; +worker.onerror = function(e) { + assert_unreached("Got error"); +}; +setTimeout(done, 2000); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/setTimeout.js b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/setTimeout.js new file mode 100644 index 0000000000..55eecb0557 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/close/setTimeout.js @@ -0,0 +1,7 @@ +function x() { + postMessage(1); + throw new Error(); +} +setTimeout(x, 0); +close(); +setTimeout(x, 0);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/helper-redirect.py b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/helper-redirect.py new file mode 100644 index 0000000000..c8cd354348 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/helper-redirect.py @@ -0,0 +1,3 @@ +def main(request, response): + response.status = 302 + response.headers.append(b"Location", b"post-location-members.js?a") diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/members.html b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/members.html new file mode 100644 index 0000000000..3da6b7484d --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/members.html @@ -0,0 +1,22 @@ +<!doctype html> +<title>members of WorkerLocation</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('members.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data[0], null); + assert_equals(e.data[1], location.href.replace('.html', '.js'), 'href'); + assert_equals(e.data[2], location.protocol, 'protocol'); + assert_equals(e.data[3], location.host, 'host'); + assert_equals(e.data[4], location.hostname, 'hostname'); + assert_equals(e.data[5], location.port, 'port'); + assert_equals(e.data[6], location.pathname.replace('.html', '.js'), 'pathname'); + assert_equals(e.data[7], location.search, 'search'); + assert_equals(e.data[8], '', 'hash'); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/members.js b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/members.js new file mode 100644 index 0000000000..37235eac83 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/members.js @@ -0,0 +1,3 @@ +postMessage([null, location.href, location.protocol, location.host, + location.hostname, location.port, location.pathname, + location.search, location.hash]);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/post-location-members.js b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/post-location-members.js new file mode 100644 index 0000000000..e850b76b6e --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/post-location-members.js @@ -0,0 +1,8 @@ +postMessage([location.href, + location.protocol, + location.host, + location.hostname, + location.port, + location.pathname, + location.search, + location.hash]);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/redirect-module.html b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/redirect-module.html new file mode 100644 index 0000000000..b1a14be8f7 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/redirect-module.html @@ -0,0 +1,20 @@ +<!doctype html> +<title>WorkerLocation with redirects: module dedicated workers</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('helper-redirect.py?fail', {type: 'module'}); + worker.onmessage = this.step_func_done(function(e) { + assert_equals(e.data[0], location.href.replace(/\/[^\/]+$/, '/post-location-members.js?a')); + assert_equals(e.data[1], location.protocol); + assert_equals(e.data[2], location.host); + assert_equals(e.data[3], location.hostname); + assert_equals(e.data[4], location.port); + assert_equals(e.data[5], location.pathname.replace(/\/[^\/]+$/, '/post-location-members.js')); + assert_equals(e.data[6], '?a'); + assert_equals(e.data[7], ''); + }); +}); +</script> diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/redirect-sharedworker.html b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/redirect-sharedworker.html new file mode 100644 index 0000000000..978a99ac8c --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/redirect-sharedworker.html @@ -0,0 +1,9 @@ +<!doctype html> +<title>WorkerLocation with redirects: classic shared workers</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +fetch_tests_from_worker( + new SharedWorker('/common/redirect.py?location=/workers/interfaces/WorkerGlobalScope/location/redirect.js?a')); +</script> diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/redirect.html b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/redirect.html new file mode 100644 index 0000000000..98a0e54760 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/redirect.html @@ -0,0 +1,28 @@ +<!-- +/* +--> +<!doctype html> +<title>WorkerLocation with redirects: classic dedicated workers</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('helper-redirect.py?fail'); + worker.onmessage = this.step_func_done(function(e) { + assert_equals(e.data[0], location.href.replace(/\/[^\/]+$/, '/post-location-members.js?a')); + assert_equals(e.data[1], location.protocol); + assert_equals(e.data[2], location.host); + assert_equals(e.data[3], location.hostname); + assert_equals(e.data[4], location.port); + assert_equals(e.data[5], location.pathname.replace(/\/[^\/]+$/, '/post-location-members.js')); + assert_equals(e.data[6], '?a'); + assert_equals(e.data[7], ''); + }); +}); +</script> +<!-- +*/ +//--> + + diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/redirect.js b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/redirect.js new file mode 100644 index 0000000000..2db48544a2 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/redirect.js @@ -0,0 +1,7 @@ +importScripts('/resources/testharness.js'); +test(t => { + assert_equals(location.pathname, '/workers/interfaces/WorkerGlobalScope/location/redirect.js'); + assert_equals(location.search, '?a'); + assert_equals(location.hash, ''); +}); +done(); diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/returns-same-object.any.js b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/returns-same-object.any.js new file mode 100644 index 0000000000..dd3560f040 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/returns-same-object.any.js @@ -0,0 +1,5 @@ +// META: global=worker + +test(function() { + assert_equals(location, location); +}, 'location === location'); diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/setting-members.html b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/setting-members.html new file mode 100644 index 0000000000..7ea79b6897 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/setting-members.html @@ -0,0 +1,23 @@ +<!doctype html> +<title>setting members of WorkerLocation</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('setting-members.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data[0], null); + assert_equals(e.data[1], location.href.replace('.html', '.js'), 'href'); + assert_equals(e.data[2], location.protocol, 'protocol'); + assert_equals(e.data[3], location.host, 'host'); + assert_equals(e.data[4], location.hostname, 'hostname'); + assert_equals(e.data[5], location.port, 'port'); + assert_equals(e.data[6], location.pathname.replace('.html', '.js'), 'pathname'); + assert_equals(e.data[7], location.search, 'search'); + assert_equals(e.data[8], '', 'hash'); + assert_array_equals(e.data[9], [], 'number of exceptions'); + this.done(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/setting-members.js b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/setting-members.js new file mode 100644 index 0000000000..4c5c8a35ae --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/setting-members.js @@ -0,0 +1,13 @@ +var exceptions = []; +try { location.href = 1; } catch(e) { exceptions.push('href'); } +try { location.protocol = 1; } catch(e) { exceptions.push('protocol'); } +try { location.host = 1; } catch(e) { exceptions.push('host'); } +try { location.hostname = 1; } catch(e) { exceptions.push('hostname');} +try { location.port = 1; } catch(e) { exceptions.push('port'); } +try { location.pathname = 1; } catch(e) { exceptions.push('pathname'); } +try { location.search = 1; } catch(e) { exceptions.push('search'); } +try { location.hash = 1; } catch(e) { exceptions.push('hash'); } + +postMessage([null, location.href, location.protocol, location.host, + location.hostname, location.port, location.pathname, + location.search, location.hash, exceptions]);
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/worker-separate-file.html b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/worker-separate-file.html new file mode 100644 index 0000000000..ac8e64dcc8 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/worker-separate-file.html @@ -0,0 +1,28 @@ +<!-- +/* +--> +<!doctype html> +<title>location with a worker in separate file</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('post-location-members.js?a#b?c'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data[0], location.href.replace(/\/[^\/]+$/, '/post-location-members.js?a#b?c')); + assert_equals(e.data[1], location.protocol); + assert_equals(e.data[2], location.host); + assert_equals(e.data[3], location.hostname); + assert_equals(e.data[4], location.port); + assert_equals(e.data[5], location.pathname.replace(/\/[^\/]+$/, '/post-location-members.js')); + assert_equals(e.data[6], '?a'); + assert_equals(e.data[7], '#b?c'); + this.done(); + }); +}); +</script> +<!-- +*/ +//--> + diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/exception-in-onerror.html b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/exception-in-onerror.html new file mode 100644 index 0000000000..5f3999db66 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/exception-in-onerror.html @@ -0,0 +1,91 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +// 1. Exception is thrown somewhere in a Worker. +// Various contexts are tested: from worker initialization, +// from setTimeout, from event handlers, etc. +// 2. WorkerGlobalScope.onerror event handler is called. +// (i.e. `onerror` in the worker script) +// 3. From the event handler, another exception is thrown. +// 4. Each of Worker.onerror handler (on the parent Document) and +// Worker error event listener should be called twice: +// once for each of the exceptions thrown in Step 1 and 2, respectively. +// (We don't check the ordering of two Worker.onerror calls, because +// browsers fires them in different orders) + +function prepareHandler(t, messages) { + const fired = {}; + let fired_count = 0; + t.step_timeout(() => { + if (fired_count < messages.length) { + let error_description = 'Worker.onerror not fired for:'; + for (const message of messages) { + if (!fired[message]) { + error_description += ' '; + error_description += message; + } + } + assert_unreached(error_description); + } + }, 2000); + return t.step_func(e => { + e.preventDefault(); + for (const message of messages) { + if (!fired[message] && e.message.indexOf(message) >= 0) { + fired[message] = true; + ++fired_count; + if (fired_count === messages.length) { + // Worker.onerror is fired for all messages. + t.done(); + } + return; + } + } + assert_unreached("Unexpected worker.onerror message: " + e.message); + }); +} + +function expectErrors(worker, title, messages) { + async_test(t => { + worker.addEventListener('error', prepareHandler(t, messages)); + }, title+ ': listener'); + async_test(t => { + worker.onerror = prepareHandler(t, messages); + }, title + ': handler'); +} + +for (const type of ['classic', 'module']) { + const workerOptions = type === 'module' ? {type: 'module'}: {}; + + const worker1 = new Worker( + 'throw.js?throw-in-toplevel&throw-in-onerror', + workerOptions); + expectErrors( + worker1, + 'Throw in worker initialization: ' + type, + ['Throw in toplevel', 'Throw in error handler']); + + const worker2 = new Worker( + 'throw.js?throw-in-setTimeout-function&throw-in-onerror', workerOptions); + expectErrors( + worker2, + 'Throw in setTimeout(function): ' + type, + ['Throw in setTimeout function', 'Throw in error handler']); + + const worker3 = new Worker( + 'throw.js?throw-in-setTimeout-string&throw-in-onerror', workerOptions); + expectErrors( + worker3, + 'Throw in setTimeout(string): ' + type, + ['Throw in setTimeout string', 'Throw in error handler']); + + const worker4 = new Worker('throw.js?throw-in-onerror', workerOptions); + worker4.postMessage('foo'); + expectErrors( + worker4, + 'Throw in message handler: ' + type, + ['Throw in message handler', 'Throw in error handler']); + +} +</script> diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/handled.html b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/handled.html new file mode 100644 index 0000000000..7d4b03c6cd --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/handled.html @@ -0,0 +1,22 @@ +<!doctype html> +<title>onerror, "handled"</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('handled.js'); + worker.onmessage = this.step_func(function(e) { + assert_equals(typeof e.data[0], 'string', 'first argument'); + assert_equals(e.data[1], document.URL.replace('.html', '.js'), 'second argument'); + assert_equals(typeof e.data[2], 'number', 'third argument'); + assert_equals(typeof e.data[3], 'number', 'fourth argument'); + setTimeout(this.step_func(function() { + this.done(); + }), 100); + }); + worker.onerror = this.step_func(function(e) { + assert_unreached(); + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/handled.js b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/handled.js new file mode 100644 index 0000000000..e58fa4a515 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/handled.js @@ -0,0 +1,8 @@ +onerror = function(a, b, c, d) { + postMessage([a, b, c, d]); + return true; // the error is "handled" +} +function x() { + y(); +} +x();
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/message-classic-DOMException.html b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/message-classic-DOMException.html new file mode 100644 index 0000000000..df8c851475 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/message-classic-DOMException.html @@ -0,0 +1,7 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="./message-helper.js"></script> +<script> +runTest('classic', 'DOMException-TypeError'); +</script> diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/message-classic-Error.html b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/message-classic-Error.html new file mode 100644 index 0000000000..e026b6ebf0 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/message-classic-Error.html @@ -0,0 +1,7 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="./message-helper.js"></script> +<script> +runTest('classic', 'Error'); +</script> diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/message-helper.js b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/message-helper.js new file mode 100644 index 0000000000..6271329b03 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/message-helper.js @@ -0,0 +1,61 @@ +// The error's `message` values in Worker error event handlers are tested. +// While not explicitly specified in the HTML spec, we expect some information +// about thrown errors (e.g. original message, the string "TypeError", etc.) +// to appear in the `message`. + +function prepareHandler(t, error, expectedCount) { + let count = 0; + return t.step_func(e => { + e.preventDefault(); + + assert_regexp_match( + e.message, + /Throw in/, + 'e.message should contain the message of the thrown error'); + + if (error === 'DOMException-TypeError') { + assert_regexp_match(e.message, /TypeError/); + } + + ++count; + if (count >= expectedCount) { + t.done(); + } + }); +} + +function expectErrors(worker, error, expectedCount, title) { + async_test(t => { + worker.addEventListener('error', + prepareHandler(t, error, expectedCount)); + }, title+ ': listener'); + async_test(t => { + worker.onerror = prepareHandler(t, error, expectedCount); + }, title + ': handler'); +} + +function runTest(type, error) { + for (const location of ['toplevel', + 'setTimeout-function', + 'setTimeout-string', + 'onmessage', + 'onerror']) { + const worker = new Worker( + 'throw.js?throw-in-' + location + '&error=' + error, + {type}); + let expectedCount = 1; + if (location === 'onmessage') { + // This makes the worker's message handler to throw an error. + worker.postMessage('foo'); + } + if (location === 'onerror') { + // This makes the worker's message handler to throw an error, + // AND worker's error handler to throw another error. + // Therefore we expect two errors here. + worker.postMessage('foo'); + expectedCount = 2; + } + expectErrors(worker, error, expectedCount, + 'Throw ' + error + ' in ' + location + ': ' + type); + } +} diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/message-module-DOMException.html b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/message-module-DOMException.html new file mode 100644 index 0000000000..8ed873bc32 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/message-module-DOMException.html @@ -0,0 +1,7 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="./message-helper.js"></script> +<script> +runTest('module', 'DOMException-TypeError'); +</script> diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/message-module-Error.html b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/message-module-Error.html new file mode 100644 index 0000000000..046ff969d6 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/message-module-Error.html @@ -0,0 +1,7 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="./message-helper.js"></script> +<script> +runTest('module', 'Error'); +</script> diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/not-handled.html b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/not-handled.html new file mode 100644 index 0000000000..11d03d728b --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/not-handled.html @@ -0,0 +1,28 @@ +<!doctype html> +<title>onerror, "not handled"</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +function createHandler(t) { + return t.step_func(function(e) { + assert_true(e instanceof ErrorEvent, 'e instanceof ErrorEvent'); + assert_equals(typeof e.message, 'string', 'typeof e.message'); + assert_equals(e.filename, document.URL.replace('.html', '.js'), 'e.filename'); + assert_equals(typeof e.lineno, 'number', 'typeof e.lineno'); + assert_equals(typeof e.colno, 'number', 'typeof e.column'); + e.preventDefault(); // "handled" + t.done(); + }); +} + +async_test(function(t) { + var worker = new Worker('not-handled.js'); + worker.onerror = createHandler(t); +}, 'Not handled evaluation error => Worker.onerror handler'); + +async_test(function(t) { + var worker = new Worker('not-handled.js'); + worker.addEventListener('error', createHandler(t)); +}, 'Not handled evaluation error => Worker error listener'); +</script> diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/not-handled.js b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/not-handled.js new file mode 100644 index 0000000000..c3254b0ba7 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/not-handled.js @@ -0,0 +1,7 @@ +onerror = function(a, b, c, d) { + return false; // the error is "not handled" +} +function x() { + y(); +} +x();
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/propagate-to-window-onerror.html b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/propagate-to-window-onerror.html new file mode 100644 index 0000000000..b3be772679 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/propagate-to-window-onerror.html @@ -0,0 +1,21 @@ +<!doctype html> +<title>onerror, "not handled" with only window.onerror defined</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +setup({ + allow_uncaught_exception: true, +}); +async_test(function() { + var worker = new Worker('propagate-to-window-onerror.js'); + window.onerror = this.step_func(function(a, b, c, d) { + assert_equals(typeof a, 'string', 'first argument'); + assert_equals(b, document.URL.replace('.html', '.js'), 'second argument'); + assert_equals(typeof c, 'number', 'third argument'); + assert_equals(typeof d, 'number', 'fourth argument'); + this.done(); + return true; // "handled" + }); +}); +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/propagate-to-window-onerror.js b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/propagate-to-window-onerror.js new file mode 100644 index 0000000000..0daf488d6f --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/propagate-to-window-onerror.js @@ -0,0 +1,4 @@ +function x() { + y(); +} +x();
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/throw.js b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/throw.js new file mode 100644 index 0000000000..704098a6d8 --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/throw.js @@ -0,0 +1,34 @@ +const params = new URL(self.location.href).searchParams; + +self.createError = (message) => { + if (params.get('error') === 'DOMException-TypeError') { + return new DOMException(message, 'TypeError'); + } else { + return new Error(message); + } +}; + +onerror = function() { + if (params.has('throw-in-onerror')) { + throw createError('Throw in error handler'); + } + return false; +}; +onmessage = function() { + throw createError('Throw in message handler'); + return false; +}; + +if (params.has('throw-in-toplevel')) { + throw createError('Throw in toplevel'); +} + +// We don't use step_timeout() here, because we have to test the behavior of +// setTimeout() without wrappers. +if (params.has('throw-in-setTimeout-function')) { + setTimeout(() => { throw createError('Throw in setTimeout function') }, 0); +} + +if (params.has('throw-in-setTimeout-string')) { + setTimeout("throw createError('Throw in setTimeout string')", 0); +} diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/self.any.js b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/self.any.js new file mode 100644 index 0000000000..64b4ee2fae --- /dev/null +++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/self.any.js @@ -0,0 +1,19 @@ +// META: global=worker + +test(function() { + assert_equals(self, self); +}, 'self === self'); + +test(function() { + assert_true(self instanceof WorkerGlobalScope); +}, 'self instanceof WorkerGlobalScope'); + +test(function() { + assert_true('self' in self); +}, '\'self\' in self'); + +test(function() { + var x = self; + self = 1; + assert_equals(self, x); +}, 'self = 1'); 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 |