Bug 1077304 - fix password manager to not fire input events if not changing input field values, r=gavin
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 06 Oct 2014 14:32:18 +0100
changeset 233133 12a7e4dd89496c92ded36eb6cb1fd73ae733c039
parent 233132 c6e8abf0f825027c38b51a4d3c32381ee4faffc3
child 233134 b557f2cb4a04b9b28d91b372ce0433e83f72076f
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs1077304
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1077304 - fix password manager to not fire input events if not changing input field values, r=gavin
toolkit/components/passwordmgr/LoginManagerContent.jsm
toolkit/components/passwordmgr/test/mochitest.ini
toolkit/components/passwordmgr/test/test_input_events_for_identical_values.html
--- 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>