Bug 557590 - code audit and create unit test plan for status.js [r=mconnor]

Initialize status values in status.js + tests for status.js.
This commit is contained in:
Philipp von Weitershausen 2010-06-01 15:12:25 -07:00
parent ceaa8fab03
commit 912b4b6b57
3 changed files with 94 additions and 3 deletions

View File

@ -260,7 +260,6 @@ WeaveSvc.prototype = {
this._initLogs();
this._log.info("Loading Weave " + WEAVE_VERSION);
Status.service = STATUS_OK;
this.enabled = true;
this._registerEngines();
@ -333,8 +332,6 @@ WeaveSvc.prototype = {
this._log.debug("checkSetup: no passphrase set");
Status.login = LOGIN_FAILED_NO_PASSPHRASE;
}
else
Status.service = STATUS_OK;
return Status.service;
},

View File

@ -76,6 +76,9 @@ let Status = {
this.minimumNextSync = 0;
},
resetSync: function resetSync() {
this.service = STATUS_OK;
this._login = LOGIN_SUCCEEDED;
this._sync = SYNC_SUCCEEDED;
this._engines = {};
this.partial = false;
},

View File

@ -0,0 +1,91 @@
Cu.import("resource://weave/constants.js");
Cu.import("resource://weave/status.js");
function run_test() {
// Check initial states
do_check_false(Status.enforceBackoff);
do_check_eq(Status.backoffInterval, 0);
do_check_eq(Status.minimumNextSync, 0);
do_check_eq(Status.service, STATUS_OK);
do_check_eq(Status.sync, SYNC_SUCCEEDED);
do_check_eq(Status.login, LOGIN_SUCCEEDED);
for (let name in Status.engines) {
do_throw('Status.engines should be empty.');
}
do_check_eq(Status.partial, false);
// Check login status
for each (let code in [LOGIN_FAILED_NO_USERNAME,
LOGIN_FAILED_NO_PASSWORD,
LOGIN_FAILED_NO_PASSPHRASE]) {
Status.login = code;
do_check_eq(Status.login, code);
do_check_eq(Status.service, CLIENT_NOT_CONFIGURED);
Status.resetSync();
}
Status.login = LOGIN_FAILED;
do_check_eq(Status.login, LOGIN_FAILED);
do_check_eq(Status.service, LOGIN_FAILED);
Status.resetSync();
Status.login = LOGIN_SUCCEEDED;
do_check_eq(Status.login, LOGIN_SUCCEEDED);
do_check_eq(Status.service, STATUS_OK);
Status.resetSync();
// Check sync status
Status.sync = SYNC_FAILED;
do_check_eq(Status.sync, SYNC_FAILED);
do_check_eq(Status.service, SYNC_FAILED);
Status.sync = SYNC_SUCCEEDED;
do_check_eq(Status.sync, SYNC_SUCCEEDED);
do_check_eq(Status.service, STATUS_OK);
Status.resetSync();
// Check engine status
Status.engines = ["testEng1", ENGINE_SUCCEEDED];
do_check_eq(Status.engines["testEng1"], ENGINE_SUCCEEDED);
do_check_eq(Status.service, STATUS_OK);
Status.engines = ["testEng2", ENGINE_DOWNLOAD_FAIL];
do_check_eq(Status.engines["testEng1"], ENGINE_SUCCEEDED);
do_check_eq(Status.engines["testEng2"], ENGINE_DOWNLOAD_FAIL);
do_check_eq(Status.service, SYNC_FAILED_PARTIAL);
Status.engines = ["testEng3", ENGINE_SUCCEEDED];
do_check_eq(Status.engines["testEng1"], ENGINE_SUCCEEDED);
do_check_eq(Status.engines["testEng2"], ENGINE_DOWNLOAD_FAIL);
do_check_eq(Status.engines["testEng3"], ENGINE_SUCCEEDED);
do_check_eq(Status.service, SYNC_FAILED_PARTIAL);
// Check resetSync
Status.sync = SYNC_FAILED;
Status.resetSync();
do_check_eq(Status.service, STATUS_OK);
do_check_eq(Status.sync, SYNC_SUCCEEDED);
for (name in Status.engines) {
do_throw('Status.engines should be empty.');
}
// Check resetBackoff
Status.enforceBackoff = true;
Status.backOffInterval = 4815162342;
Status.backOffInterval = 42;
Status.resetBackoff();
do_check_false(Status.enforceBackoff);
do_check_eq(Status.backoffInterval, 0);
do_check_eq(Status.minimumNextSync, 0);
}