diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_generation_confirm.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_generation_confirm.html index 16e920affe74..9b78428e7501 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_generation_confirm.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_generation_confirm.html @@ -29,7 +29,7 @@ Login Manager test: filling generated passwords into confirm password fields ); }); - function testConfirmPasswordFieldFilledWithGeneratedPassword({ + async function testConfirmPasswordFieldFilledWithGeneratedPassword({ title, html, afterFormAutofill, @@ -38,109 +38,106 @@ Login Manager test: filling generated passwords into confirm password fields afterPasswordGeneration }) { const content = document.querySelector("#content"); + info(`Test confirm password filled with generated password: ${title}`); - return async () => { - info(`Test confirm password filled with generated password: ${title}`); + await setupScript.sendAsyncMessage("resetLoginsAndGeneratedPasswords"); - await setupScript.sendAsyncMessage("resetLoginsAndGeneratedPasswords"); + // eslint-disable-next-line no-unsanitized/property + content.innerHTML = html; - // eslint-disable-next-line no-unsanitized/property - content.innerHTML = html; + // wait for the just created form to get autofilled + await promiseFormsProcessed(); - // wait for the just created form to get autofilled - await promiseFormsProcessed(); + const form = content.querySelector('form'); + // 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'); - // ensure form did not get initially filled - 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"); + 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"); } - add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({ + add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({ title: "fill next password field", html: `
@@ -152,7 +149,7 @@ Login Manager test: filling generated passwords into confirm password fields expectFilledPasswordConfirmation: true })); - add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({ + add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({ title: "fill next password field type text", html: ` @@ -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", html: ` @@ -179,7 +176,7 @@ Login Manager test: filling generated passwords into confirm password fields expectFilledPasswordConfirmation: "initial value" })); - add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({ + add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({ title: "do not fill edited next password field", html: ` @@ -195,7 +192,7 @@ Login Manager test: filling generated passwords into confirm password fields } })); - add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({ + add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({ title: "ignore readonly field", html: ` @@ -207,7 +204,7 @@ Login Manager test: filling generated passwords into confirm password fields expectFilledPasswordConfirmation: "" })); - add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({ + add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({ title: "ignore disabled field", html: ` @@ -219,7 +216,7 @@ Login Manager test: filling generated passwords into confirm password fields expectFilledPasswordConfirmation: "" })); - add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({ + add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({ title: "prefer matching autocomplete info password field", html: ` @@ -232,7 +229,7 @@ Login Manager test: filling generated passwords into confirm password fields expectFilledPasswordConfirmation: true })); - add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({ + add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({ title: "ignore disabled matching autocomplete info password field", html: ` @@ -245,7 +242,7 @@ Login Manager test: filling generated passwords into confirm password fields expectFilledPasswordConfirmation: "" })); - add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({ + add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({ title: "ignore too distant password confirmation field", html: ` @@ -262,7 +259,7 @@ Login Manager test: filling generated passwords into confirm password fields expectFilledPasswordConfirmation: "" })); - add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({ + add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({ title: "too many disabled fields", html: ` @@ -279,7 +276,7 @@ Login Manager test: filling generated passwords into confirm password fields expectFilledPasswordConfirmation: "" })); - add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({ + add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({ title: "skip over hidden fields", html: ` @@ -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 - add_task(testConfirmPasswordFieldFilledWithGeneratedPassword({ + add_task(() => testConfirmPasswordFieldFilledWithGeneratedPassword({ title: "do not fill third password field", html: `