|
28 | 28 | } |
29 | 29 |
|
30 | 30 | self.runTest = async function runTest() { |
31 | | - const invalidationResult = await testInvalidation(); |
32 | 31 | const adjacentPositionResult = await testAdjacentPosition(); |
33 | | - const parentPositionResult = await testParentPosition(); |
34 | 32 | const hasWithPseudoClassesResult = await testHasWithPseudoClasses(); |
35 | | - |
36 | | - return invalidationResult && adjacentPositionResult && parentPositionResult; |
| 33 | + const invalidationResult = await testInvalidation(); |
| 34 | + const parentPositionResult = await testParentPosition(); |
| 35 | + const specificityResult = await testSpecificity(); |
| 36 | + const visitednessResult = await testVisitedness() |
| 37 | + |
| 38 | + return ( |
| 39 | + adjacentPositionResult && |
| 40 | + hasWithPseudoClassesResult && |
| 41 | + invalidationResult && |
| 42 | + parentPositionResult && |
| 43 | + specificityResult && |
| 44 | + visitednessResult |
| 45 | + ); |
37 | 46 | } |
38 | 47 |
|
39 | 48 | async function testHasWithPseudoClasses() { |
|
120 | 129 | return true; |
121 | 130 | } |
122 | 131 |
|
| 132 | + async function testVisitedness() { |
| 133 | + // https://github.com/web-platform-tests/wpt/blob/master/css/selectors/has-visited.html |
| 134 | + |
| 135 | + fixture.innerHTML = ` |
| 136 | + <div id="visited-1"> |
| 137 | + <div>parent color should be green with <a href="">visited link</a>.</div> |
| 138 | + </div> |
| 139 | + <div id="visited-2"> |
| 140 | + <div>parent color should be black with <a href="unvisited">unvisited link</a>.</div> |
| 141 | + </div> |
| 142 | + <div id="visited-3"> |
| 143 | + <div>parent color should be yellowgreen with <a href="unvisited">any link</a>.</div> |
| 144 | + </div> |
| 145 | + <div id="visited-4"> |
| 146 | + <div>parent color should be black with <a href="">visited link</a>.</div> |
| 147 | + </div> |
| 148 | + `; |
| 149 | + |
| 150 | + const black = 'rgb(0, 0, 0)'; |
| 151 | + const green = 'rgb(0, 128, 0)'; |
| 152 | + const yellow_green = 'rgb(154, 205, 50)'; |
| 153 | + |
| 154 | + function testColor(el, color) { |
| 155 | + var actual = getComputedStyle(el).color; |
| 156 | + if (actual !== color) { |
| 157 | + throw new Error('div#' + el.id + '.color; expected ' + color + ' but got ' + actual); |
| 158 | + } |
| 159 | + } |
| 160 | + |
| 161 | + await rafP(() => { |
| 162 | + testColor(document.getElementById('visited-1'), green); |
| 163 | + testColor(document.getElementById('visited-2'), black); |
| 164 | + testColor(document.getElementById('visited-3'), yellow_green); |
| 165 | + testColor(document.getElementById('visited-4'), black); |
| 166 | + }); |
| 167 | + |
| 168 | + return true; |
| 169 | + } |
| 170 | + |
| 171 | + async function testSpecificity() { |
| 172 | + // https://github.com/web-platform-tests/wpt/blob/2b811aa5c2/css/selectors/has-specificity.html |
| 173 | + |
| 174 | + fixture.innerHTML = ` |
| 175 | + <main id="main_specificity"> |
| 176 | + <div id=div><p><span id=foo class=foo></span><span class=bar></span><li></li></p></div> |
| 177 | + </main> |
| 178 | + `; |
| 179 | + |
| 180 | + function test_value(name, description) { |
| 181 | + let actual = getComputedStyle(div).getPropertyValue(name); |
| 182 | + if (actual !== 'PASS') { |
| 183 | + throw new Error(`${name}: expected "PASS", got "${actual}"`); |
| 184 | + } |
| 185 | + } |
| 186 | + |
| 187 | + await rafP(() => { |
| 188 | + test_value('--t0', ':has(#foo) wins over :has(.foo)'); |
| 189 | + test_value('--t1', ':has(span#foo) wins over :has(#foo)'); |
| 190 | + test_value('--t2', ':has(.bar, #foo) has same specificity as :has(#foo, .bar)'); |
| 191 | + test_value('--t3', ':has(.bar, #foo) wins over :has(.foo, .bar)'); |
| 192 | + test_value('--t4', ':has(span + span) wins over :has(span)'); |
| 193 | + test_value('--t5', ':has(span, li, p) wins over :has(span, lo, p)'); |
| 194 | + }); |
| 195 | + |
| 196 | + return true; |
| 197 | + } |
| 198 | + |
123 | 199 | async function testParentPosition() { |
124 | 200 | // https://github.com/web-platform-tests/wpt/blob/master/css/selectors/invalidation/has-in-ancestor-position.html |
125 | 201 |
|
|
0 commit comments