toolkit/components/passwordmgr/test/mochitest/test_case_differences.html
author Andreea Pavel <apavel@mozilla.com>
Fri, 19 Apr 2019 00:36:23 +0300
changeset 528866 b44914767f72367a7e4b01c9fd0ba9258c41570c
parent 528828 c83490ca7185506ddf5e9828f8159930c03d15a0
parent 528856 2165a58403b6fe7826fe32d88a5814ff96489d8b
permissions -rw-r--r--
Merge mozilla-inbound to mozilla-central. a=merge

<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test autocomplete due to multiple matching logins</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="text/javascript" src="../../../satchel/test/satchel_common.js"></script>
  <script type="text/javascript" src="pwmgr_common.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Login Manager test: autocomplete due to multiple matching logins

<script>
runChecksAfterCommonInit(false);

SpecialPowers.loadChromeScript(function addLogins() {
  const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");

  // Create some logins just for this form, since we'll be deleting them.
  var nsLoginInfo = Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
                                           Ci.nsILoginInfo, "init");

  var login0 = new nsLoginInfo("https://example.com", "https://autocomplete:8888", null,
                               "name", "pass", "uname", "pword");

  var login1 = new nsLoginInfo("https://example.com", "https://autocomplete:8888", null,
                               "Name", "Pass", "uname", "pword");

  var login2 = new nsLoginInfo("https://example.com", "https://autocomplete:8888", null,
                               "USER", "PASS", "uname", "pword");

  try {
    Services.logins.addLogin(login0);
    Services.logins.addLogin(login1);
    Services.logins.addLogin(login2);
  } catch (e) {
    assert.ok(false, "addLogin threw: " + e);
  }
});
</script>
<p id="display"></p>

<!-- we presumably can't hide the content for this test. -->
<div id="content">

  <!-- form1 tests multiple matching logins -->
  <form id="form1" action="https://autocomplete:8888/formtest.js" onsubmit="return false;">
    <input  type="text"       name="uname">
    <input  type="password"   name="pword">
    <button type="submit">Submit</button>
  </form>

</div>

<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for Login Manager: autocomplete due to multiple matching logins **/

var uname = $_(1, "uname");
var pword = $_(1, "pword");

// Restore the form to the default state.
function restoreForm() {
  uname.value = "";
  pword.value = "";
  uname.focus();
}


add_task(async function test_empty_first_entry() {
  /* test 1 */
  // Make sure initial form is empty.
  checkLoginForm(uname, "", pword, "");
  // Trigger autocomplete popup
  restoreForm();
  let popupState = await getPopupState();
  is(popupState.open, false, "Check popup is initially closed");
  let shownPromise = promiseACShown();
  synthesizeKey("KEY_ArrowDown");
  let results = await shownPromise;
  popupState = await getPopupState();
  is(popupState.selectedIndex, -1, "Check no entries are selected");
  checkAutoCompleteResults(results, ["name", "Name", "USER"], "example.com", "initial");

  // Check first entry
  let index0Promise = notifySelectedIndex(0);
  synthesizeKey("KEY_ArrowDown");
  await index0Promise;
  checkLoginForm(uname, "", pword, ""); // value shouldn't update
  synthesizeKey("KEY_Enter");
  await promiseFormsProcessed();
  checkLoginForm(uname, "name", pword, "pass");
});

add_task(async function test_empty_second_entry() {
  restoreForm();
  let shownPromise = promiseACShown();
  synthesizeKey("KEY_ArrowDown"); // open
  await shownPromise;
  synthesizeKey("KEY_ArrowDown"); // first
  synthesizeKey("KEY_ArrowDown"); // second
  synthesizeKey("KEY_Enter");
  await promiseFormsProcessed();
  checkLoginForm(uname, "Name", pword, "Pass");
});

add_task(async function test_empty_third_entry() {
  restoreForm();
  let shownPromise = promiseACShown();
  synthesizeKey("KEY_ArrowDown"); // open
  await shownPromise;
  synthesizeKey("KEY_ArrowDown"); // first
  synthesizeKey("KEY_ArrowDown"); // second
  synthesizeKey("KEY_ArrowDown"); // third
  synthesizeKey("KEY_Enter");
  await promiseFormsProcessed();
  checkLoginForm(uname, "USER", pword, "PASS");
});

add_task(async function test_preserve_matching_username_case() {
  restoreForm();
  uname.value = "user";
  let shownPromise = promiseACShown();
  synthesizeKey("KEY_ArrowDown"); // open
  await shownPromise;

  // Check that we don't clobber user-entered text when tabbing away
  // (even with no autocomplete entry selected)
  synthesizeKey("KEY_Tab");
  await promiseFormsProcessed();
  checkLoginForm(uname, "user", pword, "PASS");
});
</script>
</pre>
</body>
</html>