test_broadcastchannel_close.html (1350B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test for BroadcastChannel</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 7 </head> 8 <body> 9 10 <div id="content"></div> 11 12 <script type="application/javascript"> 13 14 function runTest() { 15 var receiver = new BroadcastChannel("foo"); 16 var sequence = [ "2", "done" ]; 17 receiver.onmessage = function(e) { 18 if (!sequence.length) { 19 ok(false, "No more data is expected"); 20 return; 21 } 22 23 var data = sequence.shift(); 24 is(e.data, data); 25 26 if (!sequence.length) { 27 SimpleTest.executeSoon(function() { 28 SimpleTest.finish(); 29 }); 30 } 31 }; 32 33 var x = new BroadcastChannel("foo"); 34 x.close(); 35 try { 36 x.postMessage("1"); 37 ok(false, "PostMessage should throw if called after a close()."); 38 } catch (e) { 39 ok(true, "PostMessage should throw if called after a close()."); 40 } 41 42 var y = new BroadcastChannel("foo"); 43 y.postMessage("2"); 44 y.close(); 45 try { 46 y.postMessage("3"); 47 ok(false, "PostMessage should throw if called after a close()."); 48 } catch (e) { 49 ok(true, "PostMessage should throw if called after a close()."); 50 } 51 52 var z = new BroadcastChannel("foo"); 53 z.postMessage("done"); 54 } 55 56 SimpleTest.waitForExplicitFinish(); 57 runTest(); 58 59 </script> 60 </body> 61 </html>