test_websocket_loadgroup.html 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <!--
  2. Any copyright is dedicated to the Public Domain.
  3. http://creativecommons.org/publicdomain/zero/1.0/
  4. -->
  5. <!DOCTYPE HTML>
  6. <html>
  7. <head>
  8. <title>Test for WebSocket object in workers</title>
  9. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  10. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  11. </head>
  12. <body>
  13. <p id="display"></p>
  14. <div id="content" style="display: none"></div>
  15. <pre id="test"></pre>
  16. <script class="testbody" type="text/javascript">
  17. var worker = new Worker("websocket_loadgroup_worker.js");
  18. var stopped = false;
  19. worker.onmessage = function(e) {
  20. if (e.data == 'opened') {
  21. stopped = true;
  22. window.stop();
  23. } else if (e.data == 'closed') {
  24. ok(stopped, "Good!");
  25. stopped = false;
  26. runTest();
  27. } else {
  28. ok(false, "An error has been received");
  29. }
  30. };
  31. worker.onerror = function(event) {
  32. is(event.target, worker);
  33. ok(false, "Worker had an error: " + event.data);
  34. SimpleTest.finish();
  35. };
  36. var tests = [
  37. function() { worker.postMessage(0); },
  38. function() { worker.postMessage(1); }
  39. ];
  40. function runTest() {
  41. if (!tests.length) {
  42. SimpleTest.finish();
  43. return;
  44. }
  45. var test = tests.shift();
  46. test();
  47. }
  48. runTest();
  49. SimpleTest.waitForExplicitFinish();
  50. </script>
  51. </pre>
  52. </body>
  53. </html>