1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { sinon } = ChromeUtils.import("resource://testing-common/Sinon.jsm");
var gTestTab;
var gContentAPI;
add_task(setup_UITourTest);
add_UITour_task(async function test_no_user() {
const sandbox = sinon.createSandbox();
sandbox.stub(fxAccounts, "getSignedInUser").returns(null);
let result = await getConfigurationPromise("fxa");
Assert.deepEqual(result, { setup: false });
sandbox.restore();
});
add_UITour_task(async function test_no_sync_no_devices() {
const sandbox = sinon.createSandbox();
sandbox
.stub(fxAccounts, "getSignedInUser")
.returns({ email: "foo@example.com" });
sandbox.stub(fxAccounts.device, "recentDeviceList").get(() => {
return [
{
id: 1,
name: "This Device",
isCurrentDevice: true,
type: "desktop",
},
];
});
sandbox.stub(fxAccounts, "listAttachedOAuthClients").resolves([]);
sandbox.stub(fxAccounts, "hasLocalSession").resolves(true);
let result = await getConfigurationPromise("fxaConnections");
Assert.deepEqual(result, {
setup: true,
numOtherDevices: 0,
numDevicesByType: {},
accountServices: {},
});
sandbox.restore();
});
add_UITour_task(async function test_no_sync_many_devices() {
const sandbox = sinon.createSandbox();
sandbox
.stub(fxAccounts, "getSignedInUser")
.returns({ email: "foo@example.com" });
sandbox.stub(fxAccounts.device, "recentDeviceList").get(() => {
return [
{
id: 1,
name: "This Device",
isCurrentDevice: true,
type: "desktop",
},
{
id: 2,
name: "Other Device",
type: "mobile",
},
{
id: 3,
name: "My phone",
type: "phone",
},
{
id: 4,
name: "Who knows?",
},
{
id: 5,
name: "Another desktop",
type: "desktop",
},
{
id: 6,
name: "Yet Another desktop",
type: "desktop",
},
];
});
sandbox.stub(fxAccounts, "listAttachedOAuthClients").resolves([]);
sandbox.stub(fxAccounts, "hasLocalSession").resolves(true);
let result = await getConfigurationPromise("fxaConnections");
Assert.deepEqual(result, {
setup: true,
accountServices: {},
numOtherDevices: 5,
numDevicesByType: {
desktop: 2,
mobile: 1,
phone: 1,
unknown: 1,
},
});
sandbox.restore();
});
add_UITour_task(async function test_fxa_connections_no_cached_devices() {
const sandbox = sinon.createSandbox();
sandbox
.stub(fxAccounts, "getSignedInUser")
.returns({ email: "foo@example.com" });
let devicesStub = sandbox.stub(fxAccounts.device, "recentDeviceList");
devicesStub.get(() => {
// Sinon doesn't seem to support second `getters` returning a different
// value, so replace the getter here.
devicesStub.get(() => {
return [
{
id: 1,
name: "This Device",
isCurrentDevice: true,
type: "desktop",
},
{
id: 2,
name: "Other Device",
type: "mobile",
},
];
});
// and here we want to say "nothing is yet cached"
return null;
});
sandbox.stub(fxAccounts, "listAttachedOAuthClients").resolves([]);
sandbox.stub(fxAccounts, "hasLocalSession").resolves(true);
let rdlStub = sandbox.stub(fxAccounts.device, "refreshDeviceList").resolves();
let result = await getConfigurationPromise("fxaConnections");
Assert.deepEqual(result, {
setup: true,
accountServices: {},
numOtherDevices: 1,
numDevicesByType: {
mobile: 1,
},
});
Assert.ok(rdlStub.called);
sandbox.restore();
});
add_UITour_task(async function test_account_connections() {
const sandbox = sinon.createSandbox();
sandbox
.stub(fxAccounts, "getSignedInUser")
.returns({ email: "foo@example.com" });
sandbox.stub(fxAccounts.device, "recentDeviceList").get(() => []);
sandbox.stub(fxAccounts, "listAttachedOAuthClients").resolves([
{
id: "802d56ef2a9af9fa",
lastAccessedDaysAgo: 2,
},
{
id: "1f30e32975ae5112",
lastAccessedDaysAgo: 10,
},
{
id: null,
name: "Some browser",
lastAccessedDaysAgo: 10,
},
{
id: "null-last-accessed",
lastAccessedDaysAgo: null,
},
]);
Assert.deepEqual(await getConfigurationPromise("fxaConnections"), {
setup: true,
numOtherDevices: 0,
numDevicesByType: {},
accountServices: {
"802d56ef2a9af9fa": {
id: "802d56ef2a9af9fa",
lastAccessedWeeksAgo: 0,
},
"1f30e32975ae5112": {
id: "1f30e32975ae5112",
lastAccessedWeeksAgo: 1,
},
"null-last-accessed": {
id: "null-last-accessed",
lastAccessedWeeksAgo: null,
},
},
});
sandbox.restore();
});
add_UITour_task(async function test_sync() {
const sandbox = sinon.createSandbox();
sandbox
.stub(fxAccounts, "getSignedInUser")
.returns({ email: "foo@example.com" });
sandbox.stub(fxAccounts.device, "recentDeviceList").get(() => []);
sandbox.stub(fxAccounts, "listAttachedOAuthClients").resolves([]);
sandbox.stub(fxAccounts, "hasLocalSession").resolves(true);
Services.prefs.setCharPref("services.sync.username", "tests@mozilla.org");
Services.prefs.setIntPref("services.sync.clients.devices.desktop", 4);
Services.prefs.setIntPref("services.sync.clients.devices.mobile", 5);
Services.prefs.setIntPref("services.sync.numClients", 9);
Assert.deepEqual(await getConfigurationPromise("fxa"), {
setup: true,
accountStateOK: true,
browserServices: {
sync: {
setup: true,
mobileDevices: 5,
desktopDevices: 4,
totalDevices: 9,
},
},
});
Services.prefs.clearUserPref("services.sync.username");
Services.prefs.clearUserPref("services.sync.clients.devices.desktop");
Services.prefs.clearUserPref("services.sync.clients.devices.mobile");
Services.prefs.clearUserPref("services.sync.numClients");
sandbox.restore();
});
add_UITour_task(async function test_fxa_fails() {
const sandbox = sinon.createSandbox();
sandbox.stub(fxAccounts, "getSignedInUser").throws();
let result = await getConfigurationPromise("fxa");
Assert.deepEqual(result, {});
sandbox.restore();
});
|