|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 "use strict"; |
|
5 |
|
6 const Cm = Components.manager; |
|
7 |
|
8 Cu.import("resource://gre/modules/FxAccounts.jsm"); |
|
9 Cu.import("resource://gre/modules/FxAccountsCommon.js"); |
|
10 Cu.import("resource://gre/modules/FxAccountsManager.jsm"); |
|
11 Cu.import("resource://gre/modules/Promise.jsm"); |
|
12 |
|
13 // === Mocks === |
|
14 |
|
15 // Override FxAccountsUIGlue. |
|
16 const kFxAccountsUIGlueUUID = "{8f6d5d87-41ed-4bb5-aa28-625de57564c5}"; |
|
17 const kFxAccountsUIGlueContractID = |
|
18 "@mozilla.org/fxaccounts/fxaccounts-ui-glue;1"; |
|
19 |
|
20 // Save original FxAccountsUIGlue factory. |
|
21 const kFxAccountsUIGlueFactory = |
|
22 Cm.getClassObject(Cc[kFxAccountsUIGlueContractID], Ci.nsIFactory); |
|
23 |
|
24 let fakeFxAccountsUIGlueFactory = { |
|
25 createInstance: function(aOuter, aIid) { |
|
26 return FxAccountsUIGlue.QueryInterface(aIid); |
|
27 } |
|
28 }; |
|
29 |
|
30 // FxAccountsUIGlue fake component. |
|
31 let FxAccountsUIGlue = { |
|
32 _reject: false, |
|
33 |
|
34 _error: 'error', |
|
35 |
|
36 _signInFlowCalled: false, |
|
37 |
|
38 _refreshAuthCalled: false, |
|
39 |
|
40 _activeSession: null, |
|
41 |
|
42 _reset: function() { |
|
43 this._reject = false; |
|
44 this._error = 'error'; |
|
45 this._signInFlowCalled = false; |
|
46 this._refreshAuthCalled = false; |
|
47 }, |
|
48 |
|
49 QueryInterface: XPCOMUtils.generateQI([Ci.nsIFxAccountsUIGlue]), |
|
50 |
|
51 _promise: function() { |
|
52 let deferred = Promise.defer(); |
|
53 |
|
54 if (this._reject) { |
|
55 deferred.reject(this._error); |
|
56 } else { |
|
57 FxAccountsManager._activeSession = this._activeSession || { |
|
58 email: "user@domain.org", |
|
59 verified: false, |
|
60 sessionToken: "1234" |
|
61 }; |
|
62 FxAccountsManager._fxAccounts |
|
63 .setSignedInUser(FxAccountsManager._activeSession); |
|
64 deferred.resolve(FxAccountsManager._activeSession); |
|
65 } |
|
66 |
|
67 return deferred.promise; |
|
68 }, |
|
69 |
|
70 signInFlow: function() { |
|
71 this._signInFlowCalled = true; |
|
72 return this._promise(); |
|
73 }, |
|
74 |
|
75 refreshAuthentication: function() { |
|
76 this._refreshAuthCalled = true; |
|
77 return this._promise(); |
|
78 } |
|
79 }; |
|
80 |
|
81 (function registerFakeFxAccountsUIGlue() { |
|
82 Cm.QueryInterface(Ci.nsIComponentRegistrar) |
|
83 .registerFactory(Components.ID(kFxAccountsUIGlueUUID), |
|
84 "FxAccountsUIGlue", |
|
85 kFxAccountsUIGlueContractID, |
|
86 fakeFxAccountsUIGlueFactory); |
|
87 })(); |
|
88 |
|
89 // Save original fxAccounts instance |
|
90 const kFxAccounts = fxAccounts; |
|
91 // and change it for a mock FxAccounts. |
|
92 FxAccountsManager._fxAccounts = { |
|
93 _reject: false, |
|
94 _getSignedInUserCalled: false, |
|
95 _setSignedInUserCalled: false, |
|
96 |
|
97 _error: 'error', |
|
98 _assertion: 'assertion', |
|
99 _signedInUser: null, |
|
100 |
|
101 _reset: function() { |
|
102 this._getSignedInUserCalled = false; |
|
103 this._setSignedInUserCalled = false; |
|
104 this._reject = false; |
|
105 }, |
|
106 |
|
107 getAssertion: function() { |
|
108 if (!this._signedInUser) { |
|
109 return null; |
|
110 } |
|
111 |
|
112 let deferred = Promise.defer(); |
|
113 deferred.resolve(this._assertion); |
|
114 return deferred.promise; |
|
115 }, |
|
116 |
|
117 getSignedInUser: function() { |
|
118 this._getSignedInUserCalled = true; |
|
119 let deferred = Promise.defer(); |
|
120 this._reject ? deferred.reject(this._error) |
|
121 : deferred.resolve(this._signedInUser); |
|
122 return deferred.promise; |
|
123 }, |
|
124 |
|
125 setSignedInUser: function(user) { |
|
126 this._setSignedInUserCalled = true; |
|
127 let deferred = Promise.defer(); |
|
128 this._signedInUser = user; |
|
129 deferred.resolve(); |
|
130 return deferred.promise; |
|
131 }, |
|
132 |
|
133 signOut: function() { |
|
134 let deferred = Promise.defer(); |
|
135 this._signedInUser = null; |
|
136 Services.obs.notifyObservers(null, ONLOGOUT_NOTIFICATION, null); |
|
137 deferred.resolve(); |
|
138 return deferred.promise; |
|
139 } |
|
140 }; |
|
141 |
|
142 // Save original FxAccountsClient factory from FxAccountsManager. |
|
143 const kFxAccountsClient = FxAccountsManager._getFxAccountsClient; |
|
144 |
|
145 // and change it for a fake client factory. |
|
146 let FakeFxAccountsClient = { |
|
147 _reject: false, |
|
148 _recoveryEmailStatusCalled: false, |
|
149 _signInCalled: false, |
|
150 _signUpCalled: false, |
|
151 _signOutCalled: false, |
|
152 |
|
153 _accountExists: false, |
|
154 _verified: false, |
|
155 _password: null, |
|
156 |
|
157 _reset: function() { |
|
158 this._reject = false; |
|
159 this._recoveryEmailStatusCalled = false; |
|
160 this._signInCalled = false; |
|
161 this._signUpCalled = false; |
|
162 this._signOutCalled = false; |
|
163 }, |
|
164 |
|
165 recoveryEmailStatus: function() { |
|
166 this._recoveryEmailStatusCalled = true; |
|
167 let deferred = Promise.defer(); |
|
168 this._reject ? deferred.reject() |
|
169 : deferred.resolve({ verified: this._verified }); |
|
170 return deferred.promise; |
|
171 }, |
|
172 |
|
173 signIn: function(user, password) { |
|
174 this._signInCalled = true; |
|
175 this._password = password; |
|
176 let deferred = Promise.defer(); |
|
177 this._reject ? deferred.reject() |
|
178 : deferred.resolve({ email: user, |
|
179 uid: "whatever", |
|
180 verified: this._verified, |
|
181 sessionToken: "1234" }); |
|
182 return deferred.promise; |
|
183 }, |
|
184 |
|
185 signUp: function(user, password) { |
|
186 this._signUpCalled = true; |
|
187 return this.signIn(user, password); |
|
188 }, |
|
189 |
|
190 signOut: function() { |
|
191 this._signOutCalled = true; |
|
192 let deferred = Promise.defer(); |
|
193 this._reject ? deferred.reject() |
|
194 : deferred.resolve(); |
|
195 return deferred.promise; |
|
196 }, |
|
197 |
|
198 accountExists: function() { |
|
199 let deferred = Promise.defer(); |
|
200 this._reject ? deferred.reject() |
|
201 : deferred.resolve(this._accountExists); |
|
202 return deferred.promise; |
|
203 } |
|
204 }; |
|
205 |
|
206 FxAccountsManager._getFxAccountsClient = function() { |
|
207 return FakeFxAccountsClient; |
|
208 }; |
|
209 |
|
210 |
|
211 // === Global cleanup === |
|
212 |
|
213 // Unregister mocks and restore original code. |
|
214 do_register_cleanup(function() { |
|
215 // Unregister the factory so we do not leak |
|
216 Cm.QueryInterface(Ci.nsIComponentRegistrar) |
|
217 .unregisterFactory(Components.ID(kFxAccountsUIGlueUUID), |
|
218 fakeFxAccountsUIGlueFactory); |
|
219 |
|
220 // Restore the original factory. |
|
221 Cm.QueryInterface(Ci.nsIComponentRegistrar) |
|
222 .registerFactory(Components.ID(kFxAccountsUIGlueUUID), |
|
223 "FxAccountsUIGlue", |
|
224 kFxAccountsUIGlueContractID, |
|
225 kFxAccountsUIGlueFactory); |
|
226 |
|
227 // Restore the original FxAccounts instance from FxAccountsManager. |
|
228 FxAccountsManager._fxAccounts = kFxAccounts; |
|
229 |
|
230 // Restore the FxAccountsClient getter from FxAccountsManager. |
|
231 FxAccountsManager._getFxAccountsClient = kFxAccountsClient; |
|
232 }); |
|
233 |
|
234 |
|
235 // === Tests === |
|
236 |
|
237 function run_test() { |
|
238 run_next_test(); |
|
239 } |
|
240 |
|
241 add_test(function test_initial_state() { |
|
242 do_print("= Initial state ="); |
|
243 do_check_neq(FxAccountsManager, undefined); |
|
244 do_check_null(FxAccountsManager._activeSession); |
|
245 do_check_null(FxAccountsManager._user); |
|
246 run_next_test(); |
|
247 }); |
|
248 |
|
249 add_test(function(test_getAccount_no_session) { |
|
250 do_print("= getAccount no session ="); |
|
251 FxAccountsManager.getAccount().then( |
|
252 result => { |
|
253 do_check_null(result); |
|
254 do_check_null(FxAccountsManager._activeSession); |
|
255 do_check_null(FxAccountsManager._user); |
|
256 do_check_true(FxAccountsManager._fxAccounts._getSignedInUserCalled); |
|
257 FxAccountsManager._fxAccounts._reset(); |
|
258 run_next_test(); |
|
259 }, |
|
260 error => { |
|
261 do_throw("Unexpected error: " + error); |
|
262 } |
|
263 ); |
|
264 }); |
|
265 |
|
266 add_test(function(test_getAssertion_no_audience) { |
|
267 do_print("= getAssertion no audience ="); |
|
268 FxAccountsManager.getAssertion().then( |
|
269 () => { |
|
270 do_throw("Unexpected success"); |
|
271 }, |
|
272 error => { |
|
273 do_check_eq(error.error, ERROR_INVALID_AUDIENCE); |
|
274 run_next_test(); |
|
275 } |
|
276 ); |
|
277 }); |
|
278 |
|
279 add_test(function(test_getAssertion_no_session_ui_error) { |
|
280 do_print("= getAssertion no session, UI error ="); |
|
281 FxAccountsUIGlue._reject = true; |
|
282 FxAccountsManager.getAssertion("audience").then( |
|
283 () => { |
|
284 do_throw("Unexpected success"); |
|
285 }, |
|
286 error => { |
|
287 do_check_eq(error.error, ERROR_UI_ERROR); |
|
288 do_check_eq(error.details, "error"); |
|
289 FxAccountsUIGlue._reset(); |
|
290 run_next_test(); |
|
291 } |
|
292 ); |
|
293 }); |
|
294 |
|
295 add_test(function(test_getAssertion_no_session_ui_success) { |
|
296 do_print("= getAssertion no session, UI success ="); |
|
297 FxAccountsManager.getAssertion("audience").then( |
|
298 () => { |
|
299 do_throw("Unexpected success"); |
|
300 }, |
|
301 error => { |
|
302 do_check_true(FxAccountsUIGlue._signInFlowCalled); |
|
303 do_check_eq(error.error, ERROR_UNVERIFIED_ACCOUNT); |
|
304 FxAccountsUIGlue._reset(); |
|
305 run_next_test(); |
|
306 } |
|
307 ); |
|
308 }); |
|
309 |
|
310 add_test(function(test_getAssertion_active_session_unverified_account) { |
|
311 do_print("= getAssertion active session, unverified account ="); |
|
312 FxAccountsManager.getAssertion("audience").then( |
|
313 result => { |
|
314 do_throw("Unexpected success"); |
|
315 }, |
|
316 error => { |
|
317 do_check_false(FxAccountsUIGlue._signInFlowCalled); |
|
318 do_check_eq(error.error, ERROR_UNVERIFIED_ACCOUNT); |
|
319 run_next_test(); |
|
320 } |
|
321 ); |
|
322 }); |
|
323 |
|
324 add_test(function(test_getAssertion_active_session_verified_account) { |
|
325 do_print("= getAssertion active session, verified account ="); |
|
326 FxAccountsManager._fxAccounts._signedInUser.verified = true; |
|
327 FxAccountsManager._activeSession.verified = true; |
|
328 FxAccountsManager.getAssertion("audience").then( |
|
329 result => { |
|
330 do_check_false(FxAccountsUIGlue._signInFlowCalled); |
|
331 do_check_eq(result, "assertion"); |
|
332 FxAccountsManager._fxAccounts._reset(); |
|
333 run_next_test(); |
|
334 }, |
|
335 error => { |
|
336 do_throw("Unexpected error: " + error); |
|
337 } |
|
338 ); |
|
339 }); |
|
340 |
|
341 add_test(function(test_getAssertion_refreshAuth) { |
|
342 do_print("= getAssertion refreshAuth ="); |
|
343 let gracePeriod = 1200; |
|
344 FxAccountsUIGlue._activeSession = { |
|
345 email: "user@domain.org", |
|
346 verified: true, |
|
347 sessionToken: "1234" |
|
348 }; |
|
349 FxAccountsManager._fxAccounts._signedInUser.verified = true; |
|
350 FxAccountsManager._activeSession.verified = true; |
|
351 FxAccountsManager._activeSession.authAt = |
|
352 (Date.now() / 1000) - gracePeriod; |
|
353 FxAccountsManager.getAssertion("audience", { |
|
354 "refreshAuthentication": gracePeriod |
|
355 }).then( |
|
356 result => { |
|
357 do_check_false(FxAccountsUIGlue._signInFlowCalled); |
|
358 do_check_true(FxAccountsUIGlue._refreshAuthCalled); |
|
359 do_check_eq(result, "assertion"); |
|
360 FxAccountsManager._fxAccounts._reset(); |
|
361 FxAccountsUIGlue._reset(); |
|
362 run_next_test(); |
|
363 }, |
|
364 error => { |
|
365 do_throw("Unexpected error: " + error); |
|
366 } |
|
367 ); |
|
368 }); |
|
369 |
|
370 add_test(function(test_getAssertion_refreshAuth_NaN) { |
|
371 do_print("= getAssertion refreshAuth NaN="); |
|
372 let gracePeriod = "NaN"; |
|
373 FxAccountsManager.getAssertion("audience", { |
|
374 "refreshAuthentication": gracePeriod |
|
375 }).then( |
|
376 result => { |
|
377 do_throw("Unexpected success"); |
|
378 }, |
|
379 error => { |
|
380 do_check_false(FxAccountsUIGlue._signInFlowCalled); |
|
381 do_check_false(FxAccountsUIGlue._refreshAuthCalled); |
|
382 do_check_eq(error.error, ERROR_INVALID_REFRESH_AUTH_VALUE); |
|
383 FxAccountsManager._fxAccounts._reset(); |
|
384 run_next_test(); |
|
385 } |
|
386 ); |
|
387 }); |
|
388 |
|
389 add_test(function(test_getAssertion_refresh_auth_no_refresh) { |
|
390 do_print("= getAssertion refreshAuth no refresh ="); |
|
391 FxAccountsManager._fxAccounts._signedInUser.verified = true; |
|
392 FxAccountsManager._activeSession.verified = true; |
|
393 FxAccountsManager._activeSession.authAt = |
|
394 (Date.now() / 1000) + 10000; |
|
395 FxAccountsManager.getAssertion("audience", { |
|
396 "refreshAuthentication": 1 |
|
397 }).then( |
|
398 result => { |
|
399 do_check_false(FxAccountsUIGlue._signInFlowCalled); |
|
400 do_check_eq(result, "assertion"); |
|
401 FxAccountsManager._fxAccounts._reset(); |
|
402 run_next_test(); |
|
403 }, |
|
404 error => { |
|
405 do_throw("Unexpected error: " + error); |
|
406 } |
|
407 ); |
|
408 }); |
|
409 |
|
410 add_test(function(test_getAccount_existing_verified_session) { |
|
411 do_print("= getAccount, existing verified session ="); |
|
412 FxAccountsManager.getAccount().then( |
|
413 result => { |
|
414 do_check_false(FxAccountsManager._fxAccounts._getSignedInUserCalled); |
|
415 do_check_eq(result.accountId, FxAccountsManager._user.accountId); |
|
416 do_check_eq(result.verified, FxAccountsManager._user.verified); |
|
417 run_next_test(); |
|
418 }, |
|
419 error => { |
|
420 do_throw("Unexpected error: " + error); |
|
421 } |
|
422 ); |
|
423 }); |
|
424 |
|
425 add_test(function(test_getAccount_existing_unverified_session_unverified_user) { |
|
426 do_print("= getAccount, existing unverified session, unverified user ="); |
|
427 FxAccountsManager._activeSession.verified = false; |
|
428 FxAccountsManager._fxAccounts._signedInUser.verified = false; |
|
429 FxAccountsManager.getAccount().then( |
|
430 result => { |
|
431 do_check_true(FakeFxAccountsClient._recoveryEmailStatusCalled); |
|
432 do_check_false(result.verified); |
|
433 do_check_eq(result.accountId, FxAccountsManager._user.accountId); |
|
434 FakeFxAccountsClient._reset(); |
|
435 run_next_test(); |
|
436 }, |
|
437 error => { |
|
438 do_throw("Unexpected error: " + error); |
|
439 } |
|
440 ); |
|
441 }); |
|
442 |
|
443 add_test(function(test_getAccount_existing_unverified_session_verified_user) { |
|
444 do_print("= getAccount, existing unverified session, verified user ="); |
|
445 FxAccountsManager._activeSession.verified = false; |
|
446 FxAccountsManager._fxAccounts._signedInUser.verified = false; |
|
447 FakeFxAccountsClient._verified = true; |
|
448 FxAccountsManager.getAccount(); |
|
449 do_execute_soon(function() { |
|
450 do_check_true(FakeFxAccountsClient._recoveryEmailStatusCalled); |
|
451 FxAccountsManager.getAccount().then( |
|
452 result => { |
|
453 do_check_true(result.verified); |
|
454 do_check_eq(result.accountId, FxAccountsManager._user.accountId); |
|
455 FakeFxAccountsClient._reset(); |
|
456 run_next_test(); |
|
457 }); |
|
458 }); |
|
459 }); |
|
460 |
|
461 add_test(function(test_signOut) { |
|
462 do_print("= signOut ="); |
|
463 do_check_true(FxAccountsManager._activeSession != null); |
|
464 FxAccountsManager.signOut().then( |
|
465 result => { |
|
466 do_check_null(result); |
|
467 do_check_null(FxAccountsManager._activeSession); |
|
468 do_check_true(FakeFxAccountsClient._signOutCalled); |
|
469 run_next_test(); |
|
470 }, |
|
471 error => { |
|
472 do_throw("Unexpected error: " + error); |
|
473 } |
|
474 ); |
|
475 }); |
|
476 |
|
477 add_test(function(test_signUp_no_accountId) { |
|
478 do_print("= signUp, no accountId="); |
|
479 FxAccountsManager.signUp().then( |
|
480 () => { |
|
481 do_throw("Unexpected success"); |
|
482 }, |
|
483 error => { |
|
484 do_check_eq(error.error, ERROR_INVALID_ACCOUNTID); |
|
485 run_next_test(); |
|
486 } |
|
487 ); |
|
488 }); |
|
489 |
|
490 add_test(function(test_signIn_no_accountId) { |
|
491 do_print("= signIn, no accountId="); |
|
492 FxAccountsManager.signIn().then( |
|
493 () => { |
|
494 do_throw("Unexpected success"); |
|
495 }, |
|
496 error => { |
|
497 do_check_eq(error.error, ERROR_INVALID_ACCOUNTID); |
|
498 run_next_test(); |
|
499 } |
|
500 ); |
|
501 }); |
|
502 |
|
503 add_test(function(test_signUp_no_password) { |
|
504 do_print("= signUp, no accountId="); |
|
505 FxAccountsManager.signUp("user@domain.org").then( |
|
506 () => { |
|
507 do_throw("Unexpected success"); |
|
508 }, |
|
509 error => { |
|
510 do_check_eq(error.error, ERROR_INVALID_PASSWORD); |
|
511 run_next_test(); |
|
512 } |
|
513 ); |
|
514 }); |
|
515 |
|
516 add_test(function(test_signIn_no_accountId) { |
|
517 do_print("= signIn, no accountId="); |
|
518 FxAccountsManager.signIn("user@domain.org").then( |
|
519 () => { |
|
520 do_throw("Unexpected success"); |
|
521 }, |
|
522 error => { |
|
523 do_check_eq(error.error, ERROR_INVALID_PASSWORD); |
|
524 run_next_test(); |
|
525 } |
|
526 ); |
|
527 }); |
|
528 |
|
529 add_test(function(test_signUp) { |
|
530 do_print("= signUp ="); |
|
531 FakeFxAccountsClient._verified = false; |
|
532 FxAccountsManager.signUp("user@domain.org", "password").then( |
|
533 result => { |
|
534 do_check_true(FakeFxAccountsClient._signInCalled); |
|
535 do_check_true(FakeFxAccountsClient._signUpCalled); |
|
536 do_check_true(FxAccountsManager._fxAccounts._getSignedInUserCalled); |
|
537 do_check_eq(FxAccountsManager._fxAccounts._signedInUser.email, "user@domain.org"); |
|
538 do_check_eq(FakeFxAccountsClient._password, "password"); |
|
539 do_check_true(result.accountCreated); |
|
540 do_check_eq(result.user.accountId, "user@domain.org"); |
|
541 do_check_false(result.user.verified); |
|
542 FakeFxAccountsClient._reset(); |
|
543 FxAccountsManager._fxAccounts._reset(); |
|
544 run_next_test(); |
|
545 }, |
|
546 error => { |
|
547 do_throw("Unexpected error: " + error.error); |
|
548 } |
|
549 ); |
|
550 }); |
|
551 |
|
552 add_test(function(test_signUp_already_signed_user) { |
|
553 do_print("= signUp, already signed user ="); |
|
554 FxAccountsManager.signUp("user@domain.org", "password").then( |
|
555 () => { |
|
556 do_throw("Unexpected success"); |
|
557 }, |
|
558 error => { |
|
559 do_check_false(FakeFxAccountsClient._signInCalled); |
|
560 do_check_eq(error.error, ERROR_ALREADY_SIGNED_IN_USER); |
|
561 do_check_eq(error.details.user.accountId, "user@domain.org"); |
|
562 do_check_false(error.details.user.verified); |
|
563 run_next_test(); |
|
564 } |
|
565 ); |
|
566 }); |
|
567 |
|
568 add_test(function(test_signIn_already_signed_user) { |
|
569 do_print("= signIn, already signed user ="); |
|
570 FxAccountsManager.signIn("user@domain.org", "password").then( |
|
571 () => { |
|
572 do_throw("Unexpected success"); |
|
573 }, |
|
574 error => { |
|
575 do_check_eq(error.error, ERROR_ALREADY_SIGNED_IN_USER); |
|
576 do_check_eq(error.details.user.accountId, "user@domain.org"); |
|
577 do_check_false(error.details.user.verified); |
|
578 run_next_test(); |
|
579 } |
|
580 ); |
|
581 }); |
|
582 |
|
583 add_test(function(test_verificationStatus_unverified_session_unverified_user) { |
|
584 do_print("= verificationStatus unverified session and user ="); |
|
585 FakeFxAccountsClient._verified = false; |
|
586 FxAccountsManager.verificationStatus(); |
|
587 do_execute_soon(function() { |
|
588 let user = FxAccountsManager._user; |
|
589 do_check_false(user.verified); |
|
590 do_check_true(FakeFxAccountsClient._recoveryEmailStatusCalled); |
|
591 do_check_false(FxAccountsManager._fxAccounts._setSignedInUserCalled); |
|
592 run_next_test(); |
|
593 }); |
|
594 }); |
|
595 |
|
596 add_test(function(test_verificationStatus_unverified_session_verified_user) { |
|
597 do_print("= verificationStatus unverified session, verified user ="); |
|
598 FakeFxAccountsClient._verified = true; |
|
599 FxAccountsManager.verificationStatus(); |
|
600 do_execute_soon(function() { |
|
601 let user = FxAccountsManager._user; |
|
602 do_check_true(user.verified); |
|
603 do_check_true(FakeFxAccountsClient._recoveryEmailStatusCalled); |
|
604 do_check_true(FxAccountsManager._fxAccounts._setSignedInUserCalled); |
|
605 run_next_test(); |
|
606 }); |
|
607 }); |
|
608 |
|
609 add_test(function(test_queryAccount_no_exists) { |
|
610 do_print("= queryAccount, no exists ="); |
|
611 FxAccountsManager.queryAccount("user@domain.org").then( |
|
612 result => { |
|
613 do_check_false(result.registered); |
|
614 run_next_test(); |
|
615 }, |
|
616 error => { |
|
617 do_throw("Unexpected error: " + error); |
|
618 } |
|
619 ); |
|
620 }); |
|
621 |
|
622 add_test(function(test_queryAccount_exists) { |
|
623 do_print("= queryAccount, exists ="); |
|
624 FakeFxAccountsClient._accountExists = true; |
|
625 FxAccountsManager.queryAccount("user@domain.org").then( |
|
626 result => { |
|
627 do_check_true(result.registered); |
|
628 run_next_test(); |
|
629 }, |
|
630 error => { |
|
631 do_throw("Unexpected error: " + error); |
|
632 } |
|
633 ); |
|
634 }); |
|
635 |
|
636 add_test(function(test_queryAccount_no_accountId) { |
|
637 do_print("= queryAccount, no accountId ="); |
|
638 FxAccountsManager.queryAccount().then( |
|
639 () => { |
|
640 do_throw("Unexpected success"); |
|
641 }, |
|
642 error => { |
|
643 do_check_eq(error.error, ERROR_INVALID_ACCOUNTID); |
|
644 run_next_test(); |
|
645 } |
|
646 ); |
|
647 }); |
|
648 |
|
649 add_test(function() { |
|
650 do_print("= fxaccounts:onlogout notification ="); |
|
651 do_check_true(FxAccountsManager._activeSession != null); |
|
652 Services.obs.notifyObservers(null, ONLOGOUT_NOTIFICATION, null); |
|
653 do_execute_soon(function() { |
|
654 do_check_null(FxAccountsManager._activeSession); |
|
655 run_next_test(); |
|
656 }); |
|
657 }); |