michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: Cu.import("resource://testing-common/services/sync/utils.js"); michael@0: Cu.import("resource://services-sync/identity.js"); michael@0: Cu.import("resource://services-sync/browserid_identity.js"); michael@0: Cu.import("resource://services-sync/service.js"); michael@0: michael@0: function run_test() { michael@0: initTestLogging("Trace"); michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function* test_startover() { michael@0: let oldValue = Services.prefs.getBoolPref("services.sync-testing.startOverKeepIdentity", true); michael@0: Services.prefs.setBoolPref("services.sync-testing.startOverKeepIdentity", false); michael@0: michael@0: ensureLegacyIdentityManager(); michael@0: yield configureIdentity({username: "johndoe"}); michael@0: michael@0: // The boolean flag on the xpcom service should reflect a legacy provider. michael@0: let xps = Cc["@mozilla.org/weave/service;1"] michael@0: .getService(Components.interfaces.nsISupports) michael@0: .wrappedJSObject; michael@0: do_check_false(xps.fxAccountsEnabled); michael@0: michael@0: // we expect the "legacy" provider (but can't instanceof that, as BrowserIDManager michael@0: // extends it) michael@0: do_check_false(Service.identity instanceof BrowserIDManager); michael@0: michael@0: Service.serverURL = "https://localhost/"; michael@0: Service.clusterURL = Service.serverURL; michael@0: michael@0: Service.login(); michael@0: // We should have a cluster URL michael@0: do_check_true(Service.clusterURL.length > 0); michael@0: michael@0: // remember some stuff so we can reset it after. michael@0: let oldIdentity = Service.identity; michael@0: let oldClusterManager = Service._clusterManager; michael@0: let deferred = Promise.defer(); michael@0: Services.obs.addObserver(function observeStartOverFinished() { michael@0: Services.obs.removeObserver(observeStartOverFinished, "weave:service:start-over:finish"); michael@0: deferred.resolve(); michael@0: }, "weave:service:start-over:finish", false); michael@0: michael@0: Service.startOver(); michael@0: yield deferred.promise; // wait for the observer to fire. michael@0: michael@0: // the xpcom service should indicate FxA is enabled. michael@0: do_check_true(xps.fxAccountsEnabled); michael@0: // should have swapped identities. michael@0: do_check_true(Service.identity instanceof BrowserIDManager); michael@0: // should have clobbered the cluster URL michael@0: do_check_eq(Service.clusterURL, ""); michael@0: michael@0: // we should have thrown away the old identity provider and cluster manager. michael@0: do_check_neq(oldIdentity, Service.identity); michael@0: do_check_neq(oldClusterManager, Service._clusterManager); michael@0: michael@0: // reset the world. michael@0: Services.prefs.setBoolPref("services.sync-testing.startOverKeepIdentity", oldValue); michael@0: });