Changeset 86832 in webkit


Ignore:
Timestamp:
May 19, 2011 2:50:07 AM (13 years ago)
Author:
tkent@chromium.org
Message:

2011-05-19 Kent Tamura <tkent@chromium.org>

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 <tkent@chromium.org>

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.
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r86831 r86832  
     12011-05-19  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Hajime Morita.
     4
     5        tooLong validity should not be true for a value set by a script
     6        https://bugs.webkit.org/show_bug.cgi?id=60948
     7
     8        Update existing tests for the new behavior.
     9
     10        * fast/forms/ValidityState-tooLong-input-expected.txt:
     11        * fast/forms/ValidityState-tooLong-textarea-expected.txt:
     12        * fast/forms/resources/textarea-live-pseudo-selectors.js:
     13        * fast/forms/script-tests/ValidityState-tooLong-input.js:
     14        * fast/forms/script-tests/ValidityState-tooLong-textarea.js:
     15
    1162011-05-19  Yuzo Fujishima  <yuzo@google.com>
    217
  • trunk/LayoutTests/fast/forms/ValidityState-tooLong-input-expected.txt

    r73999 r86832  
    1919
    2020Sets a value via DOM property
    21 PASS input.validity.tooLong is true
     21PASS input.validity.tooLong is false
    2222
    2323Disabled
     
    2929Change the type with a too long value
    3030PASS input.validity.tooLong is true
    31 PASS input.validity.tooLong is false
     31PASS input.type = "number"; input.validity.tooLong is false
    3232PASS successfullyParsed is true
    3333
  • trunk/LayoutTests/fast/forms/ValidityState-tooLong-textarea-expected.txt

    r82913 r86832  
    1919
    2020Sets a value via DOM property
    21 PASS textarea.validity.tooLong is true
     21PASS textarea.validity.tooLong is false
    2222
    2323Disabled
     
    2727PASS textarea.validity.tooLong is false
    2828
    29 A value set by resetting a form or by a child node change doesn't make tooLong true.
     29A value set by resetting a form doesn't make tooLong true.
    3030PASS textarea.validity.tooLong is true
    31 PASS textarea.value is "abc"
     31PASS textarea.value is "abcdef"
    3232PASS textarea.validity.tooLong is false
    33 PASS textarea.validity.tooLong is true
    34 PASS textarea.value is "def"
    35 PASS textarea.validity.tooLong is true
     33
     34A value set by a child node change doesn't make tooLong true.
     35PASS textarea.validity.tooLong is false
     36PASS textarea.value is "abcdef"
     37PASS textarea.validity.tooLong is false
    3638PASS successfullyParsed is true
    3739
  • trunk/LayoutTests/fast/forms/resources/textarea-live-pseudo-selectors.js

    r61153 r86832  
    9797el.focus();
    9898el.setSelectionRange(10, 10);
    99 document.execCommand('\x08');
     99document.execCommand('delete');
    100100el.maxLength = 5;
    101101shouldBe(elBackground, 'invalidColor');
  • trunk/LayoutTests/fast/forms/script-tests/ValidityState-tooLong-input.js

    r73999 r86832  
    3737input.maxLength = 3;
    3838input.value = 'abcde';
    39 shouldBeTrue('input.validity.tooLong');
     39shouldBeFalse('input.validity.tooLong');
    4040
    4141debug('');
     
    6262input.value = 'abcde';
    6363input.type = 'search';
     64input.focus();
     65input.setSelectionRange(5, 5);
     66document.execCommand('delete');
    6467shouldBeTrue('input.validity.tooLong');
    65 
    66 input.type = 'number';
    67 shouldBeFalse('input.validity.tooLong');
     68shouldBeFalse('input.type = "number"; input.validity.tooLong');
    6869
    6970var successfullyParsed = true;
  • trunk/LayoutTests/fast/forms/script-tests/ValidityState-tooLong-textarea.js

    r82913 r86832  
    3939textarea.maxLength = 3;
    4040textarea.value = 'abcde';
    41 shouldBeTrue('textarea.validity.tooLong');
     41shouldBeFalse('textarea.validity.tooLong');
    4242
    4343debug('');
     
    6060
    6161debug('');
    62 debug('A value set by resetting a form or by a child node change doesn\'t make tooLong true.');
     62debug('A value set by resetting a form doesn\'t make tooLong true.');
    6363// Make a dirty textarea.
    6464var parent = document.createElement('div');
    6565document.body.appendChild(parent);
    66 parent.innerHTML = '<form><textarea maxlength=2>abc</textarea></form>';
     66parent.innerHTML = '<form><textarea maxlength=2>abcdef</textarea></form>';
    6767textarea = parent.firstChild.firstChild;
    68 textarea.value = 'def';
     68textarea.focus();
     69textarea.setSelectionRange(6, 6);
     70document.execCommand('delete');
    6971shouldBeTrue('textarea.validity.tooLong');
    7072parent.firstChild.reset();
    71 shouldBe('textarea.value', '"abc"');
     73shouldBe('textarea.value', '"abcdef"');
    7274shouldBeFalse('textarea.validity.tooLong');
    7375
     76debug('');
     77debug('A value set by a child node change doesn\'t make tooLong true.');
    7478parent.innerHTML = '<textarea maxlength=2>abc</textarea>';
    7579textarea = parent.firstChild;
    76 textarea.value = 'def';
    77 shouldBeTrue('textarea.validity.tooLong');
     80shouldBeFalse('textarea.validity.tooLong');
    7881parent.firstChild.innerHTML = 'abcdef';
    79 shouldBe('textarea.value', '"def"');
    80 shouldBeTrue('textarea.validity.tooLong');
     82shouldBe('textarea.value', '"abcdef"');
     83shouldBeFalse('textarea.validity.tooLong');
    8184
    8285var successfullyParsed = true;
  • trunk/Source/WebCore/ChangeLog

    r86830 r86832  
     12011-05-19  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Hajime Morita.
     4
     5        tooLong validity should not be true for a value set by a script
     6        https://bugs.webkit.org/show_bug.cgi?id=60948
     7
     8        The specification has been updated so that tooLong should be true only
     9        for user-edit values.
     10       
     11        Introduce m_wasModifiedByUser flag to HTMLInputElement and
     12        HTMLTextAreaElemnt. It is set to true when a renderer updates the
     13        value, and is cleared when the value is updated by others.
     14
     15        * html/HTMLInputElement.cpp:
     16        (WebCore::HTMLInputElement::HTMLInputElement):
     17          Initialize m_wasModifiedByUser.
     18        (WebCore::HTMLInputElement::tooLong):
     19          Skip the check if m_wasModifiedByUser is false.
     20        (WebCore::HTMLInputElement::updateType): Clear m_wasModifiedByUser.
     21        (WebCore::HTMLInputElement::copyNonAttributeProperties):
     22        (WebCore::HTMLInputElement::setValue): If sendChange is true,
     23          m_wasModifiedByUser should be true because sendChange is set in a case
     24          of form auto-fill.  We assume a value set by form auto-fill is a kind
     25          of user-edit.
     26        (WebCore::HTMLInputElement::setValueFromRenderer):
     27          m_wasModifiedByUser should be true for the update by a renderer.
     28        * html/HTMLInputElement.h: Declare m_wasModifiedByUser.
     29        * html/HTMLTextAreaElement.cpp:
     30        (WebCore::HTMLTextAreaElement::HTMLTextAreaElement):
     31          Initialize m_wasModifiedByUser.
     32        (WebCore::HTMLTextAreaElement::updateValue):
     33          m_wasModifiedByUser should be true for the update by a renderer.
     34        (WebCore::HTMLTextAreaElement::setValueCommon): Clear m_wasModifiedByUser.
     35        (WebCore::HTMLTextAreaElement::tooLong):
     36          Skip the check if m_wasModifiedByUser is false.
     37        * html/HTMLTextAreaElement.h: Declare m_wasModifiedByUser.
     38
    1392011-05-19  David Barr  <davidbarr@chromium.org>
    240
  • trunk/Source/WebCore/html/HTMLInputElement.cpp

    r86654 r86832  
    9494    , m_stateRestored(false)
    9595    , m_parsingInProgress(createdByParser)
     96    , m_wasModifiedByUser(false)
    9697    , m_inputType(InputType::createText(this))
    9798{
     
    219220        return false;
    220221    if (check == CheckDirtyFlag) {
    221         // Return false for the default value even if it is longer than maxLength.
    222         bool userEdited = !m_value.isNull();
    223         if (!userEdited)
     222        // Return false for the default value or a value set by a script even if
     223        // it is longer than maxLength.
     224        bool dirty = !m_value.isNull();
     225        if (!dirty || !m_wasModifiedByUser)
    224226            return false;
    225227    }
     
    519521    else
    520522        updateValueIfNeeded();
     523    m_wasModifiedByUser = false;
    521524
    522525    if (neededActivationCallback)
     
    862865
    863866    m_value = sourceElement->m_value;
     867    m_wasModifiedByUser = false;
    864868    setChecked(sourceElement->m_isChecked);
    865869    m_reflectsCheckedAttribute = sourceElement->m_reflectsCheckedAttribute;
     
    929933        else {
    930934            m_value = sanitizeValue(value);
     935            m_wasModifiedByUser = sendChangeEvent;
    931936            if (isTextField())
    932937                updatePlaceholderVisibility(false);
     
    10181023
    10191024    setFormControlValueMatchesRenderer(true);
     1025    m_wasModifiedByUser = true;
    10201026
    10211027    // Input event is fired by the Node::defaultEventHandler for editable controls.
  • trunk/Source/WebCore/html/HTMLInputElement.h

    r85998 r86832  
    340340    bool m_stateRestored : 1;
    341341    bool m_parsingInProgress : 1;
     342    bool m_wasModifiedByUser : 1;
    342343    OwnPtr<InputType> m_inputType;
    343344};
  • trunk/Source/WebCore/html/HTMLTextAreaElement.cpp

    r85998 r86832  
    7272    , m_cachedSelectionEnd(-1)
    7373    , m_isDirty(false)
     74    , m_wasModifiedByUser(false)
    7475{
    7576    ASSERT(hasTagName(textareaTag));
     
    278279    notifyFormStateChanged(this);
    279280    m_isDirty = true;
     281    const_cast<HTMLTextAreaElement*>(this)->m_wasModifiedByUser = true;
    280282    const_cast<HTMLTextAreaElement*>(this)->updatePlaceholderVisibility(false);
    281283}
     
    305307void HTMLTextAreaElement::setValueCommon(const String& value)
    306308{
     309    m_wasModifiedByUser = false;
    307310    // Code elsewhere normalizes line endings added by the user via the keyboard or pasting.
    308311    // We normalize line endings coming from JavaScript here.
     
    385388bool HTMLTextAreaElement::tooLong(const String& value, NeedsToCheckDirtyFlag check) const
    386389{
    387     // Return false for the default value even if it is longer than maxLength.
    388     if (check == CheckDirtyFlag && !m_isDirty)
     390    // Return false for the default value or value set by script even if it is
     391    // longer than maxLength.
     392    if (check == CheckDirtyFlag && !m_wasModifiedByUser)
    389393        return false;
    390394
  • trunk/Source/WebCore/html/HTMLTextAreaElement.h

    r82925 r86832  
    111111    int m_cachedSelectionEnd;
    112112    mutable bool m_isDirty;
     113    bool m_wasModifiedByUser;
    113114};
    114115
Note: See TracChangeset for help on using the changeset viewer.