no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / workers / test / test_fileSubWorker.xhtml
blob92aa3b1a171b137c1d91c90f06c6e73b1d36329f
1 <?xml version="1.0"?>
2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/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 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
10 <script type="application/javascript" src="dom_worker_helper.js"/>
12 <!-- test results are displayed in the html:body -->
13 <body xmlns="http://www.w3.org/1999/xhtml">
14 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=664783"
15 target="_blank">Mozilla Bug 664783</a>
17 <div id="content" style="display: none">
18 <input id="fileList" type="file"></input>
19 </div>
21 </body>
23 <!-- test code goes here -->
24 <script type="application/javascript">
25 <![CDATA[
27 /** Test for Bug 664783 **/
29 var fileNum = 0;
31 /**
32 * Create a file which contains the given data and optionally adds the specified file extension.
34 function createFileWithData(fileData, /** optional */ extension) {
35 var testFile = Cc["@mozilla.org/file/directory_service;1"]
36 .getService(Ci.nsIProperties)
37 .get("ProfD", Ci.nsIFile);
38 var fileExtension = (extension == undefined) ? "" : "." + extension;
39 testFile.append("workerSubWorker" + fileNum++ + fileExtension);
41 var outStream = Cc["@mozilla.org/network/file-output-stream;1"]
42 .createInstance(Ci.nsIFileOutputStream);
43 outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
44 0o666, 0);
45 outStream.write(fileData, fileData.length);
46 outStream.close();
48 var fileList = document.getElementById('fileList');
49 fileList.value = testFile.path;
51 return fileList.files[0];
54 /**
55 * Create a worker to access file properties.
57 function accessFileProperties(file, expectedSize, expectedType) {
58 var worker = new Worker("fileSubWorker_worker.js");
60 worker.onerror = function(event) {
61 ok(false, "Worker had an error: " + event.message);
62 finish();
65 worker.onmessage = function(event) {
66 if (event.data == undefined) {
67 ok(false, "Worker had an error.");
68 } else {
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.");
73 finish();
76 worker.postMessage(file);
77 waitForWorkerFinish();
80 // Empty file.
81 accessFileProperties(createFileWithData(""), 0, "");
83 // Typical use case.
84 accessFileProperties(createFileWithData("Hello"), 5, "");
86 // Longish file.
87 var text = "";
88 for (var i = 0; i < 10000; ++i) {
89 text += "long";
91 accessFileProperties(createFileWithData(text), 40000, "");
93 // Type detection based on extension.
94 accessFileProperties(createFileWithData("text", "txt"), 4, "text/plain");
96 ]]>
97 </script>
98 </window>