Bug 1077304 - fix password manager to not fire input events if not changing input field values, r=gavin

--HG--
extra : rebase_source : ca14ce946f9580ea73b45377cc8385292773be26
This commit is contained in:
Gijs Kruitbosch 2014-10-06 14:32:18 +01:00
parent 093a48eb3d
commit a602e4bc1d
3 changed files with 64 additions and 5 deletions

View File

@ -713,18 +713,20 @@ var LoginManagerContent = {
// 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

View File

@ -61,6 +61,7 @@ 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]

View File

@ -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>