dom/workers/test/test_fileBlobPosting.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
michael@0 3 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
michael@0 4 <!--
michael@0 5 https://bugzilla.mozilla.org/show_bug.cgi?id=664783
michael@0 6 -->
michael@0 7 <window title="Mozilla Bug 664783"
michael@0 8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 9 <script type="application/javascript"
michael@0 10 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 11 <script type="application/javascript" src="dom_worker_helper.js"/>
michael@0 12
michael@0 13 <!-- test results are displayed in the html:body -->
michael@0 14 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 15 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=664783"
michael@0 16 target="_blank">Mozilla Bug 664783</a>
michael@0 17
michael@0 18 <div id="content" style="display: none">
michael@0 19 <input id="fileList" type="file"></input>
michael@0 20 </div>
michael@0 21
michael@0 22 </body>
michael@0 23
michael@0 24 <!-- test code goes here -->
michael@0 25 <script type="application/javascript">
michael@0 26 <![CDATA[
michael@0 27
michael@0 28 /** Test for Bug 664783 **/
michael@0 29
michael@0 30 var fileNum = 0;
michael@0 31
michael@0 32 /**
michael@0 33 * Create a file which contains the given data.
michael@0 34 */
michael@0 35 function createFileWithData(fileData) {
michael@0 36 var testFile = Components.classes["@mozilla.org/file/directory_service;1"]
michael@0 37 .getService(Components.interfaces.nsIProperties)
michael@0 38 .get("ProfD", Components.interfaces.nsIFile);
michael@0 39 testFile.append("workerBlobPosting" + fileNum++);
michael@0 40
michael@0 41 var outStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
michael@0 42 .createInstance(Components.interfaces.nsIFileOutputStream);
michael@0 43 outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
michael@0 44 0666, 0);
michael@0 45 outStream.write(fileData, fileData.length);
michael@0 46 outStream.close();
michael@0 47
michael@0 48 var fileList = document.getElementById('fileList');
michael@0 49 fileList.value = testFile.path;
michael@0 50
michael@0 51 return fileList.files[0];
michael@0 52 }
michael@0 53
michael@0 54 /**
michael@0 55 * Create a worker which posts the same blob given. Used to test cloning of blobs.
michael@0 56 * Checks the size, type, name and path of the file posted from the worker to ensure it
michael@0 57 * is the same as the original.
michael@0 58 */
michael@0 59 function postBlob(file) {
michael@0 60 var worker = new Worker("filePosting_worker.js");
michael@0 61
michael@0 62 worker.onerror = function(event) {
michael@0 63 ok(false, "Worker had an error: " + event.data);
michael@0 64 finish();
michael@0 65 };
michael@0 66
michael@0 67 worker.onmessage = function(event) {
michael@0 68 console.log(event.data);
michael@0 69 is(event.data.size, file.size, "size of file posted from worker does not match file posted to worker.");
michael@0 70 finish();
michael@0 71 };
michael@0 72
michael@0 73 var blob = file.slice();
michael@0 74 worker.postMessage(blob);
michael@0 75 waitForWorkerFinish();
michael@0 76 }
michael@0 77
michael@0 78 // Empty file.
michael@0 79 postBlob(createFileWithData(""));
michael@0 80
michael@0 81 // Typical use case.
michael@0 82 postBlob(createFileWithData("Hello"));
michael@0 83
michael@0 84 ]]>
michael@0 85 </script>
michael@0 86 </window>

mercurial