author Andreea Pavel <>
Thu, 11 Apr 2019 15:16:03 +0300
changeset 468987 5d5e4df2976a4649e0a717f75c5f311ea1385046
parent 468986 03ed53e600d458cef860664cbee5d5fdaf8e33f3
child 469279 cbae72da0dc4b0ab70cb29dbec66b460c83c9d7f
permissions -rw-r--r--
Backed out changeset 03ed53e600d4 (bug 1540828) for failing eslint on a CLOSED TREE

  <meta charset="utf-8">
  <title>Test that logins with non-matching formSubmitURL appear in autocomplete dropdown</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/AddTask.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" />
Login Manager test: logins with non-matching formSubmitURL appear in autocomplete dropdown

var chromeScript = runChecksAfterCommonInit();

runInParent(function setup() {
  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(";1",
                                           Ci.nsILoginInfo, "init");
  assert.ok(nsLoginInfo != null, "nsLoginInfo constructor");

  var login1 = new nsLoginInfo("", "https://differentFormSubmitURL", null,
                               "dfsu1", "dfsp1", "uname", "pword");

<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>
<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for Login Manager: multiple login autocomplete. **/

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

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

// Check for expected username/password in form.
function checkACForm(expectedUsername, expectedPassword) {
  var formID =;
  is(uname.value, expectedUsername, "Checking " + formID + " username is: " + expectedUsername);
  is(pword.value, expectedPassword, "Checking " + formID + " password is: " + expectedPassword);

function spinEventLoop() {
  return Promise.resolve();

add_task(async function setup() {

add_task(async function test_form1_initial_empty() {
  await SimpleTest.promiseFocus(window);

  // Make sure initial form is empty.
  checkACForm("", "");
  let popupState = await getPopupState();
  is(, false, "Check popup is initially closed");

/* For this testcase, the only login that exists for this origin
 * is one with a different formSubmitURL, so the login will appear
 * in the autocomplete popup.
add_task(async function test_form1_menu_shows_logins_for_different_formSubmitURL() {
  await SimpleTest.promiseFocus(window);
  // Trigger autocomplete popup
  let shownPromise = promiseACShown();
  synthesizeKey("KEY_ArrowDown"); // open
  let results = await shownPromise;

  let popupState = await getPopupState();
  is(popupState.selectedIndex, -1, "Check no entries are selected upon opening");

  let expectedMenuItems = ["dfsu1"];
  checkAutoCompleteResults(results, expectedMenuItems, "", "Check all menuitems are displayed correctly.");

  synthesizeKey("KEY_ArrowDown"); // first item
  checkACForm("", ""); // value shouldn't update just by selecting

  await promiseFormsProcessed();
  checkACForm("dfsu1", "dfsp1");