зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1852745 - modernize test_autocomplete_hasBeenTypePassword.html - r=credential-management-reviewers,dimi
Differential Revision: https://phabricator.services.mozilla.com/D190593
This commit is contained in:
Родитель
c55d0f391a
Коммит
80bb9c6927
|
@ -10,91 +10,83 @@
|
|||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
Login Manager test: Test that passwords are autocompleted into fields that were previously type=password
|
||||
<p id="display"></p>
|
||||
|
||||
<!-- we presumably can't hide the content for this test. -->
|
||||
<div id="content"></div>
|
||||
<pre id="test">
|
||||
Login Manager test: Test that passwords are autocompleted into fields that were
|
||||
previously type=password
|
||||
|
||||
Usually the autocomplete login form only operates on password fields which are
|
||||
of type `password`. But when a password fields type has been changed to `text`
|
||||
via JavaScript, the password manager should still fill this form, because this
|
||||
is often used in real world forms to handle masking/unmasking of password
|
||||
fields.
|
||||
|
||||
<template id="form1-template">
|
||||
<form id="form1" action="https://www.example.com/formtest.js">
|
||||
<input type="text" name="uname">
|
||||
<input type="password" name="pword">
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script class="testbody" type="text/javascript">
|
||||
const formTemplate = document.getElementById("form1-template");
|
||||
|
||||
// Restore the form to the default state.
|
||||
function restoreForm(form) {
|
||||
form.uname.value = "";
|
||||
form.pword.value = "";
|
||||
form.uname.focus();
|
||||
}
|
||||
|
||||
function spinEventLoop() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
add_setup(async () => {
|
||||
const origin = window.location.origin;
|
||||
await setStoredLoginsAsync(
|
||||
[origin, origin, null, "user1", "pass1"],
|
||||
[origin, origin, null, "user2", "pass2"]
|
||||
);
|
||||
listenForUnexpectedPopupShown();
|
||||
});
|
||||
|
||||
add_task(async function test_form1_initial_empty() {
|
||||
const form = createLoginForm({
|
||||
action: "https://www.example.com/formtest.js"
|
||||
add_setup(async () => {
|
||||
const origin = window.location.origin;
|
||||
await setStoredLoginsDuringTest(
|
||||
[origin, origin, null, "user1", "pass1"],
|
||||
[origin, origin, null, "user2", "pass2"]
|
||||
);
|
||||
listenForUnexpectedPopupShown();
|
||||
});
|
||||
|
||||
await SimpleTest.promiseFocus(window);
|
||||
add_named_task("autofill operates on a password field made text", async () => {
|
||||
const form = setContentForTask(formTemplate);
|
||||
|
||||
// Make sure initial form is empty.
|
||||
checkLoginForm(form.uname, "", form.pword, "");
|
||||
const popupState = await getPopupState();
|
||||
is(popupState.open, false, "Check popup is initially closed");
|
||||
});
|
||||
// initial consume autofill event
|
||||
await formAutofillResult(form.id);
|
||||
|
||||
add_task(async function test_form1_password_to_type_text() {
|
||||
const form = createLoginForm({
|
||||
action: "https://www.example.com/formtest.js"
|
||||
info("Setting the password field type to text");
|
||||
// This is similar to a site implementing their own password visibility/unmasking toggle
|
||||
form.pword.type = "text";
|
||||
|
||||
// Trigger autocomplete popup
|
||||
form.uname.focus();
|
||||
const autocompleteItems = await popupByArrowDown();
|
||||
|
||||
const popupState = await getPopupState();
|
||||
is(popupState.selectedIndex, -1, "Check no entries are selected upon opening");
|
||||
|
||||
checkAutoCompleteResults(autocompleteItems, ["user1", "user2"], window.location.host,
|
||||
"Check all menuitems are displayed correctly.");
|
||||
|
||||
synthesizeKey("KEY_ArrowDown"); // first item
|
||||
// value shouldn't update just by selecting
|
||||
is(form.uname.value, "", "username is empty");
|
||||
is(form.pword.value, "", "password is empty");
|
||||
|
||||
synthesizeKey("KEY_Enter");
|
||||
|
||||
const autofillResult1 = await formAutofillResult(form.id);
|
||||
is(autofillResult1, "filled", "form has been filled");
|
||||
|
||||
is(form.uname.value, "user1", "username should match the login");
|
||||
is(form.pword.value, "pass1", "password should match the login");
|
||||
|
||||
form.reset();
|
||||
|
||||
form.pword.focus();
|
||||
await popupByArrowDown();
|
||||
synthesizeKey("KEY_ArrowDown"); // first item
|
||||
// value shouldn't update just by selecting
|
||||
is(form.uname.value, "", "username is empty");
|
||||
is(form.pword.value, "", "password is empty");
|
||||
|
||||
synthesizeKey("KEY_Enter");
|
||||
is(form.uname.value, "", "username should stay empty");
|
||||
is(form.pword.value, "pass1", "Password should match the login that was selected");
|
||||
});
|
||||
|
||||
await SimpleTest.promiseFocus(window);
|
||||
info("Setting the password field type to text");
|
||||
// This is similar to a site implementing their own password visibility/unmasking toggle
|
||||
form.pword.type = "text";
|
||||
|
||||
// Trigger autocomplete popup
|
||||
restoreForm(form);
|
||||
const autocompleteItems = await popupByArrowDown();
|
||||
|
||||
const popupState = await getPopupState();
|
||||
is(popupState.selectedIndex, -1, "Check no entries are selected upon opening");
|
||||
|
||||
checkAutoCompleteResults(autocompleteItems, ["user1", "user2"], window.location.host,
|
||||
"Check all menuitems are displayed correctly.");
|
||||
|
||||
synthesizeKey("KEY_ArrowDown"); // first item
|
||||
checkLoginForm(form.uname, "", form.pword, ""); // value shouldn't update just by selecting
|
||||
|
||||
synthesizeKey("KEY_Enter");
|
||||
|
||||
await promiseFormsProcessedInSameProcess();
|
||||
is(form.uname.value, "user1", "username should match the login, not the password");
|
||||
is(form.pword.value, "pass1", "password should match the login, not the username");
|
||||
checkLoginForm(form.uname, "user1", form.pword, "pass1");
|
||||
|
||||
restoreForm(form);
|
||||
info("Focusing the password field");
|
||||
form.pword.focus();
|
||||
|
||||
await popupByArrowDown();
|
||||
|
||||
synthesizeKey("KEY_ArrowDown"); // first item
|
||||
checkLoginForm(form.uname, "", form.pword, ""); // value shouldn't update just by selecting
|
||||
|
||||
synthesizeKey("KEY_Enter");
|
||||
await spinEventLoop();
|
||||
is(form.pword.value, "pass1", "Password should match the login that was selected");
|
||||
checkLoginForm(form.uname, "", form.pword, "pass1");
|
||||
});
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
|
|
Загрузка…
Ссылка в новой задаче