|
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/. */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 let Preferences = Cu.import("resource://gre/modules/Preferences.jsm", {}).Preferences; |
|
8 |
|
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; |
|
15 |
|
16 add_task(function() { |
|
17 yield PanelUI.show({type: "command"}); |
|
18 |
|
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; |
|
24 |
|
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."); |
|
27 |
|
28 let hiddenPanelPromise = promisePanelHidden(window); |
|
29 PanelUI.hide(); |
|
30 yield hiddenPanelPromise; |
|
31 |
|
32 // Part 2 - When Sync is enabled the menuitem should be shown. |
|
33 yield configureIdentity(); |
|
34 yield PanelUI.show({type: "command"}); |
|
35 |
|
36 subviewShownPromise = subviewShown(historySubview); |
|
37 EventUtils.synthesizeMouseAtCenter(historyButton, {}); |
|
38 yield subviewShownPromise; |
|
39 |
|
40 is(tabsFromOtherComputers.hidden, false, "The Tabs From Other Computers menuitem should be shown when sync is enabled."); |
|
41 |
|
42 let syncPrefBranch = new Preferences("services.sync."); |
|
43 syncPrefBranch.resetBranch(""); |
|
44 Services.logins.removeAllLogins(); |
|
45 |
|
46 hiddenPanelPromise = promisePanelHidden(window); |
|
47 PanelUI.toggle({type: "command"}); |
|
48 yield hiddenPanelPromise; |
|
49 |
|
50 if (fxaSyncIsEnabled) { |
|
51 yield fxAccounts.signOut(); |
|
52 } |
|
53 }); |
|
54 |
|
55 function configureIdentity() { |
|
56 // do the FxAccounts thang... |
|
57 configureFxAccountIdentity(); |
|
58 |
|
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 } |
|
65 |
|
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 } |
|
75 |
|
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 }; |
|
88 |
|
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 }; |
|
96 |
|
97 let MockInternal = {}; |
|
98 let mockTSC = { // TokenServerClient |
|
99 getTokenFromBrowserIDAssertion: function(uri, assertion, cb) { |
|
100 token.uid = "username"; |
|
101 cb(null, token); |
|
102 }, |
|
103 }; |
|
104 |
|
105 let authService = Weave.Service.identity; |
|
106 authService._fxaService = new FxAccounts(MockInternal); |
|
107 |
|
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 }; |
|
119 |
|
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 } |