services/fxaccounts/tests/mochitest/test_invalidEmailCase.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial