Title: [115786] trunk
Revision
115786
Author
[email protected]
Date
2012-05-01 20:35:48 -0700 (Tue, 01 May 2012)

Log Message

datalist: Form control in a <datalist> should be barred from constraint validation
https://bugs.webkit.org/show_bug.cgi?id=84359

Reviewed by Kent Tamura.

Source/WebCore:

Tests: fast/forms/datalist/datalist-child-validation.html
       fast/forms/form-control-element-crash.html

* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::HTMLFormControlElement):
(WebCore::HTMLFormControlElement::updateAncestors): Updates the ancestor information.
(WebCore::HTMLFormControlElement::insertedInto): Invalidate the ancestor information and call setNeedsWillValidateCheck because willValidate might have changed.
(WebCore::HTMLFormControlElement::removedFrom): Ditto.
(WebCore::HTMLFormControlElement::disabled):
(WebCore::HTMLFormControlElement::recalcWillValidate): Returns false if element has a datalist ancestor.
(WebCore::HTMLFormControlElement::willValidate): Check if ancestor information is valid too.
(WebCore::HTMLFormControlElement::setNeedsWillValidateCheck):
* html/HTMLFormControlElement.h:
(HTMLFormControlElement):

LayoutTests:

* fast/forms/datalist/datalist-child-validation-expected.txt: Added.
* fast/forms/datalist/datalist-child-validation.html: Added. Tests that willValidate changes from false to true when we move the element out of the datalist.
* fast/forms/form-control-element-crash-expected.txt: Added.
* fast/forms/form-control-element-crash.html: Added. Tests for the crash reported in Bug 85149.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (115785 => 115786)


--- trunk/LayoutTests/ChangeLog	2012-05-02 03:27:06 UTC (rev 115785)
+++ trunk/LayoutTests/ChangeLog	2012-05-02 03:35:48 UTC (rev 115786)
@@ -1,3 +1,15 @@
+2012-05-01  Keishi Hattori  <[email protected]>
+
+        datalist: Form control in a <datalist> should be barred from constraint validation
+        https://bugs.webkit.org/show_bug.cgi?id=84359
+
+        Reviewed by Kent Tamura.
+
+        * fast/forms/datalist/datalist-child-validation-expected.txt: Added.
+        * fast/forms/datalist/datalist-child-validation.html: Added. Tests that willValidate changes from false to true when we move the element out of the datalist.
+        * fast/forms/form-control-element-crash-expected.txt: Added.
+        * fast/forms/form-control-element-crash.html: Added. Tests for the crash reported in Bug 85149.
+
 2012-05-01  Kent Tamura  <[email protected]>
 
         [Chromium] Rebaseline for date-input-visible-strings.html.

Added: trunk/LayoutTests/fast/forms/datalist/datalist-child-validation-expected.txt (0 => 115786)


--- trunk/LayoutTests/fast/forms/datalist/datalist-child-validation-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/datalist/datalist-child-validation-expected.txt	2012-05-02 03:35:48 UTC (rev 115786)
@@ -0,0 +1,12 @@
+Test for child elements of a datalist element.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS e.willValidate is false
+PASS e.willValidate is true
+PASS document.querySelector(":invalid") is e
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/forms/datalist/datalist-child-validation.html (0 => 115786)


--- trunk/LayoutTests/fast/forms/datalist/datalist-child-validation.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/datalist/datalist-child-validation.html	2012-05-02 03:35:48 UTC (rev 115786)
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<datalist id="list">
+  <input type=text id=e required>
+</datalist>
+
+<script>
+description('Test for child elements of a datalist element.');
+
+var e = document.getElementById('e');
+shouldBeFalse('e.willValidate');
+document.body.appendChild(e);
+shouldBeTrue('e.willValidate');
+shouldBe('document.querySelector(":invalid")', 'e');
+
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/forms/form-control-element-crash-expected.txt (0 => 115786)


--- trunk/LayoutTests/fast/forms/form-control-element-crash-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/form-control-element-crash-expected.txt	2012-05-02 03:35:48 UTC (rev 115786)
@@ -0,0 +1 @@
+ 

Added: trunk/LayoutTests/fast/forms/form-control-element-crash.html (0 => 115786)


--- trunk/LayoutTests/fast/forms/form-control-element-crash.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/form-control-element-crash.html	2012-05-02 03:35:48 UTC (rev 115786)
@@ -0,0 +1,23 @@
+<html>
+<head>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+window._onload_=function(){
+    document.execCommand("SelectAll", false, false);
+    window.getSelection().deleteFromDocument();
+};
+</script>
+</head>
+<body>
+Bug 85149. This test passes if it doesn't crash.  Note: You will need to reload
+this test many times (or run the test under valgrind / ASAN) to see a crash.
+<form>
+<fieldset>
+<select></select>
+</fieldset>
+</form>
+<style> *{ animation-play-state:paused,running; } </style>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (115785 => 115786)


--- trunk/Source/WebCore/ChangeLog	2012-05-02 03:27:06 UTC (rev 115785)
+++ trunk/Source/WebCore/ChangeLog	2012-05-02 03:35:48 UTC (rev 115786)
@@ -1,3 +1,25 @@
+2012-05-01  Keishi Hattori  <[email protected]>
+
+        datalist: Form control in a <datalist> should be barred from constraint validation
+        https://bugs.webkit.org/show_bug.cgi?id=84359
+
+        Reviewed by Kent Tamura.
+
+        Tests: fast/forms/datalist/datalist-child-validation.html
+               fast/forms/form-control-element-crash.html
+
+        * html/HTMLFormControlElement.cpp:
+        (WebCore::HTMLFormControlElement::HTMLFormControlElement):
+        (WebCore::HTMLFormControlElement::updateAncestors): Updates the ancestor information.
+        (WebCore::HTMLFormControlElement::insertedInto): Invalidate the ancestor information and call setNeedsWillValidateCheck because willValidate might have changed.
+        (WebCore::HTMLFormControlElement::removedFrom): Ditto.
+        (WebCore::HTMLFormControlElement::disabled):
+        (WebCore::HTMLFormControlElement::recalcWillValidate): Returns false if element has a datalist ancestor.
+        (WebCore::HTMLFormControlElement::willValidate): Check if ancestor information is valid too.
+        (WebCore::HTMLFormControlElement::setNeedsWillValidateCheck):
+        * html/HTMLFormControlElement.h:
+        (HTMLFormControlElement):
+
 2012-05-01  Kent Tamura  <[email protected]>
 
         Calendar Picker: Close the picker by ESC key

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.cpp (115785 => 115786)


--- trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2012-05-02 03:27:06 UTC (rev 115785)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2012-05-02 03:35:48 UTC (rev 115786)
@@ -50,7 +50,7 @@
     : LabelableElement(tagName, document)
     , m_fieldSetAncestor(0)
     , m_legendAncestor(0)
-    , m_fieldSetAncestorValid(false)
+    , m_ancestorsValid(false)
     , m_disabled(false)
     , m_readOnly(false)
     , m_required(false)
@@ -60,6 +60,7 @@
     , m_isValid(true)
     , m_wasChangedSinceLastFormControlChangeEvent(false)
     , m_hasAutofocused(false)
+    , m_hasDataListAncestor(false)
 {
     setForm(form ? form : findFormAncestor());
     setHasCustomWillOrDidRecalcStyle();
@@ -100,19 +101,22 @@
     return fastHasAttribute(formnovalidateAttr);
 }
 
-void HTMLFormControlElement::updateFieldSetAndLegendAncestor() const
+void HTMLFormControlElement::updateAncestors() const
 {
     m_fieldSetAncestor = 0;
     m_legendAncestor = 0;
+    m_hasDataListAncestor = false;
     for (ContainerNode* ancestor = parentNode(); ancestor; ancestor = ancestor->parentNode()) {
         if (!m_legendAncestor && ancestor->hasTagName(legendTag))
             m_legendAncestor = static_cast<HTMLLegendElement*>(ancestor);
-        if (ancestor->hasTagName(fieldsetTag)) {
+        if (!m_fieldSetAncestor && ancestor->hasTagName(fieldsetTag))
             m_fieldSetAncestor = static_cast<HTMLFieldSetElement*>(ancestor);
+        if (!m_hasDataListAncestor && ancestor->hasTagName(datalistTag))
+            m_hasDataListAncestor = true;
+        if (m_hasDataListAncestor && m_fieldSetAncestor)
             break;
-        }
     }
-    m_fieldSetAncestorValid = true;
+    m_ancestorsValid = true;
 }
 
 void HTMLFormControlElement::parseAttribute(Attribute* attr)
@@ -225,14 +229,17 @@
 {
     HTMLElement::insertedInto(insertionPoint);
     FormAssociatedElement::insertedInto(insertionPoint);
+    m_ancestorsValid = false;
+    setNeedsWillValidateCheck();
     return InsertionDone;
 }
 
 void HTMLFormControlElement::removedFrom(Node* insertionPoint)
 {
-    m_fieldSetAncestorValid = false;
     HTMLElement::removedFrom(insertionPoint);
     FormAssociatedElement::removedFrom(insertionPoint);
+    m_ancestorsValid = false;
+    setNeedsWillValidateCheck();
 }
 
 const AtomicString& HTMLFormControlElement::formControlName() const
@@ -273,8 +280,8 @@
     if (m_disabled)
         return true;
 
-    if (!m_fieldSetAncestorValid)
-        updateFieldSetAndLegendAncestor();
+    if (!m_ancestorsValid)
+        updateAncestors();
 
     // Form controls in the first legend element inside a fieldset are not affected by fieldset.disabled.
     if (m_fieldSetAncestor && m_fieldSetAncestor->disabled())
@@ -353,9 +360,7 @@
 
 bool HTMLFormControlElement::recalcWillValidate() const
 {
-    // FIXME: Should return false if this element has a datalist element as an
-    // ancestor. See HTML5 4.10.10 'The datalist element.'
-    return !m_disabled && !m_readOnly;
+    return !m_hasDataListAncestor && !m_disabled && !m_readOnly;
 }
 
 bool HTMLFormControlElement::willValidate() const
@@ -374,6 +379,9 @@
 
 void HTMLFormControlElement::setNeedsWillValidateCheck()
 {
+    if (!m_ancestorsValid)
+        updateAncestors();
+
     // We need to recalculate willValidate immediately because willValidate change can causes style change.
     bool newWillValidate = recalcWillValidate();
     if (m_willValidateInitialized && m_willValidate == newWillValidate)

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.h (115785 => 115786)


--- trunk/Source/WebCore/html/HTMLFormControlElement.h	2012-05-02 03:27:06 UTC (rev 115785)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.h	2012-05-02 03:35:48 UTC (rev 115786)
@@ -51,7 +51,7 @@
     void setFormMethod(const String&);
     bool formNoValidate() const;
 
-    void updateFieldSetAndLegendAncestor() const;
+    void updateAncestors() const;
 
     virtual void reset() { }
 
@@ -153,7 +153,7 @@
     mutable HTMLFieldSetElement* m_fieldSetAncestor;
     mutable HTMLLegendElement* m_legendAncestor;
     OwnPtr<ValidationMessage> m_validationMessage;
-    mutable bool m_fieldSetAncestorValid : 1;
+    mutable bool m_ancestorsValid : 1;
     bool m_disabled : 1;
     bool m_readOnly : 1;
     bool m_required : 1;
@@ -172,6 +172,7 @@
     bool m_wasChangedSinceLastFormControlChangeEvent : 1;
 
     bool m_hasAutofocused : 1;
+    mutable bool m_hasDataListAncestor : 1;
 };
 
 } // namespace
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to