Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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"/>
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>
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 664783 **/
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("workerSlice" + 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 * Starts a worker which slices the blob to the given start offset and optional end offset and
57 * content type. It then verifies that the size and type of the sliced blob is correct.
58 */
59 function createSlice(blob, start, expectedLength, /** optional */ end, /** optional */ contentType) {
60 var worker = new Worker("fileSlice_worker.js");
62 worker.onerror = function(event) {
63 ok(false, "Worker had an error: " + event.data);
64 finish();
65 };
67 worker.onmessage = function(event) {
68 is(event.data.size, expectedLength, "size property of slice is incorrect.");
69 is(event.data.type, contentType ? contentType : blob.type, "type property of slice is incorrect.");
70 finish();
71 };
73 var params = {blob: blob, start: start, end: end, contentType: contentType};
74 worker.postMessage(params);
75 waitForWorkerFinish();
76 }
78 // Empty file.
79 createSlice(createFileWithData(""), 0, 0, 0);
81 // Typical use case.
82 createSlice(createFileWithData("Hello"), 1, 1, 2);
84 // Longish file.
85 var text = "";
86 for (var i = 0; i < 10000; ++i) {
87 text += "long";
88 }
89 createSlice(createFileWithData(text), 2000, 2000, 4000);
91 // Slice to different type.
92 createSlice(createFileWithData("text", "txt"), 0, 2, 2, "image/png");
94 // Length longer than blob.
95 createSlice(createFileWithData("text"), 0, 4, 20);
97 // Start longer than blob.
98 createSlice(createFileWithData("text"), 20, 0, 4);
100 // No optional arguments
101 createSlice(createFileWithData("text"), 0, 4);
102 createSlice(createFileWithData("text"), 2, 2);
104 ]]>
105 </script>
106 </window>