haikuwebkit/LayoutTests/fast/forms/textfield-onchange-without-...

23 lines
691 B
HTML
Raw Permalink Normal View History

A change event gets dispatched when textarea gets changed without focus https://bugs.webkit.org/show_bug.cgi?id=202144 Patch by ChangSeok Oh <changseok@webkit.org> on 2020-03-16 Reviewed by Ryosuke Niwa. Source/WebCore: A crash happens in WebCore::ValidationMessage::buildBubbleTree. An immediate reason is that DOM tree is modified in buildBubbleTree triggered by a timer. The function calls document.updateLayout() that causes a change event for textarea to fire when something changed in the textarea. This bug is not reproduced on Mac because buildBubbleTree is not called. See ValidationMessage::setMessage. On the other hand, the root cause of this issue is triggering the change event for textarea even if it is not focused when a change is made. This behavior is different to what Gecko and Chromium do. When loading the test, they do not trigger the change event although the textarea is filled by the script since the textarea is not focused. Only when we manually make a change (meaning the textarea is focused by user input), the event gets dispatched. To fix it, setChangedSinceLastFormControlChangeEvent(true) is moved below the focus check in HTMLTextAreaElement::subtreeHasChanged(); Test: fast/forms/textfield-onchange-without-focus.html * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::subtreeHasChanged): LayoutTests: The test should be identical to the extected result without crash. * fast/forms/textfield-onchange-without-focus-expected.html: Added. * fast/forms/textfield-onchange-without-focus.html: Added. Canonical link: https://commits.webkit.org/222072@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@258532 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-03-17 00:14:34 +00:00
<!DOCTYPE html>
<script>
function test() {
const select = document.querySelector('select');
select.setCustomValidity('validity');
select.reportValidity();
const textarea = document.querySelector('textarea');
textarea.setRangeText('lol');
select.autofocus = true;
setTimeout(() => {
select.reportValidity();
textarea.blur();
}, 0);
}
</script>
<body onload='test()'>
<p>The onchange should not be triggered by textarea when it got something changed without being focused. Pass if not crashed, and the focused select box is displayed.</p>
<select></select>
<textarea onchange="document.all[2].appendChild(document.querySelector('select'));"></textarea>
</body>