зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1248097, part 2 - If no name is specified for createFiles, use createUnique to create one. r=jmaher
This commit is contained in:
Родитель
b7841a51a8
Коммит
0d35a4fff9
|
@ -52,15 +52,34 @@
|
|||
is("emptyfile.txt", f2.name, "second test3 test file should have the right name");
|
||||
is(f1.size, f1data.length, "size of first file should be length of its data");
|
||||
is(f2.size, 0, "size of second file should be 0");
|
||||
SimpleTest.finish();
|
||||
test4();
|
||||
},
|
||||
function (msg) {
|
||||
ok(false, "Failed to create files: " + msg);
|
||||
SimpleTest.finish();
|
||||
test4();
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
// Creating a file without specifying a name should work.
|
||||
function test4() {
|
||||
let fdata = "this is same data for a file";
|
||||
SpecialPowers.createFiles([{data:fdata}],
|
||||
function (files) {
|
||||
is(files.length, 1, "Created 1 file");
|
||||
let f = files[0];
|
||||
is("[object File]", f.toString(), "first thing in array is a file");
|
||||
is(f.size, fdata.length, "test4 size of first file should be length of its data");
|
||||
ok(f.name, "test4 test file should have a name");
|
||||
SimpleTest.finish();
|
||||
},
|
||||
function (msg) {
|
||||
ok(false, "Should be able to create a file without a name without an error");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
test1();
|
||||
|
||||
|
|
|
@ -257,11 +257,16 @@ SpecialPowersObserver.prototype.receiveMessage = function(aMessage) {
|
|||
let createdFiles = this._createdFiles;
|
||||
try {
|
||||
aMessage.data.forEach(function(request) {
|
||||
const filePerms = 0666;
|
||||
let testFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
|
||||
testFile.append(request.name);
|
||||
if (request.name) {
|
||||
testFile.append(request.name);
|
||||
} else {
|
||||
testFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, filePerms);
|
||||
}
|
||||
let outStream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
|
||||
outStream.init(testFile, 0x02 | 0x08 | 0x20, // PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE
|
||||
0666, 0);
|
||||
filePerms, 0);
|
||||
if (request.data) {
|
||||
outStream.write(request.data, request.data.length);
|
||||
outStream.close();
|
||||
|
|
Загрузка…
Ссылка в новой задаче