dom/base/test/test_messageChannel_unshipped.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=677638
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <meta charset="utf-8">
michael@0 8 <title>Test for Bug 677638 - unshipped message port queue</title>
michael@0 9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
michael@0 14 <div id="content"></div>
michael@0 15 <pre id="test">
michael@0 16 </pre>
michael@0 17 <script type="application/javascript">
michael@0 18
michael@0 19 function test_orderedMessages() {
michael@0 20 var a = new MessageChannel();
michael@0 21 ok(a, "MessageChannel created");
michael@0 22
michael@0 23 var b = new MessageChannel();
michael@0 24 ok(b, "MessageChannel created");
michael@0 25
michael@0 26 var expectedNumber = 1;
michael@0 27 function testEvent(number, id) {
michael@0 28 is(expectedNumber, number, "This is the right number!");
michael@0 29 ok(!((expectedNumber - id) % 4), "From the right port: " + expectedNumber + " " + id);
michael@0 30 expectedNumber++;
michael@0 31
michael@0 32 if (expectedNumber >100) {
michael@0 33 runTests();
michael@0 34 }
michael@0 35 }
michael@0 36
michael@0 37 a.port1.onmessage = function(evt) {
michael@0 38 testEvent(evt.data, 2);
michael@0 39 };
michael@0 40
michael@0 41 a.port2.onmessage = function(evt) {
michael@0 42 testEvent(evt.data, 1);
michael@0 43 };
michael@0 44
michael@0 45 b.port1.onmessage = function(evt) {
michael@0 46 testEvent(evt.data, 4);
michael@0 47 };
michael@0 48
michael@0 49 b.port2.onmessage = function(evt) {
michael@0 50 testEvent(evt.data, 3);
michael@0 51 };
michael@0 52
michael@0 53 for (var i = 0; i < 100;) {
michael@0 54 a.port1.postMessage(++i);
michael@0 55 a.port2.postMessage(++i);
michael@0 56 b.port1.postMessage(++i);
michael@0 57 b.port2.postMessage(++i);
michael@0 58 }
michael@0 59 }
michael@0 60
michael@0 61 function test_unstarted() {
michael@0 62 var a = new MessageChannel();
michael@0 63 ok(a, "MessageChannel created");
michael@0 64
michael@0 65 var b = new MessageChannel();
michael@0 66 ok(b, "MessageChannel created");
michael@0 67
michael@0 68 var expectedNumber = 1;
michael@0 69 function testEvent(number, id) {
michael@0 70 is(expectedNumber, number, "This is the right number!");
michael@0 71 ok(!((expectedNumber - id) % 3), "From the right port: " + expectedNumber + " " + id);
michael@0 72 expectedNumber++;
michael@0 73
michael@0 74 // 102 because it's the first multiple of 3.
michael@0 75 if (expectedNumber > 102) {
michael@0 76 runTests();
michael@0 77 }
michael@0 78 }
michael@0 79
michael@0 80 a.port1.onmessage = function(evt) {
michael@0 81 testEvent(evt.data, 2);
michael@0 82 };
michael@0 83
michael@0 84 a.port2.onmessage = function(evt) {
michael@0 85 testEvent(evt.data, 1);
michael@0 86 };
michael@0 87
michael@0 88 b.port1.addEventListener("message", function() {
michael@0 89 ok(false, "shouldn't be called");
michael@0 90 });
michael@0 91
michael@0 92 b.port2.onmessage = function(evt) {
michael@0 93 testEvent(evt.data, 3);
michael@0 94 };
michael@0 95
michael@0 96 for (var i = 0; i < 100;) {
michael@0 97 a.port1.postMessage(++i);
michael@0 98 a.port2.postMessage(++i);
michael@0 99 b.port1.postMessage(++i);
michael@0 100 b.port2.postMessage(1000);
michael@0 101 }
michael@0 102 }
michael@0 103
michael@0 104 var tests = [
michael@0 105 test_orderedMessages,
michael@0 106 test_unstarted
michael@0 107 ];
michael@0 108
michael@0 109 function runTests() {
michael@0 110 if (!tests.length) {
michael@0 111 SimpleTest.finish();
michael@0 112 return;
michael@0 113 }
michael@0 114
michael@0 115 var test = tests.shift();
michael@0 116 test();
michael@0 117 }
michael@0 118
michael@0 119 SimpleTest.waitForExplicitFinish();
michael@0 120 SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTests);
michael@0 121 </script>
michael@0 122 </body>
michael@0 123 </html>

mercurial