|
1 <!-- |
|
2 Any copyright is dedicated to the Public Domain. |
|
3 http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 --> |
|
5 <!DOCTYPE HTML> |
|
6 <html> |
|
7 <!-- |
|
8 Tests for Firefox Accounts signin with invalid email case |
|
9 https://bugzilla.mozilla.org/show_bug.cgi?id=963835 |
|
10 --> |
|
11 <head> |
|
12 <title>Test for Firefox Accounts (Bug 963835)</title> |
|
13 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
14 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> |
|
15 </head> |
|
16 <body> |
|
17 |
|
18 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=963835">Mozilla Bug 963835</a> |
|
19 <p id="display"></p> |
|
20 <div id="content" style="display: none"> |
|
21 Test for correction of invalid email case in Fx Accounts signIn |
|
22 </div> |
|
23 <pre id="test"> |
|
24 <script class="testbody" type="text/javascript;version=1.8"> |
|
25 |
|
26 SimpleTest.waitForExplicitFinish(); |
|
27 |
|
28 Components.utils.import("resource://gre/modules/Promise.jsm"); |
|
29 Components.utils.import("resource://gre/modules/Services.jsm"); |
|
30 Components.utils.import("resource://gre/modules/FxAccounts.jsm"); |
|
31 Components.utils.import("resource://gre/modules/FxAccountsClient.jsm"); |
|
32 Components.utils.import("resource://services-common/hawkclient.js"); |
|
33 |
|
34 const TEST_SERVER = |
|
35 "http://mochi.test:8888/chrome/services/fxaccounts/tests/mochitest/file_invalidEmailCase.sjs?path="; |
|
36 |
|
37 let MockStorage = function() { |
|
38 this.data = null; |
|
39 }; |
|
40 MockStorage.prototype = Object.freeze({ |
|
41 set: function (contents) { |
|
42 this.data = contents; |
|
43 return Promise.resolve(null); |
|
44 }, |
|
45 get: function () { |
|
46 return Promise.resolve(this.data); |
|
47 }, |
|
48 }); |
|
49 |
|
50 function MockFxAccounts() { |
|
51 return new FxAccounts({ |
|
52 _now_is: new Date(), |
|
53 |
|
54 now: function() { |
|
55 return this._now_is; |
|
56 }, |
|
57 |
|
58 signedInUserStorage: new MockStorage(), |
|
59 |
|
60 fxAccountsClient: new FxAccountsClient(TEST_SERVER), |
|
61 }); |
|
62 } |
|
63 |
|
64 let wrongEmail = "greta.garbo@gmail.com"; |
|
65 let rightEmail = "Greta.Garbo@gmail.COM"; |
|
66 let password = "123456"; |
|
67 |
|
68 function runTest() { |
|
69 is(Services.prefs.getCharPref("identity.fxaccounts.auth.uri"), TEST_SERVER, |
|
70 "Pref for auth.uri should be set to test server"); |
|
71 |
|
72 let fxa = new MockFxAccounts(); |
|
73 let client = fxa.internal.fxAccountsClient; |
|
74 |
|
75 ok(true, !!fxa, "Couldn't mock fxa"); |
|
76 ok(true, !!client, "Couldn't mock fxa client"); |
|
77 is(client.host, TEST_SERVER, "Should be using the test auth server uri"); |
|
78 |
|
79 // First try to sign in using the email with the wrong capitalization. The |
|
80 // FxAccountsClient will receive a 400 from the server with the corrected email. |
|
81 // It will automatically try to sign in again. We expect this to succeed. |
|
82 client.signIn(wrongEmail, password).then( |
|
83 user => { |
|
84 |
|
85 // Now store the signed-in user state. This will include the correct |
|
86 // email capitalization. |
|
87 fxa.setSignedInUser(user).then( |
|
88 () => { |
|
89 |
|
90 // Confirm that the correct email got stored. |
|
91 fxa.getSignedInUser().then( |
|
92 data => { |
|
93 is(data.email, rightEmail); |
|
94 SimpleTest.finish(); |
|
95 }, |
|
96 getUserError => { |
|
97 ok(false, JSON.stringify(getUserError)); |
|
98 } |
|
99 ); |
|
100 }, |
|
101 setSignedInUserError => { |
|
102 ok(false, JSON.stringify(setSignedInUserError)); |
|
103 } |
|
104 ); |
|
105 }, |
|
106 signInError => { |
|
107 ok(false, JSON.stringify(signInError)); |
|
108 } |
|
109 ); |
|
110 }; |
|
111 |
|
112 SpecialPowers.pushPrefEnv({"set": [ |
|
113 ["dom.identity.enabled", true], // navigator.mozId |
|
114 ["identity.fxaccounts.enabled", true], // fx accounts |
|
115 ["identity.fxaccounts.auth.uri", TEST_SERVER], // our sjs server |
|
116 ["toolkit.identity.debug", true], // verbose identity logging |
|
117 ["browser.dom.window.dump.enabled", true], |
|
118 ]}, |
|
119 function () { runTest(); } |
|
120 ); |
|
121 |
|
122 </script> |
|
123 </pre> |
|
124 </body> |
|
125 </html> |
|
126 |