summaryrefslogtreecommitdiffstats
path: root/dom/messagechannel/tests/mm_messageChannel.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /dom/messagechannel/tests/mm_messageChannel.js
parentInitial commit. (diff)
downloadfirefox-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 'dom/messagechannel/tests/mm_messageChannel.js')
-rw-r--r--dom/messagechannel/tests/mm_messageChannel.js76
1 files changed, 76 insertions, 0 deletions
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" });
+}