Changeset 123178 in webkit


Ignore:
Timestamp:
Jul 19, 2012 9:48:17 PM (12 years ago)
Author:
tkent@chromium.org
Message:

Form state restore: Need to identify a form by its content
https://bugs.webkit.org/show_bug.cgi?id=91209

Reviewed by Hajime Morita.

Source/WebCore:

Add names of the first two controls of a form to its formKey
string. By this change, we can correctly restore states to
reordered forms like webkit.org/b/91209#c0.

Tests: Added test cases to fast/forms/state-restore-per-form.html.

  • html/FormController.cpp:

(WebCore::recordFormStructure):
Append at most two name attribute values.
(WebCore::createKey): Insert a string built by recordFromStructure().
(WebCore::formStateSignature): Bump the version.

LayoutTests:

  • fast/forms/state-restore-broken-state-expected.txt:

Updated for the serialized format change.

  • fast/forms/state-restore-per-form-expected.txt:
  • fast/forms/state-restore-per-form.html:
  • Add a control to #form2 before 'additionalControl' We can't identify this form if the second named control is changed.
  • Add test cases of webkit.org/b/91209#c0.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r123174 r123178  
     12012-07-19  Kent Tamura  <tkent@chromium.org>
     2
     3        Form state restore: Need to identify a form by its content
     4        https://bugs.webkit.org/show_bug.cgi?id=91209
     5
     6        Reviewed by Hajime Morita.
     7
     8        * fast/forms/state-restore-broken-state-expected.txt:
     9        Updated for the serialized format change.
     10        * fast/forms/state-restore-per-form-expected.txt:
     11        * fast/forms/state-restore-per-form.html:
     12        - Add a control to #form2 before 'additionalControl'
     13         We can't identify this form if the second named control is changed.
     14        - Add test cases of webkit.org/b/91209#c0.
     15
    1162012-07-19  Jeff Timanus  <twiz@chromium.org>
    217
  • trunk/LayoutTests/fast/forms/state-restore-broken-state-expected.txt

    r123066 r123178  
    1 CONSOLE MESSAGE: line 5: Generated state: [state-restore-broken-state-2.html #0,1,name1,text,1,modified]
     1CONSOLE MESSAGE: line 5: Generated state: [state-restore-broken-state-2.html [name1 ] #0,1,name1,text,1,modified]
    22The value was modified in the first load of state-restore-broken-state-1.html, but it should not be restored because the state-restore-broken-state-2.html breaks the state.
    33
  • trunk/LayoutTests/fast/forms/state-restore-per-form-expected.txt

    r123066 r123178  
    1717FAIL $("form3-outer2").value should be form3-outer2-modified. Was form2-outer2-modified.
    1818FAIL $("form2-outer2").value should be form2-outer2-modified. Was initial.
     19
     20Controls in forms with an identical action URL. These forms were reordered:
     21PASS $("aaa_input1").value is "aaa_input1-modified"
     22PASS $("ccc_input1").value is "ccc_input1-modified"
    1923PASS successfullyParsed is true
    2024
  • trunk/LayoutTests/fast/forms/state-restore-per-form.html

    r123066 r123178  
    2828    var sameActionForm1 = '<form action="http://example.com/foo.cgi' + query + '#bar" id=form2>' +
    2929        '<input value=initial id=form2-control1 name=common-name1>' +
     30        '<input value=initial id=form2-control2 name=name2>' +
    3031        additionalControl +
    3132        '</form>';
     
    3536        '<input value=initial id=form3-control2 name=common-name1>' +
    3637        '</form>';
     38
     39    var reorderedFormA = '<form action="PostAction" method="POST">' +
     40        '<input type="hidden" name="task" value="AAA">' +
     41        '<input name="aaa_input1" value=initial id=aaa_input1>' +
     42        '<input name="aaa_input2" value=initial>' +
     43        '</form>';
     44    var reorderedFormB = '<form action="PostAction" method="POST">' +
     45        '<input type="hidden" name="task" value="BBB">' +
     46        '<input name="bbb_input1" value=initial id=bbb_input1>' +
     47        '<input name="bbb_input2" value=initial>' +
     48        '</form>';
     49    var reorderedFormC = '<form action="PostAction" method="POST">' +
     50        '<input type="hidden" name="task" value="CCC">' +
     51        '<input name="ccc_input1" value=initial id=ccc_input1>' +
     52        '<input name="ccc_input2" value=initial>' +
     53        '</form>';
     54    var reorderedSameActionForms = stage == 1 ? reorderedFormA + reorderedFormB + reorderedFormC : reorderedFormC + reorderedFormA;
    3755
    3856    var afterForms = (stage == 1 ? '' : '<input value=initial id=noowner2 name=after>') +
     
    4462                   (stage == 1 ? backForm + sameActionForm1 : sameActionForm1 + backForm) +
    4563                   sameActionForm2 +
     64                   reorderedSameActionForms +
    4665                   afterForms);
    4766}
     
    6584            $('form2-outer2').value = 'form2-outer2-modified';
    6685            $('form3-outer2').value = 'form3-outer2-modified';
     86            $('aaa_input1').value = 'aaa_input1-modified';
     87            $('bbb_input1').value = 'bbb_input1-modified';
     88            $('ccc_input1').value = 'ccc_input1-modified';
    6789            $('form1').submit();
    6890        }, 0);
     
    91113        shouldBeEqualToString('$("form3-outer2").value', 'form3-outer2-modified');
    92114        shouldBeEqualToString('$("form2-outer2").value', 'form2-outer2-modified');
     115
     116        debug('\nControls in forms with an identical action URL. These forms were reordered:');
     117        shouldBeEqualToString('$("aaa_input1").value', 'aaa_input1-modified');
     118        shouldBeEqualToString('$("ccc_input1").value', 'ccc_input1-modified');
    93119   
    94120        $('parent').innerHTML = '';
  • trunk/Source/WebCore/ChangeLog

    r123175 r123178  
     12012-07-19  Kent Tamura  <tkent@chromium.org>
     2
     3        Form state restore: Need to identify a form by its content
     4        https://bugs.webkit.org/show_bug.cgi?id=91209
     5
     6        Reviewed by Hajime Morita.
     7
     8        Add names of the first two controls of a form to its formKey
     9        string. By this change, we can correctly restore states to
     10        reordered forms like webkit.org/b/91209#c0.
     11
     12        Tests: Added test cases to fast/forms/state-restore-per-form.html.
     13
     14        * html/FormController.cpp:
     15        (WebCore::recordFormStructure):
     16        Append at most two name attribute values.
     17        (WebCore::createKey): Insert a string built by recordFromStructure().
     18        (WebCore::formStateSignature): Bump the version.
     19
    1202012-07-19  Wei James  <james.wei@intel.com>
    221
  • trunk/Source/WebCore/html/FormController.cpp

    r123066 r123178  
    283283};
    284284
     285static inline void recordFormStructure(const HTMLFormElement& form, StringBuilder& builder)
     286{
     287    // 2 is enough to distinguish forms in webkit.org/b/91209#c0
     288    const size_t namedControlsToBeRecorded = 2;
     289    const Vector<FormAssociatedElement*>& controls = form.associatedElements();
     290    builder.append(" [");
     291    for (size_t i = 0, namedControls = 0; i < controls.size() && namedControls < namedControlsToBeRecorded; ++i) {
     292        if (!controls[i]->isFormControlElementWithState())
     293            continue;
     294        HTMLFormControlElementWithState* control = static_cast<HTMLFormControlElementWithState*>(controls[i]);
     295        if (!ownerFormForState(*control))
     296            continue;
     297        AtomicString name = control->name();
     298        if (name.isEmpty())
     299            continue;
     300        namedControls++;
     301        builder.append(name);
     302        builder.append(" ");
     303    }
     304    builder.append("]");
     305}
     306
    285307static inline AtomicString createKey(HTMLFormElement* form, unsigned index)
    286308{
     
    293315    if (!actionURL.isEmpty())
    294316        builder.append(actionURL.string());
     317
     318    recordFormStructure(*form, builder);
     319
    295320    builder.append(" #");
    296321    builder.append(String::number(index));
     
    345370    // attribute value of a form control. The following string literal should
    346371    // contain some characters which are rarely used for name attribute values.
    347     DEFINE_STATIC_LOCAL(String, signature, ("\n\r?% WebKit serialized form state version 6 \n\r=&"));
     372    DEFINE_STATIC_LOCAL(String, signature, ("\n\r?% WebKit serialized form state version 7 \n\r=&"));
    348373    return signature;
    349374}
Note: See TracChangeset for help on using the changeset viewer.