Backed out changeset 06f41c22f3a6 (bug 1888460) for causing linux xpcshell failures...
[gecko.git] / dom / workers / test / test_fileBlobPosting.xhtml
blob61f4a8e909556f4076707d6d2a198553f730d569
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.
34 function createFileWithData(fileData) {
35 var testFile = Cc["@mozilla.org/file/directory_service;1"]
36 .getService(Ci.nsIProperties)
37 .get("ProfD", Ci.nsIFile);
38 testFile.append("workerBlobPosting" + fileNum++);
40 var outStream = Cc["@mozilla.org/network/file-output-stream;1"]
41 .createInstance(Ci.nsIFileOutputStream);
42 outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
43 0o666, 0);
44 outStream.write(fileData, fileData.length);
45 outStream.close();
47 var fileList = document.getElementById('fileList');
48 fileList.value = testFile.path;
50 return fileList.files[0];
53 /**
54 * Create a worker which posts the same blob given. Used to test cloning of blobs.
55 * Checks the size, type, name and path of the file posted from the worker to ensure it
56 * is the same as the original.
58 function postBlob(file) {
59 var worker = new Worker("filePosting_worker.js");
61 worker.onerror = function(event) {
62 ok(false, "Worker had an error: " + event.message);
63 finish();
66 worker.onmessage = function(event) {
67 console.log(event.data);
68 is(event.data.size, file.size, "size of file posted from worker does not match file posted to worker.");
69 finish();
72 var blob = file.slice();
73 worker.postMessage(blob);
74 waitForWorkerFinish();
77 // Empty file.
78 postBlob(createFileWithData(""));
80 // Typical use case.
81 postBlob(createFileWithData("Hello"));
83 ]]>
84 </script>
85 </window>