gecko/dom/workers/test/test_fileBlobSubWorker.xul
Matthew Schranz 87bb64c61e Bug 725289 - Removed moz prefix in Blob.mozSlice. r=sicking
--HG--
rename : dom/workers/test/fileReadMozSlice_worker.js => dom/workers/test/fileReadSlice_worker.js
rename : dom/workers/test/fileMozSlice_worker.js => dom/workers/test/fileSlice_worker.js
rename : dom/workers/test/test_fileReadMozSlice.xul => dom/workers/test/test_fileReadSlice.xul
rename : dom/workers/test/test_fileMozSlice.xul => dom/workers/test/test_fileSlice.xul
2012-02-16 11:22:25 +01:00

99 lines
3.0 KiB
XML

<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=664783
-->
<window title="Mozilla Bug 664783"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript" src="dom_worker_helper.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=664783"
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 and optionally adds the specified file extension.
*/
function createFileWithData(fileData, /** optional */ extension) {
var testFile = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsIFile);
var fileExtension = (extension == undefined) ? "" : "." + extension;
testFile.append("workerBlobSubWorker" + fileNum++ + fileExtension);
var outStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);
outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
0666, 0);
outStream.write(fileData, fileData.length);
outStream.close();
var fileList = document.getElementById('fileList');
fileList.value = testFile.path;
return fileList.files[0];
}
/**
* Create a worker to access blob properties.
*/
function accessFileProperties(file, expectedSize) {
var worker = new Worker("fileBlobSubWorker_worker.js");
worker.onerror = function(event) {
ok(false, "Worker had an error: " + event.data);
finish();
};
worker.onmessage = function(event) {
if (event.data == undefined) {
ok(false, "Worker had an error.");
} else {
is(event.data.size, expectedSize, "size proproperty accessed from worker is not the same as on main thread.");
}
finish();
};
var blob = file.slice();
worker.postMessage(blob);
waitForWorkerFinish();
}
// Empty file.
accessFileProperties(createFileWithData(""), 0);
// Typical use case.
accessFileProperties(createFileWithData("Hello"), 5);
// Longish file.
var text = "";
for (var i = 0; i < 10000; ++i) {
text += "long";
}
accessFileProperties(createFileWithData(text), 40000);
// Type detection based on extension.
accessFileProperties(createFileWithData("text", "txt"), 4);
]]>
</script>
</window>