browser/components/customizableui/test/browser_946320_tabs_from_other_computers.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 let Preferences = Cu.import("resource://gre/modules/Preferences.jsm", {}).Preferences;
michael@0 8
michael@0 9 let tmp = {};
michael@0 10 Cu.import("resource://gre/modules/FxAccounts.jsm", tmp);
michael@0 11 Cu.import("resource://gre/modules/FxAccountsCommon.js", tmp);
michael@0 12 Cu.import("resource://services-sync/browserid_identity.js", tmp);
michael@0 13 let {FxAccounts, BrowserIDManager, DATA_FORMAT_VERSION, CERT_LIFETIME} = tmp;
michael@0 14 let fxaSyncIsEnabled = Weave.Service.identity instanceof BrowserIDManager;
michael@0 15
michael@0 16 add_task(function() {
michael@0 17 yield PanelUI.show({type: "command"});
michael@0 18
michael@0 19 let historyButton = document.getElementById("history-panelmenu");
michael@0 20 let historySubview = document.getElementById("PanelUI-history");
michael@0 21 let subviewShownPromise = subviewShown(historySubview);
michael@0 22 EventUtils.synthesizeMouseAtCenter(historyButton, {});
michael@0 23 yield subviewShownPromise;
michael@0 24
michael@0 25 let tabsFromOtherComputers = document.getElementById("sync-tabs-menuitem2");
michael@0 26 is(tabsFromOtherComputers.hidden, true, "The Tabs From Other Computers menuitem should be hidden when sync isn't enabled.");
michael@0 27
michael@0 28 let hiddenPanelPromise = promisePanelHidden(window);
michael@0 29 PanelUI.hide();
michael@0 30 yield hiddenPanelPromise;
michael@0 31
michael@0 32 // Part 2 - When Sync is enabled the menuitem should be shown.
michael@0 33 yield configureIdentity();
michael@0 34 yield PanelUI.show({type: "command"});
michael@0 35
michael@0 36 subviewShownPromise = subviewShown(historySubview);
michael@0 37 EventUtils.synthesizeMouseAtCenter(historyButton, {});
michael@0 38 yield subviewShownPromise;
michael@0 39
michael@0 40 is(tabsFromOtherComputers.hidden, false, "The Tabs From Other Computers menuitem should be shown when sync is enabled.");
michael@0 41
michael@0 42 let syncPrefBranch = new Preferences("services.sync.");
michael@0 43 syncPrefBranch.resetBranch("");
michael@0 44 Services.logins.removeAllLogins();
michael@0 45
michael@0 46 hiddenPanelPromise = promisePanelHidden(window);
michael@0 47 PanelUI.toggle({type: "command"});
michael@0 48 yield hiddenPanelPromise;
michael@0 49
michael@0 50 if (fxaSyncIsEnabled) {
michael@0 51 yield fxAccounts.signOut();
michael@0 52 }
michael@0 53 });
michael@0 54
michael@0 55 function configureIdentity() {
michael@0 56 // do the FxAccounts thang...
michael@0 57 configureFxAccountIdentity();
michael@0 58
michael@0 59 if (fxaSyncIsEnabled) {
michael@0 60 return Weave.Service.identity.initializeWithCurrentIdentity().then(() => {
michael@0 61 // need to wait until this identity manager is readyToAuthenticate.
michael@0 62 return Weave.Service.identity.whenReadyToAuthenticate.promise;
michael@0 63 });
michael@0 64 }
michael@0 65
michael@0 66 Weave.Service.createAccount("john@doe.com", "mysecretpw",
michael@0 67 "challenge", "response");
michael@0 68 Weave.Service.identity.account = "john@doe.com";
michael@0 69 Weave.Service.identity.basicPassword = "mysecretpw";
michael@0 70 Weave.Service.identity.syncKey = Weave.Utils.generatePassphrase();
michael@0 71 Weave.Svc.Prefs.set("firstSync", "newAccount");
michael@0 72 Weave.Service.persistLogin();
michael@0 73 return Promise.resolve();
michael@0 74 }
michael@0 75
michael@0 76 // Configure an instance of an FxAccount identity provider with the specified
michael@0 77 // config (or the default config if not specified).
michael@0 78 function configureFxAccountIdentity() {
michael@0 79 let user = {
michael@0 80 assertion: "assertion",
michael@0 81 email: "email",
michael@0 82 kA: "kA",
michael@0 83 kB: "kB",
michael@0 84 sessionToken: "sessionToken",
michael@0 85 uid: "user_uid",
michael@0 86 verified: true,
michael@0 87 };
michael@0 88
michael@0 89 let token = {
michael@0 90 endpoint: Weave.Svc.Prefs.get("tokenServerURI"),
michael@0 91 duration: 300,
michael@0 92 id: "id",
michael@0 93 key: "key",
michael@0 94 // uid will be set to the username.
michael@0 95 };
michael@0 96
michael@0 97 let MockInternal = {};
michael@0 98 let mockTSC = { // TokenServerClient
michael@0 99 getTokenFromBrowserIDAssertion: function(uri, assertion, cb) {
michael@0 100 token.uid = "username";
michael@0 101 cb(null, token);
michael@0 102 },
michael@0 103 };
michael@0 104
michael@0 105 let authService = Weave.Service.identity;
michael@0 106 authService._fxaService = new FxAccounts(MockInternal);
michael@0 107
michael@0 108 authService._fxaService.internal.currentAccountState.signedInUser = {
michael@0 109 version: DATA_FORMAT_VERSION,
michael@0 110 accountData: user
michael@0 111 }
michael@0 112 authService._fxaService.internal.currentAccountState.getCertificate = function(data, keyPair, mustBeValidUntil) {
michael@0 113 this.cert = {
michael@0 114 validUntil: authService._fxaService.internal.now() + CERT_LIFETIME,
michael@0 115 cert: "certificate",
michael@0 116 };
michael@0 117 return Promise.resolve(this.cert.cert);
michael@0 118 };
michael@0 119
michael@0 120 authService._tokenServerClient = mockTSC;
michael@0 121 // Set the "account" of the browserId manager to be the "email" of the
michael@0 122 // logged in user of the mockFXA service.
michael@0 123 authService._account = user.email;
michael@0 124 }

mercurial