services/sync/tests/unit/test_status.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 Cu.import("resource://services-sync/constants.js");
michael@0 2 Cu.import("resource://services-sync/status.js");
michael@0 3
michael@0 4 function run_test() {
michael@0 5
michael@0 6 // Check initial states
michael@0 7 do_check_false(Status.enforceBackoff);
michael@0 8 do_check_eq(Status.backoffInterval, 0);
michael@0 9 do_check_eq(Status.minimumNextSync, 0);
michael@0 10
michael@0 11 do_check_eq(Status.service, STATUS_OK);
michael@0 12 do_check_eq(Status.sync, SYNC_SUCCEEDED);
michael@0 13 do_check_eq(Status.login, LOGIN_SUCCEEDED);
michael@0 14 for (let name in Status.engines) {
michael@0 15 do_throw('Status.engines should be empty.');
michael@0 16 }
michael@0 17 do_check_eq(Status.partial, false);
michael@0 18
michael@0 19
michael@0 20 // Check login status
michael@0 21 for each (let code in [LOGIN_FAILED_NO_USERNAME,
michael@0 22 LOGIN_FAILED_NO_PASSWORD,
michael@0 23 LOGIN_FAILED_NO_PASSPHRASE]) {
michael@0 24 Status.login = code;
michael@0 25 do_check_eq(Status.login, code);
michael@0 26 do_check_eq(Status.service, CLIENT_NOT_CONFIGURED);
michael@0 27 Status.resetSync();
michael@0 28 }
michael@0 29
michael@0 30 Status.login = LOGIN_FAILED;
michael@0 31 do_check_eq(Status.login, LOGIN_FAILED);
michael@0 32 do_check_eq(Status.service, LOGIN_FAILED);
michael@0 33 Status.resetSync();
michael@0 34
michael@0 35 Status.login = LOGIN_SUCCEEDED;
michael@0 36 do_check_eq(Status.login, LOGIN_SUCCEEDED);
michael@0 37 do_check_eq(Status.service, STATUS_OK);
michael@0 38 Status.resetSync();
michael@0 39
michael@0 40
michael@0 41 // Check sync status
michael@0 42 Status.sync = SYNC_FAILED;
michael@0 43 do_check_eq(Status.sync, SYNC_FAILED);
michael@0 44 do_check_eq(Status.service, SYNC_FAILED);
michael@0 45
michael@0 46 Status.sync = SYNC_SUCCEEDED;
michael@0 47 do_check_eq(Status.sync, SYNC_SUCCEEDED);
michael@0 48 do_check_eq(Status.service, STATUS_OK);
michael@0 49
michael@0 50 Status.resetSync();
michael@0 51
michael@0 52
michael@0 53 // Check engine status
michael@0 54 Status.engines = ["testEng1", ENGINE_SUCCEEDED];
michael@0 55 do_check_eq(Status.engines["testEng1"], ENGINE_SUCCEEDED);
michael@0 56 do_check_eq(Status.service, STATUS_OK);
michael@0 57
michael@0 58 Status.engines = ["testEng2", ENGINE_DOWNLOAD_FAIL];
michael@0 59 do_check_eq(Status.engines["testEng1"], ENGINE_SUCCEEDED);
michael@0 60 do_check_eq(Status.engines["testEng2"], ENGINE_DOWNLOAD_FAIL);
michael@0 61 do_check_eq(Status.service, SYNC_FAILED_PARTIAL);
michael@0 62
michael@0 63 Status.engines = ["testEng3", ENGINE_SUCCEEDED];
michael@0 64 do_check_eq(Status.engines["testEng1"], ENGINE_SUCCEEDED);
michael@0 65 do_check_eq(Status.engines["testEng2"], ENGINE_DOWNLOAD_FAIL);
michael@0 66 do_check_eq(Status.engines["testEng3"], ENGINE_SUCCEEDED);
michael@0 67 do_check_eq(Status.service, SYNC_FAILED_PARTIAL);
michael@0 68
michael@0 69
michael@0 70 // Check resetSync
michael@0 71 Status.sync = SYNC_FAILED;
michael@0 72 Status.resetSync();
michael@0 73
michael@0 74 do_check_eq(Status.service, STATUS_OK);
michael@0 75 do_check_eq(Status.sync, SYNC_SUCCEEDED);
michael@0 76 for (name in Status.engines) {
michael@0 77 do_throw('Status.engines should be empty.');
michael@0 78 }
michael@0 79
michael@0 80
michael@0 81 // Check resetBackoff
michael@0 82 Status.enforceBackoff = true;
michael@0 83 Status.backOffInterval = 4815162342;
michael@0 84 Status.backOffInterval = 42;
michael@0 85 Status.resetBackoff();
michael@0 86
michael@0 87 do_check_false(Status.enforceBackoff);
michael@0 88 do_check_eq(Status.backoffInterval, 0);
michael@0 89 do_check_eq(Status.minimumNextSync, 0);
michael@0 90
michael@0 91 }

mercurial