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