From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- dom/messagechannel/tests/chrome.toml | 15 ++ .../tests/iframe_messageChannel_chrome.html | 11 + .../tests/iframe_messageChannel_cloning.html | 21 ++ .../tests/iframe_messageChannel_pingpong.html | 32 +++ .../tests/iframe_messageChannel_post.html | 23 ++ .../tests/iframe_messageChannel_sharedWorker2.html | 13 ++ .../tests/iframe_messageChannel_transferable.html | 24 +++ dom/messagechannel/tests/mm_messageChannel.js | 76 +++++++ .../tests/mm_messageChannelParent.js | 144 +++++++++++++ .../tests/mm_messageChannelParent.xhtml | 12 ++ .../tests/mm_messageChannelParentNotRemote.xhtml | 12 ++ dom/messagechannel/tests/mochitest.toml | 50 +++++ dom/messagechannel/tests/moz.build | 10 + .../tests/sharedWorker2_messageChannel.js | 9 + .../tests/sharedWorker_messageChannel.js | 10 + .../tests/test_event_listener_leaks.html | 50 +++++ dom/messagechannel/tests/test_messageChannel.html | 43 ++++ dom/messagechannel/tests/test_messageChannel.xhtml | 38 ++++ .../test_messageChannelWithMessageManager.xhtml | 27 +++ ...messageChannelWithMessageManagerNotRemote.xhtml | 27 +++ .../tests/test_messageChannel_any.html | 115 ++++++++++ .../tests/test_messageChannel_bug1178076.html | 38 ++++ .../tests/test_messageChannel_bug1224825.html | 94 +++++++++ .../tests/test_messageChannel_cloning.html | 70 ++++++ .../tests/test_messageChannel_forceClose.html | 30 +++ .../tests/test_messageChannel_pingpong.html | 77 +++++++ .../tests/test_messageChannel_post.html | 76 +++++++ .../test_messageChannel_selfTransferring.html | 32 +++ .../tests/test_messageChannel_sharedWorker.html | 36 ++++ .../tests/test_messageChannel_sharedWorker2.html | 34 +++ .../tests/test_messageChannel_start.html | 235 +++++++++++++++++++++ .../tests/test_messageChannel_transferable.html | 111 ++++++++++ .../tests/test_messageChannel_unshipped.html | 123 +++++++++++ .../tests/test_messageChannel_worker.html | 60 ++++++ .../test_messageChannel_worker_forceClose.html | 27 +++ dom/messagechannel/tests/test_removedWindow.html | 55 +++++ .../tests/unit/chromeWorker_messageChannel.js | 14 ++ .../tests/unit/test_messageChannel.js | 23 ++ dom/messagechannel/tests/unit/xpcshell.toml | 6 + dom/messagechannel/tests/worker_messageChannel.js | 110 ++++++++++ .../tests/worker_messageChannel_any.js | 7 + 41 files changed, 2020 insertions(+) create mode 100644 dom/messagechannel/tests/chrome.toml create mode 100644 dom/messagechannel/tests/iframe_messageChannel_chrome.html create mode 100644 dom/messagechannel/tests/iframe_messageChannel_cloning.html create mode 100644 dom/messagechannel/tests/iframe_messageChannel_pingpong.html create mode 100644 dom/messagechannel/tests/iframe_messageChannel_post.html create mode 100644 dom/messagechannel/tests/iframe_messageChannel_sharedWorker2.html create mode 100644 dom/messagechannel/tests/iframe_messageChannel_transferable.html create mode 100644 dom/messagechannel/tests/mm_messageChannel.js create mode 100644 dom/messagechannel/tests/mm_messageChannelParent.js create mode 100644 dom/messagechannel/tests/mm_messageChannelParent.xhtml create mode 100644 dom/messagechannel/tests/mm_messageChannelParentNotRemote.xhtml create mode 100644 dom/messagechannel/tests/mochitest.toml create mode 100644 dom/messagechannel/tests/moz.build create mode 100644 dom/messagechannel/tests/sharedWorker2_messageChannel.js create mode 100644 dom/messagechannel/tests/sharedWorker_messageChannel.js create mode 100644 dom/messagechannel/tests/test_event_listener_leaks.html create mode 100644 dom/messagechannel/tests/test_messageChannel.html create mode 100644 dom/messagechannel/tests/test_messageChannel.xhtml create mode 100644 dom/messagechannel/tests/test_messageChannelWithMessageManager.xhtml create mode 100644 dom/messagechannel/tests/test_messageChannelWithMessageManagerNotRemote.xhtml create mode 100644 dom/messagechannel/tests/test_messageChannel_any.html create mode 100644 dom/messagechannel/tests/test_messageChannel_bug1178076.html create mode 100644 dom/messagechannel/tests/test_messageChannel_bug1224825.html create mode 100644 dom/messagechannel/tests/test_messageChannel_cloning.html create mode 100644 dom/messagechannel/tests/test_messageChannel_forceClose.html create mode 100644 dom/messagechannel/tests/test_messageChannel_pingpong.html create mode 100644 dom/messagechannel/tests/test_messageChannel_post.html create mode 100644 dom/messagechannel/tests/test_messageChannel_selfTransferring.html create mode 100644 dom/messagechannel/tests/test_messageChannel_sharedWorker.html create mode 100644 dom/messagechannel/tests/test_messageChannel_sharedWorker2.html create mode 100644 dom/messagechannel/tests/test_messageChannel_start.html create mode 100644 dom/messagechannel/tests/test_messageChannel_transferable.html create mode 100644 dom/messagechannel/tests/test_messageChannel_unshipped.html create mode 100644 dom/messagechannel/tests/test_messageChannel_worker.html create mode 100644 dom/messagechannel/tests/test_messageChannel_worker_forceClose.html create mode 100644 dom/messagechannel/tests/test_removedWindow.html create mode 100644 dom/messagechannel/tests/unit/chromeWorker_messageChannel.js create mode 100644 dom/messagechannel/tests/unit/test_messageChannel.js create mode 100644 dom/messagechannel/tests/unit/xpcshell.toml create mode 100644 dom/messagechannel/tests/worker_messageChannel.js create mode 100644 dom/messagechannel/tests/worker_messageChannel_any.js (limited to 'dom/messagechannel/tests') diff --git a/dom/messagechannel/tests/chrome.toml b/dom/messagechannel/tests/chrome.toml new file mode 100644 index 0000000000..b66ebfbfd3 --- /dev/null +++ b/dom/messagechannel/tests/chrome.toml @@ -0,0 +1,15 @@ +[DEFAULT] +support-files = [ + "iframe_messageChannel_chrome.html", + "mm_messageChannelParent.xhtml", + "mm_messageChannelParentNotRemote.xhtml", + "mm_messageChannelParent.js", + "mm_messageChannel.js", +] + +["test_messageChannel.xhtml"] + +["test_messageChannelWithMessageManager.xhtml"] +skip-if = ["os == 'android'"] + +["test_messageChannelWithMessageManagerNotRemote.xhtml"] diff --git a/dom/messagechannel/tests/iframe_messageChannel_chrome.html b/dom/messagechannel/tests/iframe_messageChannel_chrome.html new file mode 100644 index 0000000000..5fcd43a34c --- /dev/null +++ b/dom/messagechannel/tests/iframe_messageChannel_chrome.html @@ -0,0 +1,11 @@ + + + + + diff --git a/dom/messagechannel/tests/iframe_messageChannel_cloning.html b/dom/messagechannel/tests/iframe_messageChannel_cloning.html new file mode 100644 index 0000000000..3012f9a845 --- /dev/null +++ b/dom/messagechannel/tests/iframe_messageChannel_cloning.html @@ -0,0 +1,21 @@ + + + + + + diff --git a/dom/messagechannel/tests/iframe_messageChannel_pingpong.html b/dom/messagechannel/tests/iframe_messageChannel_pingpong.html new file mode 100644 index 0000000000..c4decd35a7 --- /dev/null +++ b/dom/messagechannel/tests/iframe_messageChannel_pingpong.html @@ -0,0 +1,32 @@ + + + + + + diff --git a/dom/messagechannel/tests/iframe_messageChannel_post.html b/dom/messagechannel/tests/iframe_messageChannel_post.html new file mode 100644 index 0000000000..846b247f0b --- /dev/null +++ b/dom/messagechannel/tests/iframe_messageChannel_post.html @@ -0,0 +1,23 @@ + + + + + + diff --git a/dom/messagechannel/tests/iframe_messageChannel_sharedWorker2.html b/dom/messagechannel/tests/iframe_messageChannel_sharedWorker2.html new file mode 100644 index 0000000000..b96026955d --- /dev/null +++ b/dom/messagechannel/tests/iframe_messageChannel_sharedWorker2.html @@ -0,0 +1,13 @@ + + + + + + diff --git a/dom/messagechannel/tests/iframe_messageChannel_transferable.html b/dom/messagechannel/tests/iframe_messageChannel_transferable.html new file mode 100644 index 0000000000..0a00add71f --- /dev/null +++ b/dom/messagechannel/tests/iframe_messageChannel_transferable.html @@ -0,0 +1,24 @@ + + + + + + diff --git a/dom/messagechannel/tests/mm_messageChannel.js b/dom/messagechannel/tests/mm_messageChannel.js new file mode 100644 index 0000000000..7acd5df530 --- /dev/null +++ b/dom/messagechannel/tests/mm_messageChannel.js @@ -0,0 +1,76 @@ +/* eslint-env mozilla/frame-script */ + +function debug(msg) { + dump("[mmMessageChannelChild]" + msg + "\n"); +} + +/** + * Preparation Test + */ +let port; +let toString = Object.prototype.toString; + +(function prepare() { + debug("Script loaded."); + addTestReceiver(); + sendAsyncMessage("mmMessagePort:finishScriptLoad"); +})(); + +function ok(condition, message) { + debug("condition: " + condition + ", " + message + "\n"); + if (!condition) { + sendAsyncMessage("mmMessagePort:fail", { message }); + throw new Error("failed check: " + message); + } +} + +function is(a, b, message) { + ok(a === b, message); +} + +/** + * Testing codes. + */ +function addTestReceiver() { + addMessageListener("BasicTest:PortCreated", basicTest); + addMessageListener("CloseTest:PortCreated", closeTest); + addMessageListener("EmptyTest:PortCreated", emptyTest); + addMessageListener("NotTransferableTest:PortCreated", notTransferableTest); +} + +function basicTest(msg) { + port = msg.ports[0]; + is(toString.call(port), "[object MessagePort]", "created MessagePort."); + + port.onmessage = message => { + is(message.data, "BasicTest:StartTest", "Replied message is correct."); + port.postMessage("BasicTest:TestOK"); + }; + + sendAsyncMessage("BasicTest:FinishPrepare", { message: "OK" }); +} + +function closeTest(msg) { + port = msg.ports[0]; + is(toString.call(port), "[object MessagePort]", "created MessagePort."); + + port.onmessage = message => { + ok(message.data, "CloseTest:StartTest", "Replied message is correct."); + port.postMessage("CloseTest:TestOK"); + }; + + port.close(); + + sendAsyncMessage("CloseTest:FinishPrepare", { message: "OK" }); +} + +function emptyTest(msg) { + let portSize = msg.ports.length; + is(portSize, 0, "transfered port size is zero."); + + sendAsyncMessage("EmptyTest:FinishPrepare", { message: "OK" }); +} + +function notTransferableTest(msg) { + sendAsyncMessage("NotTransferableTest:FinishPrepare", { message: "OK" }); +} diff --git a/dom/messagechannel/tests/mm_messageChannelParent.js b/dom/messagechannel/tests/mm_messageChannelParent.js new file mode 100644 index 0000000000..a5595722a2 --- /dev/null +++ b/dom/messagechannel/tests/mm_messageChannelParent.js @@ -0,0 +1,144 @@ +let port; +let mm; + +function info(message) { + return window.arguments[0].info(message); +} + +function ok(condition, message) { + return window.arguments[0].ok(condition, message); +} + +function is(v1, v2, message) { + return window.arguments[0].is(v1, v2, message); +} + +function todo_is(v1, v2, message) { + return window.arguments[0].todo_is(v1, v2, message); +} + +function cleanUp() { + window.arguments[0].setTimeout(function () { + this.done(); + }, 0); + window.close(); +} + +function debug(msg) { + dump("[mmMessageChannelParent]" + msg + "\n"); +} + +let tests = [basic_test, close_test, empty_transferable, not_transferable]; + +// Test Routine +function run_tests() { + let test = tests.shift(); + if (test === undefined) { + cleanUp(); + return; + } + + test(function () { + setTimeout(run_tests, 0); + }); +} + +// Basic communication test. +function basic_test(finish) { + ok(mm, "basic_test"); + + let finishPrepare = msg => { + is(msg.data.message, "OK", ""); + ok(port, ""); + port.onmessage = message => { + is(message.data, "BasicTest:TestOK", ""); + finish(); + }; + port.postMessage("BasicTest:StartTest"); + mm.removeMessageListener("BasicTest:FinishPrepare", finishPrepare); + }; + + let channel = new MessageChannel(); + port = channel.port2; + mm.addMessageListener("BasicTest:FinishPrepare", finishPrepare); + mm.sendAsyncMessage("BasicTest:PortCreated", {}, [channel.port1]); +} + +// Communicate with closed port. +function close_test(finish) { + ok(mm, "close_test"); + + let finishPrepare = msg => { + is(msg.data.message, "OK", ""); + ok(port, ""); + + port.onmessage = message => { + ok(false, "Port is alive."); + finish(); + }; + + port.postMessage("CloseTest:StartTest"); + mm.removeMessageListener("CloseTest:FinishPrepare", finishPrepare); + finish(); + }; + + let channel = new MessageChannel(); + port = channel.port2; + mm.addMessageListener("CloseTest:FinishPrepare", finishPrepare); + mm.sendAsyncMessage("CloseTest:PortCreated", {}, [channel.port1]); +} + +// Empty transferable object +function empty_transferable(finish) { + ok(mm, "empty_transferable"); + + let finishPrepare = msg => { + ok(true, "Same basic test."); + mm.removeMessageListener("EmptyTest:FinishPrepare", finishPrepare); + finish(); + }; + + mm.addMessageListener("EmptyTest:FinishPrepare", finishPrepare); + mm.sendAsyncMessage("EmptyTest:PortCreated", {}, []); +} + +// Not transferable object. +function not_transferable(finish) { + ok(mm, "not_transferable"); + + let finishPrepare = msg => { + ok(true, "Same basic test."); + finish(); + }; + + mm.addMessageListener("NotTransferableTest:FinishPrepare", finishPrepare); + mm.sendAsyncMessage("NotTransferableTest:PortCreated", {}, [""]); +} + +/* + * Test preparation + */ +function finishLoad(msg) { + run_tests(); +} + +function prepare_test() { + debug("start run_tests()"); + var node = document.getElementById("messagechannel_remote"); + mm = node.messageManager; //Services.ppmm.getChildAt(1); + ok(mm, "created MessageManager."); + + mm.addMessageListener("mmMessagePort:finishScriptLoad", finishLoad); + mm.addMessageListener("mmMessagePort:fail", failed_test); + //mm.loadProcessScript("chrome://mochitests/content/chrome/dom/messagechannel/tests/mm_messageChannel.js", true); + mm.loadFrameScript( + "chrome://mochitests/content/chrome/dom/messagechannel/tests/mm_messageChannel.js", + true + ); + ok(true, "Loaded"); +} + +function failed_test() { + debug("failed test in child process"); + ok(false, ""); +} diff --git a/dom/messagechannel/tests/mm_messageChannelParent.xhtml b/dom/messagechannel/tests/mm_messageChannelParent.xhtml new file mode 100644 index 0000000000..5f5c5ae5be --- /dev/null +++ b/dom/messagechannel/tests/mm_messageChannelParent.xhtml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/dom/messagechannel/tests/mm_messageChannelParentNotRemote.xhtml b/dom/messagechannel/tests/mm_messageChannelParentNotRemote.xhtml new file mode 100644 index 0000000000..cb3b55dea7 --- /dev/null +++ b/dom/messagechannel/tests/mm_messageChannelParentNotRemote.xhtml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/dom/messagechannel/tests/mochitest.toml b/dom/messagechannel/tests/mochitest.toml new file mode 100644 index 0000000000..f01cd65786 --- /dev/null +++ b/dom/messagechannel/tests/mochitest.toml @@ -0,0 +1,50 @@ +[DEFAULT] +support-files = [ + "iframe_messageChannel_cloning.html", + "iframe_messageChannel_pingpong.html", + "iframe_messageChannel_post.html", + "iframe_messageChannel_transferable.html", + "worker_messageChannel.js", + "worker_messageChannel_any.js", + "sharedWorker_messageChannel.js", + "sharedWorker2_messageChannel.js", + "iframe_messageChannel_sharedWorker2.html", + "!/dom/events/test/event_leak_utils.js", +] + +["test_event_listener_leaks.html"] +skip-if = ["os == 'linux' && bits == 64"] # Bug 1777087 + +["test_messageChannel.html"] + +["test_messageChannel_any.html"] + +["test_messageChannel_bug1178076.html"] + +["test_messageChannel_bug1224825.html"] + +["test_messageChannel_cloning.html"] + +["test_messageChannel_forceClose.html"] + +["test_messageChannel_pingpong.html"] + +["test_messageChannel_post.html"] + +["test_messageChannel_selfTransferring.html"] + +["test_messageChannel_sharedWorker.html"] + +["test_messageChannel_sharedWorker2.html"] + +["test_messageChannel_start.html"] + +["test_messageChannel_transferable.html"] + +["test_messageChannel_unshipped.html"] + +["test_messageChannel_worker.html"] + +["test_messageChannel_worker_forceClose.html"] + +["test_removedWindow.html"] diff --git a/dom/messagechannel/tests/moz.build b/dom/messagechannel/tests/moz.build new file mode 100644 index 0000000000..5c3978f075 --- /dev/null +++ b/dom/messagechannel/tests/moz.build @@ -0,0 +1,10 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +MOCHITEST_MANIFESTS += ["mochitest.toml"] +MOCHITEST_CHROME_MANIFESTS += ["chrome.toml"] + +XPCSHELL_TESTS_MANIFESTS += ["unit/xpcshell.toml"] diff --git a/dom/messagechannel/tests/sharedWorker2_messageChannel.js b/dom/messagechannel/tests/sharedWorker2_messageChannel.js new file mode 100644 index 0000000000..d5084fe766 --- /dev/null +++ b/dom/messagechannel/tests/sharedWorker2_messageChannel.js @@ -0,0 +1,9 @@ +/* eslint-env worker */ + +var mc = new MessageChannel(); +var i = 0; + +onconnect = function (evt) { + dump("CONNECTING: " + i + "\n"); + evt.ports[0].postMessage(42, [mc["port" + ++i]]); +}; diff --git a/dom/messagechannel/tests/sharedWorker_messageChannel.js b/dom/messagechannel/tests/sharedWorker_messageChannel.js new file mode 100644 index 0000000000..874860e99f --- /dev/null +++ b/dom/messagechannel/tests/sharedWorker_messageChannel.js @@ -0,0 +1,10 @@ +/* eslint-env worker */ + +onconnect = function (evt) { + var mc = new MessageChannel(); + + evt.ports[0].postMessage(42, [mc.port2]); + mc.port1.onmessage = function (e) { + mc.port1.postMessage(e.data); + }; +}; diff --git a/dom/messagechannel/tests/test_event_listener_leaks.html b/dom/messagechannel/tests/test_event_listener_leaks.html new file mode 100644 index 0000000000..93ed5215d3 --- /dev/null +++ b/dom/messagechannel/tests/test_event_listener_leaks.html @@ -0,0 +1,50 @@ + + + + + Bug 1450358 - Test MessageChannel event listener leak conditions + + + + + + + + + diff --git a/dom/messagechannel/tests/test_messageChannel.html b/dom/messagechannel/tests/test_messageChannel.html new file mode 100644 index 0000000000..ce6774d33c --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannel.html @@ -0,0 +1,43 @@ + + + + + + + Test for Bug 677638 - basic support + + + + +Mozilla Bug 677638 +

+ +
+
+ + + diff --git a/dom/messagechannel/tests/test_messageChannel.xhtml b/dom/messagechannel/tests/test_messageChannel.xhtml new file mode 100644 index 0000000000..e51359d67d --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannel.xhtml @@ -0,0 +1,38 @@ + + + + + + diff --git a/dom/messagechannel/tests/test_messageChannelWithMessageManager.xhtml b/dom/messagechannel/tests/test_messageChannelWithMessageManager.xhtml new file mode 100644 index 0000000000..b95a85645c --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannelWithMessageManager.xhtml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + diff --git a/dom/messagechannel/tests/test_messageChannelWithMessageManagerNotRemote.xhtml b/dom/messagechannel/tests/test_messageChannelWithMessageManagerNotRemote.xhtml new file mode 100644 index 0000000000..e87fd4d873 --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannelWithMessageManagerNotRemote.xhtml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + diff --git a/dom/messagechannel/tests/test_messageChannel_any.html b/dom/messagechannel/tests/test_messageChannel_any.html new file mode 100644 index 0000000000..e4498b243f --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannel_any.html @@ -0,0 +1,115 @@ + + + + + + MessagePort/Channel any content + + + + +Mozilla Bug 677638 +
+
+
+ + + diff --git a/dom/messagechannel/tests/test_messageChannel_bug1178076.html b/dom/messagechannel/tests/test_messageChannel_bug1178076.html new file mode 100644 index 0000000000..e8d4d3b9fb --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannel_bug1178076.html @@ -0,0 +1,38 @@ + + + + + + Test for Bug 1178076 + + + + +Mozilla Bug 1178076 +
+
+
+ + + diff --git a/dom/messagechannel/tests/test_messageChannel_bug1224825.html b/dom/messagechannel/tests/test_messageChannel_bug1224825.html new file mode 100644 index 0000000000..067fb1581f --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannel_bug1224825.html @@ -0,0 +1,94 @@ + + + + + + Test for Bug 1224825 + + + + +Mozilla Bug 1224825 +
+
+
+ + + diff --git a/dom/messagechannel/tests/test_messageChannel_cloning.html b/dom/messagechannel/tests/test_messageChannel_cloning.html new file mode 100644 index 0000000000..7f59e9e96f --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannel_cloning.html @@ -0,0 +1,70 @@ + + + + + + Test for Bug 677638 - port cloning + + + + +Mozilla Bug 677638 +
+
+
+ + + diff --git a/dom/messagechannel/tests/test_messageChannel_forceClose.html b/dom/messagechannel/tests/test_messageChannel_forceClose.html new file mode 100644 index 0000000000..98c9e87311 --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannel_forceClose.html @@ -0,0 +1,30 @@ + + + + + + Test for Bug 1176034 - start/close + + + + +Mozilla Bug 1176034 +
+
+
+ + + diff --git a/dom/messagechannel/tests/test_messageChannel_pingpong.html b/dom/messagechannel/tests/test_messageChannel_pingpong.html new file mode 100644 index 0000000000..602478bcb7 --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannel_pingpong.html @@ -0,0 +1,77 @@ + + + + + + Test for Bug 677638 - port cloning + + + + +Mozilla Bug 677638 +
+
+
+ + + diff --git a/dom/messagechannel/tests/test_messageChannel_post.html b/dom/messagechannel/tests/test_messageChannel_post.html new file mode 100644 index 0000000000..86c27efc3e --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannel_post.html @@ -0,0 +1,76 @@ + + + + + + Test for Bug 677638 - port cloning + + + + +Mozilla Bug 677638 +
+
+
+ + + diff --git a/dom/messagechannel/tests/test_messageChannel_selfTransferring.html b/dom/messagechannel/tests/test_messageChannel_selfTransferring.html new file mode 100644 index 0000000000..b5c1b1e886 --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannel_selfTransferring.html @@ -0,0 +1,32 @@ + + + + + + MessagePort/Channel no self tranferring + + + + +Mozilla Bug 677638 +
+
+
+ + + diff --git a/dom/messagechannel/tests/test_messageChannel_sharedWorker.html b/dom/messagechannel/tests/test_messageChannel_sharedWorker.html new file mode 100644 index 0000000000..cf1864579f --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannel_sharedWorker.html @@ -0,0 +1,36 @@ + + + + + + Test for Bug 677638 - sharedWorker + + + + +Mozilla Bug 677638 +

+ +
+
+ + + diff --git a/dom/messagechannel/tests/test_messageChannel_sharedWorker2.html b/dom/messagechannel/tests/test_messageChannel_sharedWorker2.html new file mode 100644 index 0000000000..8b8f259308 --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannel_sharedWorker2.html @@ -0,0 +1,34 @@ + + + + + + Test for Bug 677638 - sharedWorker + + + + + Mozilla Bug 677638 +
+ + + + diff --git a/dom/messagechannel/tests/test_messageChannel_start.html b/dom/messagechannel/tests/test_messageChannel_start.html new file mode 100644 index 0000000000..4bc49cc0d6 --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannel_start.html @@ -0,0 +1,235 @@ + + + + + + Test for Bug 677638 - start/close + + + + +Mozilla Bug 677638 +
+
+
+ + + diff --git a/dom/messagechannel/tests/test_messageChannel_transferable.html b/dom/messagechannel/tests/test_messageChannel_transferable.html new file mode 100644 index 0000000000..44a27b34c4 --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannel_transferable.html @@ -0,0 +1,111 @@ + + + + + + Test for Bug 677638 - port cloning + + + + +Mozilla Bug 677638 +
+
+
+ + + diff --git a/dom/messagechannel/tests/test_messageChannel_unshipped.html b/dom/messagechannel/tests/test_messageChannel_unshipped.html new file mode 100644 index 0000000000..44bf56979c --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannel_unshipped.html @@ -0,0 +1,123 @@ + + + + + + Test for Bug 677638 - unshipped message port queue + + + + +Mozilla Bug 677638 +
+
+
+ + + diff --git a/dom/messagechannel/tests/test_messageChannel_worker.html b/dom/messagechannel/tests/test_messageChannel_worker.html new file mode 100644 index 0000000000..742212a5d3 --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannel_worker.html @@ -0,0 +1,60 @@ + + + + + + + Test for Bug 677638 - basic support + + + + +Mozilla Bug 677638 +

+ +
+
+ + + diff --git a/dom/messagechannel/tests/test_messageChannel_worker_forceClose.html b/dom/messagechannel/tests/test_messageChannel_worker_forceClose.html new file mode 100644 index 0000000000..8de3450fb5 --- /dev/null +++ b/dom/messagechannel/tests/test_messageChannel_worker_forceClose.html @@ -0,0 +1,27 @@ + + + + + Test for forcing the closing of the port in workers + + + + +
+
+
+ + + diff --git a/dom/messagechannel/tests/test_removedWindow.html b/dom/messagechannel/tests/test_removedWindow.html new file mode 100644 index 0000000000..b660000fd8 --- /dev/null +++ b/dom/messagechannel/tests/test_removedWindow.html @@ -0,0 +1,55 @@ + +MessagePort should not work when created from a disconnected window + + + + + + diff --git a/dom/messagechannel/tests/unit/chromeWorker_messageChannel.js b/dom/messagechannel/tests/unit/chromeWorker_messageChannel.js new file mode 100644 index 0000000000..3f557a4fb2 --- /dev/null +++ b/dom/messagechannel/tests/unit/chromeWorker_messageChannel.js @@ -0,0 +1,14 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +onmessage = function (pingEvt) { + if (pingEvt.data == "ping") { + let { port1, port2 } = new MessageChannel(); + port2.onmessage = helloEvt => { + if (helloEvt.data == "hello") { + helloEvt.ports[0].postMessage("goodbye"); + } + }; + pingEvt.ports[0].postMessage("pong", [port1]); + } +}; diff --git a/dom/messagechannel/tests/unit/test_messageChannel.js b/dom/messagechannel/tests/unit/test_messageChannel.js new file mode 100644 index 0000000000..d672920f71 --- /dev/null +++ b/dom/messagechannel/tests/unit/test_messageChannel.js @@ -0,0 +1,23 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +add_test(function test_messageChannel() { + do_test_pending(); + + let chromeWorker = new ChromeWorker( + "resource://test/chromeWorker_messageChannel.js" + ); + let { port1, port2 } = new MessageChannel(); + port2.onmessage = pongEvt => { + Assert.equal(pongEvt.data, "pong"); + let { port1: newPort1, port2: newPort2 } = new MessageChannel(); + newPort2.onmessage = goodbyeEvt => { + Assert.equal(goodbyeEvt.data, "goodbye"); + + do_test_finished(); + run_next_test(); + }; + pongEvt.ports[0].postMessage("hello", [newPort1]); + }; + chromeWorker.postMessage("ping", [port1]); +}); diff --git a/dom/messagechannel/tests/unit/xpcshell.toml b/dom/messagechannel/tests/unit/xpcshell.toml new file mode 100644 index 0000000000..ea6d7d1862 --- /dev/null +++ b/dom/messagechannel/tests/unit/xpcshell.toml @@ -0,0 +1,6 @@ +[DEFAULT] +head = "" +skip-if = ["os == 'android'"] +support-files = ["chromeWorker_messageChannel.js"] + +["test_messageChannel.js"] diff --git a/dom/messagechannel/tests/worker_messageChannel.js b/dom/messagechannel/tests/worker_messageChannel.js new file mode 100644 index 0000000000..f0b97ee36c --- /dev/null +++ b/dom/messagechannel/tests/worker_messageChannel.js @@ -0,0 +1,110 @@ +function ok(a, msg) { + postMessage({ type: "check", check: !!a, message: msg }); +} + +function is(a, b, msg) { + ok(a === b, msg); +} + +function info(msg) { + postMessage({ type: "info", message: msg }); +} + +function finish() { + postMessage({ type: "finish" }); +} + +function basic() { + var a = new MessageChannel(); + ok(a, "MessageChannel created"); + + var port1 = a.port1; + ok(port1, "MessageChannel.port1 exists"); + is(port1, a.port1, "MessageChannel.port1 is port1"); + + var port2 = a.port2; + ok(port2, "MessageChannel.port1 exists"); + is(port2, a.port2, "MessageChannel.port2 is port2"); + + ["postMessage", "start", "close"].forEach(function (e) { + ok(e in port1, "MessagePort1." + e + " exists"); + ok(e in port2, "MessagePort2." + e + " exists"); + }); + + runTests(); +} + +function sendMessages() { + var a = new MessageChannel(); + ok(a, "MessageChannel created"); + + a.port1.postMessage("Hello world!"); + a.port1.onmessage = function (e) { + is(e.data, "Hello world!", "The message is back!"); + runTests(); + }; + + a.port2.onmessage = function (e) { + a.port2.postMessage(e.data); + }; +} + +function transferPort() { + var a = new MessageChannel(); + ok(a, "MessageChannel created"); + + a.port1.postMessage("Hello world!"); + a.port1.onmessage = function (e) { + is(e.data, "Hello world!", "The message is back!"); + runTests(); + }; + + postMessage({ type: "port" }, [a.port2]); +} + +function transferPort2() { + onmessage = function (evt) { + is(evt.ports.length, 1, "A port has been received by the worker"); + evt.ports[0].onmessage = function (e) { + is(e.data, 42, "Data is 42!"); + runTests(); + }; + }; + + postMessage({ type: "newport" }); +} + +var tests = [basic, sendMessages, transferPort, transferPort2]; + +function runTests() { + if (!tests.length) { + finish(); + return; + } + + var t = tests.shift(); + t(); +} + +var subworker; +onmessage = function (evt) { + if (evt.data == 0) { + runTests(); + return; + } + + if (!subworker) { + info("Create a subworkers. ID: " + evt.data); + subworker = new Worker("worker_messageChannel.js"); + subworker.onmessage = function (e) { + info("Proxy a message to the parent."); + postMessage(e.data, e.ports); + }; + + subworker.postMessage(evt.data - 1); + return; + } + + info("Dispatch a message to the subworker."); + subworker.postMessage(evt.data, evt.ports); +}; diff --git a/dom/messagechannel/tests/worker_messageChannel_any.js b/dom/messagechannel/tests/worker_messageChannel_any.js new file mode 100644 index 0000000000..11018da9a0 --- /dev/null +++ b/dom/messagechannel/tests/worker_messageChannel_any.js @@ -0,0 +1,7 @@ +onmessage = function (evt) { + evt.data.onmessage = function (event) { + evt.data.postMessage(event.data); + }; +}; + +postMessage("READY"); -- cgit v1.2.3