Bug 1657998 - Add 'IgnorePasswordEdit' notification for tests. r=dimi

Instead of waiting for nothing to happen in some of the test cases in browser_doorhanger_form_password_edit, we now send a "IgnorePasswordEdit" notification so tests can react accordingly.
This new 'IgnorePasswordEdit' message is only used for the previously mentioned test.

Differential Revision: https://phabricator.services.mozilla.com/D126137
This commit is contained in:
Tim Giles 2021-09-28 14:49:39 +00:00
parent 79f93e7a8b
commit ec0e3ea35a
4 changed files with 39 additions and 24 deletions

View file

@ -256,6 +256,11 @@ const observer = {
);
if (!docState.fieldModificationsByRootElement.get(formLikeRoot)) {
log("Ignoring change event on form that hasn't been user-modified");
if (aEvent.composedTarget.hasBeenTypePassword) {
// Send notification that the password field has not been changed.
// This is used only for testing.
LoginManagerChild.forWindow(window)._ignorePasswordEdit();
}
break;
}
@ -284,6 +289,10 @@ const observer = {
triggeredByFillingGenerated,
}
);
} else {
// Send a notification that we are not saving the edit to the password field.
// This is used only for testing.
LoginManagerChild.forWindow(window)._ignorePasswordEdit();
}
}
break;
@ -2225,6 +2234,16 @@ this.LoginManagerChild = class LoginManagerChild extends JSWindowActorChild {
this._fillConfirmFieldWithGeneratedPassword(passwordField);
}
/**
* Notify the parent that we are ignoring the password edit
* so that tests can listen for this as opposed to waiting for
* nothing to happen.
*/
_ignorePasswordEdit() {
if (Cu.isInAutomation) {
this.sendAsyncMessage("PasswordManager:onIgnorePasswordEdit", {});
}
}
/**
* Notify the parent that a generated password was filled into a field or
* edited so that it can potentially be saved.

View file

@ -316,6 +316,15 @@ class LoginManagerParent extends JSWindowActorParent {
break;
}
case "PasswordManager:onIgnorePasswordEdit": {
log("Received PasswordManager:onIgnorePasswordEdit");
if (gListenerForTests) {
log("calling gListenerForTests");
gListenerForTests("PasswordIgnoreEdit", {});
}
break;
}
case "PasswordManager:autoCompleteLogins": {
return this.doAutocompleteSearch(context.origin, data);
}

View file

@ -63,8 +63,6 @@ support-files =
[browser_doorhanger_dismissed_for_ccnumber.js]
[browser_doorhanger_empty_password.js]
[browser_doorhanger_form_password_edit.js]
skip-if =
fission && os == "mac" && !debug # Bug 1713910 - new Fission platform triage
[browser_doorhanger_generated_password.js]
support-files =
form_basic_with_confirm_field.html

View file

@ -377,17 +377,6 @@ for (let testData of testCases) {
add_task(tmp[testData.name]);
}
async function waitForPromise(promise, timeoutMs = 5000) {
let timedOut = new Promise((resolve, reject) => {
/* eslint-disable-next-line mozilla/no-arbitrary-setTimeout */
let timerId = setTimeout(() => {
clearTimeout(timerId);
reject(`Timed out in ${timeoutMs} ms.`);
}, timeoutMs);
});
await Promise.race([promise, timedOut]);
}
async function testPasswordChange(
{
logins = [],
@ -427,23 +416,23 @@ async function testPasswordChange(
await checkForm(browser, expected.initialForm);
info("form checked");
let passwordEditedMessage = listenForTestNotification(
"PasswordEditedOrGenerated"
// A message is still sent to the parent process when Primary Password is enabled
let notificationMessage =
expected.doorhanger || !isLoggedIn
? "PasswordEditedOrGenerated"
: "PasswordIgnoreEdit";
let passwordTestNotification = listenForTestNotification(
notificationMessage
);
await changeContentFormValues(browser, formChanges, shouldBlur);
info(
"form edited, waiting for test notification of PasswordEditedOrGenerated"
`form edited, waiting for test notification of ${notificationMessage}`
);
try {
await waitForPromise(passwordEditedMessage, 5000);
// A message is still sent to the parent process when Primary Password is enabled
ok(expected.doorhanger || !isLoggedIn, "Message sent");
} catch (ex) {
ok(!expected.doorhanger, "No message sent");
}
info("Resolved listenForTestNotification promise");
await passwordTestNotification;
info("Resolved passwordTestNotification promise");
if (!expected.doorhanger) {
let notif;