<textarea> unnecessarily saves the value in some cases
authortkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 29 Jun 2012 12:08:52 +0000 (12:08 +0000)
committertkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 29 Jun 2012 12:08:52 +0000 (12:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=90259

Reviewed by Hajime Morita.

Source/WebCore:

Test: fast/forms/textarea/textarea-state-restore.html

* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::saveFormControlState):
We apply EOL normalization to value(), but don't apply it to
defaultValue(). Also value() can return a null string, which never
equals to any strings. To check m_isDirty is what we need..

LayoutTests:

* fast/forms/textarea/textarea-state-restore-expected.txt: Added.
* fast/forms/textarea/textarea-state-restore.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/forms/textarea/textarea-state-restore-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/textarea/textarea-state-restore.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLTextAreaElement.cpp

index 5f166a8..7529a96 100644 (file)
@@ -1,3 +1,13 @@
+2012-06-29  Kent Tamura  <tkent@chromium.org>
+
+        <textarea> unnecessarily saves the value in some cases
+        https://bugs.webkit.org/show_bug.cgi?id=90259
+
+        Reviewed by Hajime Morita.
+
+        * fast/forms/textarea/textarea-state-restore-expected.txt: Added.
+        * fast/forms/textarea/textarea-state-restore.html: Added.
+
 2012-06-29  Sudarsana Nagineni  <sudarsana.nagineni@linux.intel.com>
 
         [EFL] Gardening after r121468
diff --git a/LayoutTests/fast/forms/textarea/textarea-state-restore-expected.txt b/LayoutTests/fast/forms/textarea/textarea-state-restore-expected.txt
new file mode 100644 (file)
index 0000000..396a81c
--- /dev/null
@@ -0,0 +1,9 @@
+Confirm nothing is saved and restored:
+PASS $("inserted").value is ""
+PASS $("saved1").value is ""
+PASS $("saved2").value is "aaa\nbbb"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+
diff --git a/LayoutTests/fast/forms/textarea/textarea-state-restore.html b/LayoutTests/fast/forms/textarea/textarea-state-restore.html
new file mode 100644 (file)
index 0000000..163d884
--- /dev/null
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<div id="console"></div>
+
+<input id=emptyOnFirstVisit>
+
+<script>
+jsTestIsAsync = true;
+
+function makeForms(stage) {
+    document.write('<div id=parent>');
+    document.write('<form id=form1 action="data:text/html,&lt;script>history.back()&lt;/script>">');
+    if (stage == 2)
+        document.write('<textarea id=inserted></textarea>');
+    document.write('<textarea id=saved1></textarea>');
+    document.write('<textarea id=saved2>aaa&#x0d;&#x0a;bbb</textarea>');
+    document.write('</form>');
+    document.write('</div>');
+}
+
+function runTest()
+{
+    var state = $('emptyOnFirstVisit');
+    if (!state.value) {
+        // First visit.
+        state.value = 'visited';
+        makeForms(1);
+    
+        setTimeout(function() {
+            $('form1').submit();
+        }, 0);
+    } else {
+        // Second visit.
+        makeForms(2);
+    
+        debug('Confirm nothing is saved and restored:');
+        shouldBeEqualToString('$("inserted").value', '');
+        shouldBeEqualToString('$("saved1").value', '');
+        shouldBeEqualToString('$("saved2").value', 'aaa\nbbb');
+    
+        $('parent').innerHTML = '';
+        setTimeout(function() { finishJSTest(); }, 0);
+    }
+}
+
+runTest();
+</script>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
index 20d3efd..6fd5971 100644 (file)
@@ -1,3 +1,18 @@
+2012-06-29  Kent Tamura  <tkent@chromium.org>
+
+        <textarea> unnecessarily saves the value in some cases
+        https://bugs.webkit.org/show_bug.cgi?id=90259
+
+        Reviewed by Hajime Morita.
+
+        Test: fast/forms/textarea/textarea-state-restore.html
+
+        * html/HTMLTextAreaElement.cpp:
+        (WebCore::HTMLTextAreaElement::saveFormControlState):
+        We apply EOL normalization to value(), but don't apply it to
+        defaultValue(). Also value() can return a null string, which never
+        equals to any strings. To check m_isDirty is what we need..
+
 2012-06-25  Alexander Pavlov  <apavlov@chromium.org>
 
         Web Inspector: Provide source data for all known rule types in CSSParser, except "keyframe" and "region"
index 9f23013..277c4bb 100644 (file)
@@ -101,10 +101,7 @@ const AtomicString& HTMLTextAreaElement::formControlType() const
 
 FormControlState HTMLTextAreaElement::saveFormControlState() const
 {
-    String currentValue = value();
-    if (currentValue == defaultValue())
-        return FormControlState();
-    return FormControlState(currentValue);
+    return m_isDirty ? FormControlState(value()) : FormControlState();
 }
 
 void HTMLTextAreaElement::restoreFormControlState(const FormControlState& state)