|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?> |
|
3 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?> |
|
4 <!-- |
|
5 https://bugzilla.mozilla.org/show_bug.cgi?id=664783 |
|
6 --> |
|
7 <window title="Mozilla Bug 664783" |
|
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
9 <script type="application/javascript" |
|
10 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
11 <script type="application/javascript" src="dom_worker_helper.js"/> |
|
12 |
|
13 <!-- test results are displayed in the html:body --> |
|
14 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
15 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=664783" |
|
16 target="_blank">Mozilla Bug 664783</a> |
|
17 |
|
18 <div id="content" style="display: none"> |
|
19 <input id="fileList" type="file"></input> |
|
20 </div> |
|
21 |
|
22 </body> |
|
23 |
|
24 <!-- test code goes here --> |
|
25 <script type="application/javascript"> |
|
26 <![CDATA[ |
|
27 |
|
28 /** Test for Bug 664783 **/ |
|
29 |
|
30 var fileNum = 0; |
|
31 |
|
32 /** |
|
33 * Create a file which contains the given data. |
|
34 */ |
|
35 function createFileWithData(fileData) { |
|
36 var testFile = Components.classes["@mozilla.org/file/directory_service;1"] |
|
37 .getService(Components.interfaces.nsIProperties) |
|
38 .get("ProfD", Components.interfaces.nsIFile); |
|
39 testFile.append("workerFileReaderSyncErrors" + fileNum++); |
|
40 |
|
41 var outStream = Components.classes["@mozilla.org/network/file-output-stream;1"] |
|
42 .createInstance(Components.interfaces.nsIFileOutputStream); |
|
43 outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate |
|
44 0666, 0); |
|
45 outStream.write(fileData, fileData.length); |
|
46 outStream.close(); |
|
47 |
|
48 var fileList = document.getElementById('fileList'); |
|
49 fileList.value = testFile.path; |
|
50 |
|
51 return fileList.files[0]; |
|
52 } |
|
53 |
|
54 /** |
|
55 * Creates a worker which runs errors cases. |
|
56 */ |
|
57 function runWorkerErrors(file) { |
|
58 var worker = new Worker("fileReaderSyncErrors_worker.js"); |
|
59 |
|
60 worker.onerror = function(event) { |
|
61 ok(false, "Worker had an error: " + event.data); |
|
62 finish(); |
|
63 }; |
|
64 |
|
65 worker.onmessage = function(event) { |
|
66 if(event.data == undefined) { |
|
67 // Worker returns undefined when tests have finished running. |
|
68 finish(); |
|
69 } else { |
|
70 // Otherwise worker will return results of tests to be evaluated. |
|
71 is(event.data.actual, event.data.expected, event.data.message); |
|
72 } |
|
73 }; |
|
74 |
|
75 worker.postMessage(file); |
|
76 waitForWorkerFinish(); |
|
77 } |
|
78 |
|
79 // Run worker which creates exceptions. |
|
80 runWorkerErrors(createFileWithData("text")); |
|
81 |
|
82 ]]> |
|
83 </script> |
|
84 </window> |