From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../tests/workers/support/ErrorEvent-error.js | 9 +++ .../tests/workers/support/ErrorEvent.js | 10 ++++ .../tests/workers/support/ImportScripts.js | 9 +++ .../workers/support/ImportScriptsNetworkErr.js | 15 +++++ .../workers/support/ImportScriptsNosniffErr.js | 9 +++ .../tests/workers/support/SharedWorker-common.js | 32 +++++++++++ .../workers/support/SharedWorker-create-common.js | 8 +++ .../workers/support/SharedWorker-script-error.js | 22 +++++++ .../web-platform/tests/workers/support/Timer.js | 50 ++++++++++++++++ .../tests/workers/support/Worker-common.js | 16 ++++++ .../tests/workers/support/Worker-create-common.js | 4 ++ .../tests/workers/support/Worker-messageport.js | 40 +++++++++++++ .../Worker-run-forever-during-dynamic-import.js | 3 + .../Worker-run-forever-during-importScripts.js | 4 ++ ...rker-run-forever-during-nested-importScripts.js | 1 + .../Worker-run-forever-during-top-level-await.js | 4 ++ .../tests/workers/support/Worker-run-forever.js | 3 + .../workers/support/Worker-structure-message.js | 15 +++++ .../Worker-termination-with-port-messages.js | 10 ++++ .../workers/support/Worker-thread-multi-port.js | 43 ++++++++++++++ .../workers/support/Worker-timeout-cancel-order.js | 7 +++ .../support/Worker-timeout-decreasing-order.js | 7 +++ .../support/Worker-timeout-increasing-order.js | 7 +++ .../tests/workers/support/WorkerBasic.js | 7 +++ .../tests/workers/support/WorkerClose.js | 5 ++ .../tests/workers/support/WorkerDataCloneErr.js | 15 +++++ .../tests/workers/support/WorkerFetchURL.js | 8 +++ .../workers/support/WorkerGlobalScope-close.js | 43 ++++++++++++++ .../workers/support/WorkerLocation-origin.html | 6 ++ .../tests/workers/support/WorkerLocation.js | 13 +++++ .../tests/workers/support/WorkerNavigator.js | 26 +++++++++ .../workers/support/WorkerSendingPerformanceNow.js | 22 +++++++ .../tests/workers/support/WorkerTerminate.js | 10 ++++ .../tests/workers/support/WorkerText.txt | 2 + .../tests/workers/support/abrupt-completion.js | 21 +++++++ .../tests/workers/support/check-error-arguments.js | 4 ++ .../tests/workers/support/empty-worker.js | 1 + .../workers/support/iframe-sw-shared-name.html | 19 ++++++ .../tests/workers/support/iframe_sw_dataUrl.html | 13 +++++ .../tests/workers/support/importScripts-1.js | 1 + .../tests/workers/support/importScripts-2.js | 1 + .../tests/workers/support/importScripts-3.js | 1 + .../tests/workers/support/imported_script.py | 2 + .../tests/workers/support/invalidScript.js | 1 + .../workers/support/name-as-accidental-global.js | 9 +++ testing/web-platform/tests/workers/support/name.js | 18 ++++++ .../tests/workers/support/nosiniff-error-worker.py | 3 + .../workers/support/parent_of_nested_worker.js | 14 +++++ .../workers/support/post-message-on-load-worker.js | 10 ++++ .../workers/support/postMessage_block_worker.js | 2 + .../support/postMessage_block_worker.js.headers | 1 + .../tests/workers/support/sandboxed-tests.html | 67 ++++++++++++++++++++++ .../tests/workers/support/shared-name.js | 8 +++ .../web-platform/tests/workers/support/sync_xhr.js | 13 +++++ .../tests/workers/support/sync_xhr_target.xml | 1 + .../workers/support/throw-on-message-Worker.js | 11 ++++ .../workers/support/window-sw-shared-name.html | 22 +++++++ .../support/worker-request-animation-frame.js | 6 ++ 58 files changed, 734 insertions(+) create mode 100644 testing/web-platform/tests/workers/support/ErrorEvent-error.js create mode 100644 testing/web-platform/tests/workers/support/ErrorEvent.js create mode 100644 testing/web-platform/tests/workers/support/ImportScripts.js create mode 100644 testing/web-platform/tests/workers/support/ImportScriptsNetworkErr.js create mode 100644 testing/web-platform/tests/workers/support/ImportScriptsNosniffErr.js create mode 100644 testing/web-platform/tests/workers/support/SharedWorker-common.js create mode 100644 testing/web-platform/tests/workers/support/SharedWorker-create-common.js create mode 100644 testing/web-platform/tests/workers/support/SharedWorker-script-error.js create mode 100644 testing/web-platform/tests/workers/support/Timer.js create mode 100644 testing/web-platform/tests/workers/support/Worker-common.js create mode 100644 testing/web-platform/tests/workers/support/Worker-create-common.js create mode 100644 testing/web-platform/tests/workers/support/Worker-messageport.js create mode 100644 testing/web-platform/tests/workers/support/Worker-run-forever-during-dynamic-import.js create mode 100644 testing/web-platform/tests/workers/support/Worker-run-forever-during-importScripts.js create mode 100644 testing/web-platform/tests/workers/support/Worker-run-forever-during-nested-importScripts.js create mode 100644 testing/web-platform/tests/workers/support/Worker-run-forever-during-top-level-await.js create mode 100644 testing/web-platform/tests/workers/support/Worker-run-forever.js create mode 100644 testing/web-platform/tests/workers/support/Worker-structure-message.js create mode 100644 testing/web-platform/tests/workers/support/Worker-termination-with-port-messages.js create mode 100644 testing/web-platform/tests/workers/support/Worker-thread-multi-port.js create mode 100644 testing/web-platform/tests/workers/support/Worker-timeout-cancel-order.js create mode 100644 testing/web-platform/tests/workers/support/Worker-timeout-decreasing-order.js create mode 100644 testing/web-platform/tests/workers/support/Worker-timeout-increasing-order.js create mode 100644 testing/web-platform/tests/workers/support/WorkerBasic.js create mode 100644 testing/web-platform/tests/workers/support/WorkerClose.js create mode 100644 testing/web-platform/tests/workers/support/WorkerDataCloneErr.js create mode 100644 testing/web-platform/tests/workers/support/WorkerFetchURL.js create mode 100644 testing/web-platform/tests/workers/support/WorkerGlobalScope-close.js create mode 100644 testing/web-platform/tests/workers/support/WorkerLocation-origin.html create mode 100644 testing/web-platform/tests/workers/support/WorkerLocation.js create mode 100644 testing/web-platform/tests/workers/support/WorkerNavigator.js create mode 100644 testing/web-platform/tests/workers/support/WorkerSendingPerformanceNow.js create mode 100644 testing/web-platform/tests/workers/support/WorkerTerminate.js create mode 100644 testing/web-platform/tests/workers/support/WorkerText.txt create mode 100644 testing/web-platform/tests/workers/support/abrupt-completion.js create mode 100644 testing/web-platform/tests/workers/support/check-error-arguments.js create mode 100644 testing/web-platform/tests/workers/support/empty-worker.js create mode 100644 testing/web-platform/tests/workers/support/iframe-sw-shared-name.html create mode 100644 testing/web-platform/tests/workers/support/iframe_sw_dataUrl.html create mode 100644 testing/web-platform/tests/workers/support/importScripts-1.js create mode 100644 testing/web-platform/tests/workers/support/importScripts-2.js create mode 100644 testing/web-platform/tests/workers/support/importScripts-3.js create mode 100644 testing/web-platform/tests/workers/support/imported_script.py create mode 100644 testing/web-platform/tests/workers/support/invalidScript.js create mode 100644 testing/web-platform/tests/workers/support/name-as-accidental-global.js create mode 100644 testing/web-platform/tests/workers/support/name.js create mode 100644 testing/web-platform/tests/workers/support/nosiniff-error-worker.py create mode 100644 testing/web-platform/tests/workers/support/parent_of_nested_worker.js create mode 100644 testing/web-platform/tests/workers/support/post-message-on-load-worker.js create mode 100644 testing/web-platform/tests/workers/support/postMessage_block_worker.js create mode 100644 testing/web-platform/tests/workers/support/postMessage_block_worker.js.headers create mode 100644 testing/web-platform/tests/workers/support/sandboxed-tests.html create mode 100644 testing/web-platform/tests/workers/support/shared-name.js create mode 100644 testing/web-platform/tests/workers/support/sync_xhr.js create mode 100644 testing/web-platform/tests/workers/support/sync_xhr_target.xml create mode 100644 testing/web-platform/tests/workers/support/throw-on-message-Worker.js create mode 100644 testing/web-platform/tests/workers/support/window-sw-shared-name.html create mode 100644 testing/web-platform/tests/workers/support/worker-request-animation-frame.js (limited to 'testing/web-platform/tests/workers/support') diff --git a/testing/web-platform/tests/workers/support/ErrorEvent-error.js b/testing/web-platform/tests/workers/support/ErrorEvent-error.js new file mode 100644 index 0000000000..930b54c0d5 --- /dev/null +++ b/testing/web-platform/tests/workers/support/ErrorEvent-error.js @@ -0,0 +1,9 @@ +onerror = function(message, location, line, col, error) { + postMessage({ source: "onerror", value: error }); +} + +addEventListener("error", function(e) { + postMessage({ source: "event listener", value: e.error }); +}); + +throw "hello"; diff --git a/testing/web-platform/tests/workers/support/ErrorEvent.js b/testing/web-platform/tests/workers/support/ErrorEvent.js new file mode 100644 index 0000000000..22ea6d4fb5 --- /dev/null +++ b/testing/web-platform/tests/workers/support/ErrorEvent.js @@ -0,0 +1,10 @@ +onmessage = function(evt) +{ + throw(new Error(evt.data)); +} + +onerror = function(message, location, line, col) +{ + postMessage( {"message": message, "filename": location, "lineno": line, "colno": col} ); + return false; // "not handled" so the error propagates up to the Worker object +} diff --git a/testing/web-platform/tests/workers/support/ImportScripts.js b/testing/web-platform/tests/workers/support/ImportScripts.js new file mode 100644 index 0000000000..7f2a2bcb55 --- /dev/null +++ b/testing/web-platform/tests/workers/support/ImportScripts.js @@ -0,0 +1,9 @@ +try +{ + importScripts("WorkerBasic.js"); +} +catch(ex) +{ + result = "Fail"; + postMessage(result); +} diff --git a/testing/web-platform/tests/workers/support/ImportScriptsNetworkErr.js b/testing/web-platform/tests/workers/support/ImportScriptsNetworkErr.js new file mode 100644 index 0000000000..8179c8b100 --- /dev/null +++ b/testing/web-platform/tests/workers/support/ImportScriptsNetworkErr.js @@ -0,0 +1,15 @@ +var result = "Fail"; + +try +{ + importScripts("NonExistentFile.js"); +} +catch(ex) +{ + if (ex.code != null && ex.code == ex.NETWORK_ERR) + { + result = "Pass"; + } +} + +postMessage(result); \ No newline at end of file diff --git a/testing/web-platform/tests/workers/support/ImportScriptsNosniffErr.js b/testing/web-platform/tests/workers/support/ImportScriptsNosniffErr.js new file mode 100644 index 0000000000..22dc9c1ba5 --- /dev/null +++ b/testing/web-platform/tests/workers/support/ImportScriptsNosniffErr.js @@ -0,0 +1,9 @@ +importScripts('/resources/testharness.js'); + +test(t => { + assert_throws_dom('NetworkError', () => { + importScripts("nosiniff-error-worker.py"); + }); +}, "importScripts throws on 'nosniff' violation"); + +done(); diff --git a/testing/web-platform/tests/workers/support/SharedWorker-common.js b/testing/web-platform/tests/workers/support/SharedWorker-common.js new file mode 100644 index 0000000000..1c1dac3971 --- /dev/null +++ b/testing/web-platform/tests/workers/support/SharedWorker-common.js @@ -0,0 +1,32 @@ +function generateError() +{ + // Generate an exception by accessing an undefined variable. + foo.bar = 0; +} + +onconnect = function(event) { + event.ports[0].onmessage = function(evt) { handleMessage(evt, event.ports[0]); }; +}; + +function handleMessage(event, port) { + self.port = port; + if (event.data == "ping") + port.postMessage("PASS: Received ping message"); + else if (event.data == "close") + close(); + else if (event.data == "done") + port.postMessage("DONE"); + else if (event.data == "throw") + generateError(); + else if (event.data == "testingNameAttribute") + port.postMessage(self.name); + else if (/eval.+/.test(event.data)) { + try { + port.postMessage(event.data.substr(5) + ": " + eval(event.data.substr(5))); + } catch (ex) { + port.postMessage(event.data.substr(5) + ": " + ex); + } + } + else + port.postMessage("FAILURE: Received unknown message: " + event.data); +} diff --git a/testing/web-platform/tests/workers/support/SharedWorker-create-common.js b/testing/web-platform/tests/workers/support/SharedWorker-create-common.js new file mode 100644 index 0000000000..1d06174f12 --- /dev/null +++ b/testing/web-platform/tests/workers/support/SharedWorker-create-common.js @@ -0,0 +1,8 @@ +// Make a SharedWorker that has the same external interface as a DedicatedWorker, to use in shared test code. +function createWorker() +{ + var worker = new SharedWorker('support/SharedWorker-common.js', 'name'); + worker.port.onmessage = function(evt) { worker.onmessage(evt); }; + worker.postMessage = function(msg, port) { worker.port.postMessage(msg, port); }; + return worker; +} diff --git a/testing/web-platform/tests/workers/support/SharedWorker-script-error.js b/testing/web-platform/tests/workers/support/SharedWorker-script-error.js new file mode 100644 index 0000000000..0e78949d97 --- /dev/null +++ b/testing/web-platform/tests/workers/support/SharedWorker-script-error.js @@ -0,0 +1,22 @@ +onconnect = function(event) { + event.ports[0].onmessage = function(evt) { handleMessage(evt, event.ports[0]); }; +}; + +function handleMessage(event, port) { + if (event.data == "unhandledError") { + // Generate an unhandled error. + onerror = null; + setTimeout(function() { + port.postMessage("SUCCESS: unhandled error generated"); + }, 100); + generateError(); // Undefined function call + } else if (event.data == "handledError") { + onerror = function() { + port.postMessage("SUCCESS: error handled via onerror"); + return true; + }; + generateError(); // Undefined function call + } else { + port.postMessage("FAIL: Got unexpected message: " + event.data); + } +}; diff --git a/testing/web-platform/tests/workers/support/Timer.js b/testing/web-platform/tests/workers/support/Timer.js new file mode 100644 index 0000000000..a86a224dbb --- /dev/null +++ b/testing/web-platform/tests/workers/support/Timer.js @@ -0,0 +1,50 @@ +var count = 0; +var id; + +onmessage = function(evt) +{ + try + { + switch(evt.data) + { + case "TimeoutHandler": + count = 0; + id = setTimeout("TimeoutHandler()", 10); + postMessage('hello'); + break; + case "IntervalHandler": + count = 0; + id = setInterval("IntervalHandler()", 10); + postMessage('hello'); + break; + } + } + catch(ex) + { + postMessage("Fail"); + } +} + +function TimeoutHandler() +{ + count++; + postMessage("worker"); + + id = setTimeout("TimeoutHandler()", 10); + + if (count >= 2) + { + clearTimeout(id); + } +} + +function IntervalHandler() +{ + count++; + postMessage("worker"); + + if (count >= 2) + { + clearInterval(id); + } +} diff --git a/testing/web-platform/tests/workers/support/Worker-common.js b/testing/web-platform/tests/workers/support/Worker-common.js new file mode 100644 index 0000000000..55188fe913 --- /dev/null +++ b/testing/web-platform/tests/workers/support/Worker-common.js @@ -0,0 +1,16 @@ +onmessage = function(evt) +{ + if (evt.data == "ping") + postMessage("pong"); + else if (evt.data == "freeze") + while (1) {} + else if (evt.data == "close") + close(); + else if (/eval.+/.test(evt.data)) { + try { + postMessage(evt.data.substr(5) + ": " + eval(evt.data.substr(5))); + } catch (ex) { + postMessage(evt.data.substr(5) + ": " + ex); + } + } +} diff --git a/testing/web-platform/tests/workers/support/Worker-create-common.js b/testing/web-platform/tests/workers/support/Worker-create-common.js new file mode 100644 index 0000000000..f0b8efe46b --- /dev/null +++ b/testing/web-platform/tests/workers/support/Worker-create-common.js @@ -0,0 +1,4 @@ +function createWorker() +{ + return new Worker('support/Worker-common.js'); +} diff --git a/testing/web-platform/tests/workers/support/Worker-messageport.js b/testing/web-platform/tests/workers/support/Worker-messageport.js new file mode 100644 index 0000000000..1e01b0a52b --- /dev/null +++ b/testing/web-platform/tests/workers/support/Worker-messageport.js @@ -0,0 +1,40 @@ +onmessage = function(evt) { + if (evt.data == "port") { + if (evt.ports) { + postMessage("PASS: Received message port"); + evt.ports[0].onmessage = pingBack; + evt.ports[0].start(); + } else { + postMessage("FAIL: Did not receive expected MessagePort"); + } + } else if (evt.data == "noport") { + if (!evt.ports || evt.ports.length) { + postMessage("FAIL: Received message port or null ports array"); + } else { + postMessage("PASS: evt.ports = [] as expected"); + } + } else if (evt.data == "spam") { + for (var i = 0 ; i < 1000 ; i++) { + evt.ports[0].postMessage(i); + } + postMessage("spamDone"); + } else if (evt.data == "getport") { + var channel = new MessageChannel(); + postMessage("port", [channel.port1]); + channel.port2.onmessage = pingBack; + channel.port2.start(); + } else { + postMessage("Unknown message:" + evt.data); + } + +} + +function pingBack(evt) { + // Make sure we got the expected data and send a return message over + // the port. + if (evt.data == "ping") { + evt.target.postMessage("pong"); + } else { + postMessage("FAIL: unknown message: " + evt.data); + } +} diff --git a/testing/web-platform/tests/workers/support/Worker-run-forever-during-dynamic-import.js b/testing/web-platform/tests/workers/support/Worker-run-forever-during-dynamic-import.js new file mode 100644 index 0000000000..62840bd5b4 --- /dev/null +++ b/testing/web-platform/tests/workers/support/Worker-run-forever-during-dynamic-import.js @@ -0,0 +1,3 @@ +import('./Worker-run-forever.js') + .then(r => postMessage('resolved: ' + r)) + .catch(e => postMessage('rejected: ' + e)); diff --git a/testing/web-platform/tests/workers/support/Worker-run-forever-during-importScripts.js b/testing/web-platform/tests/workers/support/Worker-run-forever-during-importScripts.js new file mode 100644 index 0000000000..6a3083f382 --- /dev/null +++ b/testing/web-platform/tests/workers/support/Worker-run-forever-during-importScripts.js @@ -0,0 +1,4 @@ +importScripts('Worker-run-forever.js'); + +// This is not expected to run. +postMessage('after importScripts()'); diff --git a/testing/web-platform/tests/workers/support/Worker-run-forever-during-nested-importScripts.js b/testing/web-platform/tests/workers/support/Worker-run-forever-during-nested-importScripts.js new file mode 100644 index 0000000000..aae86a0b05 --- /dev/null +++ b/testing/web-platform/tests/workers/support/Worker-run-forever-during-nested-importScripts.js @@ -0,0 +1 @@ +importScripts('Worker-run-forever-during-importScripts.js'); diff --git a/testing/web-platform/tests/workers/support/Worker-run-forever-during-top-level-await.js b/testing/web-platform/tests/workers/support/Worker-run-forever-during-top-level-await.js new file mode 100644 index 0000000000..a1c8b32b61 --- /dev/null +++ b/testing/web-platform/tests/workers/support/Worker-run-forever-during-top-level-await.js @@ -0,0 +1,4 @@ +await 1; +postMessage('start'); +onerror = () => postMessage('onerror'); +while(1); diff --git a/testing/web-platform/tests/workers/support/Worker-run-forever.js b/testing/web-platform/tests/workers/support/Worker-run-forever.js new file mode 100644 index 0000000000..2d822d407f --- /dev/null +++ b/testing/web-platform/tests/workers/support/Worker-run-forever.js @@ -0,0 +1,3 @@ +postMessage('start'); +onerror = () => postMessage('onerror'); +while(1); diff --git a/testing/web-platform/tests/workers/support/Worker-structure-message.js b/testing/web-platform/tests/workers/support/Worker-structure-message.js new file mode 100644 index 0000000000..81cd98243b --- /dev/null +++ b/testing/web-platform/tests/workers/support/Worker-structure-message.js @@ -0,0 +1,15 @@ +self.onmessage = function(evt) { + if (evt.data.operation == 'find-edges' && + ArrayBuffer.prototype.isPrototypeOf(evt.data.input) && + evt.data.input.byteLength == 20 && + evt.data.threshold == 0.6) { + self.postMessage("PASS: Worker receives correct structure message."); + self.postMessage({ + operation: evt.data.operation, + input: evt.data.input, + threshold: evt.data.threshold + }); + } + else + self.postMessage("FAIL: Worker receives error structure message."); +} diff --git a/testing/web-platform/tests/workers/support/Worker-termination-with-port-messages.js b/testing/web-platform/tests/workers/support/Worker-termination-with-port-messages.js new file mode 100644 index 0000000000..a827db357e --- /dev/null +++ b/testing/web-platform/tests/workers/support/Worker-termination-with-port-messages.js @@ -0,0 +1,10 @@ +function echo(evt) +{ + evt.target.postMessage(evt.data); +} + +onmessage = function(evt) +{ + evt.ports[0].onmessage = echo; + evt.ports[0].start(); +} diff --git a/testing/web-platform/tests/workers/support/Worker-thread-multi-port.js b/testing/web-platform/tests/workers/support/Worker-thread-multi-port.js new file mode 100644 index 0000000000..2ce7cae596 --- /dev/null +++ b/testing/web-platform/tests/workers/support/Worker-thread-multi-port.js @@ -0,0 +1,43 @@ +onmessage = function(event) { + if (event.data == "noport") { + if (event.ports && !event.ports.length) + testPassed("event.ports is non-null and zero length when no port sent"); + else + testFailed("event.ports is null or non-zero length when no port sent"); + } else if (event.data == "zero ports") { + if (event.ports && !event.ports.length) + testPassed("event.ports is non-null and zero length when empty array sent"); + else + testFailed("event.ports is null or non-zero length when empty array sent"); + } else if (event.data == "two ports") { + if (!event.ports) { + testFailed("event.ports should be non-null when ports sent"); + return; + } + if (event.ports.length == 2) + testPassed("event.ports contains two ports when two ports sent"); + else + testFailed("event.ports contained " + event.ports.length + " when two ports sent"); + } else if (event.data == "failed ports") { + if (event.ports.length == 2) + testPassed("event.ports contains two ports when two ports re-sent after error"); + else + testFailed("event.ports contained " + event.ports.length + " when two ports re-sent after error"); + } else if (event.data == "noargs") { + try { + postMessage(); + testFailed("postMessage() did not throw"); + } catch (e) { + testPassed("postMessage() threw exception: " + e); + } + } else + testFailed("Received unexpected message: " + event.data); +}; + +function testPassed(msg) { + postMessage("PASS"+msg); +} + +function testFailed(msg) { + postMessage("FAIL"+msg); +} diff --git a/testing/web-platform/tests/workers/support/Worker-timeout-cancel-order.js b/testing/web-platform/tests/workers/support/Worker-timeout-cancel-order.js new file mode 100644 index 0000000000..afc66cf6a0 --- /dev/null +++ b/testing/web-platform/tests/workers/support/Worker-timeout-cancel-order.js @@ -0,0 +1,7 @@ +// The test will create 2 timeouts and cancel the first one. If only the second +// timeout executes then the test passes. +self.addEventListener('message', function(e) { + var t1 = setTimeout(function () { postMessage(1); }, 5); + setTimeout(function () { postMessage(2); }, 10); + clearTimeout(t1); +}, false); diff --git a/testing/web-platform/tests/workers/support/Worker-timeout-decreasing-order.js b/testing/web-platform/tests/workers/support/Worker-timeout-decreasing-order.js new file mode 100644 index 0000000000..b93dd5dc77 --- /dev/null +++ b/testing/web-platform/tests/workers/support/Worker-timeout-decreasing-order.js @@ -0,0 +1,7 @@ +// The test will create 3 timeouts with their intervals decreasing. +// If the timeouts execute in order then the test is PASS. +self.addEventListener('message', function(e) { + setTimeout(function () { postMessage(3); }, 15); + setTimeout(function () { postMessage(2); }, 10); + setTimeout(function () { postMessage(1); }, 5); +}, false); diff --git a/testing/web-platform/tests/workers/support/Worker-timeout-increasing-order.js b/testing/web-platform/tests/workers/support/Worker-timeout-increasing-order.js new file mode 100644 index 0000000000..42f81daa29 --- /dev/null +++ b/testing/web-platform/tests/workers/support/Worker-timeout-increasing-order.js @@ -0,0 +1,7 @@ +// The test will create 3 timeouts with their intervals increasing. +// If the timeouts execute in order then the test is PASS. +self.addEventListener('message', function(e) { + setTimeout(function () { postMessage(1); }, 5); + setTimeout(function () { postMessage(2); }, 10); + setTimeout(function () { postMessage(3); }, 15); +}, false); diff --git a/testing/web-platform/tests/workers/support/WorkerBasic.js b/testing/web-platform/tests/workers/support/WorkerBasic.js new file mode 100644 index 0000000000..6bb6d32b14 --- /dev/null +++ b/testing/web-platform/tests/workers/support/WorkerBasic.js @@ -0,0 +1,7 @@ +var result = "Fail"; + +onmessage = function(evt) +{ + result = "Pass"; + postMessage(result); +} \ No newline at end of file diff --git a/testing/web-platform/tests/workers/support/WorkerClose.js b/testing/web-platform/tests/workers/support/WorkerClose.js new file mode 100644 index 0000000000..81f99993d8 --- /dev/null +++ b/testing/web-platform/tests/workers/support/WorkerClose.js @@ -0,0 +1,5 @@ +onmessage = function(evt) +{ + postMessage(evt.data); + self.close(); +} \ No newline at end of file diff --git a/testing/web-platform/tests/workers/support/WorkerDataCloneErr.js b/testing/web-platform/tests/workers/support/WorkerDataCloneErr.js new file mode 100644 index 0000000000..b7e8b0ae16 --- /dev/null +++ b/testing/web-platform/tests/workers/support/WorkerDataCloneErr.js @@ -0,0 +1,15 @@ +var result = "Fail"; + +try +{ + postMessage(navigator); +} +catch(ex) +{ + if(ex.code != null && ex.code == ex.DATA_CLONE_ERR) + { + result = "Pass"; + } +} + +postMessage(result); \ No newline at end of file diff --git a/testing/web-platform/tests/workers/support/WorkerFetchURL.js b/testing/web-platform/tests/workers/support/WorkerFetchURL.js new file mode 100644 index 0000000000..4ad700bcce --- /dev/null +++ b/testing/web-platform/tests/workers/support/WorkerFetchURL.js @@ -0,0 +1,8 @@ +onconnect = e => { + let port = e.ports[0]; + port.onmessage = (e) => { + fetch(e.data) + .then(response => response.text()) + .then(text => port.postMessage('Worker reply:' + text)); + }; +} diff --git a/testing/web-platform/tests/workers/support/WorkerGlobalScope-close.js b/testing/web-platform/tests/workers/support/WorkerGlobalScope-close.js new file mode 100644 index 0000000000..e2b1c0a2fd --- /dev/null +++ b/testing/web-platform/tests/workers/support/WorkerGlobalScope-close.js @@ -0,0 +1,43 @@ +// Check to see if the worker handles pending events. Messages after close() will not be sent to the parent page, so we use exceptions instead to report failures after close(). +onmessage = function(evt) +{ + if (evt.data == "closeWithPendingEvents") { + // Set a timer to generate an event - minimum timeout is 1ms. + setTimeout(function() { + postMessage("pending event processed"); + throw "should not be executed"; + }, 1); + var start = new Date().getTime(); + // Loop for 10 ms so the timer is ready to fire + while (new Date().getTime() - start < 100) + ; + // Now close - timer should not fire + close(); + } else if (evt.data == "typeofClose") { + postMessage("typeof close: " + (typeof close)); + } else if (evt.data == "close") { + close(); + postMessage("Should be delivered"); + } else if (evt.data == "ping") { + postMessage("pong"); + } else if (evt.data == "throw") { + throw "should never be executed"; + } else if (evt.data == "closeWithError") { + close(); + nonExistentFunction(); // Undefined function - throws exception + } else if (evt.data == "close_post_loop") { + close(); + postMessage("closed"); + while(true) {} // Should loop forever. + } else if (evt.data == "take_port") { + messagePort = evt.ports[0]; + messagePort.onmessage = function(event) { + close(); + postMessage("echo_" + event.data); + } + } else if (evt.data == "start_port") { + messagePort.start(); + } else { + postMessage("FAIL: Unknown message type: " + evt.data); + } +} diff --git a/testing/web-platform/tests/workers/support/WorkerLocation-origin.html b/testing/web-platform/tests/workers/support/WorkerLocation-origin.html new file mode 100644 index 0000000000..3d948030a7 --- /dev/null +++ b/testing/web-platform/tests/workers/support/WorkerLocation-origin.html @@ -0,0 +1,6 @@ + diff --git a/testing/web-platform/tests/workers/support/WorkerLocation.js b/testing/web-platform/tests/workers/support/WorkerLocation.js new file mode 100644 index 0000000000..901e21542a --- /dev/null +++ b/testing/web-platform/tests/workers/support/WorkerLocation.js @@ -0,0 +1,13 @@ +var obj = new Object(); +obj.location = location.toString(); +obj.href = location.href; +obj.origin = location.origin; +obj.protocol = location.protocol; +obj.host = location.host; +obj.hostname = location.hostname; +obj.port = location.port; +obj.pathname = location.pathname; +obj.search = location.search; +obj.hash = location.hash; + +postMessage(obj); diff --git a/testing/web-platform/tests/workers/support/WorkerNavigator.js b/testing/web-platform/tests/workers/support/WorkerNavigator.js new file mode 100644 index 0000000000..e58e7338e9 --- /dev/null +++ b/testing/web-platform/tests/workers/support/WorkerNavigator.js @@ -0,0 +1,26 @@ +(async () => { + const obj = new Object(); + obj.appName = navigator.appName; + obj.appVersion = navigator.appVersion; + obj.platform = navigator.platform; + obj.userAgent = navigator.userAgent; + obj.onLine = navigator.onLine; + if (navigator.userAgentData) { + obj.brands = navigator.userAgentData.brands; + obj.mobile = navigator.userAgentData.mobile; + obj.platform = navigator.userAgentData.platform; + const highEntropyValues = await navigator.userAgentData.getHighEntropyValues([ + "architecture", "bitness", "fullVersionList", "model", + "platformVersion", "uaFullVersion", "wow64" + ]); + obj.architecture = highEntropyValues.architecture; + obj.bitness = highEntropyValues.bitness; + obj.fullVersionList = highEntropyValues.fullVersionList; + obj.model = highEntropyValues.model; + obj.platformVersion = highEntropyValues.platformVersion; + obj.uaFullVersion = highEntropyValues.uaFullVersion; + obj.wow64 = highEntropyValues.wow64; + obj.NavigatorUADataExposed = (typeof self.NavigatorUAData != "undefined"); + } + postMessage(obj); +})(); diff --git a/testing/web-platform/tests/workers/support/WorkerSendingPerformanceNow.js b/testing/web-platform/tests/workers/support/WorkerSendingPerformanceNow.js new file mode 100644 index 0000000000..ac12190efe --- /dev/null +++ b/testing/web-platform/tests/workers/support/WorkerSendingPerformanceNow.js @@ -0,0 +1,22 @@ +function calcResponse() { + const response = [ + typeof(workerStart), + typeof(performance), + typeof(performance.now), + performance.now() + ]; + return response; +} + +self.onmessage = function(event) { + postMessage(calcResponse()); + self.close(); +} + +self.addEventListener("connect", function(event) { + const port = event.ports[0]; + port.onmessage = function(event) { + port.postMessage(calcResponse()); + port.close(); + }; +}); diff --git a/testing/web-platform/tests/workers/support/WorkerTerminate.js b/testing/web-platform/tests/workers/support/WorkerTerminate.js new file mode 100644 index 0000000000..7c99e7ec56 --- /dev/null +++ b/testing/web-platform/tests/workers/support/WorkerTerminate.js @@ -0,0 +1,10 @@ +onmessage = function(evt) +{ + for (var i=0; true; i++) + { + if (i%1000 == 0) + { + postMessage(i); + } + } +} diff --git a/testing/web-platform/tests/workers/support/WorkerText.txt b/testing/web-platform/tests/workers/support/WorkerText.txt new file mode 100644 index 0000000000..e4eeb5391d --- /dev/null +++ b/testing/web-platform/tests/workers/support/WorkerText.txt @@ -0,0 +1,2 @@ +var result = "Pass"; +postMessage(result); diff --git a/testing/web-platform/tests/workers/support/abrupt-completion.js b/testing/web-platform/tests/workers/support/abrupt-completion.js new file mode 100644 index 0000000000..f0884cc1d2 --- /dev/null +++ b/testing/web-platform/tests/workers/support/abrupt-completion.js @@ -0,0 +1,21 @@ +const isSharedWorker = + "SharedWorkerGlobalScope" in self && self instanceof SharedWorkerGlobalScope; + +function setMessageHandler(response) { + onmessage = e => { + e.ports[0].postMessage(response); + }; + + if (isSharedWorker) { + onconnect = e => { + e.ports[0].onmessage = onmessage; + }; + } +} + +setMessageHandler("handler-before-throw"); + +throw new Error("uncaught-exception"); + +// This should never be called because of the uncaught exception above. +setMessageHandler("handler-after-throw"); diff --git a/testing/web-platform/tests/workers/support/check-error-arguments.js b/testing/web-platform/tests/workers/support/check-error-arguments.js new file mode 100644 index 0000000000..64441f9225 --- /dev/null +++ b/testing/web-platform/tests/workers/support/check-error-arguments.js @@ -0,0 +1,4 @@ +window.checkErrorArguments = args => { + assert_equals(args.length, 1); + assert_equals(args[0].constructor, Event); +}; diff --git a/testing/web-platform/tests/workers/support/empty-worker.js b/testing/web-platform/tests/workers/support/empty-worker.js new file mode 100644 index 0000000000..49ceb2648a --- /dev/null +++ b/testing/web-platform/tests/workers/support/empty-worker.js @@ -0,0 +1 @@ +// Do nothing. diff --git a/testing/web-platform/tests/workers/support/iframe-sw-shared-name.html b/testing/web-platform/tests/workers/support/iframe-sw-shared-name.html new file mode 100644 index 0000000000..c1c7a536e1 --- /dev/null +++ b/testing/web-platform/tests/workers/support/iframe-sw-shared-name.html @@ -0,0 +1,19 @@ + +Iframe for cross-origin Shared Worker + + + + + + diff --git a/testing/web-platform/tests/workers/support/iframe_sw_dataUrl.html b/testing/web-platform/tests/workers/support/iframe_sw_dataUrl.html new file mode 100644 index 0000000000..0fb0ec2280 --- /dev/null +++ b/testing/web-platform/tests/workers/support/iframe_sw_dataUrl.html @@ -0,0 +1,13 @@ + +Iframe for Shared Worker: Data URL cross-origin checks + + + + diff --git a/testing/web-platform/tests/workers/support/importScripts-1.js b/testing/web-platform/tests/workers/support/importScripts-1.js new file mode 100644 index 0000000000..8869a4fbca --- /dev/null +++ b/testing/web-platform/tests/workers/support/importScripts-1.js @@ -0,0 +1 @@ +importScripts("importScripts-2.js"); diff --git a/testing/web-platform/tests/workers/support/importScripts-2.js b/testing/web-platform/tests/workers/support/importScripts-2.js new file mode 100644 index 0000000000..7f3f1116e7 --- /dev/null +++ b/testing/web-platform/tests/workers/support/importScripts-2.js @@ -0,0 +1 @@ +importScripts("importScripts-3.js"); diff --git a/testing/web-platform/tests/workers/support/importScripts-3.js b/testing/web-platform/tests/workers/support/importScripts-3.js new file mode 100644 index 0000000000..2d103a0411 --- /dev/null +++ b/testing/web-platform/tests/workers/support/importScripts-3.js @@ -0,0 +1 @@ +importScripts("invalidScript.js"); diff --git a/testing/web-platform/tests/workers/support/imported_script.py b/testing/web-platform/tests/workers/support/imported_script.py new file mode 100644 index 0000000000..2f9c6a81d9 --- /dev/null +++ b/testing/web-platform/tests/workers/support/imported_script.py @@ -0,0 +1,2 @@ +def main(request, response): + return [(b'Content-Type', request.GET[b'mime'])], u"" diff --git a/testing/web-platform/tests/workers/support/invalidScript.js b/testing/web-platform/tests/workers/support/invalidScript.js new file mode 100644 index 0000000000..8655d4d1f1 --- /dev/null +++ b/testing/web-platform/tests/workers/support/invalidScript.js @@ -0,0 +1 @@ +SELECT * FROM TABLE; // an invalid script. diff --git a/testing/web-platform/tests/workers/support/name-as-accidental-global.js b/testing/web-platform/tests/workers/support/name-as-accidental-global.js new file mode 100644 index 0000000000..f2c39ea715 --- /dev/null +++ b/testing/web-platform/tests/workers/support/name-as-accidental-global.js @@ -0,0 +1,9 @@ +"use strict"; +importScripts("/resources/testharness.js"); + +var name = "something else"; + +// This just makes the test name not "Untitled" +test(() => { }, `Declaring name as an accidental global must not cause a harness error for ${self.constructor.name}`); + +done(); diff --git a/testing/web-platform/tests/workers/support/name.js b/testing/web-platform/tests/workers/support/name.js new file mode 100644 index 0000000000..970578e425 --- /dev/null +++ b/testing/web-platform/tests/workers/support/name.js @@ -0,0 +1,18 @@ +"use strict"; +importScripts("/resources/testharness.js"); + +test(() => { + assert_true(self.hasOwnProperty("name"), "property exists on the global"); + assert_equals(self.name, "my name"); +}, `name property value for ${self.constructor.name}`); + +test(() => { + self.name = "something new"; + const propDesc = Object.getOwnPropertyDescriptor(self, "name"); + assert_equals(propDesc.value, "something new", "value"); + assert_true(propDesc.configurable, "configurable"); + assert_true(propDesc.writable, "writable"); + assert_true(propDesc.enumerable, "enumerable"); +}, `name property is replaceable for ${self.constructor.name}`); + +done(); diff --git a/testing/web-platform/tests/workers/support/nosiniff-error-worker.py b/testing/web-platform/tests/workers/support/nosiniff-error-worker.py new file mode 100644 index 0000000000..e4367ba6e1 --- /dev/null +++ b/testing/web-platform/tests/workers/support/nosiniff-error-worker.py @@ -0,0 +1,3 @@ +def main(request, response): + return [(b'Content-Type', b'text/html'), + (b'X-Content-Type-Options', b'nosniff')], u"" diff --git a/testing/web-platform/tests/workers/support/parent_of_nested_worker.js b/testing/web-platform/tests/workers/support/parent_of_nested_worker.js new file mode 100644 index 0000000000..1f14334290 --- /dev/null +++ b/testing/web-platform/tests/workers/support/parent_of_nested_worker.js @@ -0,0 +1,14 @@ +try { + var worker = new Worker("WorkerBasic.js"); + worker.onmessage = function(e) { + if (e.data == "Pass") { + postMessage("Pass"); + } else if (e.data == "close") { + close(); + postMessage("Pass"); + } + }; + worker.postMessage("start"); +} catch (e) { + postMessage("Fail: " + e); +} diff --git a/testing/web-platform/tests/workers/support/post-message-on-load-worker.js b/testing/web-platform/tests/workers/support/post-message-on-load-worker.js new file mode 100644 index 0000000000..e1c547ab6a --- /dev/null +++ b/testing/web-platform/tests/workers/support/post-message-on-load-worker.js @@ -0,0 +1,10 @@ +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + postMessage('LOADED'); +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + self.onconnect = e => { + e.ports[0].postMessage('LOADED'); + }; +} diff --git a/testing/web-platform/tests/workers/support/postMessage_block_worker.js b/testing/web-platform/tests/workers/support/postMessage_block_worker.js new file mode 100644 index 0000000000..0c7bcaccca --- /dev/null +++ b/testing/web-platform/tests/workers/support/postMessage_block_worker.js @@ -0,0 +1,2 @@ +onmessage = e => Atomics.store(e.data, 0, 1); +postMessage('ready'); diff --git a/testing/web-platform/tests/workers/support/postMessage_block_worker.js.headers b/testing/web-platform/tests/workers/support/postMessage_block_worker.js.headers new file mode 100644 index 0000000000..6604450991 --- /dev/null +++ b/testing/web-platform/tests/workers/support/postMessage_block_worker.js.headers @@ -0,0 +1 @@ +Cross-Origin-Embedder-Policy: require-corp diff --git a/testing/web-platform/tests/workers/support/sandboxed-tests.html b/testing/web-platform/tests/workers/support/sandboxed-tests.html new file mode 100644 index 0000000000..811c925f56 --- /dev/null +++ b/testing/web-platform/tests/workers/support/sandboxed-tests.html @@ -0,0 +1,67 @@ + + + + + diff --git a/testing/web-platform/tests/workers/support/shared-name.js b/testing/web-platform/tests/workers/support/shared-name.js new file mode 100644 index 0000000000..f004482719 --- /dev/null +++ b/testing/web-platform/tests/workers/support/shared-name.js @@ -0,0 +1,8 @@ +"use strict"; + +self.counter = 0; + +self.onconnect = e => { + ++self.counter; + e.source.postMessage({ counter: self.counter, name: self.name }); +}; diff --git a/testing/web-platform/tests/workers/support/sync_xhr.js b/testing/web-platform/tests/workers/support/sync_xhr.js new file mode 100644 index 0000000000..5de7476537 --- /dev/null +++ b/testing/web-platform/tests/workers/support/sync_xhr.js @@ -0,0 +1,13 @@ +try +{ + const request = new XMLHttpRequest(); + request.open("GET", "sync_xhr_target.xml", false); + request.send(); + result = request.responseText == "sometext\n" ? "Pass" : "Fail"; + postMessage(result); +} +catch(ex) +{ + result = "Fail"; + postMessage(result); +} diff --git a/testing/web-platform/tests/workers/support/sync_xhr_target.xml b/testing/web-platform/tests/workers/support/sync_xhr_target.xml new file mode 100644 index 0000000000..d31a8c5eb4 --- /dev/null +++ b/testing/web-platform/tests/workers/support/sync_xhr_target.xml @@ -0,0 +1 @@ +sometext diff --git a/testing/web-platform/tests/workers/support/throw-on-message-Worker.js b/testing/web-platform/tests/workers/support/throw-on-message-Worker.js new file mode 100644 index 0000000000..3648f1f478 --- /dev/null +++ b/testing/web-platform/tests/workers/support/throw-on-message-Worker.js @@ -0,0 +1,11 @@ +self.onerror = function(evt) { + postMessage('error'); + return true; +} + +self.onmessage = function(evt) { + if (evt.data === "first") + throw Error(); + else + postMessage(evt.data); +} diff --git a/testing/web-platform/tests/workers/support/window-sw-shared-name.html b/testing/web-platform/tests/workers/support/window-sw-shared-name.html new file mode 100644 index 0000000000..4a0704f9e4 --- /dev/null +++ b/testing/web-platform/tests/workers/support/window-sw-shared-name.html @@ -0,0 +1,22 @@ + +Window for cross-origin iframe with Shared Worker + + + + + + diff --git a/testing/web-platform/tests/workers/support/worker-request-animation-frame.js b/testing/web-platform/tests/workers/support/worker-request-animation-frame.js new file mode 100644 index 0000000000..b73781244e --- /dev/null +++ b/testing/web-platform/tests/workers/support/worker-request-animation-frame.js @@ -0,0 +1,6 @@ +self.onmessage = function(event) { + requestAnimationFrame(time => { + postMessage(time); + self.close(); + }); +} -- cgit v1.2.3