Cloning a textarea does not clone the textarea's value
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Sep 2016 16:32:34 +0000 (16:32 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Sep 2016 16:32:34 +0000 (16:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=156637

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Import corresponding W3C web platform test.

* web-platform-tests/html/semantics/forms/the-textarea-element/cloning-steps-expected.txt: Added.
* web-platform-tests/html/semantics/forms/the-textarea-element/cloning-steps.html: Added.
* web-platform-tests/html/semantics/forms/the-textarea-element/w3c-import.log:

Source/WebCore:

Update WebKit so that cloning a textarea element also clones its value.
This matches the HTML specification after:
- https://github.com/whatwg/html/pull/1784

The new behavior also matches Chrome and Edge.

Test: imported/w3c/web-platform-tests/html/semantics/forms/the-textarea-element/cloning-steps.html

* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::copyNonAttributePropertiesFromElement):
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::copyNonAttributePropertiesFromElement):
* html/HTMLTextAreaElement.h:

LayoutTests:

Update existing test to reflect behavior change.

* fast/forms/checkValidity-cloneNode-crash-expected.txt:
* fast/forms/checkValidity-cloneNode-crash.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@206026 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/forms/checkValidity-cloneNode-crash-expected.txt
LayoutTests/fast/forms/checkValidity-cloneNode-crash.html
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-textarea-element/cloning-steps-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-textarea-element/cloning-steps.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-textarea-element/w3c-import.log
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLTextAreaElement.cpp
Source/WebCore/html/HTMLTextAreaElement.h

index 76304dc..196db70 100644 (file)
@@ -1,3 +1,15 @@
+2016-09-16  Chris Dumez  <cdumez@apple.com>
+
+        Cloning a textarea does not clone the textarea's value
+        https://bugs.webkit.org/show_bug.cgi?id=156637
+
+        Reviewed by Ryosuke Niwa.
+
+        Update existing test to reflect behavior change.
+
+        * fast/forms/checkValidity-cloneNode-crash-expected.txt:
+        * fast/forms/checkValidity-cloneNode-crash.html:
+
 2016-09-16  Youenn Fablet  <youenn@apple.com>
 
         [Fetch API] Headers should be combine with ',' and not ', '
index 079dcb0..739e77b 100644 (file)
@@ -10,8 +10,8 @@ PASS element2.checkValidity() is true
 PASS element.checkValidity() is true
 PASS element2.checkValidity() is false
 PASS element.checkValidity() is true
-PASS element2.value is ""
-PASS element2.checkValidity() is false
+PASS element2.value is "a"
+PASS element2.checkValidity() is true
 PASS element2.checkValidity() is true
 PASS successfullyParsed is true
 
index fedfb25..d614cf9 100644 (file)
@@ -44,8 +44,8 @@ function checkTextArea() {
     element.value = "a";
     shouldBeTrue("element.checkValidity()");
     element2 = element.cloneNode();
-    shouldBeEqualToString("element2.value", "");
-    shouldBeFalse("element2.checkValidity()");
+    shouldBeEqualToString("element2.value", "a");
+    shouldBeTrue("element2.checkValidity()");
     element2.value = element.value;
     shouldBeTrue("element2.checkValidity()");
 }
index b1476ea..d33becd 100644 (file)
@@ -1,3 +1,16 @@
+2016-09-16  Chris Dumez  <cdumez@apple.com>
+
+        Cloning a textarea does not clone the textarea's value
+        https://bugs.webkit.org/show_bug.cgi?id=156637
+
+        Reviewed by Ryosuke Niwa.
+
+        Import corresponding W3C web platform test.
+
+        * web-platform-tests/html/semantics/forms/the-textarea-element/cloning-steps-expected.txt: Added.
+        * web-platform-tests/html/semantics/forms/the-textarea-element/cloning-steps.html: Added.
+        * web-platform-tests/html/semantics/forms/the-textarea-element/w3c-import.log:
+
 2016-09-16  Youenn Fablet  <youenn@apple.com>
 
         [Fetch API] Headers should be combine with ',' and not ', '
diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-textarea-element/cloning-steps-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-textarea-element/cloning-steps-expected.txt
new file mode 100644 (file)
index 0000000..1a7fc4e
--- /dev/null
@@ -0,0 +1,4 @@
+
+PASS textarea element's value should be cloned 
+PASS textarea element's dirty value flag should be cloned, so setAttribute doesn't affect the cloned textarea's value 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-textarea-element/cloning-steps.html b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-textarea-element/cloning-steps.html
new file mode 100644 (file)
index 0000000..160b70a
--- /dev/null
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Cloning of textarea elements</title>
+<link rel="help" href="https://dom.spec.whatwg.org/#dom-node-clonenode">
+<link rel="help" href="https://dom.spec.whatwg.org/#concept-node-clone">
+<link rel="help" href="https://dom.spec.whatwg.org/#concept-node-clone-ext">
+<link rel="help" href="https://html.spec.whatwg.org/multipage/forms.html#the-textarea-element:concept-node-clone-ext">
+<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me">
+
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<script>
+"use strict";
+
+test(() => {
+  const textarea = document.createElement("textarea");
+  textarea.value = "foo bar";
+
+  const copy = textarea.cloneNode();
+  assert_equals(copy.value, "foo bar");
+}, "textarea element's value should be cloned");
+
+test(() => {
+  const textarea = document.createElement("textarea");
+  textarea.value = "foo bar";
+
+  const copy = textarea.cloneNode();
+  copy.setAttribute("value", "something else");
+
+  assert_equals(copy.value, "foo bar");
+}, "textarea element's dirty value flag should be cloned, so setAttribute doesn't affect the cloned textarea's value");
+
+</script>
index 22b40a0..8ca7206 100644 (file)
@@ -15,6 +15,7 @@ Property values requiring vendor prefixes:
 None
 ------------------------------------------------------------------------
 List of files:
+/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-textarea-element/cloning-steps.html
 /LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-textarea-element/textarea-newline-bidi-expected.html
 /LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-textarea-element/textarea-newline-bidi.html
 /LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-textarea-element/textarea-type.html
index 9a6b781..a1f3425 100644 (file)
@@ -1,3 +1,24 @@
+2016-09-16  Chris Dumez  <cdumez@apple.com>
+
+        Cloning a textarea does not clone the textarea's value
+        https://bugs.webkit.org/show_bug.cgi?id=156637
+
+        Reviewed by Ryosuke Niwa.
+
+        Update WebKit so that cloning a textarea element also clones its value.
+        This matches the HTML specification after:
+        - https://github.com/whatwg/html/pull/1784
+
+        The new behavior also matches Chrome and Edge.
+
+        Test: imported/w3c/web-platform-tests/html/semantics/forms/the-textarea-element/cloning-steps.html
+
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::copyNonAttributePropertiesFromElement):
+        * html/HTMLTextAreaElement.cpp:
+        (WebCore::HTMLTextAreaElement::copyNonAttributePropertiesFromElement):
+        * html/HTMLTextAreaElement.h:
+
 2016-09-16  Jer Noble  <jer.noble@apple.com>
 
         [media-source] Only fire 'resize' events when new sized frame is displayed, not parsed.
index ce25082..cd8ae95 100644 (file)
@@ -954,7 +954,7 @@ float HTMLInputElement::decorationWidth() const
 
 void HTMLInputElement::copyNonAttributePropertiesFromElement(const Element& source)
 {
-    const HTMLInputElement& sourceElement = static_cast<const HTMLInputElement&>(source);
+    auto& sourceElement = downcast<HTMLInputElement>(source);
 
     m_valueIfDirty = sourceElement.m_valueIfDirty;
     m_wasModifiedByUser = false;
index 820e1b3..4353065 100644 (file)
@@ -587,4 +587,15 @@ RenderStyle HTMLTextAreaElement::createInnerTextStyle(const RenderStyle& style)
     return textBlockStyle;
 }
 
+void HTMLTextAreaElement::copyNonAttributePropertiesFromElement(const Element& source)
+{
+    auto& sourceElement = downcast<HTMLTextAreaElement>(source);
+
+    setValueCommon(sourceElement.value());
+    m_isDirty = sourceElement.m_isDirty;
+    HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(source);
+
+    updateValidity();
+}
+
 } // namespace WebCore
index ce051fb..b9a3224 100644 (file)
@@ -55,6 +55,7 @@ public:
     
     TextControlInnerTextElement* innerTextElement() const final;
     RenderStyle createInnerTextStyle(const RenderStyle&) const final;
+    void copyNonAttributePropertiesFromElement(const Element&) final;
 
     void rendererWillBeDestroyed();