diff --git a/toolkit/components/passwordmgr/test/mochitest/pwmgr_common.js b/toolkit/components/passwordmgr/test/mochitest/pwmgr_common.js --- a/toolkit/components/passwordmgr/test/mochitest/pwmgr_common.js +++ b/toolkit/components/passwordmgr/test/mochitest/pwmgr_common.js @@ -701,16 +701,19 @@ chromeScript.destroy(); }); return chromeScript; } -/** Initialize with a list of logins. The logins are added within the parent chrome process. - * @param {array} aLogins - a list of logins to add. Each login is an array of the arguments - * that would be passed to nsLoginInfo.init(). - */ -async function addLoginsInParent(...aLogins) { - let script = runInParent(function addLoginsInParentInner() { +/** Manage logins in parent chrome process. + * */ +function manageLoginsInParent() { + return runInParent(function addLoginsInParentInner() { + /* eslint-env mozilla/chrome-script */ + addMessageListener("removeAllUserFacingLogins", () => { + Services.logins.removeAllUserFacingLogins(); + }); + /* eslint-env mozilla/chrome-script */ addMessageListener("addLogins", async logins => { let nsLoginInfo = Components.Constructor( "@mozilla.org/login-manager/loginInfo;1", Ci.nsILoginInfo, @@ -723,10 +726,30 @@ } catch (e) { assert.ok(false, "addLogins threw: " + e); } }); }); +} + +/** Initialize with a list of logins. The logins are added within the parent chrome process. + * @param {array} aLogins - a list of logins to add. Each login is an array of the arguments + * that would be passed to nsLoginInfo.init(). + */ +async function addLoginsInParent(...aLogins) { + const script = manageLoginsInParent(); + await script.sendQuery("addLogins", aLogins); + return script; +} + +/** Initialize with a list of logins, after removing all user facing logins. + * The logins are added within the parent chrome process. + * @param {array} aLogins - a list of logins to add. Each login is an array of the arguments + * that would be passed to nsLoginInfo.init(). + */ +async function setStoredLoginsAsync(...aLogins) { + const script = manageLoginsInParent(); + script.sendQuery("removeAllUserFacingLogins"); await script.sendQuery("addLogins", aLogins); return script; } /* diff --git a/toolkit/components/passwordmgr/test/mochitest/test_input_events.html b/toolkit/components/passwordmgr/test/mochitest/test_input_events.html --- a/toolkit/components/passwordmgr/test/mochitest/test_input_events.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_input_events.html @@ -6,93 +6,73 @@ - + Login Manager test: input events should fire. - +

+ +

 
-
-

+ add_task(async function username_events() { + return new Promise(resolve => { + let inputFired = false; + const form = setupForm(); + form.username.oninput = e => { + is(e.target.value, "testuser", "Should get 'testuser' as value in input event"); + inputFired = true; + }; + form.username.onchange = e => { + ok(inputFired, "Should get input event before change event for username field."); + is(e.target.value, "testuser", "Should get 'testuser' as value in change event"); + resolve(); + }; + }) + }) - -

+  add_task(async function password_events() {
+    return new Promise(resolve => {
+      let inputFired = false;
+      const form = setupForm();
+      form.password.oninput = e => {
+        is(e.target.value, "testpass", "Should get 'testpass' as value in input event");
+        inputFired = true;
+      };
+      form.password.onchange = e => {
+        ok(inputFired, "Should get input event before change event for password field.");
+        is(e.target.value, "testpass", "Should get 'testpass' as value in change event");
+        resolve();
+      };
+    })
+  })
+