OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <title>Pseudo Element Matching in Shadow DOM</title> | 3 <title>Pseudo Element Matching in Shadow DOM</title> |
4 <style> | 4 <style> |
5 input[type=range] { | 5 input[type=range] { |
6 -webkit-appearance: none; | 6 -webkit-appearance: none; |
7 } | 7 } |
8 </style> | 8 </style> |
9 <script> | 9 <script> |
10 | 10 |
11 if (window.layoutTestController) | 11 if (window.layoutTestController) |
12 layoutTestController.dumpAsText(); | 12 layoutTestController.dumpAsText(); |
13 | 13 |
14 var head; | 14 var head; |
15 var input; | 15 var input; |
16 var logDiv; | 16 var logDiv; |
17 var NAMESPACE_DECLARATION = '@namespace "http://example.com/foo/namespace";\n@na
mespace html "http://www.w3.org/1999/xhtml";\n'; | 17 var NAMESPACE_DECLARATION = '@namespace "http://example.com/foo/namespace";\n@na
mespace html "http://www.w3.org/1999/xhtml";\n'; |
18 var SELECTOR_TEST_PROPERTIES = ' { height: 1px; -webkit-appearance: none; }'; | 18 var SELECTOR_TEST_PROPERTIES = ' { height: 1px; -webkit-appearance: none; }'; |
19 var SELECTORS = [ | 19 var SELECTORS = [ |
20 '::-webkit-slider-thumb', | 20 '::-webkit-slider-thumb', |
| 21 '*::-webkit-slider-thumb', |
21 'input::-webkit-slider-thumb', | 22 'input::-webkit-slider-thumb', |
22 '#foo::-webkit-slider-thumb', | 23 '#foo::-webkit-slider-thumb', |
23 'input#foo::-webkit-slider-thumb', | 24 'input#foo::-webkit-slider-thumb', |
24 'input.bar::-webkit-slider-thumb', | 25 'input.bar::-webkit-slider-thumb', |
25 'input[type=range]::-webkit-slider-thumb' | 26 'input[type=range]::-webkit-slider-thumb' |
26 ]; | 27 ]; |
27 var DISABLED_SELECTORS = SELECTORS.map(function(selector) { return selector + ':
disabled'; }); | 28 var DISABLED_SELECTORS = SELECTORS.map(function(selector) { return selector + ':
disabled'; }); |
28 var HOVER_SELECTORS = SELECTORS.map(function(selector) { return selector + ':hov
er'; }); | 29 var HOVER_SELECTORS = SELECTORS.map(function(selector) { return selector + ':hov
er'; }); |
29 var DESCENDANT_ID_SELECTORS = SELECTORS.map(function(selector) { return '#baz '
+ selector; }); | 30 var DESCENDANT_ID_SELECTORS = SELECTORS.map(function(selector) { return '#baz '
+ selector; }); |
30 DESCENDANT_ID_SELECTORS.shift(); | |
31 var DESCENDANT_CLASS_SELECTORS = SELECTORS.map(function(selector) { return '.qux
' + selector; }); | 31 var DESCENDANT_CLASS_SELECTORS = SELECTORS.map(function(selector) { return '.qux
' + selector; }); |
32 DESCENDANT_CLASS_SELECTORS.shift(); | 32 var DIRECT_SIBLING_ID_SELECTORS = SELECTORS.map(function(selector) { return '#si
b + ' + selector; }); |
| 33 var INDIRECT_SIBLING_ID_SELECTORS = SELECTORS.map(function(selector) { return '#
sib ~ ' + selector; }); |
| 34 var DIRECT_SIBLING_CLASS_SELECTORS = SELECTORS.map(function(selector) { return '
.ling + ' + selector; }); |
| 35 var INDIRECT_SIBLING_CLASS_SELECTORS = SELECTORS.map(function(selector) { return
'.ling ~ ' + selector; }); |
33 | 36 |
34 // convenience constants | 37 // convenience constants |
35 var MATCH = true; | 38 var MATCH = true; |
36 var NO_MATCH = false; | 39 var NO_MATCH = false; |
37 var WITH_NAMESPACES = true; | 40 var WITH_NAMESPACES = true; |
38 | 41 |
39 function log(msg, success) | 42 function log(msg, success) |
40 { | 43 { |
41 logDiv.appendChild(document.createElement('div')).innerHTML = msg + (argumen
ts.length == 1 ? '' : (': ' + (success ? 'PASS' : 'FAIL'))); | 44 logDiv.appendChild(document.createElement('div')).innerHTML = msg + (argumen
ts.length == 1 ? '' : (': ' + (success ? 'PASS' : 'FAIL'))); |
42 } | 45 } |
(...skipping 16 matching lines...) Expand all Loading... |
59 head.appendChild(style); | 62 head.appendChild(style); |
60 var matched = input.offsetHeight == 1; | 63 var matched = input.offsetHeight == 1; |
61 log('<code>' + selector + '</code>' + (useNamespaces ? ', where HTML is not
default namespace' : '') + ' <strong>should' + (matchExpected ? '' : ' not') +
'</strong> match', matchExpected ? matched : !matched); | 64 log('<code>' + selector + '</code>' + (useNamespaces ? ', where HTML is not
default namespace' : '') + ' <strong>should' + (matchExpected ? '' : ' not') +
'</strong> match', matchExpected ? matched : !matched); |
62 head.removeChild(style); | 65 head.removeChild(style); |
63 } | 66 } |
64 | 67 |
65 function runTest() | 68 function runTest() |
66 { | 69 { |
67 head = document.getElementsByTagName('head')[0]; | 70 head = document.getElementsByTagName('head')[0]; |
68 input = document.getElementsByTagName('input')[0]; | 71 input = document.getElementsByTagName('input')[0]; |
| 72 testContainer = document.getElementById('baz'); |
69 logDiv = document.getElementById('log'); | 73 logDiv = document.getElementById('log'); |
70 log('Basic selector tests:'); | 74 log('Basic selector tests:'); |
71 runSelectorTest(MATCH, '::-webkit-slider-thumb'); | 75 runSelectorTest(MATCH, '::-webkit-slider-thumb'); |
| 76 runSelectorTest(MATCH, '*::-webkit-slider-thumb'); |
72 runSelectorTest(NO_MATCH, '::-webkit-slider-thumb', WITH_NAMESPACES); | 77 runSelectorTest(NO_MATCH, '::-webkit-slider-thumb', WITH_NAMESPACES); |
73 runSelectorTest(MATCH, '*|::-webkit-slider-thumb', WITH_NAMESPACES); | 78 runSelectorTest(MATCH, '*|::-webkit-slider-thumb', WITH_NAMESPACES); |
| 79 runSelectorTest(MATCH, '*|*::-webkit-slider-thumb', WITH_NAMESPACES); |
74 runSelectorTest(MATCH, 'html|::-webkit-slider-thumb', WITH_NAMESPACES); | 80 runSelectorTest(MATCH, 'html|::-webkit-slider-thumb', WITH_NAMESPACES); |
| 81 runSelectorTest(MATCH, 'html|*::-webkit-slider-thumb', WITH_NAMESPACES); |
75 runSelectorTest(MATCH, '#foo::-webkit-slider-thumb'); | 82 runSelectorTest(MATCH, '#foo::-webkit-slider-thumb'); |
76 runSelectorTest(MATCH, '.bar::-webkit-slider-thumb'); | 83 runSelectorTest(MATCH, '.bar::-webkit-slider-thumb'); |
77 runSelectorTest(NO_MATCH, '#foo::-webkit-slider-thumb', WITH_NAMESPACES); | 84 runSelectorTest(NO_MATCH, '#foo::-webkit-slider-thumb', WITH_NAMESPACES); |
78 runSelectorTest(NO_MATCH, '.bar::-webkit-slider-thumb', WITH_NAMESPACES); | 85 runSelectorTest(NO_MATCH, '.bar::-webkit-slider-thumb', WITH_NAMESPACES); |
79 runSelectorTest(MATCH, 'html|#foo::-webkit-slider-thumb', WITH_NAMESPACES); | 86 runSelectorTest(MATCH, 'html|#foo::-webkit-slider-thumb', WITH_NAMESPACES); |
80 runSelectorTest(MATCH, 'html|.bar::-webkit-slider-thumb', WITH_NAMESPACES); | 87 runSelectorTest(MATCH, 'html|.bar::-webkit-slider-thumb', WITH_NAMESPACES); |
81 runSelectorTest(MATCH, '*|#foo::-webkit-slider-thumb', WITH_NAMESPACES); | 88 runSelectorTest(MATCH, '*|#foo::-webkit-slider-thumb', WITH_NAMESPACES); |
82 runSelectorTest(MATCH, 'input::-webkit-slider-thumb'); | 89 runSelectorTest(MATCH, 'input::-webkit-slider-thumb'); |
83 runSelectorTest(MATCH, 'input#foo::-webkit-slider-thumb'); | 90 runSelectorTest(MATCH, 'input#foo::-webkit-slider-thumb'); |
84 runSelectorTest(MATCH, 'input.bar::-webkit-slider-thumb'); | 91 runSelectorTest(MATCH, 'input.bar::-webkit-slider-thumb'); |
(...skipping 15 matching lines...) Expand all Loading... |
100 input.disabled = false; | 107 input.disabled = false; |
101 if (!hoverOverSliderThumb()) { | 108 if (!hoverOverSliderThumb()) { |
102 log(':hover tests require DRT'); | 109 log(':hover tests require DRT'); |
103 return; | 110 return; |
104 } | 111 } |
105 log('<br>Should match :hover when the mouse is over the slider thumb:'); | 112 log('<br>Should match :hover when the mouse is over the slider thumb:'); |
106 HOVER_SELECTORS.forEach(expectMatch); | 113 HOVER_SELECTORS.forEach(expectMatch); |
107 log('<br>Should match when combined with descendant selectors:'); | 114 log('<br>Should match when combined with descendant selectors:'); |
108 DESCENDANT_ID_SELECTORS.forEach(expectMatch); | 115 DESCENDANT_ID_SELECTORS.forEach(expectMatch); |
109 DESCENDANT_CLASS_SELECTORS.forEach(expectMatch); | 116 DESCENDANT_CLASS_SELECTORS.forEach(expectMatch); |
110 input.parentNode.removeChild(input); | 117 log('<br>Should match when combined with sibling selectors:'); |
| 118 DIRECT_SIBLING_ID_SELECTORS.forEach(expectMatch); |
| 119 INDIRECT_SIBLING_ID_SELECTORS.forEach(expectMatch); |
| 120 DIRECT_SIBLING_CLASS_SELECTORS.forEach(expectMatch); |
| 121 INDIRECT_SIBLING_CLASS_SELECTORS.forEach(expectMatch); |
| 122 |
| 123 testContainer.parentNode.removeChild(testContainer); |
111 } | 124 } |
112 | 125 |
113 function expectNoMatch(selector) { | 126 function expectNoMatch(selector) { |
114 runSelectorTest(NO_MATCH, selector); | 127 runSelectorTest(NO_MATCH, selector); |
115 } | 128 } |
116 | 129 |
117 function expectMatch(selector) { | 130 function expectMatch(selector) { |
118 runSelectorTest(MATCH, selector); | 131 runSelectorTest(MATCH, selector); |
119 } | 132 } |
120 | 133 |
121 </script> | 134 </script> |
122 </head> | 135 </head> |
123 <body onload="runTest()"> | 136 <body onload="runTest()"> |
124 <p>Tests various selector combinations, containing unknown pseudo element se
lectors.</p> | 137 <p>Tests various selector combinations, containing unknown pseudo element se
lectors.</p> |
125 <div id="baz" class="qux"> | 138 <div id="baz" class="qux"> |
| 139 <span id="sib" class="ling">Sibling</span> |
126 <input id="foo" class="bar" type="range"> | 140 <input id="foo" class="bar" type="range"> |
127 </div> | 141 </div> |
128 <div id="log"></div> | 142 <div id="log"></div> |
129 </body> | 143 </body> |
130 </html> | 144 </html> |
OLD | NEW |