mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 1777035 - flatten function calls - r=credential-management-reviewers,sgalich
Differential Revision: https://phabricator.services.mozilla.com/D183795
This commit is contained in:
parent
4fcb7d6b20
commit
e9cbc9a22f
@ -29,7 +29,7 @@ Login Manager test: filling generated passwords into confirm password fields
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
function testConfirmPasswordFieldFilledWithGeneratedPassword({
|
async function testConfirmPasswordFieldFilledWithGeneratedPassword({
|
||||||
title,
|
title,
|
||||||
html,
|
html,
|
||||||
afterFormAutofill,
|
afterFormAutofill,
|
||||||
@ -38,109 +38,106 @@ Login Manager test: filling generated passwords into confirm password fields
|
|||||||
afterPasswordGeneration
|
afterPasswordGeneration
|
||||||
}) {
|
}) {
|
||||||
const content = document.querySelector("#content");
|
const content = document.querySelector("#content");
|
||||||
|
info(`Test confirm password filled with generated password: ${title}`);
|
||||||
|
|
||||||
return async () => {
|
await setupScript.sendAsyncMessage("resetLoginsAndGeneratedPasswords");
|
||||||
info(`Test confirm password filled with generated password: ${title}`);
|
|
||||||
|
|
||||||
await setupScript.sendAsyncMessage("resetLoginsAndGeneratedPasswords");
|
// eslint-disable-next-line no-unsanitized/property
|
||||||
|
content.innerHTML = html;
|
||||||
|
|
||||||
// eslint-disable-next-line no-unsanitized/property
|
// wait for the just created form to get autofilled
|
||||||
content.innerHTML = html;
|
await promiseFormsProcessed();
|
||||||
|
|
||||||
// wait for the just created form to get autofilled
|
const form = content.querySelector('form');
|
||||||
await promiseFormsProcessed();
|
// ensure form did not get initially filled
|
||||||
|
is(form.uname.value, "", "Username is not filled");
|
||||||
|
is(form.pword.value, "", "Password is not filled");
|
||||||
|
|
||||||
const form = content.querySelector('form');
|
if (afterFormAutofill) {
|
||||||
// ensure form did not get initially filled
|
await afterFormAutofill(form);
|
||||||
is(form.uname.value, "", "Username is not filled");
|
|
||||||
is(form.pword.value, "", "Password is not filled");
|
|
||||||
|
|
||||||
if (afterFormAutofill) {
|
|
||||||
await afterFormAutofill(form);
|
|
||||||
}
|
|
||||||
|
|
||||||
// trigger autocomplete popup
|
|
||||||
const { items } = await openPopupOn(form.pword)
|
|
||||||
info("triggering password confirmation");
|
|
||||||
|
|
||||||
// examine the popup contents
|
|
||||||
checkAutoCompleteResults(items, [
|
|
||||||
"Use a Securely Generated Password"
|
|
||||||
], location.host, "Check all rows are correct");
|
|
||||||
|
|
||||||
// Then select generated password
|
|
||||||
synthesizeKey("KEY_ArrowDown");
|
|
||||||
synthesizeKey("KEY_Enter");
|
|
||||||
|
|
||||||
// and wait until the password has been filled.
|
|
||||||
await SimpleTest.promiseWaitForCondition(() => !!form.pword.value, "Wait for generated password to get filled");
|
|
||||||
|
|
||||||
ok(form.pword.matches(":autofill"), "Highlight was applied to the form.pword field");
|
|
||||||
|
|
||||||
const generatedPassword = form.pword.value;
|
|
||||||
is(generatedPassword.length, GENERATED_PASSWORD_LENGTH, "Generated password length matches");
|
|
||||||
ok(generatedPassword.match(GENERATED_PASSWORD_REGEX), "Generated password format matches");
|
|
||||||
|
|
||||||
LOGIN_FIELD_UTILS.checkPasswordMasked(form.pword, false, "password field not masked after fill");
|
|
||||||
|
|
||||||
if (expectMaskedPasswordConfirmation) {
|
|
||||||
LOGIN_FIELD_UTILS.checkPasswordMasked(form.pwordNext, true, "password confirmation field is masked");
|
|
||||||
}
|
|
||||||
|
|
||||||
ok(!form.uname.matches(":autofill"), "Highlight was not applied to the field");
|
|
||||||
is(form.uname.value, "", "Value is still empty")
|
|
||||||
|
|
||||||
if (afterPasswordGeneration) {
|
|
||||||
afterPasswordGeneration(form);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check the 2 field values aren't mirrored
|
|
||||||
|
|
||||||
// changing the password field value should result in a message sent to the parent process
|
|
||||||
const messageSentPromise = getPasswordEditedMessage();
|
|
||||||
|
|
||||||
// add a character
|
|
||||||
form.pword.focus()
|
|
||||||
synthesizeKey("KEY_End");
|
|
||||||
synthesizeKey("@");
|
|
||||||
|
|
||||||
is(form.pword.value, `${generatedPassword}@`, "Value of the first password field changed");
|
|
||||||
|
|
||||||
// bluring results in a "change" event
|
|
||||||
form.pword.blur();
|
|
||||||
|
|
||||||
await messageSentPromise;
|
|
||||||
|
|
||||||
if (expectMaskedPasswordConfirmation) {
|
|
||||||
LOGIN_FIELD_UTILS.checkPasswordMasked(form.pwordNext, true, "password confirmation field is masked");
|
|
||||||
}
|
|
||||||
if (expectFilledPasswordConfirmation === true) {
|
|
||||||
is(form.pwordNext.value, generatedPassword, "Value of the confirm field has been filled with generated password");
|
|
||||||
ok(form.pwordNext.matches(":autofill"), "Highlight was applied to the input field");
|
|
||||||
} else {
|
|
||||||
is(form.pwordNext.value, expectFilledPasswordConfirmation, "Value of the confirm field did not change");
|
|
||||||
ok(!form.pwordNext.matches(":autofill"), "Highlight was not applied to the input field");
|
|
||||||
}
|
|
||||||
|
|
||||||
form.pwordNext.focus();
|
|
||||||
form.pwordNext.select();
|
|
||||||
synthesizeKey("KEY_Backspace");
|
|
||||||
|
|
||||||
// verify the focused confirm field now masks its input like a normal,
|
|
||||||
// non-generated password field after being emptied
|
|
||||||
form.pwordNext.focus();
|
|
||||||
synthesizeKey("a");
|
|
||||||
form.pwordNext.blur();
|
|
||||||
|
|
||||||
if (expectMaskedPasswordConfirmation) {
|
|
||||||
LOGIN_FIELD_UTILS.checkPasswordMasked(form.pwordNext, true, "password confirmation field is masked");
|
|
||||||
}
|
|
||||||
|
|
||||||
await SimpleTest.promiseWaitForCondition(() => !form.pwordNext.matches(":autofill"), "Highlight was cleared");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// trigger autocomplete popup
|
||||||
|
const { items } = await openPopupOn(form.pword)
|
||||||
|
info("triggering password confirmation");
|
||||||
|
|
||||||
|
// examine the popup contents
|
||||||
|
checkAutoCompleteResults(items, [
|
||||||
|
"Use a Securely Generated Password"
|
||||||
|
], location.host, "Check all rows are correct");
|
||||||
|
|
||||||
|
// Then select generated password
|
||||||
|
synthesizeKey("KEY_ArrowDown");
|
||||||
|
synthesizeKey("KEY_Enter");
|
||||||
|
|
||||||
|
// and wait until the password has been filled.
|
||||||
|
await SimpleTest.promiseWaitForCondition(() => !!form.pword.value, "Wait for generated password to get filled");
|
||||||
|
|
||||||
|
ok(form.pword.matches(":autofill"), "Highlight was applied to the form.pword field");
|
||||||
|
|
||||||
|
const generatedPassword = form.pword.value;
|
||||||
|
is(generatedPassword.length, GENERATED_PASSWORD_LENGTH, "Generated password length matches");
|
||||||
|
ok(generatedPassword.match(GENERATED_PASSWORD_REGEX), "Generated password format matches");
|
||||||
|
|
||||||
|
LOGIN_FIELD_UTILS.checkPasswordMasked(form.pword, false, "password field not masked after fill");
|
||||||
|
|
||||||
|
if (expectMaskedPasswordConfirmation) {
|
||||||
|
LOGIN_FIELD_UTILS.checkPasswordMasked(form.pwordNext, true, "password confirmation field is masked");
|
||||||
|
}
|
||||||
|
|
||||||
|
ok(!form.uname.matches(":autofill"), "Highlight was not applied to the field");
|
||||||
|
is(form.uname.value, "", "Value is still empty")
|
||||||
|
|
||||||
|
if (afterPasswordGeneration) {
|
||||||
|
afterPasswordGeneration(form);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the 2 field values aren't mirrored
|
||||||
|
|
||||||
|
// changing the password field value should result in a message sent to the parent process
|
||||||
|
const messageSentPromise = getPasswordEditedMessage();
|
||||||
|
|
||||||
|
// add a character
|
||||||
|
form.pword.focus()
|
||||||
|
synthesizeKey("KEY_End");
|
||||||
|
synthesizeKey("@");
|
||||||
|
|
||||||
|
is(form.pword.value, `${generatedPassword}@`, "Value of the first password field changed");
|
||||||
|
|
||||||
|
// bluring results in a "change" event
|
||||||
|
form.pword.blur();
|
||||||
|
|
||||||
|
await messageSentPromise;
|
||||||
|
|
||||||
|
if (expectMaskedPasswordConfirmation) {
|
||||||
|
LOGIN_FIELD_UTILS.checkPasswordMasked(form.pwordNext, true, "password confirmation field is masked");
|
||||||
|
}
|
||||||
|
if (expectFilledPasswordConfirmation === true) {
|
||||||
|
is(form.pwordNext.value, generatedPassword, "Value of the confirm field has been filled with generated password");
|
||||||
|
ok(form.pwordNext.matches(":autofill"), "Highlight was applied to the input field");
|
||||||
|
} else {
|
||||||
|
is(form.pwordNext.value, expectFilledPasswordConfirmation, "Value of the confirm field did not change");
|
||||||
|
ok(!form.pwordNext.matches(":autofill"), "Highlight was not applied to the input field");
|
||||||
|
}
|
||||||
|
|
||||||
|
form.pwordNext.focus();
|
||||||
|
form.pwordNext.select();
|
||||||
|
synthesizeKey("KEY_Backspace");
|
||||||
|
|
||||||
|
// verify the focused confirm field now masks its input like a normal,
|
||||||
|
// non-generated password field after being emptied
|
||||||
|
form.pwordNext.focus();
|
||||||
|
synthesizeKey("a");
|
||||||
|
form.pwordNext.blur();
|
||||||
|
|
||||||
|
if (expectMaskedPasswordConfirmation) {
|
||||||
|
LOGIN_FIELD_UTILS.checkPasswordMasked(form.pwordNext, true, "password confirmation field is masked");
|
||||||
|
}
|
||||||
|
|
||||||
|
await SimpleTest.promiseWaitForCondition(() => !form.pwordNext.matches(":autofill"), "Highlight was cleared");
|
||||||
}
|
}
|
||||||
|
|
||||||
add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({
|
add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({
|
||||||
title: "fill next password field",
|
title: "fill next password field",
|
||||||
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
||||||
<input type="text" name="uname">
|
<input type="text" name="uname">
|
||||||
@ -152,7 +149,7 @@ Login Manager test: filling generated passwords into confirm password fields
|
|||||||
expectFilledPasswordConfirmation: true
|
expectFilledPasswordConfirmation: true
|
||||||
}));
|
}));
|
||||||
|
|
||||||
add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({
|
add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({
|
||||||
title: "fill next password field type text",
|
title: "fill next password field type text",
|
||||||
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
||||||
<input type="text" name="uname">
|
<input type="text" name="uname">
|
||||||
@ -167,7 +164,7 @@ Login Manager test: filling generated passwords into confirm password fields
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({
|
add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({
|
||||||
title: "do not fill non empty next password field",
|
title: "do not fill non empty next password field",
|
||||||
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
||||||
<input type="text" name="uname">
|
<input type="text" name="uname">
|
||||||
@ -179,7 +176,7 @@ Login Manager test: filling generated passwords into confirm password fields
|
|||||||
expectFilledPasswordConfirmation: "initial value"
|
expectFilledPasswordConfirmation: "initial value"
|
||||||
}));
|
}));
|
||||||
|
|
||||||
add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({
|
add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({
|
||||||
title: "do not fill edited next password field",
|
title: "do not fill edited next password field",
|
||||||
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
||||||
<input type="text" name="uname">
|
<input type="text" name="uname">
|
||||||
@ -195,7 +192,7 @@ Login Manager test: filling generated passwords into confirm password fields
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({
|
add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({
|
||||||
title: "ignore readonly field",
|
title: "ignore readonly field",
|
||||||
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
||||||
<input type="text" name="uname">
|
<input type="text" name="uname">
|
||||||
@ -207,7 +204,7 @@ Login Manager test: filling generated passwords into confirm password fields
|
|||||||
expectFilledPasswordConfirmation: ""
|
expectFilledPasswordConfirmation: ""
|
||||||
}));
|
}));
|
||||||
|
|
||||||
add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({
|
add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({
|
||||||
title: "ignore disabled field",
|
title: "ignore disabled field",
|
||||||
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
||||||
<input type="text" name="uname">
|
<input type="text" name="uname">
|
||||||
@ -219,7 +216,7 @@ Login Manager test: filling generated passwords into confirm password fields
|
|||||||
expectFilledPasswordConfirmation: ""
|
expectFilledPasswordConfirmation: ""
|
||||||
}));
|
}));
|
||||||
|
|
||||||
add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({
|
add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({
|
||||||
title: "prefer matching autocomplete info password field",
|
title: "prefer matching autocomplete info password field",
|
||||||
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
||||||
<input type="text" name="uname">
|
<input type="text" name="uname">
|
||||||
@ -232,7 +229,7 @@ Login Manager test: filling generated passwords into confirm password fields
|
|||||||
expectFilledPasswordConfirmation: true
|
expectFilledPasswordConfirmation: true
|
||||||
}));
|
}));
|
||||||
|
|
||||||
add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({
|
add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({
|
||||||
title: "ignore disabled matching autocomplete info password field",
|
title: "ignore disabled matching autocomplete info password field",
|
||||||
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
||||||
<input type="text" name="uname">
|
<input type="text" name="uname">
|
||||||
@ -245,7 +242,7 @@ Login Manager test: filling generated passwords into confirm password fields
|
|||||||
expectFilledPasswordConfirmation: ""
|
expectFilledPasswordConfirmation: ""
|
||||||
}));
|
}));
|
||||||
|
|
||||||
add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({
|
add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({
|
||||||
title: "ignore too distant password confirmation field",
|
title: "ignore too distant password confirmation field",
|
||||||
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
||||||
<input type="text" name="uname">
|
<input type="text" name="uname">
|
||||||
@ -262,7 +259,7 @@ Login Manager test: filling generated passwords into confirm password fields
|
|||||||
expectFilledPasswordConfirmation: ""
|
expectFilledPasswordConfirmation: ""
|
||||||
}));
|
}));
|
||||||
|
|
||||||
add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({
|
add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({
|
||||||
title: "too many disabled fields",
|
title: "too many disabled fields",
|
||||||
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
||||||
<input type="text" name="uname">
|
<input type="text" name="uname">
|
||||||
@ -279,7 +276,7 @@ Login Manager test: filling generated passwords into confirm password fields
|
|||||||
expectFilledPasswordConfirmation: ""
|
expectFilledPasswordConfirmation: ""
|
||||||
}));
|
}));
|
||||||
|
|
||||||
add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({
|
add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({
|
||||||
title: "skip over hidden fields",
|
title: "skip over hidden fields",
|
||||||
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
||||||
<input type="text" name="uname">
|
<input type="text" name="uname">
|
||||||
@ -297,7 +294,7 @@ Login Manager test: filling generated passwords into confirm password fields
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
// this form has a password field after the confirm-password field we don't want to fill into
|
// this form has a password field after the confirm-password field we don't want to fill into
|
||||||
add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({
|
add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({
|
||||||
title: "do not fill third password field",
|
title: "do not fill third password field",
|
||||||
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
html: `<form id="form1" action="https://example.com" onsubmit="return false;">
|
||||||
<input type="text" name="uname">
|
<input type="text" name="uname">
|
||||||
|
Loading…
Reference in New Issue
Block a user