[WK2] selection does not disappear after coping the text
[framework/web/webkit-efl.git] / LayoutTests / fast / forms / add-selected-option.html
1 <p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=13287">bug 13287</a>:
2 Cannot change SELECT to a dynamically created option.</p>
3 <form>
4 <select onchange="onChange()"><option selected>FAILURE</option></select>
5 <select onchange="onChange()"><option selected>FAILURE</option></select>
6 <select onchange="onChange()"><option selected>SUCCESS</option></select>
7 <select onchange="onChange()" size=2><option selected>FAILURE</option></select>
8 <select onchange="onChange()" size=2><option selected>FAILURE</option></select>
9 <select onchange="onChange()" size=2><option selected>SUCCESS</option></select>
10 <select onchange="onChange()" size=2 multiple><option selected>SELECTED</option></select>
11 <select onchange="onChange()" size=2 multiple><option selected>SELECTED</option></select>
12 <select onchange="onChange()" size=2><option>FAILURE</option><option selected>FAILURE</option></select>
13 <select onchange="onChange()" size=2><option>FAILURE</option></select>
14 </form>
15 <script>
16     function onChange() {
17         document.write("<p>FAILURE: onChange fired</p>");
18     }
19
20     function testResults(expectedArr, sl)
21     {
22         var resultsArr = new Array(sl.options.length);
23         
24         var i;
25         for (i=0; i < sl.options.length; i++) {
26             resultsArr[i] = sl.options[i].selected;
27         }
28         var successString = "Failed";
29         var success = false;
30         if (expectedArr.join() == resultsArr.join()) {
31             success = true;
32             successString = "Passed";
33         }
34         
35         log(successString);
36         if (!success) {
37             log("<pre>     Expected: " + expectedArr.join() + "<br>" + "     Actual: " + resultsArr.join() + "</pre>");
38         }
39     }
40     
41     if (window.layoutTestController)
42         layoutTestController.dumpAsText();
43
44     var results = document.createElement('div');
45     results.id = "res";
46     results.appendChild(document.createTextNode("Results:"));
47     document.body.appendChild(results);
48
49     function log(msg)
50     {
51         var r = document.getElementById('res');
52         r.innerHTML = r.innerHTML + "<br>" + msg;
53     }
54
55     try {
56         var theSelect = document.forms[0].elements[0];
57         theSelect.options.add(new Option("SUCCESS", "SUCCESS", false, true), 0);
58         testResults([true, false], theSelect);
59
60         theSelect = document.forms[0].elements[1];
61         theSelect.insertBefore(new Option("SUCCESS", "SUCCESS", false, true), theSelect.firstChild);
62         testResults([true, false], theSelect);
63
64         // defaultSelected doesn't make the element selected when inserted.
65         theSelect = document.forms[0].elements[2];
66         theSelect.options.add(new Option("FAILURE", "FAILURE", true, false), 0);
67         testResults([false, true], theSelect);
68
69
70         theSelect = document.forms[0].elements[3];
71         theSelect.options[0].selected = 1;
72         theSelect.options.add(new Option("SUCCESS", "SUCCESS", false, true), 0);
73         testResults([true, false], theSelect);
74
75         theSelect = document.forms[0].elements[4];
76         theSelect.options[0].selected = 1;
77         theSelect.insertBefore(new Option("SUCCESS", "SUCCESS", false, true), theSelect.firstChild);
78         testResults([true, false], theSelect);
79
80         // defaultSelected doesn't make the element selected when inserted.
81         theSelect = document.forms[0].elements[5];
82         theSelect.options[0].selected = 1;
83         theSelect.options.add(new Option("FAILURE", "FAILURE", true, false), 0);
84         testResults([false, true], theSelect);
85
86
87         theSelect = document.forms[0].elements[6];
88         theSelect.options.add(new Option("SELECTED", "SELECTED", false, true), 0);
89         testResults([true, true], theSelect);
90
91         theSelect = document.forms[0].elements[7];
92         theSelect.insertBefore(new Option("SELECTED", "SELECTED", false, true), theSelect.firstChild);
93         testResults([true, true], theSelect);
94
95
96         theSelect = document.forms[0].elements[8];
97         theSelect.replaceChild(new Option("SUCCESS", "SUCCESS", false, true), theSelect.firstChild);
98         testResults([true, false], theSelect);
99
100
101         theSelect = document.forms[0].elements[9];
102         theSelect.appendChild(new Option("SUCCESS", "SUCCESS", false, true));
103         testResults([false, true], theSelect);
104
105     } catch (ex) {
106         alert(ex);
107     }
108 </script>