Commit 9e341d7e authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Revert "Restoring control state should dispatch 'input' and 'change' events."

This reverts commit 9fc859a3.

Reason for revert: It was a wrong approach. https://bugs.chromium.org/p/chromium/issues/detail?id=1037728#c11

Original change's description:
> Restoring control state should dispatch 'input' and 'change' events.
> 
> According to the last two paragraphs of [1], UA should dispatch 'input'
> and 'change' events if it fills control values on behalf of a user.
> 
> [1] https://html.spec.whatwg.org/C/#common-input-element-events
> 
> Bug: 1037728
> Change-Id: Ic389cc4e3bc4523f740b0164ac863baba66dcd35
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1981241
> Reviewed-by: Mason Freed <masonfreed@chromium.org>
> Commit-Queue: Kent Tamura <tkent@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#727843}

TBR=tkent@chromium.org,masonfreed@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 1037728
Change-Id: I504d202de886e4278369ab3da37c41b70b773f31
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1993078Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#729731}
parent 565c4416
......@@ -276,17 +276,6 @@ bool HTMLFormControlElementWithState::ShouldSaveAndRestoreFormControlState()
return isConnected() && ShouldAutocomplete();
}
void HTMLFormControlElementWithState::QueueInputAndChangeEvents() {
auto task_runner = GetDocument().GetTaskRunner(TaskType::kUserInteraction);
task_runner->PostTask(
FROM_HERE, WTF::Bind(&HTMLFormControlElementWithState::DispatchInputEvent,
WrapWeakPersistent(this)));
task_runner->PostTask(
FROM_HERE,
WTF::Bind(&HTMLFormControlElementWithState::DispatchChangeEvent,
WrapWeakPersistent(this)));
}
void HTMLFormControlElementWithState::DispatchInputEvent() {
// Legacy 'input' event for forms set value and checked.
Event* event = Event::CreateBubble(event_type_names::kInput);
......
......@@ -57,8 +57,6 @@ class CORE_EXPORT HTMLFormControlElementWithState
bool user_has_edited_the_field_ = false;
HTMLFormControlElementWithState(const QualifiedName& tag_name, Document&);
void QueueInputAndChangeEvents();
void FinishParsingChildren() override;
bool IsFormControlElementWithState() const final;
......
......@@ -586,7 +586,6 @@ FormControlState HTMLInputElement::SaveFormControlState() const {
void HTMLInputElement::RestoreFormControlState(const FormControlState& state) {
input_type_view_->RestoreFormControlState(state);
state_restored_ = true;
QueueInputAndChangeEvents();
}
bool HTMLInputElement::CanStartSelection() const {
......
......@@ -1237,7 +1237,6 @@ void HTMLSelectElement::RestoreFormControlState(const FormControlState& state) {
}
SetNeedsValidityCheck();
QueueInputAndChangeEvents();
}
void HTMLSelectElement::ParseMultipleAttribute(const AtomicString& value) {
......
......@@ -94,11 +94,7 @@ FormControlState HTMLTextAreaElement::SaveFormControlState() const {
void HTMLTextAreaElement::RestoreFormControlState(
const FormControlState& state) {
// We don't add kDispatchInputAndChangeEvent to setValue(), and we
// post tasks to dispatch events instead. This function can be called
// while we should not dispatch any events.
setValue(state[0]);
QueueInputAndChangeEvents();
}
void HTMLTextAreaElement::ChildrenChanged(const ChildrenChange& change) {
......
<!DOCTYPE html>
<script>
document.addEventListener('change', e => {
parent.inputOrChangeEvents.push('change/' + e.target.type);
});
document.addEventListener('input', e => {
parent.inputOrChangeEvents.push('input/' + e.target.type);
});
</script>
<div></div>
<input type=checkbox disabled>
<input type=text disabled>
<textarea></textarea>
<select><option>1<option>2</select>
<script>
document.querySelector('div').innerHTML = '<input type=checkbox><input type=text>'
</script>
......@@ -5,52 +5,30 @@
<body>
<iframe src="resources/state-restore-dynamic-controls-frame.html"></iframe>
<script>
window.inputOrChangeEvents = [];
promise_test(async t => {
await waitForEvent(window, 'load', {once:true});
const iframe = document.querySelector('iframe');
let doc = iframe.contentDocument;
const container = doc.querySelector('div');
const container = iframe.contentDocument.querySelector('div');
// Change states of controls
container.firstChild.click();
container.lastChild.focus();
eventSender.keyDown('z');
doc.querySelector('textarea').focus();
eventSender.keyDown('y');
doc.querySelector('select').focus();
eventSender.keyDown('2');
assert_true(container.firstChild.checked, 'sanity check for a checkbox');
assert_equals(container.lastChild.value, 'z', 'sanity check for a text field');
assert_equals(doc.querySelector('textarea').value, 'y', 'sanity check for a textarea');
assert_equals(doc.querySelector('select').value, '2', 'sanity check for a select');
// Flush asynchronous input/change events
await timeOut(t, 0);
// Navigate
iframe.src = 'data:text/html,<h1></h1>';
await waitForEvent(iframe, 'load', {once:true});
inputOrChangeEvents = []
// Navigate back
history.back();
await waitForEvent(iframe, 'load', {once:true});
// Wait until finishing the restore task.
await timeOut(t, 0);
doc = iframe.contentDocument;
const inputs = doc.querySelectorAll('input');
const inputs = iframe.contentDocument.querySelectorAll('input');
assert_true(inputs[0].checked, 'Checkbox state should be restored.');
assert_equals(inputs[1].value, 'z', 'Text field state should be restored.');
assert_false(inputs[2].checked, 'Checkbox should have initial value.');
assert_equals(inputs[3].value, '', 'Text field should have initial value.');
assert_equals(doc.querySelector('textarea').value, 'y');
assert_equals(doc.querySelector('select').value, '2');
// Wait for asynchronous input/change events
await timeOut(t, 0);
assert_array_equals(inputOrChangeEvents, [
'input/checkbox', 'change/checkbox', 'input/text', 'change/text',
'input/textarea', 'change/textarea', 'input/select-one', 'change/select-one']);
}, 'Control states should be restored correctly even if controls were inserted before existing controls.');
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment