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 // See also imported/wpt/html/semantics/forms/constraints/form-validation-checkV
alidity.html. |
| 8 |
| 9 function checkValidityFor(html) { |
| 10 var sample = document.getElementById('sample'); |
| 11 sample.innerHTML = html; |
| 12 return sample.firstChild.checkValidity(); |
| 13 } |
| 14 |
| 15 test(() => { |
| 16 assert_true(checkValidityFor('<fieldset></fieldset>')); |
| 17 }, 'checkValidity() for FIELDSET should return true.'); |
| 18 |
| 19 test(() => { |
| 20 assert_true(checkValidityFor('<fieldset><input required></fieldset>')); |
| 21 }, 'checkValidity() for FIELDSET with an invalid INPUT should return true.'); |
| 22 |
| 23 test(() => { |
| 24 assert_true(checkValidityFor('<button>lorem ipsum</button>')); |
| 25 }, 'checkValidity() for BUTTON should return true.'); |
| 26 |
| 27 test(() => { |
| 28 assert_true(checkValidityFor('<output></output>')); |
| 29 }, 'checkValidity() for OUTPUT should return true.'); |
| 30 |
| 31 test(() => { |
| 32 assert_true(checkValidityFor('<object></object>')); |
| 33 }, 'checkValidity() for OBJECT should return true.'); |
| 34 |
| 35 test(() => { |
| 36 assert_true(checkValidityFor('<keygen></keygen>')); |
| 37 }, 'checkValidity() for KEYGEN should return true.'); |
| 38 |
| 39 test(() => { |
| 40 assert_true(checkValidityFor('<select required>' + |
| 41 ' <option>empty</option>' + |
| 42 ' <option>another</option>' + |
| 43 '</select>')); |
| 44 }, 'checkValidity() for SELECT without a placeholder OPTION should return true.'
); |
| 45 |
| 46 test(() => { |
| 47 assert_false(checkValidityFor('<select required>' + |
| 48 ' <option value="" selected />' + |
| 49 ' <option value="X">X</option>' + |
| 50 '</select>')); |
| 51 }, 'checkValidity() for SELECT with a placeholder OPTION should return false.'); |
| 52 |
| 53 test(() => { |
| 54 assert_true(checkValidityFor('<select required>' + |
| 55 ' <option value="X">X</option>' + |
| 56 ' <option value="" selected />' + |
| 57 '</select>')); |
| 58 }, 'checkValidity() for SELECT with a selected empty second OPTION should return
true.'); |
| 59 |
| 60 test(() => { |
| 61 assert_true(checkValidityFor('<form method="get">' + |
| 62 '<fieldset name="victim"></fieldset>' + |
| 63 '<input name="victim" type="text" value="lorem ipsum"/>' + |
| 64 '<button name="victim">lorem ipsum</button>' + |
| 65 '<select name="victim"></select>' + |
| 66 '<textarea name="victim"></textarea>' + |
| 67 '</form>')); |
| 68 }, 'checkValidity() for FORM with valid controls should return true.'); |
| 69 |
| 70 test(() => { |
| 71 assert_false(checkValidityFor('<form method="get">' + |
| 72 '<fieldset name="victim"></fieldset>' + |
| 73 '<input name="victim" type="text" value="invalid" pattern="something"/>' + |
| 74 '<button name="victim">lorem ipsum</button>' + |
| 75 '<select name="victim"></select>' + |
| 76 '<textarea name="victim"></textarea>' + |
| 77 '</form>')); |
| 78 }, 'checkValidity() for FORM with an invalid control should return false.'); |
| 79 </script> |
| 80 </body> |
OLD | NEW |