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