Title: [123178] trunk
Revision
123178
Author
[email protected]
Date
2012-07-19 21:48:17 -0700 (Thu, 19 Jul 2012)

Log 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.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (123177 => 123178)


--- trunk/LayoutTests/ChangeLog	2012-07-20 04:31:58 UTC (rev 123177)
+++ trunk/LayoutTests/ChangeLog	2012-07-20 04:48:17 UTC (rev 123178)
@@ -1,3 +1,18 @@
+2012-07-19  Kent Tamura  <[email protected]>
+
+        Form state restore: Need to identify a form by its content
+        https://bugs.webkit.org/show_bug.cgi?id=91209
+
+        Reviewed by Hajime Morita.
+
+        * 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.
+
 2012-07-19  Jeff Timanus  <[email protected]>
 
         [Chromium] Suppress tests requiring a rebaseline.

Modified: trunk/LayoutTests/fast/forms/state-restore-broken-state-expected.txt (123177 => 123178)


--- trunk/LayoutTests/fast/forms/state-restore-broken-state-expected.txt	2012-07-20 04:31:58 UTC (rev 123177)
+++ trunk/LayoutTests/fast/forms/state-restore-broken-state-expected.txt	2012-07-20 04:48:17 UTC (rev 123178)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: line 5: Generated state: [state-restore-broken-state-2.html #0,1,name1,text,1,modified]
+CONSOLE MESSAGE: line 5: Generated state: [state-restore-broken-state-2.html [name1 ] #0,1,name1,text,1,modified]
 The 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.
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".

Modified: trunk/LayoutTests/fast/forms/state-restore-per-form-expected.txt (123177 => 123178)


--- trunk/LayoutTests/fast/forms/state-restore-per-form-expected.txt	2012-07-20 04:31:58 UTC (rev 123177)
+++ trunk/LayoutTests/fast/forms/state-restore-per-form-expected.txt	2012-07-20 04:48:17 UTC (rev 123178)
@@ -16,6 +16,10 @@
 FAIL $("noowner2").value should be initial. Was form3-outer2-modified.
 FAIL $("form3-outer2").value should be form3-outer2-modified. Was form2-outer2-modified.
 FAIL $("form2-outer2").value should be form2-outer2-modified. Was initial.
+
+Controls in forms with an identical action URL. These forms were reordered:
+PASS $("aaa_input1").value is "aaa_input1-modified"
+PASS $("ccc_input1").value is "ccc_input1-modified"
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/forms/state-restore-per-form.html (123177 => 123178)


--- trunk/LayoutTests/fast/forms/state-restore-per-form.html	2012-07-20 04:31:58 UTC (rev 123177)
+++ trunk/LayoutTests/fast/forms/state-restore-per-form.html	2012-07-20 04:48:17 UTC (rev 123178)
@@ -27,6 +27,7 @@
     var additionalControl = stage == 1 ? '' : '<input name=username id=form2-added value=initial>';
     var sameActionForm1 = '<form action="" + query + '#bar" id=form2>' +
         '<input value=initial id=form2-control1 name=common-name1>' +
+        '<input value=initial id=form2-control2 name=name2>' +
         additionalControl +
         '</form>';
 
@@ -35,6 +36,23 @@
         '<input value=initial id=form3-control2 name=common-name1>' +
         '</form>';
 
+    var reorderedFormA = '<form action="" method="POST">' +
+        '<input type="hidden" name="task" value="AAA">' +
+        '<input name="aaa_input1" value=initial id=aaa_input1>' +
+        '<input name="aaa_input2" value=initial>' +
+        '</form>';
+    var reorderedFormB = '<form action="" method="POST">' +
+        '<input type="hidden" name="task" value="BBB">' +
+        '<input name="bbb_input1" value=initial id=bbb_input1>' +
+        '<input name="bbb_input2" value=initial>' +
+        '</form>';
+    var reorderedFormC = '<form action="" method="POST">' +
+        '<input type="hidden" name="task" value="CCC">' +
+        '<input name="ccc_input1" value=initial id=ccc_input1>' +
+        '<input name="ccc_input2" value=initial>' +
+        '</form>';
+    var reorderedSameActionForms = stage == 1 ? reorderedFormA + reorderedFormB + reorderedFormC : reorderedFormC + reorderedFormA;
+
     var afterForms = (stage == 1 ? '' : '<input value=initial id=noowner2 name=after>') +
         '<input value=initial id=form3-outer2 name=after form=form3>' +
         '<input value=initial id=form2-outer2 name=after form=form2>' +
@@ -43,6 +61,7 @@
     document.write(beforeForms +
                    (stage == 1 ? backForm + sameActionForm1 : sameActionForm1 + backForm) +
                    sameActionForm2 +
+                   reorderedSameActionForms +
                    afterForms);
 }
 
@@ -64,6 +83,9 @@
             $('form3-outer1').value = 'form3-outer1-modified';
             $('form2-outer2').value = 'form2-outer2-modified';
             $('form3-outer2').value = 'form3-outer2-modified';
+            $('aaa_input1').value = 'aaa_input1-modified';
+            $('bbb_input1').value = 'bbb_input1-modified';
+            $('ccc_input1').value = 'ccc_input1-modified';
             $('form1').submit();
         }, 0);
     } else {
@@ -90,6 +112,10 @@
         shouldBeEqualToString('$("noowner2").value', 'initial');
         shouldBeEqualToString('$("form3-outer2").value', 'form3-outer2-modified');
         shouldBeEqualToString('$("form2-outer2").value', 'form2-outer2-modified');
+
+        debug('\nControls in forms with an identical action URL. These forms were reordered:');
+        shouldBeEqualToString('$("aaa_input1").value', 'aaa_input1-modified');
+        shouldBeEqualToString('$("ccc_input1").value', 'ccc_input1-modified');
     
         $('parent').innerHTML = '';
         setTimeout(function() { finishJSTest(); }, 0);

Modified: trunk/Source/WebCore/ChangeLog (123177 => 123178)


--- trunk/Source/WebCore/ChangeLog	2012-07-20 04:31:58 UTC (rev 123177)
+++ trunk/Source/WebCore/ChangeLog	2012-07-20 04:48:17 UTC (rev 123178)
@@ -1,3 +1,22 @@
+2012-07-19  Kent Tamura  <[email protected]>
+
+        Form state restore: Need to identify a form by its content
+        https://bugs.webkit.org/show_bug.cgi?id=91209
+
+        Reviewed by Hajime Morita.
+
+        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.
+
 2012-07-19  Wei James  <[email protected]>
 
         enable Web Audio for chromium android port

Modified: trunk/Source/WebCore/html/FormController.cpp (123177 => 123178)


--- trunk/Source/WebCore/html/FormController.cpp	2012-07-20 04:31:58 UTC (rev 123177)
+++ trunk/Source/WebCore/html/FormController.cpp	2012-07-20 04:48:17 UTC (rev 123178)
@@ -282,6 +282,28 @@
     HashSet<AtomicString> m_existingKeys;
 };
 
+static inline void recordFormStructure(const HTMLFormElement& form, StringBuilder& builder)
+{
+    // 2 is enough to distinguish forms in webkit.org/b/91209#c0
+    const size_t namedControlsToBeRecorded = 2;
+    const Vector<FormAssociatedElement*>& controls = form.associatedElements();
+    builder.append(" [");
+    for (size_t i = 0, namedControls = 0; i < controls.size() && namedControls < namedControlsToBeRecorded; ++i) {
+        if (!controls[i]->isFormControlElementWithState())
+            continue;
+        HTMLFormControlElementWithState* control = static_cast<HTMLFormControlElementWithState*>(controls[i]);
+        if (!ownerFormForState(*control))
+            continue;
+        AtomicString name = control->name();
+        if (name.isEmpty())
+            continue;
+        namedControls++;
+        builder.append(name);
+        builder.append(" ");
+    }
+    builder.append("]");
+}
+
 static inline AtomicString createKey(HTMLFormElement* form, unsigned index)
 {
     ASSERT(form);
@@ -292,6 +314,9 @@
     StringBuilder builder;
     if (!actionURL.isEmpty())
         builder.append(actionURL.string());
+
+    recordFormStructure(*form, builder);
+
     builder.append(" #");
     builder.append(String::number(index));
     return builder.toAtomicString();
@@ -344,7 +369,7 @@
     // In the legacy version of serialized state, the first item was a name
     // attribute value of a form control. The following string literal should
     // contain some characters which are rarely used for name attribute values.
-    DEFINE_STATIC_LOCAL(String, signature, ("\n\r?% WebKit serialized form state version 6 \n\r=&"));
+    DEFINE_STATIC_LOCAL(String, signature, ("\n\r?% WebKit serialized form state version 7 \n\r=&"));
     return signature;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to