test_postMessage_transfer.html (1638B)
1 <!DOCTYPE html> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=822094 5 --> 6 <head><meta charset=utf-8> 7 <title>postMessage transferable tests</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=822094">Mozilla Bug 822094</a> 13 <p id="display"></p> 14 <div id="content" style="display: none"> 15 16 <iframe src="postMessage_transfer_helper.html" 17 name="sameDomain"></iframe> 18 <iframe src="http://example.org:8000/tests/dom/tests/mochitest/whatwg/postMessage_transfer_helper.html" 19 name="crossDomain"></iframe> 20 21 </div> 22 <pre id="test"> 23 <script class="testbody" type="application/javascript"> 24 25 SimpleTest.waitForExplicitFinish(); 26 27 var tests = [ 28 function() { testFunc(window, "http://mochi.test:8888"); }, 29 function() { testFunc(frames.sameDomain, "http://mochi.test:8888"); }, 30 function() { testFunc(frames.crossDomain, "http://example.org:8000"); }, 31 function() { SimpleTest.finish(); }, 32 ]; 33 34 function testFunc(target, origin) { 35 var ab = new ArrayBuffer(1); 36 var cd = new ArrayBuffer(1); 37 38 target.postMessage([ab, cd], origin, [ab]); 39 is(ab.byteLength, 0, "ab should be detached"); 40 is(cd.byteLength, 1, "cd should not be detached"); 41 42 onmessage = function(e) { 43 is(e.data[0].byteLength, 1, "ab should be transfered"); 44 is(e.data[1].byteLength, 1, "cd should be cloned"); 45 nextTest(); 46 }; 47 } 48 49 function nextTest() { 50 var t = tests.shift(); 51 t(); 52 }; 53 54 onload = function() { 55 nextTest(); 56 }; 57 58 </script> 59 </pre> 60 </body> 61 </html>