|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 Cu.import("resource://testing-common/services/sync/utils.js"); |
|
5 Cu.import("resource://services-sync/identity.js"); |
|
6 Cu.import("resource://services-sync/browserid_identity.js"); |
|
7 Cu.import("resource://services-sync/service.js"); |
|
8 |
|
9 function run_test() { |
|
10 initTestLogging("Trace"); |
|
11 run_next_test(); |
|
12 } |
|
13 |
|
14 add_task(function* test_startover() { |
|
15 let oldValue = Services.prefs.getBoolPref("services.sync-testing.startOverKeepIdentity", true); |
|
16 Services.prefs.setBoolPref("services.sync-testing.startOverKeepIdentity", false); |
|
17 |
|
18 ensureLegacyIdentityManager(); |
|
19 yield configureIdentity({username: "johndoe"}); |
|
20 |
|
21 // The boolean flag on the xpcom service should reflect a legacy provider. |
|
22 let xps = Cc["@mozilla.org/weave/service;1"] |
|
23 .getService(Components.interfaces.nsISupports) |
|
24 .wrappedJSObject; |
|
25 do_check_false(xps.fxAccountsEnabled); |
|
26 |
|
27 // we expect the "legacy" provider (but can't instanceof that, as BrowserIDManager |
|
28 // extends it) |
|
29 do_check_false(Service.identity instanceof BrowserIDManager); |
|
30 |
|
31 Service.serverURL = "https://localhost/"; |
|
32 Service.clusterURL = Service.serverURL; |
|
33 |
|
34 Service.login(); |
|
35 // We should have a cluster URL |
|
36 do_check_true(Service.clusterURL.length > 0); |
|
37 |
|
38 // remember some stuff so we can reset it after. |
|
39 let oldIdentity = Service.identity; |
|
40 let oldClusterManager = Service._clusterManager; |
|
41 let deferred = Promise.defer(); |
|
42 Services.obs.addObserver(function observeStartOverFinished() { |
|
43 Services.obs.removeObserver(observeStartOverFinished, "weave:service:start-over:finish"); |
|
44 deferred.resolve(); |
|
45 }, "weave:service:start-over:finish", false); |
|
46 |
|
47 Service.startOver(); |
|
48 yield deferred.promise; // wait for the observer to fire. |
|
49 |
|
50 // the xpcom service should indicate FxA is enabled. |
|
51 do_check_true(xps.fxAccountsEnabled); |
|
52 // should have swapped identities. |
|
53 do_check_true(Service.identity instanceof BrowserIDManager); |
|
54 // should have clobbered the cluster URL |
|
55 do_check_eq(Service.clusterURL, ""); |
|
56 |
|
57 // we should have thrown away the old identity provider and cluster manager. |
|
58 do_check_neq(oldIdentity, Service.identity); |
|
59 do_check_neq(oldClusterManager, Service._clusterManager); |
|
60 |
|
61 // reset the world. |
|
62 Services.prefs.setBoolPref("services.sync-testing.startOverKeepIdentity", oldValue); |
|
63 }); |