mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Factored out the fake filesystem related functions in test_passwords.js into a FakeFilesystemService class in head.js.
This commit is contained in:
parent
4489fb2ce3
commit
01b47a4865
@ -208,3 +208,55 @@ function FakePasswordService(contents) {
|
||||
return null;
|
||||
};
|
||||
};
|
||||
|
||||
function FakeFilesystemService(contents) {
|
||||
this.fakeContents = contents;
|
||||
|
||||
let self = this;
|
||||
|
||||
Utils.getProfileFile = function fake_getProfileFile(arg) {
|
||||
let fakeNsILocalFile = {
|
||||
exists: function() {
|
||||
return this._fakeFilename in self.fakeContents;
|
||||
},
|
||||
_fakeFilename: (typeof(arg) == "object") ? arg.path : arg
|
||||
};
|
||||
return fakeNsILocalFile;
|
||||
};
|
||||
|
||||
Utils.readStream = function fake_readStream(stream) {
|
||||
getTestLogger().info("Reading from stream.");
|
||||
return stream._fakeData;
|
||||
};
|
||||
|
||||
Utils.open = function fake_open(file, mode) {
|
||||
switch (mode) {
|
||||
case "<":
|
||||
mode = "reading";
|
||||
break;
|
||||
case ">":
|
||||
mode = "writing";
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unexpected mode: " + mode);
|
||||
}
|
||||
|
||||
getTestLogger().info("Opening '" + file._fakeFilename + "' for " +
|
||||
mode + ".");
|
||||
var contents = "";
|
||||
if (file._fakeFilename in self.fakeContents && mode == "reading")
|
||||
contents = self.fakeContents[file._fakeFilename];
|
||||
let fakeStream = {
|
||||
writeString: function(data) {
|
||||
contents += data;
|
||||
getTestLogger().info("Writing data to local file '" +
|
||||
file._fakeFilename +"': " + data);
|
||||
},
|
||||
close: function() {
|
||||
self.fakeContents[file._fakeFilename] = contents;
|
||||
},
|
||||
get _fakeData() { return contents; }
|
||||
};
|
||||
return [fakeStream];
|
||||
};
|
||||
};
|
||||
|
@ -106,7 +106,7 @@ var fprefs = new FakePrefService(__fakePrefs);
|
||||
var fds = new FakeDAVService({});
|
||||
var fts = new FakeTimerService();
|
||||
var logStats = initTestLogging();
|
||||
var fakeFilesystem = {};
|
||||
var ffs = new FakeFilesystemService({});
|
||||
|
||||
Utils.makeGUID = function fake_makeGUID() {
|
||||
return "fake-guid";
|
||||
@ -116,48 +116,3 @@ Utils.getLoginManager = function fake_getLoginManager() {
|
||||
// Return a fake nsILoginManager object.
|
||||
return {getAllLogins: function() { return __fakeUsers; }};
|
||||
};
|
||||
|
||||
Utils.getProfileFile = function fake_getProfileFile(arg) {
|
||||
return {
|
||||
exists: function() {
|
||||
return this._fakeFilename in fakeFilesystem;
|
||||
},
|
||||
_fakeFilename: (typeof(arg) == "object") ? arg.path : arg
|
||||
};
|
||||
};
|
||||
|
||||
Utils.readStream = function fake_readStream(stream) {
|
||||
getTestLogger().info("Reading from stream.");
|
||||
return stream._fakeContents;
|
||||
};
|
||||
|
||||
Utils.open = function fake_open(file, mode) {
|
||||
switch (mode) {
|
||||
case "<":
|
||||
mode = "reading";
|
||||
break;
|
||||
case ">":
|
||||
mode = "writing";
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unexpected mode: " + mode);
|
||||
}
|
||||
|
||||
getTestLogger().info("Opening '" + file._fakeFilename + "' for " +
|
||||
mode + ".");
|
||||
var contents = "";
|
||||
if (file._fakeFilename in fakeFilesystem && mode == "reading")
|
||||
contents = fakeFilesystem[file._fakeFilename];
|
||||
let fakeStream = {
|
||||
writeString: function(data) {
|
||||
contents += data;
|
||||
getTestLogger().info("Writing data to local file '" +
|
||||
file._fakeFilename +"': " + data);
|
||||
},
|
||||
close: function() {
|
||||
fakeFilesystem[file._fakeFilename] = contents;
|
||||
},
|
||||
get _fakeContents() { return contents; }
|
||||
};
|
||||
return [fakeStream];
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user