|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 "use strict"; |
|
5 |
|
6 XPCOMUtils.defineLazyModuleGetter(this, "IDService", |
|
7 "resource://gre/modules/identity/Identity.jsm", |
|
8 "IdentityService"); |
|
9 |
|
10 function test_overall() { |
|
11 do_check_neq(IDService, null); |
|
12 run_next_test(); |
|
13 } |
|
14 |
|
15 function test_mock_doc() { |
|
16 do_test_pending(); |
|
17 let mockedDoc = mock_doc(null, TEST_URL, function(action, params) { |
|
18 do_check_eq(action, 'coffee'); |
|
19 do_test_finished(); |
|
20 run_next_test(); |
|
21 }); |
|
22 |
|
23 mockedDoc.doCoffee(); |
|
24 } |
|
25 |
|
26 function test_add_identity() { |
|
27 IDService.reset(); |
|
28 |
|
29 IDService.addIdentity(TEST_USER); |
|
30 |
|
31 let identities = IDService.RP.getIdentitiesForSite(TEST_URL); |
|
32 do_check_eq(identities.result.length, 1); |
|
33 do_check_eq(identities.result[0], TEST_USER); |
|
34 |
|
35 run_next_test(); |
|
36 } |
|
37 |
|
38 function test_select_identity() { |
|
39 do_test_pending(); |
|
40 |
|
41 IDService.reset(); |
|
42 |
|
43 let id = "ishtar@mockmyid.com"; |
|
44 setup_test_identity(id, TEST_CERT, function() { |
|
45 let gotAssertion = false; |
|
46 let mockedDoc = mock_doc(null, TEST_URL, call_sequentially( |
|
47 function(action, params) { |
|
48 // ready emitted from first watch() call |
|
49 do_check_eq(action, 'ready'); |
|
50 do_check_null(params); |
|
51 }, |
|
52 // first the login call |
|
53 function(action, params) { |
|
54 do_check_eq(action, 'login'); |
|
55 do_check_neq(params, null); |
|
56 |
|
57 // XXX - check that the assertion is for the right email |
|
58 |
|
59 gotAssertion = true; |
|
60 }, |
|
61 // then the ready call |
|
62 function(action, params) { |
|
63 do_check_eq(action, 'ready'); |
|
64 do_check_null(params); |
|
65 |
|
66 // we should have gotten the assertion already |
|
67 do_check_true(gotAssertion); |
|
68 |
|
69 do_test_finished(); |
|
70 run_next_test(); |
|
71 })); |
|
72 |
|
73 // register the callbacks |
|
74 IDService.RP.watch(mockedDoc); |
|
75 |
|
76 // register the request UX observer |
|
77 makeObserver("identity-request", function (aSubject, aTopic, aData) { |
|
78 // do the select identity |
|
79 // we expect this to succeed right away because of test_identity |
|
80 // so we don't mock network requests or otherwise |
|
81 IDService.selectIdentity(aSubject.wrappedJSObject.rpId, id); |
|
82 }); |
|
83 |
|
84 // do the request |
|
85 IDService.RP.request(mockedDoc.id, {}); |
|
86 }); |
|
87 } |
|
88 |
|
89 function test_parse_good_email() { |
|
90 var parsed = IDService.parseEmail('prime-minister@jed.gov'); |
|
91 do_check_eq(parsed.username, 'prime-minister'); |
|
92 do_check_eq(parsed.domain, 'jed.gov'); |
|
93 run_next_test(); |
|
94 } |
|
95 |
|
96 function test_parse_bogus_emails() { |
|
97 do_check_eq(null, IDService.parseEmail('@evil.org')); |
|
98 do_check_eq(null, IDService.parseEmail('foo@bar@baz.com')); |
|
99 do_check_eq(null, IDService.parseEmail('you@wellsfargo.com/accounts/transfer?to=dolske&amt=all')); |
|
100 run_next_test(); |
|
101 } |
|
102 |
|
103 let TESTS = [test_overall, test_mock_doc]; |
|
104 |
|
105 TESTS.push(test_add_identity); |
|
106 TESTS.push(test_select_identity); |
|
107 TESTS.push(test_parse_good_email); |
|
108 TESTS.push(test_parse_bogus_emails); |
|
109 |
|
110 TESTS.forEach(add_test); |
|
111 |
|
112 function run_test() { |
|
113 run_next_test(); |
|
114 } |