Bug 787273 - Part 7: Expose Status an an instance variable on Service; r=rnewman

The global Status is still there. But Service and its derived objects
avoid the singleton lookup.

There are likely a few lingering tests that reference Status when they
should reference Service.status. These will be dealt with when Status is
refactored.
This commit is contained in:
Gregory Szorc 2012-09-14 16:02:33 -07:00
Родитель 4192f76f6e
Коммит b6376f859c
12 изменённых файлов: 110 добавлений и 118 удалений

Просмотреть файл

@ -312,8 +312,8 @@ Sync11Service.prototype = {
throw new Error("Status or Status._authManager not initialized.");
}
this.status = Status;
this.identity = Status._authManager;
this.collectionKeys = new CollectionKeyManager();
this.errorHandler = new ErrorHandler(this);
@ -361,16 +361,16 @@ Sync11Service.prototype = {
// synchronously so that observers can import this module before
// registering an observer.
Utils.nextTick(function onNextTick() {
Status.ready = true;
this.status.ready = true;
Svc.Obs.notify("weave:service:ready");
});
}.bind(this));
},
_checkSetup: function _checkSetup() {
if (!this.enabled) {
return Status.service = STATUS_DISABLED;
return this.status.service = STATUS_DISABLED;
}
return Status.checkSetup();
return this.status.checkSetup();
},
_migratePrefs: function _migratePrefs() {
@ -528,8 +528,8 @@ Sync11Service.prototype = {
// and fail if that assumption is invalidated.
if (!this.identity.syncKey) {
Status.login = LOGIN_FAILED_NO_PASSPHRASE;
Status.sync = CREDENTIALS_CHANGED;
this.status.login = LOGIN_FAILED_NO_PASSPHRASE;
this.status.sync = CREDENTIALS_CHANGED;
return false;
}
@ -537,8 +537,8 @@ Sync11Service.prototype = {
if (!syncKeyBundle) {
this._log.error("Sync Key Bundle not set. Invalid Sync Key?");
Status.login = LOGIN_FAILED_INVALID_PASSPHRASE;
Status.sync = CREDENTIALS_CHANGED;
this.status.login = LOGIN_FAILED_INVALID_PASSPHRASE;
this.status.sync = CREDENTIALS_CHANGED;
return false;
}
@ -549,7 +549,7 @@ Sync11Service.prototype = {
// This only applies when the server is already at version 4.
if (infoResponse.status != 200) {
this._log.warn("info/collections returned non-200 response. Failing key fetch.");
Status.login = LOGIN_FAILED_SERVER_ERROR;
this.status.login = LOGIN_FAILED_SERVER_ERROR;
this.errorHandler.checkServerError(infoResponse);
return false;
}
@ -583,7 +583,7 @@ Sync11Service.prototype = {
}
else {
// Some other problem.
Status.login = LOGIN_FAILED_SERVER_ERROR;
this.status.login = LOGIN_FAILED_SERVER_ERROR;
this.errorHandler.checkServerError(cryptoResp);
this._log.warn("Got status " + cryptoResp.status + " fetching crypto keys.");
return false;
@ -595,13 +595,13 @@ Sync11Service.prototype = {
// One kind of exception: HMAC failure.
if (Utils.isHMACMismatch(ex)) {
Status.login = LOGIN_FAILED_INVALID_PASSPHRASE;
Status.sync = CREDENTIALS_CHANGED;
this.status.login = LOGIN_FAILED_INVALID_PASSPHRASE;
this.status.sync = CREDENTIALS_CHANGED;
}
else {
// In the absence of further disambiguation or more precise
// failure constants, just report failure.
Status.login = LOGIN_FAILED;
this.status.login = LOGIN_FAILED;
}
return false;
}
@ -641,7 +641,7 @@ Sync11Service.prototype = {
verifyLogin: function verifyLogin() {
if (!this.identity.username) {
this._log.warn("No username in verifyLogin.");
Status.login = LOGIN_FAILED_NO_USERNAME;
this.status.login = LOGIN_FAILED_NO_USERNAME;
return false;
}
@ -655,7 +655,7 @@ Sync11Service.prototype = {
} catch (ex) {
this._log.debug("Fetching passphrase threw " + ex +
"; assuming master password locked.");
Status.login = MASTER_PASSWORD_LOCKED;
this.status.login = MASTER_PASSWORD_LOCKED;
return false;
}
@ -664,7 +664,7 @@ Sync11Service.prototype = {
// This is a little weird, if we don't get a node we pretend
// to succeed, since that probably means we just don't have storage.
if (this.clusterURL == "" && !this._clusterManager.setCluster()) {
Status.sync = NO_SYNC_NODE_FOUND;
this.status.sync = NO_SYNC_NODE_FOUND;
Svc.Obs.notify("weave:service:sync:delayed");
return true;
}
@ -681,7 +681,7 @@ Sync11Service.prototype = {
// Just make the most trivial checks.
if (!this.identity.syncKey) {
this._log.warn("No passphrase in verifyLogin.");
Status.login = LOGIN_FAILED_NO_PASSPHRASE;
this.status.login = LOGIN_FAILED_NO_PASSPHRASE;
return false;
}
@ -689,7 +689,7 @@ Sync11Service.prototype = {
// conclusively that our passphrase is correct.
if (this._remoteSetup()) {
// Username/password verified.
Status.login = LOGIN_SUCCEEDED;
this.status.login = LOGIN_SUCCEEDED;
return true;
}
@ -708,19 +708,19 @@ Sync11Service.prototype = {
}
// We must have the right cluster, but the server doesn't expect us
Status.login = LOGIN_FAILED_LOGIN_REJECTED;
this.status.login = LOGIN_FAILED_LOGIN_REJECTED;
return false;
default:
// Server didn't respond with something that we expected
Status.login = LOGIN_FAILED_SERVER_ERROR;
this.status.login = LOGIN_FAILED_SERVER_ERROR;
this.errorHandler.checkServerError(test);
return false;
}
} catch (ex) {
// Must have failed on some network issue
this._log.debug("verifyLogin failed: " + Utils.exceptionStr(ex));
Status.login = LOGIN_FAILED_NETWORK_ERROR;
this.status.login = LOGIN_FAILED_NETWORK_ERROR;
this.errorHandler.checkServerError(ex);
return false;
}
@ -830,13 +830,13 @@ Sync11Service.prototype = {
startOver: function startOver() {
this._log.trace("Invoking Service.startOver.");
Svc.Obs.notify("weave:engine:stop-tracking");
Status.resetSync();
this.status.resetSync();
// We want let UI consumers of the following notification know as soon as
// possible, so let's fake for the CLIENT_NOT_CONFIGURED status for now
// by emptying the passphrase (we still need the password).
this.identity.syncKey = null;
Status.login = LOGIN_FAILED_NO_PASSPHRASE;
this.status.login = LOGIN_FAILED_NO_PASSPHRASE;
this.logout();
Svc.Obs.notify("weave:service:start-over");
@ -858,7 +858,7 @@ Sync11Service.prototype = {
// Reset all engines and clear keys.
this.resetClient();
this.collectionKeys.clear();
Status.resetBackoff();
this.status.resetBackoff();
// Reset Weave prefs.
this._ignorePrefObserver = true;
@ -882,7 +882,7 @@ Sync11Service.prototype = {
function onNotify() {
this._loggedIn = false;
if (Services.io.offline) {
Status.login = LOGIN_FAILED_NETWORK_ERROR;
this.status.login = LOGIN_FAILED_NETWORK_ERROR;
throw "Application is offline, login should not be called";
}
@ -913,7 +913,7 @@ Sync11Service.prototype = {
if (!this.verifyLogin()) {
// verifyLogin sets the failure states here.
throw "Login failed: " + Status.login;
throw "Login failed: " + this.status.login;
}
this._loggedIn = true;
@ -1038,7 +1038,7 @@ Sync11Service.prototype = {
// abort the server wipe if the GET status was anything other than 404 or 200
let status = this.recordManager.response.status;
if (status != 200 && status != 404) {
Status.sync = METARECORD_DOWNLOAD_FAIL;
this.status.sync = METARECORD_DOWNLOAD_FAIL;
this.errorHandler.checkServerError(this.recordManager.response);
this._log.warn("Unknown error while downloading metadata record. " +
"Aborting sync.");
@ -1064,7 +1064,7 @@ Sync11Service.prototype = {
return true;
}
else if (remoteVersion > STORAGE_VERSION) {
Status.sync = VERSION_OUT_OF_DATE;
this.status.sync = VERSION_OUT_OF_DATE;
this._log.warn("Upgrade required to access newer storage version.");
return false;
}
@ -1088,7 +1088,7 @@ Sync11Service.prototype = {
// bug 545725 - re-verify creds and fail sanely
if (!this.verifyLogin()) {
Status.sync = CREDENTIALS_CHANGED;
this.status.sync = CREDENTIALS_CHANGED;
this._log.info("Credentials have changed, aborting sync and forcing re-login.");
return false;
}
@ -1137,9 +1137,9 @@ Sync11Service.prototype = {
reason = kSyncWeaveDisabled;
else if (Services.io.offline)
reason = kSyncNetworkOffline;
else if (Status.minimumNextSync > Date.now())
else if (this.status.minimumNextSync > Date.now())
reason = kSyncBackoffNotMet;
else if ((Status.login == MASTER_PASSWORD_LOCKED) &&
else if ((this.status.login == MASTER_PASSWORD_LOCKED) &&
Utils.mpLocked())
reason = kSyncMasterPasswordLocked;
else if (Svc.Prefs.get("firstSync") == "notReady")

Просмотреть файл

@ -9,7 +9,6 @@ const {utils: Cu} = Components;
Cu.import("resource://services-common/log4moz.js");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/policies.js");
Cu.import("resource://services-sync/status.js");
Cu.import("resource://services-sync/util.js");
/**
@ -43,7 +42,7 @@ ClusterManager.prototype = {
let node = res.get();
switch (node.status) {
case 400:
Status.login = LOGIN_FAILED_LOGIN_REJECTED;
this.service.status.login = LOGIN_FAILED_LOGIN_REJECTED;
fail = "Find cluster denied: " + this.service.errorHandler.errorStr(node);
break;
case 404:
@ -63,7 +62,7 @@ ClusterManager.prototype = {
}
} catch (e) {
this._log.debug("Network error on findCluster");
Status.login = LOGIN_FAILED_NETWORK_ERROR;
this.service.status.login = LOGIN_FAILED_NETWORK_ERROR;
this.service.errorHandler.checkServerError(e);
fail = e;
}

Просмотреть файл

@ -14,7 +14,6 @@ Cu.import("resource://services-common/log4moz.js");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/engines.js");
Cu.import("resource://services-sync/policies.js");
Cu.import("resource://services-sync/status.js");
Cu.import("resource://services-sync/util.js");
/**
@ -39,13 +38,13 @@ EngineSynchronizer.prototype = {
let startTime = Date.now();
Status.resetSync();
this.service.status.resetSync();
// Make sure we should sync or record why we shouldn't.
let reason = this.service._checkSync();
if (reason) {
if (reason == kSyncNetworkOffline) {
Status.sync = LOGIN_FAILED_NETWORK_ERROR;
this.service.status.sync = LOGIN_FAILED_NETWORK_ERROR;
}
// this is a purposeful abort rather than a failure, so don't set
@ -57,7 +56,7 @@ EngineSynchronizer.prototype = {
// If we don't have a node, get one. If that fails, retry in 10 minutes.
if (!this.service.clusterURL && !this.service._clusterManager.setCluster()) {
Status.sync = NO_SYNC_NODE_FOUND;
this.service.status.sync = NO_SYNC_NODE_FOUND;
this._log.info("No cluster URL found. Cannot sync.");
this.onComplete(null);
return;
@ -111,7 +110,7 @@ EngineSynchronizer.prototype = {
if (this.service.clientsEngine.localCommands) {
try {
if (!(this.service.clientsEngine.processIncomingCommands())) {
Status.sync = ABORT_SYNC_COMMAND;
this.service.status.sync = ABORT_SYNC_COMMAND;
this.onComplete(new Error("Processed command aborted sync."));
return;
}
@ -145,7 +144,7 @@ EngineSynchronizer.prototype = {
try {
for each (let engine in this.service.engineManager.getEnabled()) {
// If there's any problems with syncing the engine, report the failure
if (!(this._syncEngine(engine)) || Status.enforceBackoff) {
if (!(this._syncEngine(engine)) || this.service.status.enforceBackoff) {
this._log.info("Aborting sync for failure in " + engine.name);
break;
}
@ -170,9 +169,9 @@ EngineSynchronizer.prototype = {
}
// If there were no sync engine failures
if (Status.service != SYNC_FAILED_PARTIAL) {
if (this.service.status.service != SYNC_FAILED_PARTIAL) {
Svc.Prefs.set("lastSync", new Date().toString());
Status.sync = SYNC_SUCCEEDED;
this.service.status.sync = SYNC_SUCCEEDED;
}
} finally {
Svc.Prefs.reset("firstSync");

Просмотреть файл

@ -3,7 +3,6 @@
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/status.js");
Cu.import("resource://services-sync/util.js");
function test_urls() {

Просмотреть файл

@ -7,7 +7,6 @@ Cu.import("resource://services-sync/keys.js");
Cu.import("resource://services-sync/engines/tabs.js");
Cu.import("resource://services-sync/engines.js");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/status.js");
Cu.import("resource://services-sync/util.js");
Service.engineManager.register(TabEngine);
@ -62,7 +61,7 @@ add_test(function v4_upgrade() {
getBrowserState: function () JSON.stringify(myTabs)
};
Status.resetSync();
Service.status.resetSync();
_("Logging in.");
Service.serverURL = TEST_SERVER_URL;
@ -85,7 +84,7 @@ add_test(function v4_upgrade() {
}
catch (ex) {
}
do_check_eq(Status.sync, VERSION_OUT_OF_DATE);
do_check_eq(Service.status.sync, VERSION_OUT_OF_DATE);
}
// See what happens when we bump the storage version.
@ -235,7 +234,7 @@ add_test(function v5_upgrade() {
getBrowserState: function () JSON.stringify(myTabs)
};
Status.resetSync();
Service.status.resetSync();
setBasicCredentials("johndoe", "ilovejane", passphrase);
Service.serverURL = TEST_SERVER_URL;
@ -279,9 +278,9 @@ add_test(function v5_upgrade() {
catch (e) {
_("Exception: " + e);
}
_("Status: " + Status);
_("Status: " + Service.status);
do_check_false(Service.isLoggedIn);
do_check_eq(VERSION_OUT_OF_DATE, Status.sync);
do_check_eq(VERSION_OUT_OF_DATE, Service.status.sync);
// Clean up.
Service.startOver();

Просмотреть файл

@ -1,9 +1,11 @@
Cu.import("resource://services-sync/constants.js");
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
Cu.import("resource://services-common/log4moz.js");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/status.js");
Cu.import("resource://services-sync/util.js");
Cu.import("resource://services-sync/policies.js");
Cu.import("resource://services-sync/util.js");
function login_handling(handler) {
return function (request, response) {
@ -31,7 +33,7 @@ add_test(function test_offline() {
_("The right bits are set when we're offline.");
Services.io.offline = true;
do_check_false(!!Service.login());
do_check_eq(Status.login, LOGIN_FAILED_NETWORK_ERROR);
do_check_eq(Service.status.login, LOGIN_FAILED_NETWORK_ERROR);
Services.io.offline = false;
} finally {
Svc.Prefs.resetBranch("");
@ -69,41 +71,41 @@ add_test(function test_login_logout() {
try {
_("Force the initial state.");
Status.service = STATUS_OK;
do_check_eq(Status.service, STATUS_OK);
Service.status.service = STATUS_OK;
do_check_eq(Service.status.service, STATUS_OK);
_("Try logging in. It won't work because we're not configured yet.");
Service.login();
do_check_eq(Status.service, CLIENT_NOT_CONFIGURED);
do_check_eq(Status.login, LOGIN_FAILED_NO_USERNAME);
do_check_eq(Service.status.service, CLIENT_NOT_CONFIGURED);
do_check_eq(Service.status.login, LOGIN_FAILED_NO_USERNAME);
do_check_false(Service.isLoggedIn);
_("Try again with username and password set.");
Service.identity.account = "johndoe";
Service.identity.basicPassword = "ilovejane";
Service.login();
do_check_eq(Status.service, CLIENT_NOT_CONFIGURED);
do_check_eq(Status.login, LOGIN_FAILED_NO_PASSPHRASE);
do_check_eq(Service.status.service, CLIENT_NOT_CONFIGURED);
do_check_eq(Service.status.login, LOGIN_FAILED_NO_PASSPHRASE);
do_check_false(Service.isLoggedIn);
_("Success if passphrase is set.");
Service.identity.syncKey = "foo";
Service.login();
do_check_eq(Status.service, STATUS_OK);
do_check_eq(Status.login, LOGIN_SUCCEEDED);
do_check_eq(Service.status.service, STATUS_OK);
do_check_eq(Service.status.login, LOGIN_SUCCEEDED);
do_check_true(Service.isLoggedIn);
_("We can also pass username, password and passphrase to login().");
Service.login("janedoe", "incorrectpassword", "bar");
setBasicCredentials("janedoe", "incorrectpassword", "bar");
do_check_eq(Status.service, LOGIN_FAILED);
do_check_eq(Status.login, LOGIN_FAILED_LOGIN_REJECTED);
do_check_eq(Service.status.service, LOGIN_FAILED);
do_check_eq(Service.status.login, LOGIN_FAILED_LOGIN_REJECTED);
do_check_false(Service.isLoggedIn);
_("Try again with correct password.");
Service.login("janedoe", "ilovejohn");
do_check_eq(Status.service, STATUS_OK);
do_check_eq(Status.login, LOGIN_SUCCEEDED);
do_check_eq(Service.status.service, STATUS_OK);
do_check_eq(Service.status.login, LOGIN_SUCCEEDED);
do_check_true(Service.isLoggedIn);
_("Calling login() with parameters when the client is unconfigured sends notification.");
@ -114,8 +116,8 @@ add_test(function test_login_logout() {
setBasicCredentials(null, null, null);
Service.login("janedoe", "ilovejohn", "bar");
do_check_true(notified);
do_check_eq(Status.service, STATUS_OK);
do_check_eq(Status.login, LOGIN_SUCCEEDED);
do_check_eq(Service.status.service, STATUS_OK);
do_check_eq(Service.status.login, LOGIN_SUCCEEDED);
do_check_true(Service.isLoggedIn);
_("Logout.");
@ -142,7 +144,7 @@ add_test(function test_login_on_sync() {
let loginCalled = false;
Service.login = function() {
loginCalled = true;
Status.login = LOGIN_SUCCEEDED;
Service.status.login = LOGIN_SUCCEEDED;
this._loggedIn = false; // So that sync aborts.
return true;
};
@ -216,8 +218,8 @@ add_test(function test_login_on_sync() {
_("If master password is canceled, login fails and we report lockage.");
do_check_false(!!Service.login());
do_check_eq(Status.login, MASTER_PASSWORD_LOCKED);
do_check_eq(Status.service, LOGIN_FAILED);
do_check_eq(Service.status.login, MASTER_PASSWORD_LOCKED);
do_check_eq(Service.status.service, LOGIN_FAILED);
_("Locked? " + Utils.mpLocked());
_("checkSync reports the correct term.");
do_check_eq(Service._checkSync(), kSyncMasterPasswordLocked);

Просмотреть файл

@ -4,7 +4,6 @@
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/engines.js");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/status.js");
Cu.import("resource://services-sync/util.js");
function BlaEngine() {
@ -32,13 +31,13 @@ add_test(function test_resetLocalData() {
// Set up.
setBasicCredentials("foobar", "blablabla", // Law Blog
"abcdeabcdeabcdeabcdeabcdea");
Status.enforceBackoff = true;
Status.backoffInterval = 42;
Status.minimumNextSync = 23;
Service.status.enforceBackoff = true;
Service.status.backoffInterval = 42;
Service.status.minimumNextSync = 23;
Service.persistLogin();
// Verify set up.
do_check_eq(Status.checkSetup(), STATUS_OK);
do_check_eq(Service.status.checkSetup(), STATUS_OK);
// Verify state that the observer sees.
let observerCalled = false;
@ -46,7 +45,7 @@ add_test(function test_resetLocalData() {
Svc.Obs.remove("weave:service:start-over", onStartOver);
observerCalled = true;
do_check_eq(Status.service, CLIENT_NOT_CONFIGURED);
do_check_eq(Service.status.service, CLIENT_NOT_CONFIGURED);
});
Service.startOver();
@ -57,10 +56,10 @@ add_test(function test_resetLocalData() {
do_check_eq(Service.identity.basicPassword, null);
do_check_eq(Service.identity.syncKey, null);
do_check_eq(Status.service, CLIENT_NOT_CONFIGURED);
do_check_false(Status.enforceBackoff);
do_check_eq(Status.backoffInterval, 0);
do_check_eq(Status.minimumNextSync, 0);
do_check_eq(Service.status.service, CLIENT_NOT_CONFIGURED);
do_check_false(Service.status.enforceBackoff);
do_check_eq(Service.status.backoffInterval, 0);
do_check_eq(Service.status.minimumNextSync, 0);
run_next_test();
});

Просмотреть файл

@ -3,7 +3,6 @@
Cu.import("resource://services-common/observers.js");
Cu.import("resource://services-sync/engines.js");
Cu.import("resource://services-sync/status.js");
Cu.import("resource://services-sync/util.js");
Svc.Prefs.set("registerEngines", "Tab,Bookmarks,Form,History");
@ -30,9 +29,9 @@ function run_test() {
_("Observers are notified of startup");
do_test_pending();
do_check_false(Status.ready);
do_check_false(Service.status.ready);
Observers.add("weave:service:ready", function (subject, data) {
do_check_true(Status.ready);
do_check_true(Service.status.ready);
// Clean up.
Svc.Prefs.resetBranch("");

Просмотреть файл

@ -4,7 +4,6 @@
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/policies.js");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/status.js");
Cu.import("resource://services-sync/util.js");
function login_handling(handler) {
@ -51,7 +50,7 @@ function run_test() {
_("Initial state: We're successfully logged in.");
Service.login();
do_check_true(Service.isLoggedIn);
do_check_eq(Status.login, LOGIN_SUCCEEDED);
do_check_eq(Service.status.login, LOGIN_SUCCEEDED);
_("Simulate having changed the password somewhere else.");
Service.identity.basicPassword = "ilovejosephine";
@ -75,7 +74,7 @@ function run_test() {
Service.sync();
} catch (ex) {
}
do_check_eq(Status.login, LOGIN_FAILED_LOGIN_REJECTED);
do_check_eq(Service.status.login, LOGIN_FAILED_LOGIN_REJECTED);
} finally {
Svc.Prefs.resetBranch("");

Просмотреть файл

@ -5,7 +5,6 @@ Cu.import("resource://services-common/log4moz.js");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/keys.js");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/status.js");
Cu.import("resource://services-sync/util.js");
function run_test() {
@ -69,8 +68,8 @@ function run_test() {
_("Checking Status.sync with no credentials.");
Service.verifyAndFetchSymmetricKeys();
do_check_eq(Status.sync, CREDENTIALS_CHANGED);
do_check_eq(Status.login, LOGIN_FAILED_NO_PASSPHRASE);
do_check_eq(Service.status.sync, CREDENTIALS_CHANGED);
do_check_eq(Service.status.login, LOGIN_FAILED_NO_PASSPHRASE);
_("Log in with an old secret phrase, is upgraded to Sync Key.");
Service.login("johndoe", "ilovejane", "my old secret phrase!!1!");
@ -126,8 +125,8 @@ function run_test() {
let pp = Service.identity.syncKey;
Service.identity.syncKey = "notvalid";
do_check_false(Service.verifyAndFetchSymmetricKeys());
do_check_eq(Status.sync, CREDENTIALS_CHANGED);
do_check_eq(Status.login, LOGIN_FAILED_INVALID_PASSPHRASE);
do_check_eq(Service.status.sync, CREDENTIALS_CHANGED);
do_check_eq(Service.status.login, LOGIN_FAILED_INVALID_PASSPHRASE);
Service.identity.syncKey = pp;
do_check_true(Service.verifyAndFetchSymmetricKeys());
@ -159,7 +158,7 @@ function run_test() {
keys.upload(Service.resource(Service.cryptoKeysURL));
do_check_false(Service.verifyAndFetchSymmetricKeys());
do_check_eq(Status.login, LOGIN_FAILED_INVALID_PASSPHRASE);
do_check_eq(Service.status.login, LOGIN_FAILED_INVALID_PASSPHRASE);
} finally {
Svc.Prefs.resetBranch("");

Просмотреть файл

@ -6,7 +6,6 @@ Cu.import("resource://services-sync/engines.js");
Cu.import("resource://services-sync/engines/clients.js");
Cu.import("resource://services-sync/record.js");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/status.js");
Cu.import("resource://services-sync/util.js");
initTestLogging();
@ -221,7 +220,7 @@ add_test(function test_disabledLocally_wipe503() {
Svc.Obs.add("weave:ui:sync:error", function onSyncError() {
Svc.Obs.remove("weave:ui:sync:error", onSyncError);
do_check_eq(Status.sync, SERVER_MAINTENANCE);
do_check_eq(Service.status.sync, SERVER_MAINTENANCE);
Service.startOver();
server.stop(run_next_test);

Просмотреть файл

@ -4,7 +4,6 @@
Cu.import("resource://services-common/log4moz.js");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/status.js");
Cu.import("resource://services-sync/util.js");
function login_handling(handler) {
@ -50,61 +49,61 @@ function run_test() {
Service.serverURL = TEST_SERVER_URL;
_("Force the initial state.");
Status.service = STATUS_OK;
do_check_eq(Status.service, STATUS_OK);
Service.status.service = STATUS_OK;
do_check_eq(Service.status.service, STATUS_OK);
_("Credentials won't check out because we're not configured yet.");
Status.resetSync();
Service.status.resetSync();
do_check_false(Service.verifyLogin());
do_check_eq(Status.service, CLIENT_NOT_CONFIGURED);
do_check_eq(Status.login, LOGIN_FAILED_NO_USERNAME);
do_check_eq(Service.status.service, CLIENT_NOT_CONFIGURED);
do_check_eq(Service.status.login, LOGIN_FAILED_NO_USERNAME);
_("Try again with username and password set.");
Status.resetSync();
Service.status.resetSync();
setBasicCredentials("johndoe", "ilovejane", null);
do_check_false(Service.verifyLogin());
do_check_eq(Status.service, CLIENT_NOT_CONFIGURED);
do_check_eq(Status.login, LOGIN_FAILED_NO_PASSPHRASE);
do_check_eq(Service.status.service, CLIENT_NOT_CONFIGURED);
do_check_eq(Service.status.login, LOGIN_FAILED_NO_PASSPHRASE);
_("verifyLogin() has found out the user's cluster URL, though.");
do_check_eq(Service.clusterURL, "http://localhost:8080/api/");
_("Success if passphrase is set.");
Status.resetSync();
Service.status.resetSync();
Service.identity.syncKey = "foo";
do_check_true(Service.verifyLogin());
do_check_eq(Status.service, STATUS_OK);
do_check_eq(Status.login, LOGIN_SUCCEEDED);
do_check_eq(Service.status.service, STATUS_OK);
do_check_eq(Service.status.login, LOGIN_SUCCEEDED);
_("If verifyLogin() encounters a server error, it flips on the backoff flag and notifies observers on a 503 with Retry-After.");
Status.resetSync();
Service.status.resetSync();
Service.identity.account = "janedoe";
Service._updateCachedURLs();
do_check_false(Status.enforceBackoff);
do_check_false(Service.status.enforceBackoff);
let backoffInterval;
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
Svc.Obs.remove("weave:service:backoff:interval", observe);
backoffInterval = subject;
});
do_check_false(Service.verifyLogin());
do_check_true(Status.enforceBackoff);
do_check_true(Service.status.enforceBackoff);
do_check_eq(backoffInterval, 42);
do_check_eq(Status.service, LOGIN_FAILED);
do_check_eq(Status.login, SERVER_MAINTENANCE);
do_check_eq(Service.status.service, LOGIN_FAILED);
do_check_eq(Service.status.login, SERVER_MAINTENANCE);
_("Ensure a network error when finding the cluster sets the right Status bits.");
Status.resetSync();
Service.status.resetSync();
Service.serverURL = "http://localhost:12345/";
do_check_false(Service.verifyLogin());
do_check_eq(Status.service, LOGIN_FAILED);
do_check_eq(Status.login, LOGIN_FAILED_NETWORK_ERROR);
do_check_eq(Service.status.service, LOGIN_FAILED);
do_check_eq(Service.status.login, LOGIN_FAILED_NETWORK_ERROR);
_("Ensure a network error when getting the collection info sets the right Status bits.");
Status.resetSync();
Service.status.resetSync();
Service.clusterURL = "http://localhost:12345/";
do_check_false(Service.verifyLogin());
do_check_eq(Status.service, LOGIN_FAILED);
do_check_eq(Status.login, LOGIN_FAILED_NETWORK_ERROR);
do_check_eq(Service.status.service, LOGIN_FAILED);
do_check_eq(Service.status.login, LOGIN_FAILED_NETWORK_ERROR);
} finally {
Svc.Prefs.resetBranch("");