Bug 1077304 - fix password manager to not fire input events if not changing input field values, r=gavin
--- a/toolkit/components/passwordmgr/LoginManagerContent.jsm
+++ b/toolkit/components/passwordmgr/LoginManagerContent.jsm
@@ -708,28 +708,30 @@ var LoginManagerContent = {
var didFillForm = false;
if (selectedLogin && autofillForm && !isFormDisabled) {
// Fill the form
if (usernameField) {
// Don't modify the username field if it's disabled or readOnly so we preserve its case.
let disabledOrReadOnly = usernameField.disabled || usernameField.readOnly;
+ let userNameDiffers = selectedLogin.username != usernameField.value;
// Don't replace the username if it differs only in case, and the user triggered
// this autocomplete. We assume that if it was user-triggered the entered text
// is desired.
- let userEnteredDifferentCase = userTriggered &&
- (usernameField.value != selectedLogin.username &&
- usernameField.value.toLowerCase() == selectedLogin.username.toLowerCase());
+ let userEnteredDifferentCase = userTriggered && userNameDiffers &&
+ usernameField.value.toLowerCase() == selectedLogin.username.toLowerCase();
- if (!disabledOrReadOnly && !userEnteredDifferentCase) {
+ if (!disabledOrReadOnly && !userEnteredDifferentCase && userNameDiffers) {
usernameField.setUserInput(selectedLogin.username);
}
}
- passwordField.setUserInput(selectedLogin.password);
+ if (passwordField.value != selectedLogin.password) {
+ passwordField.setUserInput(selectedLogin.password);
+ }
didFillForm = true;
} else if (selectedLogin && !autofillForm) {
// For when autofillForm is false, but we still have the information
// to fill a form, we notify observers.
didntFillReason = "noAutofillForms";
Services.obs.notifyObservers(form, "passwordmgr-found-form", didntFillReason);
log("autofillForms=false but form can be filled; notified observers");
} else if (selectedLogin && isFormDisabled) {
--- a/toolkit/components/passwordmgr/test/mochitest.ini
+++ b/toolkit/components/passwordmgr/test/mochitest.ini
@@ -56,16 +56,17 @@ skip-if = true
[test_bug_391514.html]
[test_bug_427033.html]
[test_bug_444968.html]
[test_bug_627616.html]
skip-if = toolkit == 'android' #TIMED_OUT
[test_bug_654348.html]
[test_bug_776171.html]
[test_input_events.html]
+[test_input_events_for_identical_values.html]
[test_master_password.html]
skip-if = toolkit == 'android' #TIMED_OUT
[test_master_password_cleanup.html]
skip-if = toolkit == 'android'
[test_notifications.html]
skip-if = toolkit == 'android'
[test_notifications_popup.html]
skip-if = os == "linux" || toolkit == 'android' # bug 934057
new file mode 100644
--- /dev/null
+++ b/toolkit/components/passwordmgr/test/test_input_events_for_identical_values.html
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for input events in Login Manager when username/password are filled in already</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+ <script type="text/javascript" src="pwmgr_common.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body onload="onNewEvent(event)">
+Login Manager test: input events should fire.
+
+<script>
+commonInit();
+SimpleTest.waitForExplicitFinish();
+
+/** Test for Login Manager: form fill when form is already filled, should not get input events. **/
+
+var onloadFired = false;
+
+function onNewEvent(e) {
+ console.error("Got " + e.type + " event.");
+ if (e.type == "load") {
+ onloadFired = true;
+ $_(1, "uname").focus();
+ sendKey("Tab");
+ } else {
+ ok(false, "Got an input event for " + e.target.name + " field, which shouldn't happen.");
+ }
+}
+
+SimpleTest.registerCleanupFunction(function cleanup() {
+ $_(1, "uname").removeAttribute("oninput");
+ $_(1, "pword").removeAttribute("onfocus");
+ $_(1, "pword").removeAttribute("oninput");
+ document.body.removeAttribute("onload");
+});
+</script>
+
+<p id="display"></p>
+
+<div id="content">
+
+ <form id="form1" action="formtest.js">
+ <p>This is form 1.</p>
+ <input type="text" name="uname" oninput="onNewEvent(event)" value="testuser">
+ <input type="password" name="pword" oninput="onNewEvent(event)" onfocus="setTimeout(function() { SimpleTest.finish() }, 1000);" value="testpass">
+
+ <button type="submit">Submit</button>
+ <button type="reset"> Reset </button>
+ </form>
+
+</div>
+<pre id="test"></pre>
+</body>
+</html>