test_blobConstructor.html 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. <!--
  8. Tests of DOM Worker Blob constructor
  9. -->
  10. <head>
  11. <title>Test for DOM Worker Blob constructor</title>
  12. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  13. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  14. </head>
  15. <body>
  16. <p id="display"></p>
  17. <div id="content" style="display: none">
  18. </div>
  19. <pre id="test">
  20. <script class="testbody" type="text/javascript">
  21. (function() {
  22. onerror = function(e) {
  23. ok(false, "Main Thread had an error: " + event.data);
  24. SimpleTest.finish();
  25. };
  26. function f() {
  27. onmessage = function(e) {
  28. var b = new Blob([e.data, "World"],{type: "text/plain"});
  29. var fr = new FileReaderSync();
  30. postMessage({text: fr.readAsText(b), type: b.type});
  31. };
  32. }
  33. var b = new Blob([f,"f();"]);
  34. var u = URL.createObjectURL(b);
  35. var w = new Worker(u);
  36. w.onmessage = function(e) {
  37. URL.revokeObjectURL(u);
  38. is(e.data.text, fr.result);
  39. is(e.data.type, "text/plain");
  40. SimpleTest.finish();
  41. };
  42. w.onerror = function(e) {
  43. is(e.target, w);
  44. ok(false, "Worker had an error: " + e.message);
  45. SimpleTest.finish();
  46. };
  47. b = new Blob(["Hello, "]);
  48. var fr = new FileReader();
  49. fr.readAsText(new Blob([b, "World"],{}));
  50. fr.onload = function() {
  51. w.postMessage(b);
  52. };
  53. SimpleTest.waitForExplicitFinish();
  54. })();
  55. </script>
  56. </pre>
  57. </body>
  58. </html>