summaryrefslogtreecommitdiffstats
path: root/dom/messagechannel/tests/mm_messageChannel.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/messagechannel/tests/mm_messageChannel.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
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 000000000..914d800fd
--- /dev/null
+++ b/dom/messagechannel/tests/mm_messageChannel.js
@@ -0,0 +1,76 @@
+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: message });
+ throw '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 = (msg) => {
+ is(msg.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 = (msg) => {
+ ok(msg.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"});
+}
+