LayoutTests:
authoradele <adele@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Aug 2006 23:49:39 +0000 (23:49 +0000)
committeradele <adele@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Aug 2006 23:49:39 +0000 (23:49 +0000)
        Reviewed by Brady.

        Test case for <rdar://problem/4656274>
        REGRESSION: option elements are selected when added regardless of "selected" property

        * fast/forms/option-constructor-selected-expected.txt: Added.
        * fast/forms/option-constructor-selected.html: Added.

WebCore:

        Reviewed by Brady.

        - Fix for <rdar://problem/4656274>
        REGRESSION: option elements are selected when added regardless of "selected" property

        Test: fast/forms/option-constructor-selected.html

        * html/HTMLSelectElement.cpp: (WebCore::HTMLSelectElement::setOption):
        When adding an option element, check that the option element is selected before calling setSelectedIndex.

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

LayoutTests/ChangeLog
LayoutTests/fast/forms/option-constructor-selected-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/option-constructor-selected.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/html/HTMLSelectElement.cpp

index 5b60b2eb39771e9027ed8a6def44c5c36bc0c0f9..fd36b3f237316acbdadbb4615dbc9c7a8db4a21f 100644 (file)
@@ -1,3 +1,13 @@
+2006-08-11  Adele Peterson  <adele@apple.com>
+
+        Reviewed by Brady.
+
+        Test case for <rdar://problem/4656274> 
+        REGRESSION: option elements are selected when added regardless of "selected" property
+
+        * fast/forms/option-constructor-selected-expected.txt: Added.
+        * fast/forms/option-constructor-selected.html: Added.
+
 2006-08-08  Rob Buis  <buis@kde.org>
 
         Reviewed by Darin.
diff --git a/LayoutTests/fast/forms/option-constructor-selected-expected.txt b/LayoutTests/fast/forms/option-constructor-selected-expected.txt
new file mode 100644 (file)
index 0000000..6839f2d
--- /dev/null
@@ -0,0 +1,9 @@
+This tests that the "selected" argument is honored when constructing an option element.
+
+Test 0 Passed: the selected index is 0.
+Test 1 Passed: the selected index is 0.
+Test 2 Passed: the selected index is 0.
+Test 3 Passed: the selected index is 3.
+Test 4 Passed: the selected index is 4.
+Test 5 Passed: the selected index is 4.
+
diff --git a/LayoutTests/fast/forms/option-constructor-selected.html b/LayoutTests/fast/forms/option-constructor-selected.html
new file mode 100644 (file)
index 0000000..55724ac
--- /dev/null
@@ -0,0 +1,70 @@
+<html>
+<script>
+    function test() {
+        if (window.layoutTestController)
+            layoutTestController.dumpAsText();
+
+        var popup = document.getElementById('popup');
+        var success;
+        
+        // Test 0
+        popup.options[0] = new Option ( "option0", "0" );
+        if (popup.selectedIndex == 0)
+            success = "Passed";
+        else
+            success = "Failed";
+        log("Test 0 " + success + ": the selected index is " + popup.selectedIndex + ".");
+
+        
+        // Test 1
+        popup.options[1] = new Option ( "option1", "1" , false, false);
+        if (popup.selectedIndex == 0)
+            success = "Passed";
+        else
+            success = "Failed";
+        log("Test 1 " + success + ": the selected index is " + popup.selectedIndex + ".");
+          
+        // Test 2
+        popup.options[2] = new Option ( "option2", "2", true, false );
+        if (popup.selectedIndex == 0)
+            success = "Passed";
+        else
+            success = "Failed";
+        log("Test 2 " + success + ": the selected index is " + popup.selectedIndex + ".");
+            
+        // Test 3
+        popup.options[3] = new Option ( "option3", "3", false, true );
+        if (popup.selectedIndex == 3)
+            success = "Passed";
+        else
+            success = "Failed";
+        log("Test 3 " + success + ": the selected index is " + popup.selectedIndex + ".");
+
+        // Test 4
+        popup.options[4] = new Option ( "option4", "4", true, true );
+        if (popup.selectedIndex == 4)
+            success = "Passed";
+        else
+            success = "Failed";
+        log("Test 4 " + success + ": the selected index is " + popup.selectedIndex + ".");  
+        
+        // Test 5
+        popup.options[5] = new Option ( "option5", "5");
+        if (popup.selectedIndex == 4)
+            success = "Passed";
+        else
+            success = "Failed";
+        log("Test 5 " + success + ": the selected index is " + popup.selectedIndex + ".");  
+    }
+    
+    function log(msg) {
+        var console = document.getElementById('console');
+        console.innerHTML = console.innerHTML + msg + "<br>";
+    }
+</script>
+<body onload="test()">
+    This tests that the "selected" argument is honored when constructing an option element.<br>
+    <select id="popup"></select><br>
+    <div id="console"></div>
+</body>
+</html>
\ No newline at end of file
index f4340d806e71139b2d7c6f4a681f0bbb213b6da4..47ff700af2e27c55f6c58ad8306f1b98f9e005f9 100644 (file)
@@ -1,3 +1,15 @@
+2006-08-11  Adele Peterson  <adele@apple.com>
+
+        Reviewed by Brady.
+
+        - Fix for <rdar://problem/4656274> 
+        REGRESSION: option elements are selected when added regardless of "selected" property
+
+        Test: fast/forms/option-constructor-selected.html
+
+        * html/HTMLSelectElement.cpp: (WebCore::HTMLSelectElement::setOption):
+        When adding an option element, check that the option element is selected before calling setSelectedIndex.
+
 2006-08-11  David Hyatt  <hyatt@apple.com>
 
         Fix for bug 10349, make sure to call setChanged when an anchor changes
index a91439d5df7b36074c6f3adf096ca5b3ca0469f1..b164d993a6e79b1ebda0332d48fe60d96449775d 100644 (file)
@@ -537,7 +537,7 @@ void HTMLSelectElement::setOption(unsigned index, HTMLOptionElement* option, Exc
     // finally add the new element
     if (ec == 0) {
         add(option, before, ec);
-        if (diff >= 0)
+        if (diff >= 0 && option->selected())
             setSelectedIndex(index, !m_multiple);
     }
 }