browser/components/customizableui/test/browser_946320_tabs_from_other_computers.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/customizableui/test/browser_946320_tabs_from_other_computers.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,124 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +let Preferences = Cu.import("resource://gre/modules/Preferences.jsm", {}).Preferences;
    1.11 +
    1.12 +let tmp = {};
    1.13 +Cu.import("resource://gre/modules/FxAccounts.jsm", tmp);
    1.14 +Cu.import("resource://gre/modules/FxAccountsCommon.js", tmp);
    1.15 +Cu.import("resource://services-sync/browserid_identity.js", tmp);
    1.16 +let {FxAccounts, BrowserIDManager, DATA_FORMAT_VERSION, CERT_LIFETIME} = tmp;
    1.17 +let fxaSyncIsEnabled = Weave.Service.identity instanceof BrowserIDManager;
    1.18 +
    1.19 +add_task(function() {
    1.20 +  yield PanelUI.show({type: "command"});
    1.21 +
    1.22 +  let historyButton = document.getElementById("history-panelmenu");
    1.23 +  let historySubview = document.getElementById("PanelUI-history");
    1.24 +  let subviewShownPromise = subviewShown(historySubview);
    1.25 +  EventUtils.synthesizeMouseAtCenter(historyButton, {});
    1.26 +  yield subviewShownPromise;
    1.27 +
    1.28 +  let tabsFromOtherComputers = document.getElementById("sync-tabs-menuitem2");
    1.29 +  is(tabsFromOtherComputers.hidden, true, "The Tabs From Other Computers menuitem should be hidden when sync isn't enabled.");
    1.30 +
    1.31 +  let hiddenPanelPromise = promisePanelHidden(window);
    1.32 +  PanelUI.hide();
    1.33 +  yield hiddenPanelPromise;
    1.34 +
    1.35 +  // Part 2 - When Sync is enabled the menuitem should be shown.
    1.36 +  yield configureIdentity();
    1.37 +  yield PanelUI.show({type: "command"});
    1.38 +
    1.39 +  subviewShownPromise = subviewShown(historySubview);
    1.40 +  EventUtils.synthesizeMouseAtCenter(historyButton, {});
    1.41 +  yield subviewShownPromise;
    1.42 +
    1.43 +  is(tabsFromOtherComputers.hidden, false, "The Tabs From Other Computers menuitem should be shown when sync is enabled.");
    1.44 +
    1.45 +  let syncPrefBranch = new Preferences("services.sync.");
    1.46 +  syncPrefBranch.resetBranch("");
    1.47 +  Services.logins.removeAllLogins();
    1.48 +
    1.49 +  hiddenPanelPromise = promisePanelHidden(window);
    1.50 +  PanelUI.toggle({type: "command"});
    1.51 +  yield hiddenPanelPromise;
    1.52 +
    1.53 +  if (fxaSyncIsEnabled) {
    1.54 +    yield fxAccounts.signOut();
    1.55 +  }
    1.56 +});
    1.57 +
    1.58 +function configureIdentity() {
    1.59 +  // do the FxAccounts thang...
    1.60 +  configureFxAccountIdentity();
    1.61 +
    1.62 +  if (fxaSyncIsEnabled) {
    1.63 +    return Weave.Service.identity.initializeWithCurrentIdentity().then(() => {
    1.64 +      // need to wait until this identity manager is readyToAuthenticate.
    1.65 +      return Weave.Service.identity.whenReadyToAuthenticate.promise;
    1.66 +    });
    1.67 +  }
    1.68 +
    1.69 +  Weave.Service.createAccount("john@doe.com", "mysecretpw",
    1.70 +                              "challenge", "response");
    1.71 +  Weave.Service.identity.account = "john@doe.com";
    1.72 +  Weave.Service.identity.basicPassword = "mysecretpw";
    1.73 +  Weave.Service.identity.syncKey = Weave.Utils.generatePassphrase();
    1.74 +  Weave.Svc.Prefs.set("firstSync", "newAccount");
    1.75 +  Weave.Service.persistLogin();
    1.76 +  return Promise.resolve();
    1.77 +}
    1.78 +
    1.79 +// Configure an instance of an FxAccount identity provider with the specified
    1.80 +// config (or the default config if not specified).
    1.81 +function configureFxAccountIdentity() {
    1.82 +  let user = {
    1.83 +    assertion: "assertion",
    1.84 +    email: "email",
    1.85 +    kA: "kA",
    1.86 +    kB: "kB",
    1.87 +    sessionToken: "sessionToken",
    1.88 +    uid: "user_uid",
    1.89 +    verified: true,
    1.90 +  };
    1.91 +
    1.92 +  let token = {
    1.93 +    endpoint: Weave.Svc.Prefs.get("tokenServerURI"),
    1.94 +    duration: 300,
    1.95 +    id: "id",
    1.96 +    key: "key",
    1.97 +    // uid will be set to the username.
    1.98 +  };
    1.99 +
   1.100 +  let MockInternal = {};
   1.101 +  let mockTSC = { // TokenServerClient
   1.102 +    getTokenFromBrowserIDAssertion: function(uri, assertion, cb) {
   1.103 +      token.uid = "username";
   1.104 +      cb(null, token);
   1.105 +    },
   1.106 +  };
   1.107 +
   1.108 +  let authService = Weave.Service.identity;
   1.109 +  authService._fxaService = new FxAccounts(MockInternal);
   1.110 +
   1.111 +  authService._fxaService.internal.currentAccountState.signedInUser = {
   1.112 +    version: DATA_FORMAT_VERSION,
   1.113 +    accountData: user
   1.114 +  }
   1.115 +  authService._fxaService.internal.currentAccountState.getCertificate = function(data, keyPair, mustBeValidUntil) {
   1.116 +    this.cert = {
   1.117 +      validUntil: authService._fxaService.internal.now() + CERT_LIFETIME,
   1.118 +      cert: "certificate",
   1.119 +    };
   1.120 +    return Promise.resolve(this.cert.cert);
   1.121 +  };
   1.122 +
   1.123 +  authService._tokenServerClient = mockTSC;
   1.124 +  // Set the "account" of the browserId manager to be the "email" of the
   1.125 +  // logged in user of the mockFXA service.
   1.126 +  authService._account = user.email;
   1.127 +}

mercurial