toolkit/components/passwordmgr/test/mochitest/test_autofill_different_formSubmitURL.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 autofill on an HTTPS page using upgraded HTTP logins wtih different formSubmitURL</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="text/javascript" src="pwmgr_common.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script>
const MISSING_ACTION_PATH = TESTS_DIR + "mochitest/form_basic.html";

const chromeScript = runChecksAfterCommonInit(false);

let nsLoginInfo = SpecialPowers.wrap(SpecialPowers.Components).Constructor("@mozilla.org/login-manager/loginInfo;1",
                                                                           SpecialPowers.Ci.nsILoginInfo,
                                                                           "init");
</script>
<p id="display"></p>

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

<pre id="test">
<script class="testbody" type="text/javascript">
let iframe = SpecialPowers.wrap(document.getElementsByTagName("iframe")[0]);

async function prepareLoginsAndProcessForm(url, logins = []) {
  LoginManager.removeAllLogins();

  let dates = Date.now();
  for (let login of logins) {
    SpecialPowers.do_QueryInterface(login, SpecialPowers.Ci.nsILoginMetaInfo);
    // Force all dates to be the same so they don't affect things like deduping.
    login.timeCreated = login.timePasswordChanged = login.timeLastUsed = dates;
    LoginManager.addLogin(login);
  }

  iframe.src = url;
  await promiseFormsProcessed();
}

add_task(async function test_formSubmitURL_wildcard_should_autofill() {
  await prepareLoginsAndProcessForm("https://example.com" + MISSING_ACTION_PATH, [
    new nsLoginInfo("https://example.com", "", null,
                    "name2", "pass2", "uname", "pword"),
  ]);

  let iframeDoc = iframe.contentDocument;
  let uname = iframeDoc.getElementById("form-basic-username");
  let pword = iframeDoc.getElementById("form-basic-password");
  checkLoginForm(uname, "name2", pword, "pass2");
});

add_task(async function test_formSubmitURL_different_shouldnt_autofill() {
  await prepareLoginsAndProcessForm("https://example.com" + MISSING_ACTION_PATH, [
    new nsLoginInfo("https://example.com", "https://another.domain", null,
                    "name2", "pass2", "uname", "pword"),
  ]);

  let iframeDoc = iframe.contentDocument;
  let uname = iframeDoc.getElementById("form-basic-username");
  let pword = iframeDoc.getElementById("form-basic-password");
  checkLoginForm(uname, "", pword, "");
});

</script>
</pre>
</body>
</html>