Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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>
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">
26 SimpleTest.waitForExplicitFinish();
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");
34 const TEST_SERVER =
35 "http://mochi.test:8888/chrome/services/fxaccounts/tests/mochitest/file_invalidEmailCase.sjs?path=";
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 });
50 function MockFxAccounts() {
51 return new FxAccounts({
52 _now_is: new Date(),
54 now: function() {
55 return this._now_is;
56 },
58 signedInUserStorage: new MockStorage(),
60 fxAccountsClient: new FxAccountsClient(TEST_SERVER),
61 });
62 }
64 let wrongEmail = "greta.garbo@gmail.com";
65 let rightEmail = "Greta.Garbo@gmail.COM";
66 let password = "123456";
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");
72 let fxa = new MockFxAccounts();
73 let client = fxa.internal.fxAccountsClient;
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");
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 => {
85 // Now store the signed-in user state. This will include the correct
86 // email capitalization.
87 fxa.setSignedInUser(user).then(
88 () => {
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 };
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 );
122 </script>
123 </pre>
124 </body>
125 </html>