test_bug1301094.html (1793B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1301094 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1301094</title> 9 <script 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=1301094">Mozilla Bug 1301094</a> 14 <input id="file" type="file"></input> 15 <script type="application/javascript"> 16 17 SimpleTest.waitForExplicitFinish(); 18 19 var url = SimpleTest.getTestFileURL("script_createFile.js"); 20 script = SpecialPowers.loadChromeScript(url); 21 22 var mainThreadOk, workerOk; 23 24 function maybeFinish() { 25 if (mainThreadOk & workerOk) { 26 SimpleTest.finish(); 27 } 28 } 29 30 function onOpened(message) { 31 var input = document.getElementById('file'); 32 SpecialPowers.wrap(input).mozSetDndFilesAndDirectories([message.data]); 33 34 var worker = new Worker('worker_bug1301094.js'); 35 worker.onerror = function() { 36 ok(false, "We should not see any error."); 37 SimpleTest.finish(); 38 } 39 40 worker.onmessage = function(e) { 41 ok(e.data, "Everything seems OK on the worker-side."); 42 43 workerOk = true; 44 maybeFinish(); 45 } 46 47 is(input.files.length, 1, "We have something"); 48 ok(input.files[0] instanceof Blob, "We have one Blob"); 49 worker.postMessage(input.files[0]); 50 51 var xhr = new XMLHttpRequest(); 52 xhr.open("POST", 'worker_bug1301094.js', false); 53 xhr.onload = function() { 54 ok(xhr.responseText, "Everything seems OK on the main-thread-side."); 55 mainThreadOk = true; 56 maybeFinish(); 57 }; 58 59 var fd = new FormData(); 60 fd.append('file', input.files[0]); 61 xhr.send(fd); 62 } 63 64 script.addMessageListener("file.opened", onOpened); 65 script.sendAsyncMessage("file.open"); 66 67 </script> 68 </body> 69 </html>