Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | Cu.import("resource://services-sync/constants.js"); |
michael@0 | 5 | Cu.import("resource://services-sync/engines.js"); |
michael@0 | 6 | Cu.import("resource://services-sync/service.js"); |
michael@0 | 7 | Cu.import("resource://services-sync/util.js"); |
michael@0 | 8 | Cu.import("resource://testing-common/services/sync/utils.js"); |
michael@0 | 9 | |
michael@0 | 10 | function BlaEngine() { |
michael@0 | 11 | SyncEngine.call(this, "Bla", Service); |
michael@0 | 12 | } |
michael@0 | 13 | BlaEngine.prototype = { |
michael@0 | 14 | __proto__: SyncEngine.prototype, |
michael@0 | 15 | |
michael@0 | 16 | removed: false, |
michael@0 | 17 | removeClientData: function() { |
michael@0 | 18 | this.removed = true; |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | }; |
michael@0 | 22 | |
michael@0 | 23 | Service.engineManager.register(BlaEngine); |
michael@0 | 24 | |
michael@0 | 25 | |
michael@0 | 26 | function run_test() { |
michael@0 | 27 | initTestLogging("Trace"); |
michael@0 | 28 | run_next_test(); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | add_identity_test(this, function test_resetLocalData() { |
michael@0 | 32 | yield configureIdentity(); |
michael@0 | 33 | Service.status.enforceBackoff = true; |
michael@0 | 34 | Service.status.backoffInterval = 42; |
michael@0 | 35 | Service.status.minimumNextSync = 23; |
michael@0 | 36 | Service.persistLogin(); |
michael@0 | 37 | |
michael@0 | 38 | // Verify set up. |
michael@0 | 39 | do_check_eq(Service.status.checkSetup(), STATUS_OK); |
michael@0 | 40 | |
michael@0 | 41 | // Verify state that the observer sees. |
michael@0 | 42 | let observerCalled = false; |
michael@0 | 43 | Svc.Obs.add("weave:service:start-over", function onStartOver() { |
michael@0 | 44 | Svc.Obs.remove("weave:service:start-over", onStartOver); |
michael@0 | 45 | observerCalled = true; |
michael@0 | 46 | |
michael@0 | 47 | do_check_eq(Service.status.service, CLIENT_NOT_CONFIGURED); |
michael@0 | 48 | }); |
michael@0 | 49 | |
michael@0 | 50 | Service.startOver(); |
michael@0 | 51 | do_check_true(observerCalled); |
michael@0 | 52 | |
michael@0 | 53 | // Verify the site was nuked from orbit. |
michael@0 | 54 | do_check_eq(Svc.Prefs.get("username"), undefined); |
michael@0 | 55 | do_check_eq(Service.identity.basicPassword, null); |
michael@0 | 56 | do_check_eq(Service.identity.syncKey, null); |
michael@0 | 57 | |
michael@0 | 58 | do_check_eq(Service.status.service, CLIENT_NOT_CONFIGURED); |
michael@0 | 59 | do_check_false(Service.status.enforceBackoff); |
michael@0 | 60 | do_check_eq(Service.status.backoffInterval, 0); |
michael@0 | 61 | do_check_eq(Service.status.minimumNextSync, 0); |
michael@0 | 62 | }); |
michael@0 | 63 | |
michael@0 | 64 | add_test(function test_removeClientData() { |
michael@0 | 65 | let engine = Service.engineManager.get("bla"); |
michael@0 | 66 | |
michael@0 | 67 | // No cluster URL = no removal. |
michael@0 | 68 | do_check_false(engine.removed); |
michael@0 | 69 | Service.startOver(); |
michael@0 | 70 | do_check_false(engine.removed); |
michael@0 | 71 | |
michael@0 | 72 | Service.serverURL = "https://localhost/"; |
michael@0 | 73 | Service.clusterURL = Service.serverURL; |
michael@0 | 74 | |
michael@0 | 75 | do_check_false(engine.removed); |
michael@0 | 76 | Service.startOver(); |
michael@0 | 77 | do_check_true(engine.removed); |
michael@0 | 78 | |
michael@0 | 79 | run_next_test(); |
michael@0 | 80 | }); |
michael@0 | 81 | |
michael@0 | 82 | add_test(function test_reset_SyncScheduler() { |
michael@0 | 83 | // Some non-default values for SyncScheduler's attributes. |
michael@0 | 84 | Service.scheduler.idle = true; |
michael@0 | 85 | Service.scheduler.hasIncomingItems = true; |
michael@0 | 86 | Service.scheduler.numClients = 42; |
michael@0 | 87 | Service.scheduler.nextSync = Date.now(); |
michael@0 | 88 | Service.scheduler.syncThreshold = MULTI_DEVICE_THRESHOLD; |
michael@0 | 89 | Service.scheduler.syncInterval = Service.scheduler.activeInterval; |
michael@0 | 90 | |
michael@0 | 91 | Service.startOver(); |
michael@0 | 92 | |
michael@0 | 93 | do_check_false(Service.scheduler.idle); |
michael@0 | 94 | do_check_false(Service.scheduler.hasIncomingItems); |
michael@0 | 95 | do_check_eq(Service.scheduler.numClients, 0); |
michael@0 | 96 | do_check_eq(Service.scheduler.nextSync, 0); |
michael@0 | 97 | do_check_eq(Service.scheduler.syncThreshold, SINGLE_USER_THRESHOLD); |
michael@0 | 98 | do_check_eq(Service.scheduler.syncInterval, Service.scheduler.singleDeviceInterval); |
michael@0 | 99 | |
michael@0 | 100 | run_next_test(); |
michael@0 | 101 | }); |