OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <body> |
| 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <div id="sample"></div> |
| 6 <script> |
| 7 function valueMissingFor(html) { |
| 8 var sample = document.getElementById('sample'); |
| 9 sample.innerHTML = html; |
| 10 return sample.firstChild.validity.valueMissing; |
| 11 } |
| 12 |
| 13 test(() => { |
| 14 assert_true(valueMissingFor('<input required>')); |
| 15 }, 'Empty-value INPUT[required] should be valueMissing.'); |
| 16 |
| 17 test(() => { |
| 18 assert_false(valueMissingFor('<input value="something" required>')); |
| 19 }, 'INPUT[required] with a non-empty value should not be valueMissing.'); |
| 20 |
| 21 test(() => { |
| 22 assert_true(valueMissingFor('<textarea required></textarea>')); |
| 23 }, 'Empty value TEXTAREA[required] should be valueMissing.'); |
| 24 |
| 25 test(() => { |
| 26 assert_false(valueMissingFor('<textarea required>something</textarea>')); |
| 27 }, 'TEXTAREA[required] with a non-empty value should not be valueMissing.'); |
| 28 |
| 29 test(() => { |
| 30 assert_true(valueMissingFor('<select required></select>')); |
| 31 }, 'SELECT[required] with no OPTIONS should be valueMissing.'); |
| 32 |
| 33 test(() => { |
| 34 assert_true(valueMissingFor('<select required>' + |
| 35 '<option value="" selected />' + |
| 36 '<option value="X">X</option>' + |
| 37 '</select>')); |
| 38 }, 'SELECT[required] with a selected placeholder OPTION should be valueMissing.'
); |
| 39 |
| 40 test(() => { |
| 41 assert_false(valueMissingFor('<select required>' + |
| 42 '<option value="X">X</option>' + |
| 43 '<option value="" selected />' + |
| 44 '</select>')); |
| 45 }, 'SELECT[required] with a selected non-placeholder OPTION should not be valueM
issing.'); |
| 46 |
| 47 test(() => { |
| 48 assert_false(valueMissingFor('<select size="2" required>' + |
| 49 '<option value="" selected />' + |
| 50 '<option value="X">X</option>' + |
| 51 '</select>')); |
| 52 }, 'SELECT[required][size=2] with a selected placeholder OPTION should not be va
lueMissing.'); |
| 53 |
| 54 test(() => { |
| 55 assert_false(valueMissingFor('<select size="2" required>' + |
| 56 '<option value="X">X</option>' + |
| 57 '<option value="" selected />' + |
| 58 '</select>')); |
| 59 }, 'SELECT[rquired][size=2] with a selected non-placeholder OPTION should not be
valueMissing.'); |
| 60 |
| 61 test(() => { |
| 62 assert_true(valueMissingFor('<select multiple required>' + |
| 63 '<option value="" />' + |
| 64 '<option value="X">X</option>' + |
| 65 '</select>')); |
| 66 }, 'SELECT[required][multiple] without selected OPTIONs should be valueMissing.'
); |
| 67 |
| 68 test(() => { |
| 69 assert_false(valueMissingFor('<select multiple required>' + |
| 70 '<option value="" selected />' + |
| 71 '<option value="X">X</option>' + |
| 72 '</select>')); |
| 73 }, 'SELECT[required][multiple] with a selected placeholder-like OPTION should no
t be valueMissing.'); |
| 74 |
| 75 test(() => { |
| 76 assert_false(valueMissingFor('<select multiple required>' + |
| 77 '<option value="X">X</option>' + |
| 78 '<option value="" selected />' + |
| 79 '</select>')); |
| 80 }, 'SELECT[required][multiple] with a selected OPTION should not be valueMissing
.'); |
| 81 |
| 82 test(() => { |
| 83 assert_true(valueMissingFor('<select multiple size="2" required>' + |
| 84 '<option value="" />' + |
| 85 '<option value="X">X</option>' + |
| 86 '</select>')); |
| 87 }, 'SELECT[required][multiple][size=2] without selected OPTIONs should be valueM
issing.'); |
| 88 |
| 89 test(() => { |
| 90 assert_false(valueMissingFor('<select multiple size="2" required>' + |
| 91 '<option value="" selected />' + |
| 92 '<option value="X">X</option>' + |
| 93 '</select>')); |
| 94 }, 'SELECT[required][multiple][size=2] with a selected placeholder-liek OPTION s
hould not be valueMissing.'); |
| 95 |
| 96 test(() => { |
| 97 assert_false(valueMissingFor('<select multiple size="2" required>' + |
| 98 '<option value="X">X</option>' + |
| 99 '<option value="" selected />' + |
| 100 '</select>')); |
| 101 }, 'SELECT[required][multiple][size=2] with a selected OPTION should not be valu
eMissing.'); |
| 102 |
| 103 test(() => { |
| 104 assert_false(valueMissingFor('<select required>' + |
| 105 '<optgroup label="1">' + |
| 106 ' <option value="" selected />' + |
| 107 '</optgroup>' + |
| 108 '<option value="X">X</option>' + |
| 109 '</select>')); |
| 110 }, 'SELECT[required] with a selected placeholder-like OPTION inside an OPTGROUP
should not be valueMissing.'); |
| 111 |
| 112 test(() => { |
| 113 assert_true(valueMissingFor('<select required>' + |
| 114 '<option value="" disabled selected />' + |
| 115 '<option value="X">X</option>' + |
| 116 '</select>')); |
| 117 }, 'SELECT[required] with a selected disabled placeholder OPTION should be value
Missing.'); |
| 118 |
| 119 test(() => { |
| 120 assert_false(valueMissingFor('<select id="select-disabled-option-2" required>'
+ |
| 121 '<option value="" disabled />' + |
| 122 '<option value="X">X</option>' + |
| 123 '</select>')); |
| 124 assert_equals(document.getElementById('select-disabled-option-2').selectedInde
x, 1); |
| 125 }, 'SELECT[required] with a non-selected disabled placeholder OPTION should not
be valueMissing.'); |
| 126 |
| 127 test(() => { |
| 128 assert_false(valueMissingFor('<select required>' + |
| 129 '<option value="" />' + |
| 130 '<option value="X" selected>X</option>' + |
| 131 '</select>')); |
| 132 }, 'SELECT[required] with a unselected placeholder OPTION should not be valueMis
sing.'); |
| 133 |
| 134 test(() => { |
| 135 assert_false(valueMissingFor('<select size="2" required>' + |
| 136 '<option value="" />' + |
| 137 '<option value="X" selected>X</option>' + |
| 138 '</select>')); |
| 139 }, 'SELECT[required][size=2] with a unselected placeholder OPTION should not be
valueMissing.'); |
| 140 |
| 141 test(() => { |
| 142 assert_false(valueMissingFor('<select size="2" required>' + |
| 143 '<option value="X" selected>X</option>' + |
| 144 '<option value="" />' + |
| 145 '</select>')); |
| 146 }, 'SELECT[required][size=2] with a unselected placeholder-like OPTION should no
t be valueMissing.'); |
| 147 |
| 148 test(() => { |
| 149 assert_false(valueMissingFor('<select multiple required>' + |
| 150 '<option value="" />' + |
| 151 '<option value="X" selected>X</option>' + |
| 152 '</select>')); |
| 153 }, 'SELECT[required][multiple] with a unselected placeholder OPTION should not b
e valueMissing.'); |
| 154 |
| 155 test(() => { |
| 156 assert_false(valueMissingFor('<select multiple required>' + |
| 157 '<option value="X" selected>X</option>' + |
| 158 '<option value="" />' + |
| 159 '</select>')); |
| 160 }, 'SELECT[required][multiple] with a unselected placeholder-like OPTION should
not be valueMissing.'); |
| 161 |
| 162 test(() => { |
| 163 assert_false(valueMissingFor('<select multiple size="2" required>' + |
| 164 '<option value="" />' + |
| 165 '<option value="X" selected>X</option>' + |
| 166 '</select>')); |
| 167 }, 'SELECT[required][size=2][multiple] with a unselected placeholder OPTION shou
ld not be valueMissing.'); |
| 168 |
| 169 test(() => { |
| 170 assert_false(valueMissingFor('<select multiple size="2" required>' + |
| 171 '<option value="X" selected>X</option>' + |
| 172 '<option value="" />' + |
| 173 '</select>')); |
| 174 }, 'SELECT[required][size=2][multiple] with a unselected placeholder-like OPTION
should not be valueMissing.'); |
| 175 |
| 176 test(() => { |
| 177 assert_true(!!window.eventSender, 'Needs eventSender.'); |
| 178 // Select by type-ahead. |
| 179 assert_true(valueMissingFor('<select id="select-selecting-by-key" required>' + |
| 180 '<option value="" selected/>' + |
| 181 '<option>a</option>' + |
| 182 '</select>')); |
| 183 var select = document.getElementById('select-selecting-by-key'); |
| 184 select.focus(); |
| 185 eventSender.keyDown('a'); |
| 186 assert_equals(select.value, 'a'); |
| 187 assert_false(select.validity.valueMissing); |
| 188 |
| 189 // Select by accesskey. |
| 190 assert_true(valueMissingFor('<select id="select-selecting-by-key-2" required>'
+ |
| 191 '<option value="" selected/>' + |
| 192 '<option accesskey="1">a</option>' + |
| 193 '</select>')); |
| 194 select = document.getElementById('select-selecting-by-key-2'); |
| 195 select.focus(); |
| 196 eventSender.keyDown('1', 'accessKey'); |
| 197 assert_equals(select.value, 'a'); |
| 198 assert_false(select.validity.valueMissing); |
| 199 }, 'Updating valueMissing state by user input.'); |
| 200 |
| 201 test(() => { |
| 202 document.querySelector('#sample').innerHTML = '<input name="victim" disabled r
equired />' + |
| 203 '<textarea name="victim" disabled required></textarea>' + |
| 204 '<select name="victim" disabled required>' + |
| 205 '</select>' + |
| 206 '<select name="victim" disabled required>' + |
| 207 ' <option value="" selected />' + |
| 208 ' <option value="X">X</option>' + |
| 209 '</select>' + |
| 210 '<select name="victim" disabled required>' + |
| 211 ' <option value="X">X</option>' + |
| 212 ' <option value="" selected />' + |
| 213 '</select>' + |
| 214 '<select name="victim" size="2" disabled required>' + |
| 215 ' <option value="" selected />' + |
| 216 ' <option value="X">X</option>' + |
| 217 '</select>' + |
| 218 '<select name="victim" size="2" disabled required>' + |
| 219 ' <option value="X">X</option>' + |
| 220 ' <option value="" selected />' + |
| 221 '</select>' + |
| 222 '<select name="victim" multiple disabled required>' + |
| 223 ' <option value="" />' + |
| 224 ' <option value="X">X</option>' + |
| 225 '</select>' + |
| 226 '<select name="victim" multiple disabled required>' + |
| 227 ' <option value="" selected />' + |
| 228 ' <option value="X">X</option>' + |
| 229 '</select>' + |
| 230 '<select name="victim" multiple disabled required>' + |
| 231 ' <option value="X">X</option>' + |
| 232 ' <option value="" selected />' + |
| 233 '</select>' + |
| 234 '<select name="victim" multiple size="2" disabled required>' + |
| 235 ' <option value="" />' + |
| 236 ' <option value="X">X</option>' + |
| 237 '</select>' + |
| 238 '<select name="victim" multiple size="2" disabled required>' + |
| 239 ' <option value="" selected />' + |
| 240 ' <option value="X">X</option>' + |
| 241 '</select>' + |
| 242 '<select name="victim" multiple size="2" disabled required>' + |
| 243 ' <option value="X">X</option>' + |
| 244 ' <option value="" selected />' + |
| 245 '</select>'; |
| 246 var controls = document.querySelectorAll(':disabled'); |
| 247 for (var c of controls) { |
| 248 assert_false(c.validity.valueMissing); |
| 249 } |
| 250 }, 'Disabled controls never be valueMissing.'); |
| 251 |
| 252 test(() => { |
| 253 document.querySelector('#sample').innerHTML = |
| 254 '<input readonly required />' + |
| 255 '<textarea readonly required></textarea>'; |
| 256 var controls = document.querySelectorAll('[readonly]'); |
| 257 for (var c of controls) { |
| 258 assert_false(c.validity.valueMissing); |
| 259 } |
| 260 }, 'Read-only controls never be valueMissing.'); |
| 261 |
| 262 test(() => { |
| 263 document.querySelector('#sample').innerHTML = |
| 264 '<fieldset id="non-supported-container">' + |
| 265 '<input name="victim" type="hidden" required />' + |
| 266 '<input name="victim" type="range" required />' + |
| 267 '<input name="victim" type="image" required />' + |
| 268 '<input name="victim" type="reset" required />' + |
| 269 '<input name="victim" type="button" required />' + |
| 270 '<input name="victim" type="submit" required />' + |
| 271 '</fieldset>'; |
| 272 var fieldset = document.querySelector('#non-supported-container'); |
| 273 for (var c of fieldset.elements) { |
| 274 assert_false(c.validity.valueMissing); |
| 275 } |
| 276 }, 'INPUT elements of some types never be valueMissing.'); |
| 277 |
| 278 test(() => { |
| 279 document.querySelector('#sample').innerHTML = |
| 280 '<input name="victim" type="checkbox" required checked />' + |
| 281 '<input name="victim" type="checkbox" required />'; |
| 282 var controls = document.querySelectorAll('input[type=checkbox]'); |
| 283 assert_false(controls[0].validity.valueMissing); |
| 284 assert_true(controls[1].validity.valueMissing); |
| 285 }, 'INPUT[type=checkbox] supports valueMissing.'); |
| 286 |
| 287 test(() => { |
| 288 assert_true(valueMissingFor('<input type="file" required />')); |
| 289 }, 'INPUT[type=file] supports valueMissing.'); |
| 290 |
| 291 test(() => { |
| 292 assert_true(valueMissingFor('<input type="text" required />')); |
| 293 }, 'INPUT[type=text] supports valueMissing.'); |
| 294 |
| 295 test(() => { |
| 296 assert_true(valueMissingFor('<input type="search" required />')); |
| 297 }, 'INPUT[type=search] supports valueMissing.'); |
| 298 |
| 299 test(() => { |
| 300 assert_true(valueMissingFor('<input type="url" required />')); |
| 301 }, 'INPUT[type=url] supports valueMissing.'); |
| 302 |
| 303 test(() => { |
| 304 assert_true(valueMissingFor('<input type="tel" required />')); |
| 305 }, 'INPUT[type=tel] supports valueMissing.'); |
| 306 |
| 307 test(() => { |
| 308 assert_true(valueMissingFor('<input type="email" required />')); |
| 309 }, 'INPUT[type=email] supports valueMissing.'); |
| 310 |
| 311 test(() => { |
| 312 assert_true(valueMissingFor('<input type="password" required />')); |
| 313 }, 'INPUT[type=password] supports valueMissing.'); |
| 314 |
| 315 test(() => { |
| 316 assert_true(valueMissingFor('<input type="number" required />')); |
| 317 }, 'INPUT[type=number] supports valueMissing.'); |
| 318 </script> |
| 319 </body> |
OLD | NEW |