test_option_index_attribute.html (1928B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 See those bugs: 5 https://bugzilla.mozilla.org/show_bug.cgi?id=720385 6 --> 7 <head> 8 <meta charset="utf-8"> 9 <title>Test for option.index</title> 10 <script src="/tests/SimpleTest/SimpleTest.js"></script> 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 12 </head> 13 <body> 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=720385">Mozilla Bug 720385</a> 15 <p id="display"></p> 16 <div id="content" style="display: none"> 17 <datalist> 18 <option></option> 19 <option></option> 20 </datalist> 21 <select> 22 <option></option> 23 <foo> 24 <option></option> 25 <optgroup> 26 <option></option> 27 </optgroup> 28 <option></option> 29 </foo> 30 <option></option> 31 </select> 32 </div> 33 <pre id="test"> 34 <script type="application/javascript"> 35 36 /** Test for Bug 720385 */ 37 38 var initialIndexes = [ 0, 0, 0, 1, 2, 3, 4 ]; 39 var options = document.getElementsByTagName('option'); 40 41 is(options.length, initialIndexes.length, 42 "Must have " + initialIndexes.length +" options"); 43 44 for (var i=0; i<options.length; ++i) { 45 is(options[i].index, initialIndexes[i], "test"); 46 } 47 48 var o = document.createElement('option'); 49 is(o.index, 0, "option outside of a document have index=0"); 50 51 document.body.appendChild(o); 52 is(o.index, 0, "option outside of a select have index=0"); 53 54 var datalist = document.getElementsByTagName('datalist')[0]; 55 56 datalist.appendChild(o); 57 is(o.index, 0, "option outside of a select have index=0"); 58 59 datalist.removeChild(o); 60 is(o.index, 0, "option outside of a select have index=0"); 61 62 var select = document.getElementsByTagName('select')[0]; 63 64 select.appendChild(o); 65 is(o.index, 5, "option inside a select have an index"); 66 67 select.removeChild(select.options[0]); 68 is(o.index, 4, "option inside a select have an index"); 69 70 select.insertBefore(o, select.options[0]); 71 is(o.index, 0, "option inside a select have an index"); 72 73 </script> 74 </pre> 75 </body> 76 </html>