services/fxaccounts/tests/mochitest/test_invalidEmailCase.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/services/fxaccounts/tests/mochitest/test_invalidEmailCase.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,126 @@
     1.4 +<!--
     1.5 +     Any copyright is dedicated to the Public Domain.
     1.6 +     http://creativecommons.org/publicdomain/zero/1.0/
     1.7 +-->
     1.8 +<!DOCTYPE HTML>
     1.9 +<html>
    1.10 +<!--
    1.11 +Tests for Firefox Accounts signin with invalid email case
    1.12 +https://bugzilla.mozilla.org/show_bug.cgi?id=963835
    1.13 +-->
    1.14 +<head>
    1.15 +  <title>Test for Firefox Accounts (Bug 963835)</title>
    1.16 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.17 +  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
    1.18 +</head>
    1.19 +<body>
    1.20 +
    1.21 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=963835">Mozilla Bug 963835</a>
    1.22 +<p id="display"></p>
    1.23 +<div id="content" style="display: none">
    1.24 +  Test for correction of invalid email case in Fx Accounts signIn
    1.25 +</div>
    1.26 +<pre id="test">
    1.27 +<script class="testbody" type="text/javascript;version=1.8">
    1.28 +
    1.29 +SimpleTest.waitForExplicitFinish();
    1.30 +
    1.31 +Components.utils.import("resource://gre/modules/Promise.jsm");
    1.32 +Components.utils.import("resource://gre/modules/Services.jsm");
    1.33 +Components.utils.import("resource://gre/modules/FxAccounts.jsm");
    1.34 +Components.utils.import("resource://gre/modules/FxAccountsClient.jsm");
    1.35 +Components.utils.import("resource://services-common/hawkclient.js");
    1.36 +
    1.37 +const TEST_SERVER =
    1.38 +  "http://mochi.test:8888/chrome/services/fxaccounts/tests/mochitest/file_invalidEmailCase.sjs?path=";
    1.39 +
    1.40 +let MockStorage = function() {
    1.41 +  this.data = null;
    1.42 +};
    1.43 +MockStorage.prototype = Object.freeze({
    1.44 +  set: function (contents) {
    1.45 +    this.data = contents;
    1.46 +    return Promise.resolve(null);
    1.47 +  },
    1.48 +  get: function () {
    1.49 +    return Promise.resolve(this.data);
    1.50 +  },
    1.51 +});
    1.52 +
    1.53 +function MockFxAccounts() {
    1.54 +  return new FxAccounts({
    1.55 +    _now_is: new Date(),
    1.56 +
    1.57 +    now: function() {
    1.58 +      return this._now_is;
    1.59 +    },
    1.60 +
    1.61 +    signedInUserStorage: new MockStorage(),
    1.62 +
    1.63 +    fxAccountsClient: new FxAccountsClient(TEST_SERVER),
    1.64 +  });
    1.65 +}
    1.66 +
    1.67 +let wrongEmail = "greta.garbo@gmail.com";
    1.68 +let rightEmail = "Greta.Garbo@gmail.COM";
    1.69 +let password = "123456";
    1.70 +
    1.71 +function runTest() {
    1.72 +  is(Services.prefs.getCharPref("identity.fxaccounts.auth.uri"), TEST_SERVER,
    1.73 +     "Pref for auth.uri should be set to test server");
    1.74 +
    1.75 +  let fxa = new MockFxAccounts();
    1.76 +  let client = fxa.internal.fxAccountsClient;
    1.77 +
    1.78 +  ok(true, !!fxa, "Couldn't mock fxa");
    1.79 +  ok(true, !!client, "Couldn't mock fxa client");
    1.80 +  is(client.host, TEST_SERVER, "Should be using the test auth server uri");
    1.81 +
    1.82 +  // First try to sign in using the email with the wrong capitalization.  The
    1.83 +  // FxAccountsClient will receive a 400 from the server with the corrected email.
    1.84 +  // It will automatically try to sign in again.  We expect this to succeed.
    1.85 +  client.signIn(wrongEmail, password).then(
    1.86 +    user => {
    1.87 +
    1.88 +      // Now store the signed-in user state.  This will include the correct
    1.89 +      // email capitalization.
    1.90 +      fxa.setSignedInUser(user).then(
    1.91 +        () => {
    1.92 +
    1.93 +          // Confirm that the correct email got stored.
    1.94 +          fxa.getSignedInUser().then(
    1.95 +            data => {
    1.96 +              is(data.email, rightEmail);
    1.97 +              SimpleTest.finish();
    1.98 +            },
    1.99 +            getUserError => {
   1.100 +              ok(false, JSON.stringify(getUserError));
   1.101 +            }
   1.102 +          );
   1.103 +        },
   1.104 +        setSignedInUserError => {
   1.105 +          ok(false, JSON.stringify(setSignedInUserError));
   1.106 +        }
   1.107 +      );
   1.108 +    },
   1.109 +    signInError => {
   1.110 +      ok(false, JSON.stringify(signInError));
   1.111 +    }
   1.112 +  );
   1.113 +};
   1.114 +
   1.115 +SpecialPowers.pushPrefEnv({"set": [
   1.116 +    ["dom.identity.enabled", true],                // navigator.mozId
   1.117 +    ["identity.fxaccounts.enabled", true],         // fx accounts
   1.118 +    ["identity.fxaccounts.auth.uri", TEST_SERVER], // our sjs server
   1.119 +    ["toolkit.identity.debug", true],              // verbose identity logging
   1.120 +    ["browser.dom.window.dump.enabled", true],
   1.121 +  ]},
   1.122 +  function () { runTest(); }
   1.123 +);
   1.124 +
   1.125 +</script>
   1.126 +</pre>
   1.127 +</body>
   1.128 +</html>
   1.129 +

mercurial