Title: [104864] trunk
- Revision
- 104864
- Author
- jon...@apple.com
- Date
- 2012-01-12 14:57:14 -0800 (Thu, 12 Jan 2012)
Log Message
Setting value on a select element to a non existing option value should clear selection
https://bugs.webkit.org/show_bug.cgi?id=67233
<rdar://problem/10057159>
Reviewed by Darin Adler.
Source/WebCore:
Test: fast/forms/select/setting-to-invalid-value.html
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::setValue): Clear the selection in the cases where we cannot
find an option with the specified value. The spec states to clear the selectedness of all
options first. To avoid calling setSelectedIndex() multiple times, we clear the selected
option(s) only when don't find the appropriate option.
Also, correct the sentence style of a comment.
LayoutTests:
New tests check to see that setting the value of a select element clears the
selection, even if the value is invalid, null, or undefined.
* fast/forms/select/setting-to-invalid-value-expected.txt: Added.
* fast/forms/select/setting-to-invalid-value.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (104863 => 104864)
--- trunk/LayoutTests/ChangeLog 2012-01-12 22:54:55 UTC (rev 104863)
+++ trunk/LayoutTests/ChangeLog 2012-01-12 22:57:14 UTC (rev 104864)
@@ -1,3 +1,17 @@
+2012-01-12 Jon Lee <jon...@apple.com>
+
+ Setting value on a select element to a non existing option value should clear selection
+ https://bugs.webkit.org/show_bug.cgi?id=67233
+ <rdar://problem/10057159>
+
+ Reviewed by Darin Adler.
+
+ New tests check to see that setting the value of a select element clears the
+ selection, even if the value is invalid, null, or undefined.
+
+ * fast/forms/select/setting-to-invalid-value-expected.txt: Added.
+ * fast/forms/select/setting-to-invalid-value.html: Added.
+
2012-01-12 Simon Fraser <simon.fra...@apple.com>
Borders and box masks behave incorrectly with overlapping offsets
Added: trunk/LayoutTests/fast/forms/select/setting-to-invalid-value-expected.txt (0 => 104864)
--- trunk/LayoutTests/fast/forms/select/setting-to-invalid-value-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/forms/select/setting-to-invalid-value-expected.txt 2012-01-12 22:57:14 UTC (rev 104864)
@@ -0,0 +1,24 @@
+
+https://bugs.webkit.org/show_bug.cgi?id=67233 - Setting the value of a select to an invalid value should unset the selection.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+-- Menu list select:
+Setting the value to an invalid value:
+PASS sel.selectedIndex is -1
+Setting the value to null:
+PASS sel.selectedIndex is -1
+Setting the value to undefined:
+PASS sel.selectedIndex is -1
+-- List box select:
+Setting the value to an invalid value:
+PASS sel.selectedIndex is -1
+Setting the value to null:
+PASS sel.selectedIndex is -1
+Setting the value to undefined:
+PASS sel.selectedIndex is -1
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/forms/select/setting-to-invalid-value.html (0 => 104864)
--- trunk/LayoutTests/fast/forms/select/setting-to-invalid-value.html (rev 0)
+++ trunk/LayoutTests/fast/forms/select/setting-to-invalid-value.html 2012-01-12 22:57:14 UTC (rev 104864)
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<select id="theSelect">
+ <option value="a">A</option>
+ <option value="b">B</option>
+</select>
+<select id="theMultipleSelect" multiple>
+ <option value="a">A</option>
+ <option value="b">B</option>
+ <option value="c">C</option>
+ <option value="d">D</option>
+</select>
+<div id="console"></div>
+
+<script>
+description("https://bugs.webkit.org/show_bug.cgi?id=67233 - Setting the value of a select to an invalid value should unset the selection.");
+
+function resetSingleSelect() {
+ sel.value = 'a';
+ shouldBe("sel.selectedIndex", "0", true);
+}
+
+function resetMultipleSelect() {
+ sel.item(1).selected = true;
+ sel.item(3).selected = true;
+}
+
+function runTestsOnSelect(resetSelect) {
+ debug("Setting the value to an invalid value:");
+ resetSelect(sel);
+ sel.value = 'x';
+ shouldBe("sel.selectedIndex", "-1");
+
+ debug("Setting the value to null:");
+ resetSelect(sel);
+ sel.value = null;
+ shouldBe("sel.selectedIndex", "-1");
+
+ debug("Setting the value to undefined:");
+ resetSelect(sel);
+ sel.value = undefined;
+ shouldBe("sel.selectedIndex", "-1");
+}
+
+debug("-- Menu list select:");
+sel = document.getElementById("theSelect");
+runTestsOnSelect(resetSingleSelect);
+
+debug("-- List box select:");
+sel = document.getElementById("theMultipleSelect");
+runTestsOnSelect(resetMultipleSelect);
+
+successfullyParsed = true;
+</script>
+
+<script src=""
+</body>
+</html>
\ No newline at end of file
Modified: trunk/Source/WebCore/ChangeLog (104863 => 104864)
--- trunk/Source/WebCore/ChangeLog 2012-01-12 22:54:55 UTC (rev 104863)
+++ trunk/Source/WebCore/ChangeLog 2012-01-12 22:57:14 UTC (rev 104864)
@@ -1,3 +1,21 @@
+2012-01-12 Jon Lee <jon...@apple.com>
+
+ Setting value on a select element to a non existing option value should clear selection
+ https://bugs.webkit.org/show_bug.cgi?id=67233
+ <rdar://problem/10057159>
+
+ Reviewed by Darin Adler.
+
+ Test: fast/forms/select/setting-to-invalid-value.html
+
+ * html/HTMLSelectElement.cpp:
+ (WebCore::HTMLSelectElement::setValue): Clear the selection in the cases where we cannot
+ find an option with the specified value. The spec states to clear the selectedness of all
+ options first. To avoid calling setSelectedIndex() multiple times, we clear the selected
+ option(s) only when don't find the appropriate option.
+
+ Also, correct the sentence style of a comment.
+
2012-01-12 Jer Noble <jer.no...@apple.com>
Unreviewed build fix after r104858.
Modified: trunk/Source/WebCore/html/HTMLSelectElement.cpp (104863 => 104864)
--- trunk/Source/WebCore/html/HTMLSelectElement.cpp 2012-01-12 22:54:55 UTC (rev 104863)
+++ trunk/Source/WebCore/html/HTMLSelectElement.cpp 2012-01-12 22:57:14 UTC (rev 104864)
@@ -247,10 +247,13 @@
void HTMLSelectElement::setValue(const String &value)
{
- if (value.isNull())
+ // We clear the previously selected option(s) when needed, to guarantee calling setSelectedIndex() only once.
+ if (value.isNull()) {
+ setSelectedIndex(-1);
return;
- // find the option with value() matching the given parameter
- // and make it the current selection.
+ }
+
+ // Find the option with value() matching the given parameter and make it the current selection.
const Vector<HTMLElement*>& items = listItems();
unsigned optionIndex = 0;
for (unsigned i = 0; i < items.size(); i++) {
@@ -262,6 +265,8 @@
optionIndex++;
}
}
+
+ setSelectedIndex(-1);
}
void HTMLSelectElement::parseMappedAttribute(Attribute* attr)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes