test_blobConstructor.html (1485B)
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 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 19 </div> 20 <pre id="test"> 21 <script class="testbody" type="text/javascript"> 22 (function() { 23 onerror = function(e) { 24 ok(false, "Main Thread had an error: " + event.data); 25 SimpleTest.finish(); 26 }; 27 function f() { 28 onmessage = function(e) { 29 var b = new Blob([e.data, "World"],{type: "text/plain"}); 30 var fr = new FileReaderSync(); 31 postMessage({text: fr.readAsText(b), type: b.type}); 32 }; 33 } 34 var b = new Blob([f,"f();"]); 35 var u = URL.createObjectURL(b); 36 var w = new Worker(u); 37 w.onmessage = function(e) { 38 URL.revokeObjectURL(u); 39 is(e.data.text, fr.result); 40 is(e.data.type, "text/plain"); 41 SimpleTest.finish(); 42 }; 43 w.onerror = function(e) { 44 is(e.target, w); 45 ok(false, "Worker had an error: " + e.message); 46 SimpleTest.finish(); 47 }; 48 49 b = new Blob(["Hello, "]); 50 var fr = new FileReader(); 51 fr.readAsText(new Blob([b, "World"],{})); 52 fr.onload = function() { 53 w.postMessage(b); 54 }; 55 SimpleTest.waitForExplicitFinish(); 56 })(); 57 </script> 58 </pre> 59 </body> 60 </html>