|
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 if (navigator.platform.startsWith("Win")) { |
|
29 SimpleTest.expectAssertions(0, 1); |
|
30 } |
|
31 |
|
32 /** Test for Bug 664783 **/ |
|
33 |
|
34 var fileNum = 0; |
|
35 |
|
36 /** |
|
37 * Create a file which contains the given data. |
|
38 */ |
|
39 function createFileWithData(fileData) { |
|
40 var testFile = Components.classes["@mozilla.org/file/directory_service;1"] |
|
41 .getService(Components.interfaces.nsIProperties) |
|
42 .get("ProfD", Components.interfaces.nsIFile); |
|
43 testFile.append("workerReadSlice" + fileNum++); |
|
44 |
|
45 var outStream = Components.classes["@mozilla.org/network/file-output-stream;1"] |
|
46 .createInstance(Components.interfaces.nsIFileOutputStream); |
|
47 outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate |
|
48 0666, 0); |
|
49 outStream.write(fileData, fileData.length); |
|
50 outStream.close(); |
|
51 |
|
52 var fileList = document.getElementById('fileList'); |
|
53 fileList.value = testFile.path; |
|
54 |
|
55 return fileList.files[0]; |
|
56 } |
|
57 |
|
58 /** |
|
59 * Creates a worker which slices a blob to the given start and end offset and |
|
60 * reads the content as text. |
|
61 */ |
|
62 function readSlice(blob, start, end, expectedText) { |
|
63 var worker = new Worker("fileReadSlice_worker.js"); |
|
64 |
|
65 worker.onerror = function(event) { |
|
66 ok(false, "Worker had an error: " + event.data); |
|
67 finish(); |
|
68 }; |
|
69 |
|
70 worker.onmessage = function(event) { |
|
71 is(event.data, expectedText, "Text from sliced blob in worker is incorrect."); |
|
72 finish(); |
|
73 }; |
|
74 |
|
75 var params = {blob: blob, start: start, end: end}; |
|
76 worker.postMessage(params); |
|
77 waitForWorkerFinish(); |
|
78 } |
|
79 |
|
80 // Empty file. |
|
81 readSlice(createFileWithData(""), 0, 0, ""); |
|
82 |
|
83 // Typical use case. |
|
84 readSlice(createFileWithData("HelloBye"), 5, 8, "Bye"); |
|
85 |
|
86 // End offset too large. |
|
87 readSlice(createFileWithData("HelloBye"), 5, 9, "Bye"); |
|
88 |
|
89 // Start of file. |
|
90 readSlice(createFileWithData("HelloBye"), 0, 5, "Hello"); |
|
91 |
|
92 ]]> |
|
93 </script> |
|
94 </window> |