Bug 963865 - [Australis] Fix browser_946320_tabs_from_other_computers.js to run with FxA enabled r=markh
authorTim Taubert <ttaubert@mozilla.com>
Thu, 30 Jan 2014 15:54:36 -0800
changeset 182244 08d8f9e97fdde7829db98382e174d790ea1412d8
parent 182243 a177ec633a06baac69ca9e9703d62d15a5f9bcf2
child 182245 d9d7a18c14f367fad80e4223bcad699ff816eab1
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs963865
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 963865 - [Australis] Fix browser_946320_tabs_from_other_computers.js to run with FxA enabled r=markh
browser/components/customizableui/test/browser_946320_tabs_from_other_computers.js
--- a/browser/components/customizableui/test/browser_946320_tabs_from_other_computers.js
+++ b/browser/components/customizableui/test/browser_946320_tabs_from_other_computers.js
@@ -1,50 +1,125 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-"use strict";
-
-let Preferences = Cu.import("resource://gre/modules/Preferences.jsm", {}).Preferences;
-Cu.import("resource://gre/modules/Promise.jsm");
-
-add_task(function() {
-  yield PanelUI.show({type: "command"});
-
-  let historyButton = document.getElementById("history-panelmenu");
-  let historySubview = document.getElementById("PanelUI-history");
-  let subviewShownPromise = subviewShown(historySubview);
-  EventUtils.synthesizeMouseAtCenter(historyButton, {});
-  yield subviewShownPromise;
-
-  let tabsFromOtherComputers = document.getElementById("sync-tabs-menuitem2");
-  is(tabsFromOtherComputers.hidden, true, "The Tabs From Other Computers menuitem should be hidden when sync isn't enabled.");
-
-  let hiddenPanelPromise = promisePanelHidden(window);
-  PanelUI.hide();
-  yield hiddenPanelPromise;
-
-  // Part 2 - When Sync is enabled the menuitem should be shown.
-  Weave.Service.createAccount("john@doe.com", "mysecretpw",
-                              "challenge", "response");
-  Weave.Service.identity.account = "john@doe.com";
-  Weave.Service.identity.basicPassword = "mysecretpw";
-  Weave.Service.identity.syncKey = Weave.Utils.generatePassphrase();
-  Weave.Svc.Prefs.set("firstSync", "newAccount");
-  Weave.Service.persistLogin();
-
-  yield PanelUI.show({type: "command"});
-
-  subviewShownPromise = subviewShown(historySubview);
-  EventUtils.synthesizeMouseAtCenter(historyButton, {});
-  yield subviewShownPromise;
-
-  is(tabsFromOtherComputers.hidden, false, "The Tabs From Other Computers menuitem should be shown when sync is enabled.");
-
-  let syncPrefBranch = new Preferences("services.sync.");
-  syncPrefBranch.resetBranch("");
-  Services.logins.removeAllLogins();
-
-  hiddenPanelPromise = promisePanelHidden(window);
-  PanelUI.toggle({type: "command"});
-  yield hiddenPanelPromise;
-});
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+let Preferences = Cu.import("resource://gre/modules/Preferences.jsm", {}).Preferences;
+Cu.import("resource://gre/modules/Promise.jsm");
+
+let tmp = {};
+Cu.import("resource://gre/modules/FxAccounts.jsm", tmp);
+Cu.import("resource://gre/modules/FxAccountsCommon.js", tmp);
+Cu.import("resource://services-sync/browserid_identity.js", tmp);
+let {FxAccounts, BrowserIDManager, DATA_FORMAT_VERSION, CERT_LIFETIME} = tmp;
+let fxaSyncIsEnabled = Weave.Service.identity instanceof BrowserIDManager;
+
+add_task(function() {
+  yield PanelUI.show({type: "command"});
+
+  let historyButton = document.getElementById("history-panelmenu");
+  let historySubview = document.getElementById("PanelUI-history");
+  let subviewShownPromise = subviewShown(historySubview);
+  EventUtils.synthesizeMouseAtCenter(historyButton, {});
+  yield subviewShownPromise;
+
+  let tabsFromOtherComputers = document.getElementById("sync-tabs-menuitem2");
+  is(tabsFromOtherComputers.hidden, true, "The Tabs From Other Computers menuitem should be hidden when sync isn't enabled.");
+
+  let hiddenPanelPromise = promisePanelHidden(window);
+  PanelUI.hide();
+  yield hiddenPanelPromise;
+
+  // Part 2 - When Sync is enabled the menuitem should be shown.
+  yield configureIdentity();
+  yield PanelUI.show({type: "command"});
+
+  subviewShownPromise = subviewShown(historySubview);
+  EventUtils.synthesizeMouseAtCenter(historyButton, {});
+  yield subviewShownPromise;
+
+  is(tabsFromOtherComputers.hidden, false, "The Tabs From Other Computers menuitem should be shown when sync is enabled.");
+
+  let syncPrefBranch = new Preferences("services.sync.");
+  syncPrefBranch.resetBranch("");
+  Services.logins.removeAllLogins();
+
+  hiddenPanelPromise = promisePanelHidden(window);
+  PanelUI.toggle({type: "command"});
+  yield hiddenPanelPromise;
+
+  if (fxaSyncIsEnabled) {
+    yield fxAccounts.signOut();
+  }
+});
+
+function configureIdentity() {
+  // do the FxAccounts thang...
+  configureFxAccountIdentity();
+
+  if (fxaSyncIsEnabled) {
+    return Weave.Service.identity.initializeWithCurrentIdentity().then(() => {
+      // need to wait until this identity manager is readyToAuthenticate.
+      return Weave.Service.identity.whenReadyToAuthenticate.promise;
+    });
+  }
+
+  Weave.Service.createAccount("john@doe.com", "mysecretpw",
+                              "challenge", "response");
+  Weave.Service.identity.account = "john@doe.com";
+  Weave.Service.identity.basicPassword = "mysecretpw";
+  Weave.Service.identity.syncKey = Weave.Utils.generatePassphrase();
+  Weave.Svc.Prefs.set("firstSync", "newAccount");
+  Weave.Service.persistLogin();
+  return Promise.resolve();
+}
+
+// Configure an instance of an FxAccount identity provider with the specified
+// config (or the default config if not specified).
+function configureFxAccountIdentity() {
+  let user = {
+    assertion: "assertion",
+    email: "email",
+    kA: "kA",
+    kB: "kB",
+    sessionToken: "sessionToken",
+    uid: "user_uid",
+    verified: true,
+  };
+
+  let token = {
+    endpoint: Weave.Svc.Prefs.get("tokenServerURI"),
+    duration: 300,
+    id: "id",
+    key: "key",
+    // uid will be set to the username.
+  };
+
+  let MockInternal = {
+    signedInUser: {
+      version: DATA_FORMAT_VERSION,
+      accountData: user
+    },
+    getCertificate: function(data, keyPair, mustBeValidUntil) {
+      this.cert = {
+        validUntil: Date.now() + CERT_LIFETIME,
+        cert: "certificate",
+      };
+      return Promise.resolve(this.cert.cert);
+    },
+  };
+
+  let mockTSC = { // TokenServerClient
+    getTokenFromBrowserIDAssertion: function(uri, assertion, cb) {
+      token.uid = "username";
+      cb(null, token);
+    },
+  };
+
+  let authService = Weave.Service.identity;
+  authService._fxaService = new FxAccounts(MockInternal);
+  authService._tokenServerClient = mockTSC;
+  // Set the "account" of the browserId manager to be the "email" of the
+  // logged in user of the mockFXA service.
+  authService._account = user.email;
+}