mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Separated test_passwords into itself, which contains pure unit tests, and test_password_syncing, which contains a suite that's more along the lines of a system test, though still with plenty of stuff faked-out. fake_login_manager.js contains code shared between the two suites.
--HG-- rename : services/sync/tests/unit/test_passwords.log.expected => services/sync/tests/unit/test_password_syncing.log.expected
This commit is contained in:
parent
0258487f7a
commit
f9ab00520c
38
services/sync/tests/unit/fake_login_manager.js
Normal file
38
services/sync/tests/unit/fake_login_manager.js
Normal file
@ -0,0 +1,38 @@
|
||||
Cu.import("resource://weave/util.js");
|
||||
|
||||
// ----------------------------------------
|
||||
// Fake Sample Data
|
||||
// ----------------------------------------
|
||||
|
||||
let fakeSampleLogins = [
|
||||
// Fake nsILoginInfo object.
|
||||
{hostname: "www.boogle.com",
|
||||
formSubmitURL: "http://www.boogle.com/search",
|
||||
httpRealm: "",
|
||||
username: "",
|
||||
password: "",
|
||||
usernameField: "test_person",
|
||||
passwordField: "test_password"}
|
||||
];
|
||||
|
||||
// ----------------------------------------
|
||||
// Fake Login Manager
|
||||
// ----------------------------------------
|
||||
|
||||
function FakeLoginManager(fakeLogins) {
|
||||
this.fakeLogins = fakeLogins;
|
||||
|
||||
let self = this;
|
||||
|
||||
Utils.getLoginManager = function fake_getLoginManager() {
|
||||
// Return a fake nsILoginManager object.
|
||||
return {
|
||||
getAllLogins: function() { return self.fakeLogins; },
|
||||
addLogin: function(login) {
|
||||
getTestLogger().info("nsILoginManager.addLogin() called " +
|
||||
"with hostname '" + login.hostname + "'.");
|
||||
self.fakeLogins.push(login);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
42
services/sync/tests/unit/test_password_syncing.js
Normal file
42
services/sync/tests/unit/test_password_syncing.js
Normal file
@ -0,0 +1,42 @@
|
||||
Cu.import("resource://weave/engines/passwords.js");
|
||||
|
||||
load("fake_login_manager.js");
|
||||
|
||||
// ----------------------------------------
|
||||
// Test Logic
|
||||
// ----------------------------------------
|
||||
|
||||
function run_test() {
|
||||
var syncTesting = new SyncTestingInfrastructure();
|
||||
var fakeLoginManager = new FakeLoginManager(fakeSampleLogins);
|
||||
|
||||
function freshEngineSync(cb) {
|
||||
let engine = new PasswordEngine();
|
||||
engine.sync(cb);
|
||||
};
|
||||
|
||||
syncTesting.runAsyncFunc("initial sync", freshEngineSync);
|
||||
|
||||
syncTesting.runAsyncFunc("trivial re-sync", freshEngineSync);
|
||||
|
||||
fakeLoginManager.fakeLogins.push(
|
||||
{hostname: "www.yoogle.com",
|
||||
formSubmitURL: "http://www.yoogle.com/search",
|
||||
httpRealm: "",
|
||||
username: "",
|
||||
password: "",
|
||||
usernameField: "test_person2",
|
||||
passwordField: "test_password2"}
|
||||
);
|
||||
|
||||
syncTesting.runAsyncFunc("add user and re-sync", freshEngineSync);
|
||||
|
||||
fakeLoginManager.fakeLogins.pop();
|
||||
|
||||
syncTesting.runAsyncFunc("remove user and re-sync", freshEngineSync);
|
||||
|
||||
syncTesting.fakeFilesystem.fakeContents = {};
|
||||
fakeLoginManager.fakeLogins = [];
|
||||
|
||||
syncTesting.runAsyncFunc("resync on second computer", freshEngineSync);
|
||||
}
|
@ -1,92 +1,19 @@
|
||||
Cu.import("resource://weave/util.js");
|
||||
load("fake_login_manager.js");
|
||||
|
||||
// ----------------------------------------
|
||||
// Fake Data
|
||||
// ----------------------------------------
|
||||
var loginMgr = new FakeLoginManager(fakeSampleLogins);
|
||||
|
||||
let __fakeLogins = [
|
||||
// Fake nsILoginInfo object.
|
||||
{hostname: "www.boogle.com",
|
||||
formSubmitURL: "http://www.boogle.com/search",
|
||||
httpRealm: "",
|
||||
username: "",
|
||||
password: "",
|
||||
usernameField: "test_person",
|
||||
passwordField: "test_password"}
|
||||
];
|
||||
// The JS module we're testing, with all members exposed.
|
||||
var passwords = loadInSandbox("resource://weave/engines/passwords.js");
|
||||
|
||||
// ----------------------------------------
|
||||
// Test Logic
|
||||
// ----------------------------------------
|
||||
|
||||
function run_test() {
|
||||
// The JS module we're testing, with all members exposed.
|
||||
var passwords = loadInSandbox("resource://weave/engines/passwords.js");
|
||||
|
||||
// Ensure that _hashLoginInfo() works.
|
||||
var fakeUserHash = passwords._hashLoginInfo(__fakeLogins[0]);
|
||||
function test_hashLoginInfo_works() {
|
||||
var fakeUserHash = passwords._hashLoginInfo(fakeSampleLogins[0]);
|
||||
do_check_eq(typeof fakeUserHash, 'string');
|
||||
do_check_eq(fakeUserHash.length, 40);
|
||||
}
|
||||
|
||||
// Ensure that PasswordSyncCore._itemExists() works.
|
||||
function test_synccore_itemexists_works() {
|
||||
var fakeUserHash = passwords._hashLoginInfo(fakeSampleLogins[0]);
|
||||
var psc = new passwords.PasswordSyncCore();
|
||||
psc.__loginManager = {getAllLogins: function() { return __fakeLogins; }};
|
||||
do_check_false(psc._itemExists("invalid guid"));
|
||||
do_check_true(psc._itemExists(fakeUserHash));
|
||||
|
||||
// Make sure the engine can sync.
|
||||
var syncTesting = new SyncTestingInfrastructure();
|
||||
var fakeLoginManager = new FakeLoginManager(__fakeLogins);
|
||||
|
||||
function freshEngineSync(cb) {
|
||||
let engine = new passwords.PasswordEngine();
|
||||
engine.sync(cb);
|
||||
};
|
||||
|
||||
syncTesting.runAsyncFunc("initial sync", freshEngineSync);
|
||||
|
||||
syncTesting.runAsyncFunc("trivial re-sync", freshEngineSync);
|
||||
|
||||
fakeLoginManager.fakeLogins.push(
|
||||
{hostname: "www.yoogle.com",
|
||||
formSubmitURL: "http://www.yoogle.com/search",
|
||||
httpRealm: "",
|
||||
username: "",
|
||||
password: "",
|
||||
usernameField: "test_person2",
|
||||
passwordField: "test_password2"}
|
||||
);
|
||||
|
||||
syncTesting.runAsyncFunc("add user and re-sync", freshEngineSync);
|
||||
|
||||
fakeLoginManager.fakeLogins.pop();
|
||||
|
||||
syncTesting.runAsyncFunc("remove user and re-sync", freshEngineSync);
|
||||
|
||||
syncTesting.fakeFilesystem.fakeContents = {};
|
||||
fakeLoginManager.fakeLogins = [];
|
||||
|
||||
syncTesting.runAsyncFunc("resync on second computer", freshEngineSync);
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// Fake Infrastructure
|
||||
// ----------------------------------------
|
||||
|
||||
function FakeLoginManager(fakeLogins) {
|
||||
this.fakeLogins = fakeLogins;
|
||||
|
||||
let self = this;
|
||||
|
||||
Utils.getLoginManager = function fake_getLoginManager() {
|
||||
// Return a fake nsILoginManager object.
|
||||
return {
|
||||
getAllLogins: function() { return self.fakeLogins; },
|
||||
addLogin: function(login) {
|
||||
getTestLogger().info("nsILoginManager.addLogin() called " +
|
||||
"with hostname '" + login.hostname + "'.");
|
||||
self.fakeLogins.push(login);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user