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>
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>
17 document
.write("<p>FAILURE: onChange fired</p>");
20 function testResults(expectedArr
, sl
)
22 var resultsArr
= new Array(sl
.options
.length
);
25 for (i
=0; i
< sl
.options
.length
; i
++) {
26 resultsArr
[i
] = sl
.options
[i
].selected
;
28 var successString
= "Failed";
30 if (expectedArr
.join() == resultsArr
.join()) {
32 successString
= "Passed";
37 log("<pre> Expected: " + expectedArr
.join() + "<br>" + " Actual: " + resultsArr
.join() + "</pre>");
41 if (window
.testRunner
)
42 testRunner
.dumpAsText();
44 var results
= document
.createElement('div');
46 results
.appendChild(document
.createTextNode("Results:"));
47 document
.body
.appendChild(results
);
51 var r
= document
.getElementById('res');
52 r
.innerHTML
= r
.innerHTML
+ "<br>" + msg
;
56 var theSelect
= document
.forms
[0].elements
[0];
57 theSelect
.options
.add(new Option("SUCCESS", "SUCCESS", false, true), 0);
58 testResults([true, false], theSelect
);
60 theSelect
= document
.forms
[0].elements
[1];
61 theSelect
.insertBefore(new Option("SUCCESS", "SUCCESS", false, true), theSelect
.firstChild
);
62 testResults([true, false], theSelect
);
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
);
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
);
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
);
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
);
87 theSelect
= document
.forms
[0].elements
[6];
88 theSelect
.options
.add(new Option("SELECTED", "SELECTED", false, true), 0);
89 testResults([true, true], theSelect
);
91 theSelect
= document
.forms
[0].elements
[7];
92 theSelect
.insertBefore(new Option("SELECTED", "SELECTED", false, true), theSelect
.firstChild
);
93 testResults([true, true], theSelect
);
96 theSelect
= document
.forms
[0].elements
[8];
97 theSelect
.replaceChild(new Option("SUCCESS", "SUCCESS", false, true), theSelect
.firstChild
);
98 testResults([true, false], theSelect
);
101 theSelect
= document
.forms
[0].elements
[9];
102 theSelect
.appendChild(new Option("SUCCESS", "SUCCESS", false, true));
103 testResults([false, true], theSelect
);