select-selectedOptions-nesting.window.js (3621B)
1 for (const optionParentElementName of ["option", "hr", "select"]) { 2 test(() => { 3 const select = document.createElement("select"); 4 const selectedOptions = select.selectedOptions; 5 select.innerHTML = "<option>1"; 6 7 assert_equals(selectedOptions.length, 1); 8 assert_equals(selectedOptions[0], select.firstChild); 9 assert_equals(select.value, "1"); 10 11 const optionParent = select.appendChild(document.createElement(optionParentElementName)); 12 13 assert_equals(selectedOptions.length, 1); 14 assert_equals(selectedOptions[0], select.firstChild); 15 assert_equals(select.value, "1"); 16 17 const option = optionParent.appendChild(document.createElement("option")); 18 option.setAttribute("selected", ""); 19 option.textContent = "2"; 20 21 assert_equals(selectedOptions.length, 1); 22 assert_equals(selectedOptions[0], select.firstChild); 23 assert_equals(select.value, "1"); 24 }, `<select> containing <${optionParentElementName}><option selected>`); 25 } 26 27 for (const optionParentElementName of ["option", "hr", "select", "optgroup"]) { 28 test(() => { 29 const select = document.createElement("select"); 30 const selectedOptions = select.selectedOptions; 31 select.innerHTML = "<optgroup><option>1"; 32 33 assert_equals(selectedOptions.length, 1); 34 assert_equals(selectedOptions[0], select.firstChild.firstChild); 35 assert_equals(select.value, "1"); 36 37 const optionParent = select.firstChild.appendChild(document.createElement(optionParentElementName)); 38 39 assert_equals(selectedOptions.length, 1); 40 assert_equals(selectedOptions[0], select.firstChild.firstChild); 41 assert_equals(select.value, "1"); 42 43 const option = optionParent.appendChild(document.createElement("option")); 44 option.setAttribute("selected", ""); 45 option.textContent = "2"; 46 47 assert_equals(selectedOptions.length, 1); 48 assert_equals(selectedOptions[0], select.firstChild.firstChild); 49 assert_equals(select.value, "1"); 50 51 }, `<select><optgroup> containing <${optionParentElementName}><option selected>`); 52 } 53 54 for (const optionParentElementName of ["option", "hr", "select", "optgroup"]) { 55 test(() => { 56 const select = document.createElement("select"); 57 select.multiple = true; 58 const selectedOptions = select.selectedOptions; 59 select.innerHTML = "<div><optgroup><div><option selected>1"; 60 61 assert_equals(selectedOptions.length, 1); 62 assert_equals(selectedOptions[0], select.firstChild.firstChild.firstChild.firstChild); 63 assert_equals(select.value, "1"); 64 65 const optionParent = select.firstChild.firstChild.firstChild.appendChild(document.createElement(optionParentElementName)); 66 67 assert_equals(selectedOptions.length, 1); 68 assert_equals(selectedOptions[0], select.firstChild.firstChild.firstChild.firstChild); 69 assert_equals(select.value, "1"); 70 71 const option = optionParent.appendChild(document.createElement("option")); 72 option.setAttribute("selected", ""); 73 option.textContent = "2"; 74 75 assert_equals(selectedOptions.length, 1); 76 assert_equals(selectedOptions[0], select.firstChild.firstChild.firstChild.firstChild); 77 assert_equals(select.value, "1"); 78 79 const secondOption = select.appendChild(document.createElement("option")); 80 secondOption.setAttribute("selected", ""); 81 secondOption.textContent = "3"; 82 83 assert_equals(selectedOptions.length, 2); 84 assert_equals(selectedOptions[0], select.firstChild.firstChild.firstChild.firstChild); 85 assert_equals(selectedOptions[1], secondOption); 86 assert_equals(select.value, "1"); 87 }, `<select><div><optgroup><div> containing <${optionParentElementName}><option selected>`); 88 }