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 <p>Test that DOM is updated before DOMNodeInserted is dispatched.
</p>
5 <select ><option selected
>1</option><option >2</option></select>
6 <select multiple
><option selected
>1</option><option >2</option></select>
7 <select size=
5><option selected
>1</option><option selected
>2</option></select>
11 if (window
.testRunner
)
12 testRunner
.dumpAsText();
16 var r
= document
.getElementById('res');
17 r
.innerHTML
= r
.innerHTML
+ "<br>" + msg
;
22 function testResults(expectedArr
)
24 var resultsArr
= new Array(theSelect
.options
.length
);
27 for (i
=0; i
< theSelect
.options
.length
; i
++) {
28 resultsArr
[i
] = theSelect
.options
[i
].selected
;
30 var successString
= "Failed";
32 if (expectedArr
.join() == resultsArr
.join()) {
34 successString
= "Passed";
39 log("<pre> Expected: " + expectedArr
.join() + "<br>" + " Actual: " + resultsArr
.join() + "</pre>");
43 function nodeInserted()
45 if (theSelect
.options
.length
!= 3)
46 log("Incorrect options length: " + theSelect
.options
.length
);
47 theSelect
.removeChild(theSelect
.firstChild
);
48 if (theSelect
.options
.length
!= 2)
49 log("Incorrect options length: " + theSelect
.options
.length
);
53 theSelect
= document
.forms
[0].elements
[0];
54 theSelect
.addEventListener("DOMNodeInserted", nodeInserted
, true);
55 theSelect
.options
.add(new Option("3", "3", false, true), 0);
56 testResults([true, false], theSelect
);
58 theSelect
= document
.forms
[0].elements
[1];
59 theSelect
.addEventListener("DOMNodeInserted", nodeInserted
, true);
60 theSelect
.options
.add(new Option("3", "3", false, true), 0);
61 testResults([true, false], theSelect
);
63 theSelect
= document
.forms
[0].elements
[2];
64 theSelect
.addEventListener("DOMNodeInserted", nodeInserted
, true);
65 theSelect
.insertBefore(new Option("3", "3", false, true), theSelect
.firstChild
);
66 testResults([false, false], theSelect
);