Title: [86832] trunk
Revision
86832
Author
[email protected]
Date
2011-05-19 02:50:07 -0700 (Thu, 19 May 2011)

Log Message

2011-05-19  Kent Tamura  <[email protected]>

        Reviewed by Hajime Morita.

        tooLong validity should not be true for a value set by a script
        https://bugs.webkit.org/show_bug.cgi?id=60948

        Update existing tests for the new behavior.

        * fast/forms/ValidityState-tooLong-input-expected.txt:
        * fast/forms/ValidityState-tooLong-textarea-expected.txt:
        * fast/forms/resources/textarea-live-pseudo-selectors.js:
        * fast/forms/script-tests/ValidityState-tooLong-input.js:
        * fast/forms/script-tests/ValidityState-tooLong-textarea.js:
2011-05-19  Kent Tamura  <[email protected]>

        Reviewed by Hajime Morita.

        tooLong validity should not be true for a value set by a script
        https://bugs.webkit.org/show_bug.cgi?id=60948

        The specification has been updated so that tooLong should be true only
        for user-edit values.

        Introduce m_wasModifiedByUser flag to HTMLInputElement and
        HTMLTextAreaElemnt. It is set to true when a renderer updates the
        value, and is cleared when the value is updated by others.

        * html/HTMLInputElement.cpp:
        (WebCore::HTMLInputElement::HTMLInputElement):
          Initialize m_wasModifiedByUser.
        (WebCore::HTMLInputElement::tooLong):
          Skip the check if m_wasModifiedByUser is false.
        (WebCore::HTMLInputElement::updateType): Clear m_wasModifiedByUser.
        (WebCore::HTMLInputElement::copyNonAttributeProperties):
        (WebCore::HTMLInputElement::setValue): If sendChange is true,
          m_wasModifiedByUser should be true because sendChange is set in a case
          of form auto-fill.  We assume a value set by form auto-fill is a kind
          of user-edit.
        (WebCore::HTMLInputElement::setValueFromRenderer):
          m_wasModifiedByUser should be true for the update by a renderer.
        * html/HTMLInputElement.h: Declare m_wasModifiedByUser.
        * html/HTMLTextAreaElement.cpp:
        (WebCore::HTMLTextAreaElement::HTMLTextAreaElement):
          Initialize m_wasModifiedByUser.
        (WebCore::HTMLTextAreaElement::updateValue):
          m_wasModifiedByUser should be true for the update by a renderer.
        (WebCore::HTMLTextAreaElement::setValueCommon): Clear m_wasModifiedByUser.
        (WebCore::HTMLTextAreaElement::tooLong):
          Skip the check if m_wasModifiedByUser is false.
        * html/HTMLTextAreaElement.h: Declare m_wasModifiedByUser.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (86831 => 86832)


--- trunk/LayoutTests/ChangeLog	2011-05-19 09:47:53 UTC (rev 86831)
+++ trunk/LayoutTests/ChangeLog	2011-05-19 09:50:07 UTC (rev 86832)
@@ -1,3 +1,18 @@
+2011-05-19  Kent Tamura  <[email protected]>
+
+        Reviewed by Hajime Morita.
+
+        tooLong validity should not be true for a value set by a script
+        https://bugs.webkit.org/show_bug.cgi?id=60948
+
+        Update existing tests for the new behavior.
+
+        * fast/forms/ValidityState-tooLong-input-expected.txt:
+        * fast/forms/ValidityState-tooLong-textarea-expected.txt:
+        * fast/forms/resources/textarea-live-pseudo-selectors.js:
+        * fast/forms/script-tests/ValidityState-tooLong-input.js:
+        * fast/forms/script-tests/ValidityState-tooLong-textarea.js:
+
 2011-05-19  Yuzo Fujishima  <[email protected]>
 
         Unreviewed Chromium test expectation change.

Modified: trunk/LayoutTests/fast/forms/ValidityState-tooLong-input-expected.txt (86831 => 86832)


--- trunk/LayoutTests/fast/forms/ValidityState-tooLong-input-expected.txt	2011-05-19 09:47:53 UTC (rev 86831)
+++ trunk/LayoutTests/fast/forms/ValidityState-tooLong-input-expected.txt	2011-05-19 09:50:07 UTC (rev 86832)
@@ -18,7 +18,7 @@
 PASS input.validity.tooLong is false
 
 Sets a value via DOM property
-PASS input.validity.tooLong is true
+PASS input.validity.tooLong is false
 
 Disabled
 PASS input.validity.tooLong is false
@@ -28,7 +28,7 @@
 
 Change the type with a too long value
 PASS input.validity.tooLong is true
-PASS input.validity.tooLong is false
+PASS input.type = "number"; input.validity.tooLong is false
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/forms/ValidityState-tooLong-textarea-expected.txt (86831 => 86832)


--- trunk/LayoutTests/fast/forms/ValidityState-tooLong-textarea-expected.txt	2011-05-19 09:47:53 UTC (rev 86831)
+++ trunk/LayoutTests/fast/forms/ValidityState-tooLong-textarea-expected.txt	2011-05-19 09:50:07 UTC (rev 86832)
@@ -18,7 +18,7 @@
 PASS textarea.validity.tooLong is false
 
 Sets a value via DOM property
-PASS textarea.validity.tooLong is true
+PASS textarea.validity.tooLong is false
 
 Disabled
 PASS textarea.validity.tooLong is false
@@ -26,13 +26,15 @@
 Grapheme length is not greater than maxLength though character length is greater
 PASS textarea.validity.tooLong is false
 
-A value set by resetting a form or by a child node change doesn't make tooLong true.
+A value set by resetting a form doesn't make tooLong true.
 PASS textarea.validity.tooLong is true
-PASS textarea.value is "abc"
+PASS textarea.value is "abcdef"
 PASS textarea.validity.tooLong is false
-PASS textarea.validity.tooLong is true
-PASS textarea.value is "def"
-PASS textarea.validity.tooLong is true
+
+A value set by a child node change doesn't make tooLong true.
+PASS textarea.validity.tooLong is false
+PASS textarea.value is "abcdef"
+PASS textarea.validity.tooLong is false
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/forms/resources/textarea-live-pseudo-selectors.js (86831 => 86832)


--- trunk/LayoutTests/fast/forms/resources/textarea-live-pseudo-selectors.js	2011-05-19 09:47:53 UTC (rev 86831)
+++ trunk/LayoutTests/fast/forms/resources/textarea-live-pseudo-selectors.js	2011-05-19 09:50:07 UTC (rev 86832)
@@ -96,7 +96,7 @@
 // Make the value dirty by deleting the last character.
 el.focus();
 el.setSelectionRange(10, 10);
-document.execCommand('\x08');
+document.execCommand('delete');
 el.maxLength = 5;
 shouldBe(elBackground, 'invalidColor');
 el.maxLength = 10;

Modified: trunk/LayoutTests/fast/forms/script-tests/ValidityState-tooLong-input.js (86831 => 86832)


--- trunk/LayoutTests/fast/forms/script-tests/ValidityState-tooLong-input.js	2011-05-19 09:47:53 UTC (rev 86831)
+++ trunk/LayoutTests/fast/forms/script-tests/ValidityState-tooLong-input.js	2011-05-19 09:50:07 UTC (rev 86832)
@@ -36,7 +36,7 @@
 debug('Sets a value via DOM property');
 input.maxLength = 3;
 input.value = 'abcde';
-shouldBeTrue('input.validity.tooLong');
+shouldBeFalse('input.validity.tooLong');
 
 debug('');
 debug('Disabled');
@@ -61,9 +61,10 @@
 input.maxLength = 3;
 input.value = 'abcde';
 input.type = 'search';
+input.focus();
+input.setSelectionRange(5, 5);
+document.execCommand('delete');
 shouldBeTrue('input.validity.tooLong');
+shouldBeFalse('input.type = "number"; input.validity.tooLong');
 
-input.type = 'number';
-shouldBeFalse('input.validity.tooLong');
-
 var successfullyParsed = true;

Modified: trunk/LayoutTests/fast/forms/script-tests/ValidityState-tooLong-textarea.js (86831 => 86832)


--- trunk/LayoutTests/fast/forms/script-tests/ValidityState-tooLong-textarea.js	2011-05-19 09:47:53 UTC (rev 86831)
+++ trunk/LayoutTests/fast/forms/script-tests/ValidityState-tooLong-textarea.js	2011-05-19 09:50:07 UTC (rev 86832)
@@ -38,7 +38,7 @@
 document.body.appendChild(textarea);
 textarea.maxLength = 3;
 textarea.value = 'abcde';
-shouldBeTrue('textarea.validity.tooLong');
+shouldBeFalse('textarea.validity.tooLong');
 
 debug('');
 debug('Disabled');
@@ -59,24 +59,27 @@
 shouldBeFalse('textarea.validity.tooLong');
 
 debug('');
-debug('A value set by resetting a form or by a child node change doesn\'t make tooLong true.');
+debug('A value set by resetting a form doesn\'t make tooLong true.');
 // Make a dirty textarea.
 var parent = document.createElement('div');
 document.body.appendChild(parent);
-parent.innerHTML = '<form><textarea maxlength=2>abc</textarea></form>';
+parent.innerHTML = '<form><textarea maxlength=2>abcdef</textarea></form>';
 textarea = parent.firstChild.firstChild;
-textarea.value = 'def';
+textarea.focus();
+textarea.setSelectionRange(6, 6);
+document.execCommand('delete');
 shouldBeTrue('textarea.validity.tooLong');
 parent.firstChild.reset();
-shouldBe('textarea.value', '"abc"');
+shouldBe('textarea.value', '"abcdef"');
 shouldBeFalse('textarea.validity.tooLong');
 
+debug('');
+debug('A value set by a child node change doesn\'t make tooLong true.');
 parent.innerHTML = '<textarea maxlength=2>abc</textarea>';
 textarea = parent.firstChild;
-textarea.value = 'def';
-shouldBeTrue('textarea.validity.tooLong');
+shouldBeFalse('textarea.validity.tooLong');
 parent.firstChild.innerHTML = 'abcdef';
-shouldBe('textarea.value', '"def"');
-shouldBeTrue('textarea.validity.tooLong');
+shouldBe('textarea.value', '"abcdef"');
+shouldBeFalse('textarea.validity.tooLong');
 
 var successfullyParsed = true;

Modified: trunk/Source/WebCore/ChangeLog (86831 => 86832)


--- trunk/Source/WebCore/ChangeLog	2011-05-19 09:47:53 UTC (rev 86831)
+++ trunk/Source/WebCore/ChangeLog	2011-05-19 09:50:07 UTC (rev 86832)
@@ -1,3 +1,41 @@
+2011-05-19  Kent Tamura  <[email protected]>
+
+        Reviewed by Hajime Morita.
+
+        tooLong validity should not be true for a value set by a script
+        https://bugs.webkit.org/show_bug.cgi?id=60948
+
+        The specification has been updated so that tooLong should be true only
+        for user-edit values.
+        
+        Introduce m_wasModifiedByUser flag to HTMLInputElement and
+        HTMLTextAreaElemnt. It is set to true when a renderer updates the
+        value, and is cleared when the value is updated by others.
+
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::HTMLInputElement):
+          Initialize m_wasModifiedByUser.
+        (WebCore::HTMLInputElement::tooLong):
+          Skip the check if m_wasModifiedByUser is false.
+        (WebCore::HTMLInputElement::updateType): Clear m_wasModifiedByUser.
+        (WebCore::HTMLInputElement::copyNonAttributeProperties):
+        (WebCore::HTMLInputElement::setValue): If sendChange is true,
+          m_wasModifiedByUser should be true because sendChange is set in a case
+          of form auto-fill.  We assume a value set by form auto-fill is a kind
+          of user-edit.
+        (WebCore::HTMLInputElement::setValueFromRenderer):
+          m_wasModifiedByUser should be true for the update by a renderer.
+        * html/HTMLInputElement.h: Declare m_wasModifiedByUser.
+        * html/HTMLTextAreaElement.cpp:
+        (WebCore::HTMLTextAreaElement::HTMLTextAreaElement):
+          Initialize m_wasModifiedByUser.
+        (WebCore::HTMLTextAreaElement::updateValue):
+          m_wasModifiedByUser should be true for the update by a renderer.
+        (WebCore::HTMLTextAreaElement::setValueCommon): Clear m_wasModifiedByUser.
+        (WebCore::HTMLTextAreaElement::tooLong):
+          Skip the check if m_wasModifiedByUser is false.
+        * html/HTMLTextAreaElement.h: Declare m_wasModifiedByUser.
+
 2011-05-19  David Barr  <[email protected]>
 
         Reviewed by Simon Fraser.

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (86831 => 86832)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2011-05-19 09:47:53 UTC (rev 86831)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2011-05-19 09:50:07 UTC (rev 86832)
@@ -93,6 +93,7 @@
     , m_isAutofilled(false)
     , m_stateRestored(false)
     , m_parsingInProgress(createdByParser)
+    , m_wasModifiedByUser(false)
     , m_inputType(InputType::createText(this))
 {
     ASSERT(hasTagName(inputTag) || hasTagName(isindexTag));
@@ -218,9 +219,10 @@
     if (max < 0)
         return false;
     if (check == CheckDirtyFlag) {
-        // Return false for the default value even if it is longer than maxLength.
-        bool userEdited = !m_value.isNull();
-        if (!userEdited)
+        // Return false for the default value or a value set by a script even if
+        // it is longer than maxLength.
+        bool dirty = !m_value.isNull();
+        if (!dirty || !m_wasModifiedByUser)
             return false;
     }
     return numGraphemeClusters(value) > static_cast<unsigned>(max);
@@ -518,6 +520,7 @@
         m_value = sanitizeValue(fastGetAttribute(valueAttr));
     else
         updateValueIfNeeded();
+    m_wasModifiedByUser = false;
 
     if (neededActivationCallback)
         unregisterForActivationCallbackIfNeeded();
@@ -861,6 +864,7 @@
     const HTMLInputElement* sourceElement = static_cast<const HTMLInputElement*>(source);
 
     m_value = sourceElement->m_value;
+    m_wasModifiedByUser = false;
     setChecked(sourceElement->m_isChecked);
     m_reflectsCheckedAttribute = sourceElement->m_reflectsCheckedAttribute;
     m_isIndeterminate = sourceElement->m_isIndeterminate;
@@ -928,6 +932,7 @@
             files()->clear();
         else {
             m_value = sanitizeValue(value);
+            m_wasModifiedByUser = sendChangeEvent;
             if (isTextField())
                 updatePlaceholderVisibility(false);
         }
@@ -1017,6 +1022,7 @@
     m_value = value == "\n" ? String("") : value;
 
     setFormControlValueMatchesRenderer(true);
+    m_wasModifiedByUser = true;
 
     // Input event is fired by the Node::defaultEventHandler for editable controls.
     if (!isTextField())

Modified: trunk/Source/WebCore/html/HTMLInputElement.h (86831 => 86832)


--- trunk/Source/WebCore/html/HTMLInputElement.h	2011-05-19 09:47:53 UTC (rev 86831)
+++ trunk/Source/WebCore/html/HTMLInputElement.h	2011-05-19 09:50:07 UTC (rev 86832)
@@ -339,6 +339,7 @@
 #endif
     bool m_stateRestored : 1;
     bool m_parsingInProgress : 1;
+    bool m_wasModifiedByUser : 1;
     OwnPtr<InputType> m_inputType;
 };
 

Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.cpp (86831 => 86832)


--- trunk/Source/WebCore/html/HTMLTextAreaElement.cpp	2011-05-19 09:47:53 UTC (rev 86831)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.cpp	2011-05-19 09:50:07 UTC (rev 86832)
@@ -71,6 +71,7 @@
     , m_cachedSelectionStart(-1)
     , m_cachedSelectionEnd(-1)
     , m_isDirty(false)
+    , m_wasModifiedByUser(false)
 {
     ASSERT(hasTagName(textareaTag));
     setFormControlValueMatchesRenderer(true);
@@ -277,6 +278,7 @@
     const_cast<HTMLTextAreaElement*>(this)->setFormControlValueMatchesRenderer(true);
     notifyFormStateChanged(this);
     m_isDirty = true;
+    const_cast<HTMLTextAreaElement*>(this)->m_wasModifiedByUser = true;
     const_cast<HTMLTextAreaElement*>(this)->updatePlaceholderVisibility(false);
 }
 
@@ -304,6 +306,7 @@
 
 void HTMLTextAreaElement::setValueCommon(const String& value)
 {
+    m_wasModifiedByUser = false;
     // Code elsewhere normalizes line endings added by the user via the keyboard or pasting.
     // We normalize line endings coming from _javascript_ here.
     String normalizedValue = value.isNull() ? "" : value;
@@ -384,8 +387,9 @@
 
 bool HTMLTextAreaElement::tooLong(const String& value, NeedsToCheckDirtyFlag check) const
 {
-    // Return false for the default value even if it is longer than maxLength.
-    if (check == CheckDirtyFlag && !m_isDirty)
+    // Return false for the default value or value set by script even if it is
+    // longer than maxLength.
+    if (check == CheckDirtyFlag && !m_wasModifiedByUser)
         return false;
 
     int max = maxLength();

Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.h (86831 => 86832)


--- trunk/Source/WebCore/html/HTMLTextAreaElement.h	2011-05-19 09:47:53 UTC (rev 86831)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.h	2011-05-19 09:50:07 UTC (rev 86832)
@@ -110,6 +110,7 @@
     int m_cachedSelectionStart;
     int m_cachedSelectionEnd;
     mutable bool m_isDirty;
+    bool m_wasModifiedByUser;
 };
 
 } //namespace
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to