mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 949695 tests followup - Add ability to run tests twice - once with each identity manager - and have test_service_startOver use it.
This commit is contained in:
parent
a1683f8a40
commit
d2933b41f3
@ -10,16 +10,21 @@ this.EXPORTED_SYMBOLS = [
|
||||
"setBasicCredentials",
|
||||
"makeIdentityConfig",
|
||||
"configureFxAccountIdentity",
|
||||
"configureIdentity",
|
||||
"SyncTestingInfrastructure",
|
||||
"waitForZeroTimer",
|
||||
"Promise", // from a module import
|
||||
"add_identity_test",
|
||||
];
|
||||
|
||||
const {utils: Cu} = Components;
|
||||
|
||||
Cu.import("resource://services-sync/status.js");
|
||||
Cu.import("resource://services-sync/identity.js");
|
||||
Cu.import("resource://services-common/utils.js");
|
||||
Cu.import("resource://services-crypto/utils.js");
|
||||
Cu.import("resource://services-sync/util.js");
|
||||
Cu.import("resource://services-sync/browserid_identity.js");
|
||||
Cu.import("resource://testing-common/services-common/logging.js");
|
||||
Cu.import("resource://testing-common/services/sync/fakeservices.js");
|
||||
Cu.import("resource://gre/modules/FxAccounts.jsm");
|
||||
@ -80,20 +85,29 @@ this.makeIdentityConfig = function(overrides) {
|
||||
key: "key",
|
||||
// uid will be set to the username.
|
||||
}
|
||||
},
|
||||
sync: {
|
||||
// username will come from the top-level username
|
||||
password: "whatever",
|
||||
syncKey: "abcdeabcdeabcdeabcdeabcdea",
|
||||
}
|
||||
// XXX - todo - basic identity provider config
|
||||
};
|
||||
|
||||
// Now handle any specified overrides.
|
||||
if (overrides) {
|
||||
if (overrides.username) {
|
||||
result.username = overrides.username;
|
||||
}
|
||||
// XXX - todo - basic identity provider config
|
||||
if (overrides.sync) {
|
||||
// TODO: allow just some attributes to be specified
|
||||
result.sync = overrides.sync;
|
||||
}
|
||||
if (overrides.fxaccount) {
|
||||
// TODO: allow just some attributes to be specified
|
||||
result.fxaccount = overrides.fxaccount;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Configure an instance of an FxAccount identity provider with the specified
|
||||
@ -128,6 +142,23 @@ this.configureFxAccountIdentity = function(authService,
|
||||
authService._account = config.fxaccount.user.email;
|
||||
}
|
||||
|
||||
this.configureIdentity = function(identityOverrides) {
|
||||
let config = makeIdentityConfig(identityOverrides);
|
||||
let ns = {};
|
||||
Cu.import("resource://services-sync/service.js", ns);
|
||||
|
||||
if (ns.Service.identity instanceof BrowserIDManager) {
|
||||
// do the FxAccounts thang...
|
||||
configureFxAccountIdentity(ns.Service.identity, config);
|
||||
return ns.Service.identity.initWithLoggedInUser();
|
||||
}
|
||||
// old style identity provider.
|
||||
setBasicCredentials(config.username, config.sync.password, config.sync.syncKey);
|
||||
let deferred = Promise.defer();
|
||||
deferred.resolve();
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
this.SyncTestingInfrastructure = function (server, username, password, syncKey) {
|
||||
let ns = {};
|
||||
Cu.import("resource://services-sync/service.js", ns);
|
||||
@ -165,3 +196,38 @@ this.encryptPayload = function encryptPayload(cleartext) {
|
||||
};
|
||||
}
|
||||
|
||||
// This helper can be used instead of 'add_test' or 'add_task' to run the
|
||||
// specified test function twice - once with the old-style sync identity
|
||||
// manager and once with the new-style BrowserID identity manager, to ensure
|
||||
// it works in both cases.
|
||||
//
|
||||
// * The test itself should be passed as 'test' - ie, test code will generally
|
||||
// pass |this|.
|
||||
// * The test function is a regular test function - although note that it must
|
||||
// be a generator - async operations should yield them, and run_next_test
|
||||
// mustn't be called.
|
||||
this.add_identity_test = function(test, testFunction) {
|
||||
function note(what) {
|
||||
let msg = "running test " + testFunction.name + " with " + what + " identity manager";
|
||||
test._log("test_info",
|
||||
{_message: "TEST-INFO | | " + msg + "\n"});
|
||||
}
|
||||
let ns = {};
|
||||
Cu.import("resource://services-sync/service.js", ns);
|
||||
// one task for the "old" identity manager.
|
||||
test.add_task(function() {
|
||||
note("sync");
|
||||
let oldIdentity = Status._authManager;
|
||||
Status._authManager = ns.Service.identity = new IdentityManager();
|
||||
yield testFunction();
|
||||
Status._authManager = ns.Service.identity = oldIdentity;
|
||||
});
|
||||
// another task for the FxAccounts identity manager.
|
||||
test.add_task(function() {
|
||||
note("FxAccounts");
|
||||
let oldIdentity = Status._authManager;
|
||||
Status._authManager = ns.Service.identity = new BrowserIDManager();
|
||||
yield testFunction();
|
||||
Status._authManager = ns.Service.identity = oldIdentity;
|
||||
});
|
||||
}
|
||||
|
@ -28,10 +28,8 @@ function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_test(function test_resetLocalData() {
|
||||
// Set up.
|
||||
setBasicCredentials("foobar", "blablabla", // Law Blog
|
||||
"abcdeabcdeabcdeabcdeabcdea");
|
||||
add_identity_test(this, function test_resetLocalData() {
|
||||
yield configureIdentity();
|
||||
Service.status.enforceBackoff = true;
|
||||
Service.status.backoffInterval = 42;
|
||||
Service.status.minimumNextSync = 23;
|
||||
@ -61,8 +59,6 @@ add_test(function test_resetLocalData() {
|
||||
do_check_false(Service.status.enforceBackoff);
|
||||
do_check_eq(Service.status.backoffInterval, 0);
|
||||
do_check_eq(Service.status.minimumNextSync, 0);
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_removeClientData() {
|
||||
|
Loading…
Reference in New Issue
Block a user