Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / add-selected-option.html
blobeb829720e2d0d0c9b75f25d0d1881a4d38003c16
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 <form>
4 <select onchange="onChange()"><option selected>FAILURE</option></select>
5 <select onchange="onChange()"><option selected>FAILURE</option></select>
6 <select onchange="onChange()"><option selected>SUCCESS</option></select>
7 <select onchange="onChange()" size=2><option selected>FAILURE</option></select>
8 <select onchange="onChange()" size=2><option selected>FAILURE</option></select>
9 <select onchange="onChange()" size=2><option selected>SUCCESS</option></select>
10 <select onchange="onChange()" size=2 multiple><option selected>SELECTED</option></select>
11 <select onchange="onChange()" size=2 multiple><option selected>SELECTED</option></select>
12 <select onchange="onChange()" size=2><option>FAILURE</option><option selected>FAILURE</option></select>
13 <select onchange="onChange()" size=2><option>FAILURE</option></select>
14 </form>
15 <script>
16 function onChange() {
17 document.write("<p>FAILURE: onChange fired</p>");
20 function testResults(expectedArr, sl)
22 var resultsArr = new Array(sl.options.length);
24 var i;
25 for (i=0; i < sl.options.length; i++) {
26 resultsArr[i] = sl.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 if (window.testRunner)
42 testRunner.dumpAsText();
44 var results = document.createElement('div');
45 results.id = "res";
46 results.appendChild(document.createTextNode("Results:"));
47 document.body.appendChild(results);
49 function log(msg)
51 var r = document.getElementById('res');
52 r.innerHTML = r.innerHTML + "<br>" + msg;
55 try {
56 var theSelect = document.forms[0].elements[0];
57 theSelect.options.add(new Option("SUCCESS", "SUCCESS", false, true), 0);
58 testResults([true, false], theSelect);
60 theSelect = document.forms[0].elements[1];
61 theSelect.insertBefore(new Option("SUCCESS", "SUCCESS", false, true), theSelect.firstChild);
62 testResults([true, false], theSelect);
64 // defaultSelected doesn't make the element selected when inserted.
65 theSelect = document.forms[0].elements[2];
66 theSelect.options.add(new Option("FAILURE", "FAILURE", true, false), 0);
67 testResults([false, true], theSelect);
70 theSelect = document.forms[0].elements[3];
71 theSelect.options[0].selected = 1;
72 theSelect.options.add(new Option("SUCCESS", "SUCCESS", false, true), 0);
73 testResults([true, false], theSelect);
75 theSelect = document.forms[0].elements[4];
76 theSelect.options[0].selected = 1;
77 theSelect.insertBefore(new Option("SUCCESS", "SUCCESS", false, true), theSelect.firstChild);
78 testResults([true, false], theSelect);
80 // defaultSelected doesn't make the element selected when inserted.
81 theSelect = document.forms[0].elements[5];
82 theSelect.options[0].selected = 1;
83 theSelect.options.add(new Option("FAILURE", "FAILURE", true, false), 0);
84 testResults([false, true], theSelect);
87 theSelect = document.forms[0].elements[6];
88 theSelect.options.add(new Option("SELECTED", "SELECTED", false, true), 0);
89 testResults([true, true], theSelect);
91 theSelect = document.forms[0].elements[7];
92 theSelect.insertBefore(new Option("SELECTED", "SELECTED", false, true), theSelect.firstChild);
93 testResults([true, true], theSelect);
96 theSelect = document.forms[0].elements[8];
97 theSelect.replaceChild(new Option("SUCCESS", "SUCCESS", false, true), theSelect.firstChild);
98 testResults([true, false], theSelect);
101 theSelect = document.forms[0].elements[9];
102 theSelect.appendChild(new Option("SUCCESS", "SUCCESS", false, true));
103 testResults([false, true], theSelect);
105 } catch (ex) {
106 alert(ex);
108 </script>