Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
-->
<window title="Mozilla Bug 664783"
<script type="application/javascript" src="dom_worker_helper.js"/>
<!-- test results are displayed in the html:body -->
target="_blank">Mozilla Bug 664783</a>
<div id="content" style="display: none">
<input id="fileList" type="file"></input>
</div>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 664783 **/
var fileNum = 0;
/**
* Create a file which contains the given data.
*/
function createFileWithData(fileData) {
var testFile = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("ProfD", Ci.nsIFile);
testFile.append("workerBlobPosting" + fileNum++);
var outStream = Cc["@mozilla.org/network/file-output-stream;1"]
.createInstance(Ci.nsIFileOutputStream);
outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
0o666, 0);
outStream.write(fileData, fileData.length);
outStream.close();
var fileList = document.getElementById('fileList');
fileList.value = testFile.path;
return fileList.files[0];
}
/**
* Create a worker which posts the same blob given. Used to test cloning of blobs.
* Checks the size, type, name and path of the file posted from the worker to ensure it
* is the same as the original.
*/
function postBlob(file) {
var worker = new Worker("filePosting_worker.js");
worker.onerror = function(event) {
ok(false, "Worker had an error: " + event.message);
finish();
};
worker.onmessage = function(event) {
console.log(event.data);
is(event.data.size, file.size, "size of file posted from worker does not match file posted to worker.");
finish();
};
var blob = file.slice();
worker.postMessage(blob);
waitForWorkerFinish();
}
// Empty file.
postBlob(createFileWithData(""));
// Typical use case.
postBlob(createFileWithData("Hello"));
]]>
</script>
</window>