Bug 1220304 - Part 2 - Make ArchiveReader tests use SpecialPowers.createFiles(). r=baku

This commit is contained in:
Andrew McCreight 2015-11-13 09:22:00 +01:00
parent e80aa118fa
commit 9365b8b1ab
5 changed files with 40 additions and 106 deletions

View File

@ -10,8 +10,15 @@ function runTest()
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({'set': [ ["dom.archivereader.enabled", true] ]}, function() {
testGenerator = testSteps();
return testGenerator.next();
SpecialPowers.createFiles(filesToCreate(),
function (files) {
testGenerator = testSteps(files);
return testGenerator.next();
},
function (msg) {
ok(false, "File creation error: " + msg);
finishTest();
});
});
}

View File

@ -1,5 +1,4 @@
[DEFAULT]
skip-if = e10s
support-files =
helpers.js

View File

@ -10,57 +10,7 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript;version=1.7">
function createZipFileWithData(fileData) {
var Cc = SpecialPowers.Cc;
var Ci = SpecialPowers.Ci;
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
var testFile = dirSvc.get("ProfD", Ci.nsIFile);
testFile.append("fileArchiveReader.zip");
var outStream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
0666, 0);
outStream.write(fileData, fileData.length);
outStream.close();
var fileList = document.getElementById('fileList');
SpecialPowers.wrap(fileList).value = testFile.path;
return fileList.files[0];
}
function createTextFileWithData(fileData) {
var Cc = SpecialPowers.Cc;
var Ci = SpecialPowers.Ci;
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
var testFile = dirSvc.get("ProfD", Ci.nsIFile);
testFile.append("fileArchiveReader.txt");
var outStream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
0666, 0);
outStream.write(fileData, fileData.length);
outStream.close();
var fileList = document.getElementById('fileList');
SpecialPowers.wrap(fileList).value = testFile.path;
return fileList.files[0];
}
handleFinished = 0;
function markTestDone() {
++handleFinished;
if (isFinished()) {
finishTest();
}
}
function isFinished() {
return handleFinished == 6;
}
function testSteps()
{
function filesToCreate() {
var binaryString = '504B03040A00000000002E6BF14000000000000000000000000005001C00746573742F555409000337CA055039CA055075780B' +
'000104E803000004E8030000504B03041400000008002D6BF1401780E15015000000580200000A001C00746573742F612E7478' +
'74555409000336CA05503ACA055075780B000104E803000004E8030000CB48CDC9C95728CF2FCA49E1CA18658FB2A9C4060050' +
@ -78,8 +28,25 @@
binaryData += String.fromCharCode(parseInt(hex,16));
}
var binaryFile = createZipFileWithData(binaryData);
var textFile = createTextFileWithData("Hello World");
return [ {name: "fileArchiveReader.zip", data: binaryData},
{name: "fileArchiveReader.txt", data: "Hello World"}];
}
handleFinished = 0;
function markTestDone() {
++handleFinished;
if (isFinished()) {
finishTest();
}
}
function isFinished() {
return handleFinished == 6;
}
function testSteps(files)
{
var binaryFile = files[0];
var textFile = files[1];
var status;
@ -254,7 +221,6 @@
<body onload="runTest();">
<p id="display">
<input id="fileList" type="file"></input>
</p>
</body>

View File

@ -10,35 +10,17 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript;version=1.7">
function createNonUnicodeData() {
const Cc = SpecialPowers.Cc;
const Ci = SpecialPowers.Ci;
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
var testFile = dirSvc.get("ProfD", Ci.nsIFile);
testFile.append("fileArchiveReader_nonUnicode.zip");
var outStream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
0666, 0);
function filesToCreate() {
var binaryData = "";
for (var i = 0, len = binaryString.length / 2; i < len; ++i) {
var hex = binaryString[i * 2] + binaryString[i * 2 + 1];
binaryData += String.fromCharCode(parseInt(hex,16));
}
outStream.write(binaryData, binaryData.length);
outStream.close();
var fileList = document.getElementById('fileList');
SpecialPowers.wrap(fileList).value = testFile.path;
return fileList.files[0];
return [ {name: "fileArchiveReader_nonUnicode.zip", data: binaryData} ];
}
function test1()
function test1(binaryFile)
{
var binaryFile = createNonUnicodeData();
var r = new ArchiveReader(binaryFile, { encoding: "ISO-8859-1" });
isnot(r, null, "ArchiveReader cannot be null");
@ -51,14 +33,12 @@
is(this.result.length, 1, "ArchiveReader.getFilenames(): the array contains 1 item");
ok(this.reader, r, "ArchiveRequest.reader should be == ArchiveReader");
dump('Content: ' + this.result[0] + '\n');
test2();
test2(binaryFile);
}
}
function test2()
function test2(binaryFile)
{
var binaryFile = createNonUnicodeData();
try {
new ArchiveReader(binaryFile, { encoding: "random stuff" });
ok(false, "Should have thrown for bogus encoding label.");
@ -68,9 +48,9 @@
finishTest();
}
function testSteps()
function testSteps(files)
{
test1();
test1(files[0]);
yield undefined;
}
@ -82,7 +62,6 @@
<body onload="runTest();">
<p id="display">
<input id="fileList" type="file"></input>
</p>
<script type="text/javascript;version=1.7">
var binaryString = '' +

View File

@ -10,34 +10,18 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript;version=1.7">
function createZipInZipData() {
var Cc = SpecialPowers.Cc;
var Ci = SpecialPowers.Ci;
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
var testFile = dirSvc.get("ProfD", Ci.nsIFile);
testFile.append("fileArchiveReader_42.zip");
var outStream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
0666, 0);
function filesToCreate() {
var binaryData = "";
for (var i = 0, len = binaryString.length / 2; i < len; ++i) {
var hex = binaryString[i * 2] + binaryString[i * 2 + 1];
binaryData += String.fromCharCode(parseInt(hex,16));
}
outStream.write(binaryData, binaryData.length);
outStream.close();
var fileList = document.getElementById('fileList');
SpecialPowers.wrap(fileList).value = testFile.path;
return fileList.files[0];
return [ {name: "fileArchiveReader_42.zip", data: binaryData} ];
}
function testSteps()
function testSteps(files)
{
var binaryFile = createZipInZipData();
var binaryFile = files[0];
// The input is 4 nested zip archives:
doLoop(binaryFile, 4);
@ -96,7 +80,6 @@
<body onload="runTest();">
<p id="display">
<input id="fileList" type="file"></input>
</p>
<script type="text/javascript;version=1.7">
var binaryString = '' +