Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / add-and-remove-option.html
blob57df475b0e7c33e7b3dd62dd2a1bd1fb09d5b0c2
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>
4 <form>
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>
8 </form>
9 <div id=res></div>
10 <script>
11 if (window.testRunner)
12 testRunner.dumpAsText();
14 function log(msg)
16 var r = document.getElementById('res');
17 r.innerHTML = r.innerHTML + "<br>" + msg;
20 var theSelect;
22 function testResults(expectedArr)
24 var resultsArr = new Array(theSelect.options.length);
26 var i;
27 for (i=0; i < theSelect.options.length; i++) {
28 resultsArr[i] = theSelect.options[i].selected;
30 var successString = "Failed";
31 var success = false;
32 if (expectedArr.join() == resultsArr.join()) {
33 success = true;
34 successString = "Passed";
37 log(successString);
38 if (!success) {
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);
52 try {
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);
68 } catch (ex) {
69 alert(ex);
71 </script>