Commit 0fe6f9e2 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

<textarea>: defaultValue setter should be same as textContent setter.

[1]:
> On setting, it must act as the setter for the element's textContent
> IDL attribute.

The new behavior matches to Firefox and Safari.

This CL is almost equivalent to crrev.com/489300 by Shanmuga Pandi M.
The regression caused by it was fixed by crrev.com/639382 .

[1] https://html.spec.whatwg.org/multipage/form-elements.html#dom-textarea-defaultvalue

Bug: 392843
Change-Id: I8b4ea4cd5fffffdc136ab3812a2c34e43f681345
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1538057Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#643790}
parent f96c21b0
......@@ -459,26 +459,7 @@ String HTMLTextAreaElement::defaultValue() const {
}
void HTMLTextAreaElement::setDefaultValue(const String& default_value) {
// To preserve comments, remove only the text nodes, then add a single text
// node.
HeapVector<Member<Node>> text_nodes;
for (Node* n = firstChild(); n; n = n->nextSibling()) {
if (n->IsTextNode())
text_nodes.push_back(n);
}
for (const auto& text : text_nodes)
RemoveChild(text.Get(), IGNORE_EXCEPTION_FOR_TESTING);
// Normalize line endings.
String value = default_value;
value.Replace("\r\n", "\n");
value.Replace('\r', '\n');
InsertBefore(GetDocument().createTextNode(value), firstChild(),
IGNORE_EXCEPTION_FOR_TESTING);
if (!is_dirty_)
SetNonDirtyValue(value);
setTextContent(default_value);
}
void HTMLTextAreaElement::SetSuggestedValue(const String& value) {
......
This is a testharness.js-based test.
PASS defaultValue and value are the empty string by default
PASS defaultValue and value are affected by setting textContent
PASS defaultValue and value are affected by setting nodeValue on a child text node
PASS defaultValue and value are affected by setting data on a child text node
PASS defaultValue and value are affected by textContent in combination with appending a text node
PASS defaultValue and value are affected by textContent in combination with appending a DocumentFragment
PASS defaultValue and value reflect child text content, not textContent
FAIL Setting defaultValue wipes out any children, including elements (just like setting textContent) assert_equals: Only one child node should exist expected 1 but got 2
PASS defaultValue and value treat CRLF differently
PASS value normalizes CRLF even spread over multiple text nodes
PASS tests for the value setter
PASS tests for U+0000 NULL
Harness: the test ran to completion.
......@@ -31,8 +31,8 @@ PASS ta.selectionEnd is 7
PASS ta.selectionStart is 9
PASS ta.selectionEnd is 9
- set same defaultValue
PASS ta.selectionStart is 9
PASS ta.selectionEnd is 9
PASS ta.selectionStart is 2
PASS ta.selectionEnd is 3
- append a text node
PASS ta.selectionStart is 12
PASS ta.selectionEnd is 12
......
......@@ -57,8 +57,8 @@
debug("- set same defaultValue");
ta.setSelectionRange(2, 3);
ta.defaultValue = 'abc123456';
shouldBe('ta.selectionStart', '9');
shouldBe('ta.selectionEnd', '9');
shouldBe('ta.selectionStart', '2');
shouldBe('ta.selectionEnd', '3');
debug("- append a text node");
ta.appendChild(document.createTextNode('foo'));
......
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