зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1077308 - If a field is auto-filled while not in focus, fire a change event immediately. r=smaug r=MattN
This commit is contained in:
Родитель
c2c8b8f869
Коммит
b536647980
|
@ -2408,10 +2408,18 @@ HTMLInputElement::SetUserInput(const nsAString& aValue)
|
|||
SetValueInternal(aValue, true, true);
|
||||
}
|
||||
|
||||
return nsContentUtils::DispatchTrustedEvent(OwnerDoc(),
|
||||
static_cast<nsIDOMHTMLInputElement*>(this),
|
||||
NS_LITERAL_STRING("input"), true,
|
||||
true);
|
||||
nsContentUtils::DispatchTrustedEvent(OwnerDoc(),
|
||||
static_cast<nsIDOMHTMLInputElement*>(this),
|
||||
NS_LITERAL_STRING("input"), true,
|
||||
true);
|
||||
|
||||
// If this element is not currently focused, it won't receive a change event for this
|
||||
// update through the normal channels. So fire a change event immediately, instead.
|
||||
if (!ShouldBlur(this)) {
|
||||
FireChangeEventIfNeeded();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIEditor*
|
||||
|
|
|
@ -42,7 +42,7 @@ function testUserInput() {
|
|||
"Change event dispatched when setting the value of the input element (2).");
|
||||
|
||||
SpecialPowers.wrap(input).setUserInput("foo");
|
||||
is(inputChange, 1,
|
||||
is(inputChange, 2,
|
||||
"Change event dispatched when input element doesn't have focus.");
|
||||
|
||||
textarea.focus();
|
||||
|
|
|
@ -17,22 +17,38 @@ SimpleTest.waitForExplicitFinish();
|
|||
|
||||
var usernameInputFired = false;
|
||||
var passwordInputFired = false;
|
||||
var usernameChangeFired = false;
|
||||
var passwordChangeFired = false;
|
||||
var onloadFired = false;
|
||||
|
||||
function onNewEvent(e) {
|
||||
info("Got " + e.type + " event.");
|
||||
if (e.type == "load") {
|
||||
onloadFired = true;
|
||||
} else if (e.target.name == "uname") {
|
||||
ise(e.target.value, "testuser", "Should get 'testuser' as username");
|
||||
ok(!usernameInputFired, "Should not have gotten an input event for the username field yet.");
|
||||
usernameInputFired = true;
|
||||
} else if (e.target.name == "pword") {
|
||||
ise(e.target.value, "testpass", "Should get 'testpass' as password");
|
||||
ok(!passwordInputFired, "Should not have gotten an input event for the password field yet.");
|
||||
passwordInputFired = true;
|
||||
} else if (e.type == "input") {
|
||||
if (e.target.name == "uname") {
|
||||
ise(e.target.value, "testuser", "Should get 'testuser' as username");
|
||||
ok(!usernameInputFired, "Should not have gotten an input event for the username field yet.");
|
||||
usernameInputFired = true;
|
||||
} else if (e.target.name == "pword") {
|
||||
ise(e.target.value, "testpass", "Should get 'testpass' as password");
|
||||
ok(!passwordInputFired, "Should not have gotten an input event for the password field yet.");
|
||||
passwordInputFired = true;
|
||||
}
|
||||
} else if (e.type == "change") {
|
||||
if (e.target.name == "uname") {
|
||||
ise(e.target.value, "testuser", "Should get 'testuser' as username");
|
||||
ok(usernameInputFired, "Should get input event before change event for username field.");
|
||||
ok(!usernameChangeFired, "Should not have gotten a change event for the username field yet.");
|
||||
usernameChangeFired = true;
|
||||
} else if (e.target.name == "pword") {
|
||||
ise(e.target.value, "testpass", "Should get 'testpass' as password");
|
||||
ok(passwordInputFired, "Should get input event before change event for password field.");
|
||||
ok(!passwordChangeFired, "Should not have gotten a change event for the password field yet.");
|
||||
passwordChangeFired = true;
|
||||
}
|
||||
}
|
||||
if (onloadFired && usernameInputFired && passwordInputFired) {
|
||||
if (onloadFired && usernameInputFired && passwordInputFired && usernameChangeFired && passwordChangeFired) {
|
||||
ok(true, "All events fired as expected, we're done.");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
@ -42,12 +58,16 @@ SimpleTest.registerCleanupFunction(function cleanup() {
|
|||
clearTimeout(timeout);
|
||||
$_(1, "uname").removeAttribute("oninput");
|
||||
$_(1, "pword").removeAttribute("oninput");
|
||||
$_(1, "uname").removeAttribute("onchange");
|
||||
$_(1, "pword").removeAttribute("onchange");
|
||||
document.body.removeAttribute("onload");
|
||||
});
|
||||
|
||||
var timeout = setTimeout(function() {
|
||||
ok(usernameInputFired, "Username input event should have fired by now.");
|
||||
ok(passwordInputFired, "Password input event should have fired by now.");
|
||||
ok(usernameChangeFired, "Username change event should have fired by now.");
|
||||
ok(passwordChangeFired, "Password change event should have fired by now.");
|
||||
ok(onloadFired, "Window load event should have fired by now.");
|
||||
ok(false, "Not all events fired yet.");
|
||||
SimpleTest.finish();
|
||||
|
@ -61,8 +81,8 @@ var timeout = setTimeout(function() {
|
|||
|
||||
<form id="form1" action="formtest.js">
|
||||
<p>This is form 1.</p>
|
||||
<input type="text" name="uname" oninput="onNewEvent(event)">
|
||||
<input type="password" name="pword" oninput="onNewEvent(event)">
|
||||
<input type="text" name="uname" oninput="onNewEvent(event)" onchange="onNewEvent(event)">
|
||||
<input type="password" name="pword" oninput="onNewEvent(event)" onchange="onNewEvent(event)">
|
||||
|
||||
<button type="submit">Submit</button>
|
||||
<button type="reset"> Reset </button>
|
||||
|
|
Загрузка…
Ссылка в новой задаче