test_messageChannel_bug1224825.html 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=1224825
  5. -->
  6. <head>
  7. <meta charset="utf-8">
  8. <title>Test for Bug 1224825</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=1224825">Mozilla Bug 1224825</a>
  14. <div id="content"></div>
  15. <pre id="test">
  16. </pre>
  17. <script type="application/javascript">
  18. var MAX = 100;
  19. function test_fullDeliveredMessages() {
  20. var worker = new Worker('data:javascript,onmessage = function(e) { e.ports[0].onmessage = function(evt) { postMessage(evt.data);}}');
  21. var count = 0;
  22. worker.onmessage = function(e) {
  23. is(e.data, count, "Correct value expected!");
  24. ok(count < MAX,"No count > MAX messages!");
  25. if (++count == MAX) {
  26. SimpleTest.requestFlakyTimeout("Testing an event not happening");
  27. setTimeout(function() {
  28. runTests();
  29. }, 200);
  30. info("All the messages correctly received");
  31. }
  32. }
  33. var mc = new MessageChannel();
  34. worker.postMessage(42, [mc.port2]);
  35. for (var i = 0; i < MAX; ++i) {
  36. mc.port1.postMessage(i);
  37. }
  38. mc.port1.close();
  39. for (var i = 0; i < MAX * 2; ++i) {
  40. mc.port1.postMessage(i);
  41. }
  42. }
  43. function test_closeInBetween() {
  44. var mc = new MessageChannel();
  45. for (var i = 0; i < MAX; ++i) {
  46. mc.port1.postMessage(i);
  47. }
  48. mc.port1.onmessage = function(e) {
  49. ok (e.data < MAX/2, "Correct message received from port1:" + e.data);
  50. }
  51. mc.port2.onmessage = function(e) {
  52. ok (e.data < MAX, "Correct message received from port2:" + e.data);
  53. if (e.data == MAX/2) {
  54. mc.port2.close();
  55. }
  56. mc.port2.postMessage(e.data);
  57. if (e.data == MAX - 1) {
  58. runTests();
  59. }
  60. }
  61. }
  62. var tests = [ test_fullDeliveredMessages, test_closeInBetween ];
  63. function runTests() {
  64. if (!tests.length) {
  65. SimpleTest.finish();
  66. return;
  67. }
  68. var test = tests.shift();
  69. test();
  70. }
  71. SimpleTest.waitForExplicitFinish();
  72. runTests();
  73. </script>
  74. </body>
  75. </html>