REGRESSION(r106388): Form hidden element values being restored
authortkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 29 Jun 2012 06:12:22 +0000 (06:12 +0000)
committertkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 29 Jun 2012 06:12:22 +0000 (06:12 +0000)
incorrectly for dynamically generated content
https://bugs.webkit.org/show_bug.cgi?id=88685

Reviewed by Hajime Morita.

Source/WebCore:

We should not save value attribute updated during parsing.

Test: fast/forms/state-restore-to-non-edited-controls.html

* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::HTMLInputElement):
Initialize m_valueAttributeWasUpdatedAfterParsing.
(WebCore::HTMLInputElement::parseAttribute):
Set true to m_valueAttributeWasUpdatedAfterParsing if value
attribute is updated and it's not in parsing.
* html/HTMLInputElement.h:
(WebCore::HTMLInputElement::valueAttributeWasUpdatedAfterParsing):
Added for HiddenInputType.
* html/HiddenInputType.cpp:
(WebCore::HiddenInputType::saveFormControlState):
Save the value only if valueAttributeWasUpdatedAfterParsing() is true.

LayoutTests:

* fast/forms/state-restore-to-non-edited-controls-expected.txt:
A failing test is fixed.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@121519 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/forms/state-restore-to-non-edited-controls-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLInputElement.h
Source/WebCore/html/HiddenInputType.cpp

index 1d23383..b470e86 100644 (file)
@@ -1,3 +1,14 @@
+2012-06-28  Kent Tamura  <tkent@chromium.org>
+
+        REGRESSION(r106388): Form hidden element values being restored
+        incorrectly for dynamically generated content
+        https://bugs.webkit.org/show_bug.cgi?id=88685
+
+        Reviewed by Hajime Morita.
+
+        * fast/forms/state-restore-to-non-edited-controls-expected.txt:
+        A failing test is fixed.
+
 2012-06-28  Kenichi Ishibashi  <bashi@chromium.org>
 
         [Chromium] unreviewed test expectations update after r121510.
index 0a9b0d8..9c6ce97 100644 (file)
@@ -1,7 +1,7 @@
 Test to NOT save state for non-edited controls
 
 PASS document.getElementById("button").value is "2"
-FAIL document.getElementById("hidden").value should be 2. Was 1.
+PASS document.getElementById("hidden").value is "2"
 PASS document.getElementById("image").value is "2"
 PASS document.getElementById("reset").value is "2"
 PASS document.getElementById("submit1").value is "2"
index fdefb59..0f34a3c 100644 (file)
@@ -1,3 +1,28 @@
+2012-06-28  Kent Tamura  <tkent@chromium.org>
+
+        REGRESSION(r106388): Form hidden element values being restored
+        incorrectly for dynamically generated content
+        https://bugs.webkit.org/show_bug.cgi?id=88685
+
+        Reviewed by Hajime Morita.
+
+        We should not save value attribute updated during parsing.
+
+        Test: fast/forms/state-restore-to-non-edited-controls.html
+
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::HTMLInputElement):
+        Initialize m_valueAttributeWasUpdatedAfterParsing.
+        (WebCore::HTMLInputElement::parseAttribute):
+        Set true to m_valueAttributeWasUpdatedAfterParsing if value
+        attribute is updated and it's not in parsing.
+        * html/HTMLInputElement.h:
+        (WebCore::HTMLInputElement::valueAttributeWasUpdatedAfterParsing):
+        Added for HiddenInputType.
+        * html/HiddenInputType.cpp:
+        (WebCore::HiddenInputType::saveFormControlState):
+        Save the value only if valueAttributeWasUpdatedAfterParsing() is true.
+
 2012-06-28  MORITA Hajime  <morrita@google.com>
 
         [Refactoring] NodeRenderingContext ctor could be built on top of the ComposedShadowTreeWalker
index 6fcd158..e773284 100644 (file)
@@ -95,6 +95,7 @@ HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document* docum
     , m_isAutofilled(false)
     , m_stateRestored(false)
     , m_parsingInProgress(createdByParser)
+    , m_valueAttributeWasUpdatedAfterParsing(false)
     , m_wasModifiedByUser(false)
     , m_canReceiveDroppedFiles(false)
     , m_inputType(InputType::createText(this))
@@ -594,6 +595,7 @@ void HTMLInputElement::parseAttribute(const Attribute& attribute)
         }
         setFormControlValueMatchesRenderer(false);
         setNeedsValidityCheck();
+        m_valueAttributeWasUpdatedAfterParsing = !m_parsingInProgress;
     } else if (attribute.name() == checkedAttr) {
         // Another radio button in the same group might be checked by state
         // restore. We shouldn't call setChecked() even if this has the checked
index faeabff..1ec5ef0 100644 (file)
@@ -238,11 +238,12 @@ public:
     HTMLInputElement* checkedRadioButtonForGroup() const;
     bool isInRequiredRadioButtonGroup() const;
 
+    // Functions for InputType classes.
     void setValueInternal(const String&, TextFieldEventBehavior);
-
     bool isTextFormControlFocusable() const;
     bool isTextFormControlKeyboardFocusable(KeyboardEvent*) const;
     bool isTextFormControlMouseFocusable() const;
+    bool valueAttributeWasUpdatedAfterParsing() const { return m_valueAttributeWasUpdatedAfterParsing; }
 
     void cacheSelectionInResponseToSetValue(int caretOffset) { cacheSelection(caretOffset, caretOffset, SelectionHasNoDirection); }
 
@@ -386,6 +387,7 @@ private:
 #endif
     bool m_stateRestored : 1;
     bool m_parsingInProgress : 1;
+    bool m_valueAttributeWasUpdatedAfterParsing : 1;
     bool m_wasModifiedByUser : 1;
     bool m_canReceiveDroppedFiles : 1;
     OwnPtr<InputType> m_inputType;
index 049637c..fb6f36a 100644 (file)
@@ -54,8 +54,11 @@ const AtomicString& HiddenInputType::formControlType() const
 
 FormControlState HiddenInputType::saveFormControlState() const
 {
-    // FIXME: We should not always save the value. http://webkit.org/b/88685
-    return FormControlState(element()->value());
+    // valueAttributeWasUpdatedAfterParsing() never be true for form
+    // controls create by createElement() or cloneNode(). It's ok for
+    // now because we restore values only to form controls created by
+    // parsing.
+    return element()->valueAttributeWasUpdatedAfterParsing() ? FormControlState(element()->value()) : FormControlState();
 }
 
 void HiddenInputType::restoreFormControlState(const FormControlState& state)