michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: let Preferences = Cu.import("resource://gre/modules/Preferences.jsm", {}).Preferences; michael@0: michael@0: let tmp = {}; michael@0: Cu.import("resource://gre/modules/FxAccounts.jsm", tmp); michael@0: Cu.import("resource://gre/modules/FxAccountsCommon.js", tmp); michael@0: Cu.import("resource://services-sync/browserid_identity.js", tmp); michael@0: let {FxAccounts, BrowserIDManager, DATA_FORMAT_VERSION, CERT_LIFETIME} = tmp; michael@0: let fxaSyncIsEnabled = Weave.Service.identity instanceof BrowserIDManager; michael@0: michael@0: add_task(function() { michael@0: yield PanelUI.show({type: "command"}); michael@0: michael@0: let historyButton = document.getElementById("history-panelmenu"); michael@0: let historySubview = document.getElementById("PanelUI-history"); michael@0: let subviewShownPromise = subviewShown(historySubview); michael@0: EventUtils.synthesizeMouseAtCenter(historyButton, {}); michael@0: yield subviewShownPromise; michael@0: michael@0: let tabsFromOtherComputers = document.getElementById("sync-tabs-menuitem2"); michael@0: is(tabsFromOtherComputers.hidden, true, "The Tabs From Other Computers menuitem should be hidden when sync isn't enabled."); michael@0: michael@0: let hiddenPanelPromise = promisePanelHidden(window); michael@0: PanelUI.hide(); michael@0: yield hiddenPanelPromise; michael@0: michael@0: // Part 2 - When Sync is enabled the menuitem should be shown. michael@0: yield configureIdentity(); michael@0: yield PanelUI.show({type: "command"}); michael@0: michael@0: subviewShownPromise = subviewShown(historySubview); michael@0: EventUtils.synthesizeMouseAtCenter(historyButton, {}); michael@0: yield subviewShownPromise; michael@0: michael@0: is(tabsFromOtherComputers.hidden, false, "The Tabs From Other Computers menuitem should be shown when sync is enabled."); michael@0: michael@0: let syncPrefBranch = new Preferences("services.sync."); michael@0: syncPrefBranch.resetBranch(""); michael@0: Services.logins.removeAllLogins(); michael@0: michael@0: hiddenPanelPromise = promisePanelHidden(window); michael@0: PanelUI.toggle({type: "command"}); michael@0: yield hiddenPanelPromise; michael@0: michael@0: if (fxaSyncIsEnabled) { michael@0: yield fxAccounts.signOut(); michael@0: } michael@0: }); michael@0: michael@0: function configureIdentity() { michael@0: // do the FxAccounts thang... michael@0: configureFxAccountIdentity(); michael@0: michael@0: if (fxaSyncIsEnabled) { michael@0: return Weave.Service.identity.initializeWithCurrentIdentity().then(() => { michael@0: // need to wait until this identity manager is readyToAuthenticate. michael@0: return Weave.Service.identity.whenReadyToAuthenticate.promise; michael@0: }); michael@0: } michael@0: michael@0: Weave.Service.createAccount("john@doe.com", "mysecretpw", michael@0: "challenge", "response"); michael@0: Weave.Service.identity.account = "john@doe.com"; michael@0: Weave.Service.identity.basicPassword = "mysecretpw"; michael@0: Weave.Service.identity.syncKey = Weave.Utils.generatePassphrase(); michael@0: Weave.Svc.Prefs.set("firstSync", "newAccount"); michael@0: Weave.Service.persistLogin(); michael@0: return Promise.resolve(); michael@0: } michael@0: michael@0: // Configure an instance of an FxAccount identity provider with the specified michael@0: // config (or the default config if not specified). michael@0: function configureFxAccountIdentity() { michael@0: let user = { michael@0: assertion: "assertion", michael@0: email: "email", michael@0: kA: "kA", michael@0: kB: "kB", michael@0: sessionToken: "sessionToken", michael@0: uid: "user_uid", michael@0: verified: true, michael@0: }; michael@0: michael@0: let token = { michael@0: endpoint: Weave.Svc.Prefs.get("tokenServerURI"), michael@0: duration: 300, michael@0: id: "id", michael@0: key: "key", michael@0: // uid will be set to the username. michael@0: }; michael@0: michael@0: let MockInternal = {}; michael@0: let mockTSC = { // TokenServerClient michael@0: getTokenFromBrowserIDAssertion: function(uri, assertion, cb) { michael@0: token.uid = "username"; michael@0: cb(null, token); michael@0: }, michael@0: }; michael@0: michael@0: let authService = Weave.Service.identity; michael@0: authService._fxaService = new FxAccounts(MockInternal); michael@0: michael@0: authService._fxaService.internal.currentAccountState.signedInUser = { michael@0: version: DATA_FORMAT_VERSION, michael@0: accountData: user michael@0: } michael@0: authService._fxaService.internal.currentAccountState.getCertificate = function(data, keyPair, mustBeValidUntil) { michael@0: this.cert = { michael@0: validUntil: authService._fxaService.internal.now() + CERT_LIFETIME, michael@0: cert: "certificate", michael@0: }; michael@0: return Promise.resolve(this.cert.cert); michael@0: }; michael@0: michael@0: authService._tokenServerClient = mockTSC; michael@0: // Set the "account" of the browserId manager to be the "email" of the michael@0: // logged in user of the mockFXA service. michael@0: authService._account = user.email; michael@0: }