OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
2 <meta charset=utf-8> | 4 <meta charset=utf-8> |
3 <title>Selector: pseudo-classes (:valid, :invalid)</title> | 5 <title>Selector: pseudo-classes (:valid, :invalid)</title> |
4 <link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org" id=link1> | 6 <link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org" id=link1> |
5 <link rel=help href="https://html.spec.whatwg.org/multipage/#pseudo-classes" id=
link2> | 7 <link rel=help href="https://html.spec.whatwg.org/multipage/#pseudo-classes" id=
link2> |
6 <script src="/resources/testharness.js"></script> | 8 <script src="/resources/testharness.js"></script> |
7 <script src="/resources/testharnessreport.js"></script> | 9 <script src="/resources/testharnessreport.js"></script> |
8 <script src="utils.js"></script> | 10 <script src="utils.js"></script> |
| 11 <style> |
| 12 #styleTests form, #styleTests fieldset, #failExample { background-color:red; } |
| 13 #styleTests > :valid, #validExample { background-color:green; } |
| 14 #styleTests > :invalid, #invalidExample { background-color:lime; } |
| 15 </style> |
| 16 </head> |
| 17 <body> |
9 <div id="log"></div> | 18 <div id="log"></div> |
10 <div id='simpleConstraints'> | 19 <div id='simpleConstraints'> |
11 <input type=text id=text1 value="foobar" required> | 20 <input type=text id=text1 value="foobar" required> |
12 <input type=text id=text2 required> | 21 <input type=text id=text2 required> |
13 </div> | 22 </div> |
14 <div id='FormSelection'> | 23 <div id='FormSelection'> |
15 <form id=form1> | 24 <form id=form1> |
16 <input type=text id=text3 value="foobar" required> | 25 <input type=text id=text3 value="foobar" required> |
17 </form> | 26 </form> |
18 <form id=form2> | 27 <form id=form2> |
19 <input type=text id=text4 required> | 28 <input type=text id=text4 required> |
20 </form> | 29 </form> |
21 </div> | 30 </div> |
22 <div id='FieldSetSelection'> | 31 <div id='FieldSetSelection'> |
23 <fieldset id=fieldset1> | 32 <fieldset id=fieldset1> |
24 <input type=text id=text5 value="foobar" required> | 33 <input type=text id=text5 value="foobar" required> |
25 </fieldset> | 34 </fieldset> |
26 <fieldset id=fieldset2> | 35 <fieldset id=fieldset2> |
27 <input type=text id=text6 required> | 36 <input type=text id=text6 required> |
28 </fieldset> | 37 </fieldset> |
29 </div> | 38 </div> |
30 <div id='patternConstraints'> | 39 <div id='patternConstraints'> |
31 <input type=text id=text7 value="AAA" pattern="[0-9][A-Z]{3}"> | 40 <input type=text id=text7 value="AAA" pattern="[0-9][A-Z]{3}"> |
32 <input type=text id=text8 value="0AAA" pattern="[0-9][A-Z]{3}"> | 41 <input type=text id=text8 value="0AAA" pattern="[0-9][A-Z]{3}"> |
33 </div> | 42 </div> |
34 <div id='numberConstraints'> | 43 <div id='numberConstraints'> |
35 <input type=number id=number1 value=0 min=1> | 44 <input type=number id=number1 value=0 min=1> |
36 <input type=number id=number2 value=1 min=1> | 45 <input type=number id=number2 value=1 min=1> |
37 </div> | 46 </div> |
38 | 47 <div id='styleTests'> |
| 48 <form> |
| 49 </form> |
| 50 <form> |
| 51 <input type=text min=8 value=4> |
| 52 </form> |
| 53 <form> |
| 54 <input type=number min=8 value=4> |
| 55 </form> |
| 56 <fieldset> |
| 57 </fieldset> |
| 58 <fieldset> |
| 59 <input type=text min=8 value=4> |
| 60 </fieldset> |
| 61 <fieldset> |
| 62 <input type=number min=8 value=4> |
| 63 </fieldset> |
| 64 <div id='validExample'></div> |
| 65 <div id='invalidExample'></div> |
| 66 <div id='failExample'></div> |
| 67 </div> |
39 <script> | 68 <script> |
40 testSelectorIdsMatch("#simpleConstraints :valid", ["text1"], "':valid' matches
elements that satisfy their constraints"); | 69 testSelectorIdsMatch("#simpleConstraints :valid", ["text1"], "':valid' matches
elements that satisfy their constraints"); |
41 | 70 |
42 testSelectorIdsMatch("#FormSelection :valid", ["form1", "text3"], "':valid' ma
tches form elements that are not the form owner of any elements that themselves
are candidates for constraint validation but do not satisfy their constraints"); | 71 testSelectorIdsMatch("#FormSelection :valid", ["form1", "text3"], "':valid' ma
tches form elements that are not the form owner of any elements that themselves
are candidates for constraint validation but do not satisfy their constraints"); |
43 | 72 |
44 testSelectorIdsMatch("#FieldSetSelection :valid", ["fieldset1", "text5"], "':v
alid' matches fieldset elements that have no descendant elements that themselves
are candidates for constraint validation but do not satisfy their constraints")
; | 73 testSelectorIdsMatch("#FieldSetSelection :valid", ["fieldset1", "text5"], "':v
alid' matches fieldset elements that have no descendant elements that themselves
are candidates for constraint validation but do not satisfy their constraints")
; |
45 | 74 |
46 testSelectorIdsMatch("#patternConstraints :valid", [ "text8" ], "':valid' matc
hes elements that satisfy their pattern constraints"); | 75 testSelectorIdsMatch("#patternConstraints :valid", [ "text8" ], "':valid' matc
hes elements that satisfy their pattern constraints"); |
47 | 76 |
48 testSelectorIdsMatch("#numberConstraints :valid", [ "number2" ], "':valid' mat
ches elements that satisfy their number constraints"); | 77 testSelectorIdsMatch("#numberConstraints :valid", [ "number2" ], "':valid' mat
ches elements that satisfy their number constraints"); |
49 | 78 |
50 | 79 |
51 testSelectorIdsMatch("#simpleConstraints :invalid", ["text2"], "':invalid' mat
ches elements that do not satisfy their simple text constraints"); | 80 testSelectorIdsMatch("#simpleConstraints :invalid", ["text2"], "':invalid' mat
ches elements that do not satisfy their simple text constraints"); |
52 | 81 |
53 testSelectorIdsMatch("#FormSelection :invalid", ["form2", "text4"], "':invalid
' matches form elements that are the form owner of one or more elements that the
mselves are candidates for constraint validation but do not satisfy their constr
aints"); | 82 testSelectorIdsMatch("#FormSelection :invalid", ["form2", "text4"], "':invalid
' matches form elements that are the form owner of one or more elements that the
mselves are candidates for constraint validation but do not satisfy their constr
aints"); |
54 | 83 |
55 testSelectorIdsMatch("#FieldSetSelection :invalid", ["fieldset2", "text6"], "'
:invalid' matches fieldset elements that have of one or more descendant elements
that themselves are candidates for constraint validation but do not satisfy the
ir constraints"); | 84 testSelectorIdsMatch("#FieldSetSelection :invalid", ["fieldset2", "text6"], "'
:invalid' matches fieldset elements that have of one or more descendant elements
that themselves are candidates for constraint validation but do not satisfy the
ir constraints"); |
56 | 85 |
57 testSelectorIdsMatch("#patternConstraints :invalid", ["text7"], "':invalid' ma
tches elements that do not satisfy their pattern constraints"); | 86 testSelectorIdsMatch("#patternConstraints :invalid", ["text7"], "':invalid' ma
tches elements that do not satisfy their pattern constraints"); |
58 | 87 |
59 testSelectorIdsMatch("#numberConstraints :invalid", ["number1"], "':invalid' m
atches elements that do not satisfy their number constraints"); | 88 testSelectorIdsMatch("#numberConstraints :invalid", ["number1"], "':invalid' m
atches elements that do not satisfy their number constraints"); |
60 | 89 |
61 document.getElementById("text7").value="0BBB"; | 90 document.getElementById("text7").value="0BBB"; |
62 testSelectorIdsMatch("#patternConstraints :valid", [ "text7", "text8" ], "':va
lid' matches new elements that satisfy their constraints"); | 91 testSelectorIdsMatch("#patternConstraints :valid", [ "text7", "text8" ], "':va
lid' matches new elements that satisfy their constraints"); |
63 testSelectorIdsMatch("#patternConstraints :invalid", [], "':invalid' doesn't m
atch new elements that satisfy their constraints"); | 92 testSelectorIdsMatch("#patternConstraints :invalid", [], "':invalid' doesn't m
atch new elements that satisfy their constraints"); |
64 | 93 |
65 document.getElementById("text8").value="BBB"; | 94 document.getElementById("text8").value="BBB"; |
66 testSelectorIdsMatch("#patternConstraints :valid", ["text7"], "':valid' doesn'
t match new elements that do not satisfy their constraints"); | 95 testSelectorIdsMatch("#patternConstraints :valid", ["text7"], "':valid' doesn'
t match new elements that do not satisfy their constraints"); |
67 testSelectorIdsMatch("#patternConstraints :invalid", ["text8"], "':invalid' ma
tches new elements that do not satisfy their constraints"); | 96 testSelectorIdsMatch("#patternConstraints :invalid", ["text8"], "':invalid' ma
tches new elements that do not satisfy their constraints"); |
| 97 |
| 98 function getBGColor(elem) { |
| 99 return getComputedStyle(elem).backgroundColor; |
| 100 } |
| 101 |
| 102 function testStyles(type) { |
| 103 var elems = document.querySelectorAll("#styleTests " + type), |
| 104 empty = elems[0], |
| 105 valid = elems[1], |
| 106 invalid = elems[2], |
| 107 validInput = valid.querySelector("input"), |
| 108 invalidInput = invalid.querySelector("input"), |
| 109 expectedValidBGColor = getBGColor(document.getElementById("validExample"
)), |
| 110 expectedInvalidBGColor = getBGColor(document.getElementById("invalidExam
ple")), |
| 111 expectedFailBGColor = getBGColor(document.getElementById("failExample"))
; |
| 112 |
| 113 test(function() { |
| 114 assert_equals(getBGColor(empty), expectedValidBGColor, "wrong background-c
olor"); |
| 115 }, 'empty ' + type + ' correctly styled on page-load'); |
| 116 |
| 117 test(function() { |
| 118 assert_equals(getBGColor(valid), expectedValidBGColor, "wrong background-c
olor"); |
| 119 }, 'valid ' + type + ' correctly styled on page-load'); |
| 120 test(function() { |
| 121 assert_equals(getBGColor(invalid), expectedInvalidBGColor, "wrong backgrou
nd-color"); |
| 122 }, 'invalid ' + type + ' correctly styled on page-load'); |
| 123 |
| 124 test(function() { |
| 125 empty.appendChild(validInput.cloneNode()); |
| 126 assert_equals(getBGColor(empty), expectedValidBGColor, "wrong background-c
olor"); |
| 127 }, 'programmatically adding valid to empty ' + type + ' results in correct s
tyle'); |
| 128 test(function() { |
| 129 empty.appendChild(invalidInput.cloneNode()); |
| 130 assert_equals(getBGColor(empty), expectedInvalidBGColor, "wrong background
-color"); |
| 131 }, 'programmatically adding invalid to empty ' + type + ' results in correct
style'); |
| 132 |
| 133 validInput.type = "number"; |
| 134 invalidInput.type = "text"; |
| 135 test(function() { |
| 136 assert_equals(getBGColor(valid), expectedInvalidBGColor, "wrong background
-color"); |
| 137 }, 'programmatically-invalidated ' + type + ' correctly styled'); |
| 138 test(function() { |
| 139 assert_equals(getBGColor(invalid), expectedValidBGColor, "wrong background
-color"); |
| 140 }, 'programmatically-validated ' + type + ' correctly styled'); |
| 141 } |
| 142 test(testStyles.bind(undefined, "form"), ":valid/:invalid styling for <form>")
; |
| 143 test(testStyles.bind(undefined, "fieldset"), ":valid/:invalid styling for <fie
ldset>"); |
68 </script> | 144 </script> |
| 145 </body> |
| 146 </html> |
OLD | NEW |