1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/services/sync/tests/unit/test_fxa_startOver.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,63 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +Cu.import("resource://testing-common/services/sync/utils.js"); 1.8 +Cu.import("resource://services-sync/identity.js"); 1.9 +Cu.import("resource://services-sync/browserid_identity.js"); 1.10 +Cu.import("resource://services-sync/service.js"); 1.11 + 1.12 +function run_test() { 1.13 + initTestLogging("Trace"); 1.14 + run_next_test(); 1.15 +} 1.16 + 1.17 +add_task(function* test_startover() { 1.18 + let oldValue = Services.prefs.getBoolPref("services.sync-testing.startOverKeepIdentity", true); 1.19 + Services.prefs.setBoolPref("services.sync-testing.startOverKeepIdentity", false); 1.20 + 1.21 + ensureLegacyIdentityManager(); 1.22 + yield configureIdentity({username: "johndoe"}); 1.23 + 1.24 + // The boolean flag on the xpcom service should reflect a legacy provider. 1.25 + let xps = Cc["@mozilla.org/weave/service;1"] 1.26 + .getService(Components.interfaces.nsISupports) 1.27 + .wrappedJSObject; 1.28 + do_check_false(xps.fxAccountsEnabled); 1.29 + 1.30 + // we expect the "legacy" provider (but can't instanceof that, as BrowserIDManager 1.31 + // extends it) 1.32 + do_check_false(Service.identity instanceof BrowserIDManager); 1.33 + 1.34 + Service.serverURL = "https://localhost/"; 1.35 + Service.clusterURL = Service.serverURL; 1.36 + 1.37 + Service.login(); 1.38 + // We should have a cluster URL 1.39 + do_check_true(Service.clusterURL.length > 0); 1.40 + 1.41 + // remember some stuff so we can reset it after. 1.42 + let oldIdentity = Service.identity; 1.43 + let oldClusterManager = Service._clusterManager; 1.44 + let deferred = Promise.defer(); 1.45 + Services.obs.addObserver(function observeStartOverFinished() { 1.46 + Services.obs.removeObserver(observeStartOverFinished, "weave:service:start-over:finish"); 1.47 + deferred.resolve(); 1.48 + }, "weave:service:start-over:finish", false); 1.49 + 1.50 + Service.startOver(); 1.51 + yield deferred.promise; // wait for the observer to fire. 1.52 + 1.53 + // the xpcom service should indicate FxA is enabled. 1.54 + do_check_true(xps.fxAccountsEnabled); 1.55 + // should have swapped identities. 1.56 + do_check_true(Service.identity instanceof BrowserIDManager); 1.57 + // should have clobbered the cluster URL 1.58 + do_check_eq(Service.clusterURL, ""); 1.59 + 1.60 + // we should have thrown away the old identity provider and cluster manager. 1.61 + do_check_neq(oldIdentity, Service.identity); 1.62 + do_check_neq(oldClusterManager, Service._clusterManager); 1.63 + 1.64 + // reset the world. 1.65 + Services.prefs.setBoolPref("services.sync-testing.startOverKeepIdentity", oldValue); 1.66 +});