Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / add-remove-option-modification-event.html
blobe45735f03904b2c89bf4b2aa0b7addb8e61a0345
1 <p>Test that SELECT is in correct state when handling a DOM modification event for option removing.</p>
2 <form>
3 <select ><option selected>1</option><option>2</option></select>
4 <select multiple><option selected>1</option><option selected>2</option></select>
5 <select multiple></select>
6 </form>
7 <div id=res></div>
8 <script>
9 if (window.testRunner)
10 testRunner.dumpAsText();
12 function log(msg)
14 var r = document.getElementById('res');
15 r.innerHTML = r.innerHTML + "<br>" + msg;
18 var theSelect;
20 function testResults(expectedArr)
22 var resultsArr = new Array(theSelect.options.length);
24 var i;
25 for (i=0; i < theSelect.options.length; i++) {
26 resultsArr[i] = theSelect.options[i].selected;
28 var successString = "Failed";
29 var success = false;
30 if (expectedArr.join() == resultsArr.join()) {
31 success = true;
32 successString = "Passed";
35 log(successString);
36 if (!success) {
37 log("<pre> Expected: " + expectedArr.join() + "<br>" + " Actual: " + resultsArr.join() + "</pre>");
41 function subtreeModified()
43 testResults([true], theSelect);
46 function nodeInserted()
48 testResults([false], theSelect);
51 try {
52 theSelect = document.forms[0].elements[0];
53 theSelect.addEventListener("DOMSubtreeModified", subtreeModified, true);
54 theSelect.remove(theSelect.options[0]);
56 theSelect = document.forms[0].elements[1];
57 theSelect.addEventListener("DOMSubtreeModified", subtreeModified, true);
58 theSelect.remove(theSelect.options[0]);
60 theSelect = document.forms[0].elements[2];
61 theSelect.addEventListener("DOMNodeInserted", nodeInserted, true);
62 theSelect.options.add(new Option("2", "2", false, false), 0);
64 } catch (ex) {
65 alert(ex);
67 </script>