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
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
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");
9 function run_test() {
10 initTestLogging("Trace");
11 run_next_test();
12 }
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);
18 ensureLegacyIdentityManager();
19 yield configureIdentity({username: "johndoe"});
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);
27 // we expect the "legacy" provider (but can't instanceof that, as BrowserIDManager
28 // extends it)
29 do_check_false(Service.identity instanceof BrowserIDManager);
31 Service.serverURL = "https://localhost/";
32 Service.clusterURL = Service.serverURL;
34 Service.login();
35 // We should have a cluster URL
36 do_check_true(Service.clusterURL.length > 0);
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);
47 Service.startOver();
48 yield deferred.promise; // wait for the observer to fire.
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, "");
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);
61 // reset the world.
62 Services.prefs.setBoolPref("services.sync-testing.startOverKeepIdentity", oldValue);
63 });