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 --- dom/base/test/worker_postMessages.js | 73 ++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 dom/base/test/worker_postMessages.js (limited to 'dom/base/test/worker_postMessages.js') diff --git a/dom/base/test/worker_postMessages.js b/dom/base/test/worker_postMessages.js new file mode 100644 index 0000000000..77bfa80748 --- /dev/null +++ b/dom/base/test/worker_postMessages.js @@ -0,0 +1,73 @@ +function test_workers() { + onmessage = function (e) { + postMessage(e.data, e.ports); + }; + + onmessageerror = function (e) { + postMessage("error"); + }; +} + +function test_sharedWorkers(port) { + port.onmessage = function (e) { + if (e.data == "terminate") { + close(); + } else { + port.postMessage(e.data, e.ports); + } + }; + + port.onmessageerror = function (e) { + port.postMessage("error"); + }; +} + +function test_broadcastChannel(obj) { + var bc = new BroadcastChannel("postMessagesTest_inWorkers"); + bc.onmessage = function (e) { + obj.postMessage(e.data); + }; + + bc.onmessageerror = function () { + obj.postMessage("error"); + }; +} + +function test_messagePort(port) { + port.onmessage = function (e) { + postMessage(e.data, e.ports); + }; + + port.onmessageerror = function (e) { + postMessage("error"); + }; +} + +onconnect = function (e) { + e.ports[0].onmessage = ee => { + if (ee.data == "sharedworkers") { + test_sharedWorkers(e.ports[0]); + e.ports[0].postMessage("ok"); + } else if (ee.data == "broadcastChannel") { + test_broadcastChannel(e.ports[0]); + e.ports[0].postMessage("ok"); + } else if (ee.data == "terminate") { + close(); + } + }; +}; + +onmessage = function (e) { + if (e.data == "workers") { + test_workers(); + postMessage("ok"); + } else if (e.data == "broadcastChannel") { + test_broadcastChannel(self); + postMessage("ok"); + } else if (e.data == "messagePort") { + test_messagePort(e.ports[0]); + postMessage("ok"); + } else { + postMessage("ko"); + } +}; -- cgit v1.2.3