test_loadError.html 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <!--
  2. Any copyright is dedicated to the Public Domain.
  3. http://creativecommons.org/publicdomain/zero/1.0/
  4. -->
  5. <html>
  6. <head>
  7. <title>Test for DOM Worker Threads</title>
  8. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  10. </head>
  11. <body>
  12. <pre id="test">
  13. <script class="testbody" type="text/javascript">
  14. "use strict";
  15. function nextTest() {
  16. (function(){
  17. function workerfunc() {
  18. var subworker = new Worker("about:blank");
  19. subworker.onerror = function(e) {
  20. e.preventDefault();
  21. postMessage("ERROR");
  22. }
  23. }
  24. var b = new Blob([workerfunc+'workerfunc();']);
  25. var u = URL.createObjectURL(b);
  26. function callworker(i) {
  27. try {
  28. var w = new Worker(u);
  29. URL.revokeObjectURL(u);
  30. is(i, 0, 'worker creation succeeded');
  31. } catch (e) {
  32. is(i, 1, 'worker creation failed');
  33. SimpleTest.finish();
  34. return;
  35. }
  36. w.onmessage = function(e) {
  37. is(e.data, "ERROR",
  38. "Should catch the error when loading inner script");
  39. if (++i < 2) callworker(i);
  40. else SimpleTest.finish();
  41. };
  42. w.onerrror = function(e) {
  43. ok(false, "Should not get any errors from this worker");
  44. }
  45. }
  46. callworker(0);
  47. })();
  48. }
  49. try {
  50. var worker = new Worker("about:blank");
  51. worker.onerror = function(e) {
  52. e.preventDefault();
  53. nextTest();
  54. }
  55. worker.onmessage = function(event) {
  56. ok(false, "Shouldn't get a message!");
  57. SimpleTest.finish();
  58. }
  59. } catch (e) {
  60. ok(false, "This should not happen.");
  61. }
  62. SimpleTest.waitForExplicitFinish();
  63. </script>
  64. </pre>
  65. </body>
  66. </html>