test_service_startOver.js (2701B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 const { Service } = ChromeUtils.importESModule( 5 "resource://services-sync/service.sys.mjs" 6 ); 7 8 function BlaEngine() { 9 SyncEngine.call(this, "Bla", Service); 10 } 11 BlaEngine.prototype = { 12 removed: false, 13 async removeClientData() { 14 this.removed = true; 15 }, 16 }; 17 Object.setPrototypeOf(BlaEngine.prototype, SyncEngine.prototype); 18 19 add_task(async function setup() { 20 await Service.engineManager.register(BlaEngine); 21 }); 22 23 add_task(async function test_resetLocalData() { 24 await configureIdentity(); 25 Service.status.enforceBackoff = true; 26 Service.status.backoffInterval = 42; 27 Service.status.minimumNextSync = 23; 28 29 // Verify set up. 30 Assert.equal(Service.status.checkSetup(), STATUS_OK); 31 32 // Verify state that the observer sees. 33 let observerCalled = false; 34 Svc.Obs.add("weave:service:start-over", function onStartOver() { 35 Svc.Obs.remove("weave:service:start-over", onStartOver); 36 observerCalled = true; 37 38 Assert.equal(Service.status.service, CLIENT_NOT_CONFIGURED); 39 }); 40 41 await Service.startOver(); 42 Assert.ok(observerCalled); 43 44 // Verify the site was nuked from orbit. 45 Assert.equal( 46 Svc.PrefBranch.getPrefType("username"), 47 Ci.nsIPrefBranch.PREF_INVALID 48 ); 49 50 Assert.equal(Service.status.service, CLIENT_NOT_CONFIGURED); 51 Assert.ok(!Service.status.enforceBackoff); 52 Assert.equal(Service.status.backoffInterval, 0); 53 Assert.equal(Service.status.minimumNextSync, 0); 54 }); 55 56 add_task(async function test_removeClientData() { 57 let engine = Service.engineManager.get("bla"); 58 59 // No cluster URL = no removal. 60 Assert.ok(!engine.removed); 61 await Service.startOver(); 62 Assert.ok(!engine.removed); 63 64 Service.clusterURL = "https://localhost/"; 65 66 Assert.ok(!engine.removed); 67 await Service.startOver(); 68 Assert.ok(engine.removed); 69 }); 70 71 add_task(async function test_reset_SyncScheduler() { 72 // Some non-default values for SyncScheduler's attributes. 73 Service.scheduler.idle = true; 74 Service.scheduler.hasIncomingItems = true; 75 Svc.PrefBranch.setIntPref("clients.devices.desktop", 42); 76 Service.scheduler.nextSync = Date.now(); 77 Service.scheduler.syncThreshold = MULTI_DEVICE_THRESHOLD; 78 Service.scheduler.syncInterval = Service.scheduler.activeInterval; 79 80 await Service.startOver(); 81 82 Assert.ok(!Service.scheduler.idle); 83 Assert.ok(!Service.scheduler.hasIncomingItems); 84 Assert.equal(Service.scheduler.numClients, 0); 85 Assert.equal(Service.scheduler.nextSync, 0); 86 Assert.equal(Service.scheduler.syncThreshold, SINGLE_USER_THRESHOLD); 87 Assert.equal( 88 Service.scheduler.syncInterval, 89 Service.scheduler.singleDeviceInterval 90 ); 91 });