Bug 671066 - Unknown error on conclusion of easy setup of second client. r=rnewman

Part 2: Make sure we don't run into the kNotLoggedIn reason first and then ignore it. It's a useless sentinel anyway, so remove it altogether.
This commit is contained in:
Philipp von Weitershausen 2011-07-13 15:20:07 -07:00
Родитель 0a3f4b459e
Коммит c03c0646a2
6 изменённых файлов: 86 добавлений и 102 удалений

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

@ -199,7 +199,6 @@ JPAKE_ERROR_USERABORT: "jpake.error.userabort",
// Ways that a sync can be disabled (messages only to be printed in debug log)
kSyncMasterPasswordLocked: "User elected to leave Master Password locked",
kSyncWeaveDisabled: "Weave is disabled",
kSyncNotLoggedIn: "User is not logged in",
kSyncNetworkOffline: "Network is offline",
kSyncBackoffNotMet: "Trying to sync before the server said it's okay",
kFirstSyncChoiceNotMade: "User has not selected an action for first sync",

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

@ -249,16 +249,8 @@ let SyncScheduler = {
*/
checkSyncStatus: function checkSyncStatus() {
// Should we be syncing now, if not, cancel any sync timers and return
// if we're in backoff, we'll schedule the next sync
let ignore = [kSyncBackoffNotMet];
// We're ready to sync even if we're not logged in... so long as the
// master password isn't locked.
if (Utils.mpLocked()) {
ignore.push(kSyncNotLoggedIn);
ignore.push(kSyncMasterPasswordLocked);
}
// if we're in backoff, we'll schedule the next sync.
let ignore = [kSyncBackoffNotMet, kSyncMasterPasswordLocked];
let skip = Weave.Service._checkSync(ignore);
this._log.trace("_checkSync returned \"" + skip + "\".");
if (skip) {

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

@ -1066,7 +1066,7 @@ WeaveSvc.prototype = {
return;
}
let reason = this._checkSync([kSyncNotLoggedIn]);
let reason = this._checkSync();
// Can't autoconnect if we're missing these values.
if (!reason) {
@ -1392,8 +1392,6 @@ WeaveSvc.prototype = {
else if ((Status.login == MASTER_PASSWORD_LOCKED) &&
Utils.mpLocked())
reason = kSyncMasterPasswordLocked;
else if (!this._loggedIn)
reason = kSyncNotLoggedIn;
else if (Svc.Prefs.get("firstSync") == "notReady")
reason = kFirstSyncChoiceNotMade;

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

@ -55,10 +55,11 @@ function run_test() {
add_test(function test_successful_sync_adjustSyncInterval() {
_("Test successful sync calling adjustSyncInterval");
let syncSuccesses = 0;
Svc.Obs.add("weave:service:sync:finish", function onSyncFinish() {
function onSyncFinish() {
_("Sync success.");
syncSuccesses++;
});
};
Svc.Obs.add("weave:service:sync:finish", onSyncFinish);
let server = sync_httpd_setup();
setUp();
@ -145,11 +146,8 @@ add_test(function test_successful_sync_adjustSyncInterval() {
do_check_false(SyncScheduler.hasIncomingItems); //gets reset to false
do_check_eq(SyncScheduler.syncInterval, SyncScheduler.immediateInterval);
Records.clearCache();
Svc.Prefs.resetBranch("");
SyncScheduler.setDefaults();
Clients.resetClient();
Svc.Obs.remove("weave:service:sync:finish", onSyncFinish);
Service.startOver();
server.stop(run_next_test);
});
@ -157,18 +155,15 @@ add_test(function test_unsuccessful_sync_adjustSyncInterval() {
_("Test unsuccessful sync calling adjustSyncInterval");
let syncFailures = 0;
Svc.Obs.add("weave:service:sync:error", function onSyncError() {
function onSyncError() {
_("Sync error.");
syncFailures++;
});
}
Svc.Obs.add("weave:service:sync:error", onSyncError);
_("Test unsuccessful sync calls adjustSyncInterval");
let origLockedSync = Service._lockedSync;
Service._lockedSync = function () {
// Force a sync fail.
Service._loggedIn = false;
origLockedSync.call(Service);
};
// Force sync to fail.
Svc.Prefs.set("firstSync", "notReady");
let server = sync_httpd_setup();
setUp();
@ -260,12 +255,8 @@ add_test(function test_unsuccessful_sync_adjustSyncInterval() {
do_check_false(SyncScheduler.hasIncomingItems); //gets reset to false
do_check_eq(SyncScheduler.syncInterval, SyncScheduler.immediateInterval);
Records.clearCache();
Svc.Prefs.resetBranch("");
SyncScheduler.setDefaults();
Clients.resetClient();
Service._lockedSync = origLockedSync;
Service.startOver();
Svc.Obs.remove("weave:service:sync:error", onSyncError);
server.stop(run_next_test);
});
@ -290,6 +281,7 @@ add_test(function test_back_triggers_sync() {
SyncScheduler.setDefaults();
Clients.resetClient();
Service.startOver();
server.stop(run_next_test);
});

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

@ -22,6 +22,10 @@ function run_test() {
let logger = Log4Moz.repository.rootLogger;
Log4Moz.repository.rootLogger.addAppender(new Log4Moz.DumpAppender());
run_next_test();
}
add_test(function test_offline() {
try {
_("The right bits are set when we're offline.");
Services.io.offline = true;
@ -32,7 +36,13 @@ function run_test() {
Services.io.offline = false;
} finally {
Svc.Prefs.resetBranch("");
run_next_test();
}
});
function setup() {
Service.serverURL = "http://localhost:8080/";
Service.clusterURL = "http://localhost:8080/";
let janeHelper = track_collections_helper();
let janeU = janeHelper.with_updated_collection;
@ -41,8 +51,7 @@ function run_test() {
let johnU = johnHelper.with_updated_collection;
let johnColls = johnHelper.collections;
do_test_pending();
let server = httpd_setup({
return httpd_setup({
"/1.1/johndoe/info/collections": login_handling(johnHelper.handler),
"/1.1/janedoe/info/collections": login_handling(janeHelper.handler),
@ -54,11 +63,12 @@ function run_test() {
"/1.1/janedoe/storage/crypto/keys": janeU("crypto", new ServerWBO("keys").handler()),
"/1.1/janedoe/storage/meta/global": janeU("meta", new ServerWBO("global").handler())
});
}
add_test(function test_login_logout() {
let server = setup();
try {
Service.serverURL = "http://localhost:8080/";
Service.clusterURL = "http://localhost:8080/";
_("Force the initial state.");
Status.service = STATUS_OK;
do_check_eq(Status.service, STATUS_OK);
@ -121,10 +131,19 @@ function run_test() {
Service.logout();
do_check_false(Service.isLoggedIn);
/*
* Testing login-on-sync.
*/
} finally {
Svc.Prefs.resetBranch("");
server.stop(run_next_test);
}
});
add_test(function test_login_on_sync() {
let server = setup();
Service.username = "johndoe";
Service.password = "ilovejane";
Service.passphrase = "bar";
try {
_("Sync calls login.");
let oldLogin = Service.login;
let loginCalled = false;
@ -133,10 +152,9 @@ function run_test() {
Status.login = LOGIN_SUCCEEDED;
this._loggedIn = false; // So that sync aborts.
return true;
}
try {
Service.sync();
} catch (ex) {}
};
Service.sync();
do_check_true(loginCalled);
Service.login = oldLogin;
@ -153,7 +171,7 @@ function run_test() {
SyncScheduler.scheduleNextSync = function(wait) {
scheduleCalled = true;
scheduleNextSyncF.call(this, wait);
}
};
// Autoconnect still tries to connect in the background (useful behavior:
// for non-MP users and unlocked MPs, this will detect version expiry
@ -173,12 +191,11 @@ function run_test() {
SyncScheduler.checkSyncStatus();
do_check_true(scheduleCalled);
_("... and also if we're not locked.");
scheduleCalled = false;
mpLocked = false;
_("... and not if not.");
SyncScheduler.checkSyncStatus();
do_check_false(scheduleCalled);
do_check_true(scheduleCalled);
SyncScheduler.scheduleNextSync = scheduleNextSyncF;
// TODO: need better tests around master password prompting. See Bug 620583.
@ -222,6 +239,6 @@ function run_test() {
} finally {
Svc.Prefs.resetBranch("");
server.stop(do_test_finished);
server.stop(run_next_test);
}
}
});

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

@ -162,9 +162,7 @@ add_test(function test_masterpassword_locked_retry_interval() {
Service.verifyLogin = Service._verifyLogin;
SyncScheduler.scheduleAtInterval = SyncScheduler._scheduleAtInterval;
Svc.Prefs.resetBranch("");
SyncScheduler.setDefaults();
Clients.resetClient();
Service.startOver();
server.stop(run_next_test);
});
@ -204,6 +202,7 @@ add_test(function test_scheduleNextSync() {
Svc.Prefs.resetBranch("");
SyncScheduler.syncTimer.clear();
Svc.Obs.remove("weave:service:sync:finish", onSyncFinish);
Service.startOver();
server.stop(run_next_test);
}, this);
});
@ -243,12 +242,8 @@ add_test(function test_handleSyncError() {
let server = sync_httpd_setup();
setUp();
let origLockedSync = Service._lockedSync;
Service._lockedSync = function () {
// Force a sync fail.
Service._loggedIn = false;
origLockedSync.call(Service);
};
// Force sync to fail.
Svc.Prefs.set("firstSync", "notReady");
_("Ensure expected initial environment.");
do_check_eq(SyncScheduler._syncErrors, 0);
@ -298,8 +293,7 @@ add_test(function test_handleSyncError() {
do_check_true(Status.enforceBackoff);
SyncScheduler.syncTimer.clear();
Service._lockedSync = origLockedSync;
SyncScheduler.setDefaults();
Service.startOver();
server.stop(run_next_test);
});
@ -334,9 +328,7 @@ add_test(function test_client_sync_finish_updateClientMode() {
do_check_false(SyncScheduler.numClients > 1);
do_check_false(SyncScheduler.idle);
Svc.Prefs.resetBranch("");
SyncScheduler.setDefaults();
Clients.resetClient();
Service.startOver();
server.stop(run_next_test);
});
@ -344,10 +336,7 @@ add_test(function test_sync_at_startup() {
Svc.Obs.add("weave:service:sync:finish", function onSyncFinish() {
Svc.Obs.remove("weave:service:sync:finish", onSyncFinish);
Svc.Prefs.resetBranch("");
SyncScheduler.setDefaults();
Clients.resetClient();
Service.startOver();
server.stop(run_next_test);
});
@ -365,11 +354,11 @@ add_test(function test_no_autoconnect_during_wizard() {
// Simulate the Sync setup wizard.
Svc.Prefs.set("firstSync", "notReady");
// Ensure we don't actually try to sync.
function onSyncStart() {
// Ensure we don't actually try to sync (or log in for that matter).
function onLoginStart() {
do_throw("Should not get here!");
}
Svc.Obs.add("weave:service:sync:start", onSyncStart);
Svc.Obs.add("weave:service:login:start", onLoginStart);
// First wait >100ms (nsITimers can take up to that much time to fire, so
// we can account for the timer in delayedAutoconnect) and then two event
@ -381,12 +370,9 @@ add_test(function test_no_autoconnect_during_wizard() {
Utils.nextTick(wait);
return;
}
Svc.Obs.remove("weave:service:sync:start", onSyncStart);
Svc.Prefs.resetBranch("");
SyncScheduler.setDefaults();
Clients.resetClient();
Svc.Obs.remove("weave:service:login:start", onLoginStart);
Service.startOver();
server.stop(run_next_test);
}
timer = Utils.namedTimer(wait, 150, {}, "timer");