From ec0e3ea35ac48a367a49943a39f63ec5cb3625cc Mon Sep 17 00:00:00 2001 From: Tim Giles Date: Tue, 28 Sep 2021 14:49:39 +0000 Subject: [PATCH] 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 --- .../passwordmgr/LoginManagerChild.jsm | 19 +++++++++++ .../passwordmgr/LoginManagerParent.jsm | 9 +++++ .../passwordmgr/test/browser/browser.ini | 2 -- .../browser_doorhanger_form_password_edit.js | 33 +++++++------------ 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/toolkit/components/passwordmgr/LoginManagerChild.jsm b/toolkit/components/passwordmgr/LoginManagerChild.jsm index 631998473de4..c42f429cd70b 100644 --- a/toolkit/components/passwordmgr/LoginManagerChild.jsm +++ b/toolkit/components/passwordmgr/LoginManagerChild.jsm @@ -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. diff --git a/toolkit/components/passwordmgr/LoginManagerParent.jsm b/toolkit/components/passwordmgr/LoginManagerParent.jsm index 3e68a9ba0a91..518bae75ae9f 100644 --- a/toolkit/components/passwordmgr/LoginManagerParent.jsm +++ b/toolkit/components/passwordmgr/LoginManagerParent.jsm @@ -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); } diff --git a/toolkit/components/passwordmgr/test/browser/browser.ini b/toolkit/components/passwordmgr/test/browser/browser.ini index 72bf4f5fba87..a9dac7d74078 100644 --- a/toolkit/components/passwordmgr/test/browser/browser.ini +++ b/toolkit/components/passwordmgr/test/browser/browser.ini @@ -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 diff --git a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_form_password_edit.js b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_form_password_edit.js index 31e9534564d0..75934332365d 100644 --- a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_form_password_edit.js +++ b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_form_password_edit.js @@ -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;