2 <p>Test that HTMLSelectElement DOM is in a consistent state when handling mutation events.
</p>
4 <select multiple size=
5><option>1</option><option>2</option></select>
9 testRunner
.dumpAsText();
11 var select
= document
.forms
[0].elements
[0];
12 var res
= document
.getElementById("res");
13 var hadFailure
= false;
15 function logError(message
)
17 res
.innerHTML
+= message
+ "<br>";
21 // { test number, expected length, item to check, expected result }
24 function checkSelect(evt
)
26 // Force layout to verify that DOM is in a consistent state.
27 document
.body
.offsetTop
;
32 if (select
.length
!= testInfo
[1])
33 logError("Test " + testInfo
[0] + ". " + evt
.type
+ ": Incorrect length. Was " + select
.length
+ ", expected " + testInfo
[1] + ".");
36 if (select
.item(testInfo
[2]).value
!= testInfo
[3])
37 logError("Test " + testInfo
[0] + ". " + evt
.type
+ ": Incorrect item " + testInfo
[2] + " value. Was " + select
.item(testInfo
[2]).value
+ ", expected " + testInfo
[3] + ".");
39 if (select
.item(testInfo
[2]))
40 logError("Test " + testInfo
[0] + ". " + evt
.type
+ ": Item " + testInfo
[2] + " exists when it should not.");
44 function onNodeRemoved()
46 // Force layout to verify that DOM is in a consistent state.
47 document
.body
.offsetTop
;
49 if (select
.length
!= 2) {
50 alert("FAIL: Incorrect length after removing an option.");
55 alert("FAIL: A removed option is still present when handling a DOMNodeRemoved event.");
60 select
.addEventListener("DOMNodeInserted", checkSelect
, true);
61 select
.addEventListener("DOMNodeInsertedIntoDocument", checkSelect
, true);
62 select
.addEventListener("DOMSubtreeModified", checkSelect
, true);
63 select
.addEventListener("DOMSubtreeModified", checkSelect
, true);
65 testInfo
= [1, 3, 2, "3"];
66 select
.appendChild(new Option("3", "3", false, false));
69 testInfo
= [2, 2, 2, undefined];
70 select
.removeChild(select
.lastChild
);
73 testInfo
= []; // A DOMSubtreeModified event may be dispatched between removal and addition, skip checks.
74 select
.replaceChild(new Option("new", "new", false, false), select
.lastChild
);
75 testInfo
= [3, 2, 1, "new"];
78 testInfo
= [4, 3, 0, "0"];
79 select
.add(new Option("0", "0", false, false), select
.firstChild
);
80 testInfo
= [4, 3, 0, "0"];
83 testInfo
= [5, 2, 0, "1"];
85 testInfo
= [5, 2, 0, "1"];
88 testInfo
= [6, 3, 0, "-1"];
89 select
.insertBefore(new Option("-1", "-1", false, false), select
.firstChild
);
90 testInfo
= [6, 3, 0, "-1"];
93 testInfo
= [7, 3, 0, "-"];
94 select
.firstChild
.value
= "-";
95 select
.firstChild
.text
= "-";
96 testInfo
= [7, 3, 0, "-"];
99 testInfo
= []; // Multiple DOMSubtreeModified event may be dispatched, skip check.
100 select
.innerHTML
= "<optgroup><option>1</option><option>2</option></optgroup>";
101 testInfo
= [8, 2, 0, 1];
104 var optgroup
= select
.firstChild
;
106 testInfo
= [9, 3, 2, "3"];
107 optgroup
.appendChild(new Option("3", "3", false, false));
110 testInfo
= [10, 2, 2, undefined];
111 optgroup
.removeChild(optgroup
.lastChild
);
114 testInfo
= []; // A DOMSubtreeModified event may be dispatched between removal and addition, skip checks.
115 optgroup
.replaceChild(new Option("new", "new", false, false), optgroup
.lastChild
);
116 testInfo
= [11, 2, 1, "new"];
119 /* WebKit cannot add options right into a group via HTMLSelectElement.add().
120 See <https://bugs.webkit.org/show_bug.cgi?id=24606>.
121 testInfo = [12, 3, 0, "0"];
122 select.add(new Option("0", "0", false, false), optgroup.firstChild);
123 testInfo = [12, 3, 0, "0"];
126 testInfo = [13, 2, 0, "1"];
131 testInfo
= [14, 3, 0, "-1"];
132 optgroup
.insertBefore(new Option("-1", "-1", false, false), optgroup
.firstChild
);
135 testInfo
= [15, 3, 0, "-"];
136 optgroup
.firstChild
.value
= "-";
137 optgroup
.firstChild
.text
= "-";
140 testInfo
= [16, 0, 0, undefined];
141 optgroup
.innerHTML
= "";
145 res
.innerHTML
= "SUCCESS";