summaryrefslogtreecommitdiffstats
path: root/dom/messagechannel/tests/test_messageChannel_start.html
diff options
context:
space:
mode:
Diffstat (limited to 'dom/messagechannel/tests/test_messageChannel_start.html')
-rw-r--r--dom/messagechannel/tests/test_messageChannel_start.html235
1 files changed, 235 insertions, 0 deletions
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 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=677638
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 677638 - start/close</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
+<div id="content"></div>
+<pre id="test">
+</pre>
+ <script type="application/javascript">
+
+ function runTests() {
+ if (!tests.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ var test = tests.shift();
+ test();
+ }
+
+ function testOnMessage() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ a.port1.postMessage(42);
+ a.port2.postMessage(43);
+ ok(true, "MessagePort{1,2}.postmessage() invoked");
+
+ var events = 2;
+
+ a.port1.onmessage = function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ }
+
+ a.port2.onmessage = function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ }
+ }
+
+ function testAddEventListener() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ a.port1.postMessage(42);
+ a.port2.postMessage(43);
+ ok(true, "MessagePort{1,2}.postmessage() invoked");
+
+ a.port1.addEventListener('message', function(evt) {
+ ok(false, "This method should not be called");
+ });
+
+ a.port2.addEventListener('message', function(evt) {
+ ok(false, "This method should not be called");
+ });
+
+ setTimeout(runTests, 0);
+ }
+
+ function testAddEventListenerAndStart() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ a.port1.postMessage(42);
+ a.port2.postMessage(43);
+ ok(true, "MessagePort{1,2}.postmessage() invoked");
+
+ var events = 2;
+
+ a.port1.addEventListener('message', function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ });
+
+ a.port2.addEventListener('message', function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ });
+
+ a.port1.start();
+ a.port2.start();
+ }
+
+ function testAddEventListener1AndStart() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ a.port1.postMessage(42);
+ a.port2.postMessage(43);
+ ok(true, "MessagePort{1,2}.postmessage() invoked");
+
+ var events = 1;
+
+ a.port1.addEventListener('message', function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ });
+
+ a.port2.addEventListener('message', function(evt) {
+ ok(false, "This method should not be called");
+ });
+
+ a.port1.start();
+ }
+
+ function testAddEventListener2AndStart() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ a.port1.postMessage(42);
+ a.port2.postMessage(43);
+ ok(true, "MessagePort{1,2}.postmessage() invoked");
+
+ var events = 1;
+
+ a.port1.addEventListener('message', function(evt) {
+ ok(false, "This method should not be called");
+ });
+
+ a.port2.addEventListener('message', function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ });
+
+ a.port2.start();
+ }
+
+ function testTimer() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ a.port1.postMessage(42);
+ a.port2.postMessage(43);
+ ok(true, "MessagePort{1,2}.postmessage() invoked");
+
+ setTimeout(function() {
+ var events = 2;
+ a.port1.onmessage = function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ }
+
+ a.port2.onmessage = function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ }
+ }, 200);
+ }
+
+ function testAddEventListenerAndStartWrongOrder() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ a.port1.postMessage(42);
+ a.port2.postMessage(43);
+ ok(true, "MessagePort{1,2}.postmessage() invoked");
+
+ var events = 2;
+
+ a.port1.start();
+ a.port1.addEventListener('message', function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ });
+
+ a.port2.start();
+ a.port2.addEventListener('message', function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ });
+ }
+
+ function testOnMessageClone() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ a.port1.postMessage(42);
+ a.port2.postMessage(43);
+ ok(true, "MessagePort{1,2}.postmessage() invoked");
+
+ var events = 2;
+
+ addEventListener('message', testOnMessageCloneCb, false);
+ function testOnMessageCloneCb(event) {
+ a.port1.onmessage = function(evt) {
+ ok(true, "This method should be called");
+ testOnMessageCloneFinish();
+ }
+
+ event.data.onmessage = function(evt) {
+ ok(true, "This method should be called");
+ testOnMessageCloneFinish();
+ }
+
+ a.port2.onmessage = function(evt) {
+ ok(false, "This method should not be called");
+ }
+ }
+
+ function testOnMessageCloneFinish() {
+ if (!--events) {
+ removeEventListener('message', testOnMessageCloneCb);
+ runTests();
+ }
+ }
+
+ postMessage(a.port2, '*', [a.port2]);
+ }
+
+ var tests = [
+ testOnMessage,
+ testAddEventListener,
+ testAddEventListenerAndStart,
+ testAddEventListener1AndStart,
+ testAddEventListener2AndStart,
+ testTimer,
+ testAddEventListenerAndStartWrongOrder,
+ testOnMessageClone,
+ ];
+
+ SimpleTest.waitForExplicitFinish();
+ SimpleTest.requestFlakyTimeout("untriaged");
+ runTests();
+ </script>
+</body>
+</html>