<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test no autofill into a password field that is no longer type=password</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="pwmgr_common.js"></script>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
</head>
<body>
Login Manager test: Test no autofill into a password field that is no longer type=password

<script>
let DEFAULT_ORIGIN = window.location.origin;

/** Test for Login Manager: Test no autofill into a password field that is no longer type=password **/

add_setup(async () => {
  await setStoredLoginsAsync(
    [DEFAULT_ORIGIN, "https://autofill", null, "user1", "pass1"]
  );
});


// As a control, test that autofill is working on this page.
add_task(async function test_autofill_control() {
  let win = window.open("about:blank");
  SimpleTest.registerCleanupFunction(() => win.close());
  await loadFormIntoWindow(DEFAULT_ORIGIN, `
    <form id="form1" action="https://autofill">
      <p>This is form 1.</p>
      <input id="username-1" type="text"       name="uname">
      <input id="password-1" type="password"   name="pword">

      <button type="submit">Submit</button>
    </form>`, win);
  await checkLoginFormInFrame(win, "username-1", "user1", "password-1", "pass1");
});

add_task(async function test_no_autofill() {
  let win = window.open("about:blank");
  SimpleTest.registerCleanupFunction(() => win.close());
  // Synchronously change the password field type to text before the fill happens.
  await loadFormIntoWindow(DEFAULT_ORIGIN, `
    <form id="form1" action="https://autofill">
      <p>This is form 1.</p>
      <input id="username-1" type="text"       name="uname">
      <input id="password-1" type="password"   name="pword">

      <button type="submit">Submit</button>
    </form>`, win, 1, () => {
      this.content.document.getElementById("password-1").type = "text";
    });
  await checkLoginFormInFrame(win, "username-1", "", "password-1", "");
});
</script>

<p id="display"></p>

<div id="content"></div>

<pre id="test"></pre>
</body>
</html>
