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

mercurial