Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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=123456
6 -->
7 <window title="Mozilla Bug 123456"
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"/>
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=123456"
16 target="_blank">Mozilla Bug 123456</a>
18 <div id="content" style="display: none">
19 <input id="fileList" type="file"></input>
20 </div>
22 </body>
24 <!-- test code goes here -->
25 <script type="application/javascript">
26 <![CDATA[
28 /** Test for Bug 123456 **/
30 var fileNum = 0;
32 /**
33 * Create a file which contains the given data and optionally adds the specified file extension.
34 */
35 function createFileWithData(fileData, /** optional */ extension) {
36 var testFile = Components.classes["@mozilla.org/file/directory_service;1"]
37 .getService(Components.interfaces.nsIProperties)
38 .get("ProfD", Components.interfaces.nsIFile);
39 var fileExtension = (extension == undefined) ? "" : "." + extension;
40 testFile.append("workerFile" + fileNum++ + fileExtension);
42 var outStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
43 .createInstance(Components.interfaces.nsIFileOutputStream);
44 outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
45 0666, 0);
46 outStream.write(fileData, fileData.length);
47 outStream.close();
49 var fileList = document.getElementById('fileList');
50 fileList.value = testFile.path;
52 return fileList.files[0];
53 }
55 /**
56 * Create a worker to access file properties.
57 */
58 function accessFileProperties(file, expectedSize, expectedType) {
59 waitForWorkerFinish();
61 var worker = new Worker("file_worker.js");
63 worker.onerror = function(event) {
64 ok(false, "Worker had an error: " + event.data);
65 finish();
66 };
68 worker.onmessage = function(event) {
69 is(event.data.size, expectedSize, "size proproperty accessed from worker is not the same as on main thread.");
70 is(event.data.type, expectedType, "type proproperty accessed from worker is incorrect.");
71 is(event.data.name, file.name, "name proproperty accessed from worker is incorrect.");
72 is(event.data.path, file.path, "path proproperty accessed from worker is incorrect.");
73 is(event.data.lastModifiedDate.toString(), file.lastModifiedDate.toString(), "lastModifiedDate proproperty accessed from worker is incorrect.");
74 is(event.data.mozFullPath, file.mozFullPath, "mozFullPath proproperty accessed from worker is not the same as on main thread.");
75 finish();
76 };
78 worker.postMessage(file);
79 }
81 // Empty file.
82 accessFileProperties(createFileWithData(""), 0, "");
84 // Typical use case.
85 accessFileProperties(createFileWithData("Hello"), 5, "");
87 // Longish file.
88 var text = "";
89 for (var i = 0; i < 10000; ++i) {
90 text += "long";
91 }
92 accessFileProperties(createFileWithData(text), 40000, "");
94 // Type detection based on extension.
95 accessFileProperties(createFileWithData("text", "txt"), 4, "text/plain");
97 ]]>
98 </script>
99 </window>