|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=677638 |
|
5 --> |
|
6 <head> |
|
7 <meta charset="utf-8"> |
|
8 <title>Test for Bug 677638 - port cloning</title> |
|
9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
11 </head> |
|
12 <body> |
|
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a> |
|
14 <div id="content"></div> |
|
15 <pre id="test"> |
|
16 </pre> |
|
17 <script type="application/javascript"> |
|
18 |
|
19 function start() { |
|
20 var a = new MessageChannel(); |
|
21 ok(a, "MessageChannel created"); |
|
22 |
|
23 window.addEventListener('message', receiveMessage, false); |
|
24 function receiveMessage(evt) { |
|
25 if (evt.data.status == 'READY') { |
|
26 runTest(); |
|
27 } else { |
|
28 ok(false, "Unknown message"); |
|
29 } |
|
30 } |
|
31 |
|
32 var div = document.getElementById("content"); |
|
33 ok(div, "Parent exists"); |
|
34 |
|
35 var ifr = document.createElement("iframe"); |
|
36 ifr.addEventListener("load", iframeLoaded, false); |
|
37 ifr.setAttribute('src', "iframe_messageChannel_post.html"); |
|
38 div.appendChild(ifr); |
|
39 |
|
40 function iframeLoaded() { |
|
41 ifr.contentWindow.postMessage({ port: a.port2 }, '*', [a.port2]); |
|
42 } |
|
43 |
|
44 a.port1.addEventListener('message', receivePortMessage, false); |
|
45 function receivePortMessage(evt) { |
|
46 is(evt.data.ab.byteLength, size, "The size is: " + size + " == " + ab.byteLength); |
|
47 SimpleTest.finish(); |
|
48 } |
|
49 |
|
50 // Start() is not implicity invoked when addEventListener is used. |
|
51 a.port1.start(); |
|
52 |
|
53 var size = 1024 * 1024 * 32; |
|
54 var ab = new ArrayBuffer(size); |
|
55 is(ab.byteLength, size, "The size is: " + size + " == " + ab.byteLength); |
|
56 |
|
57 function runTest() { |
|
58 a.port1.postMessage({ab: ab, cb: ab}, [ab]); |
|
59 ok(ab.byteLength == 0, "PostMessage - The size is: 0 == " + ab.byteLength) |
|
60 } |
|
61 } |
|
62 |
|
63 SimpleTest.waitForExplicitFinish(); |
|
64 SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, start); |
|
65 </script> |
|
66 </body> |
|
67 </html> |