OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <meta charset=utf-8> |
| 3 <title>Matching of child-indexed pseudo-classes</title> |
| 4 <link rel="author" title="Emilio Cobos Álvarez" href="mailto:ecoal95@gmail.com"> |
| 5 <link rel="help" href="https://drafts.csswg.org/selectors-4/#child-index"> |
| 6 <script src=../../resources/testharness.js></script> |
| 7 <script src=../../resources/testharnessreport.js></script> |
| 8 <script> |
| 9 test(function() { |
| 10 var check = function(element, selectors, qsRoot) { |
| 11 for (var i = 0; i < selectors.length; ++i) { |
| 12 var selector = selectors[i][0]; |
| 13 var expected = selectors[i][1]; |
| 14 |
| 15 var message = "Expected " + element.tagName + " element to " + |
| 16 (expected ? "match " : "not match ") + selector; |
| 17 |
| 18 assert_equals(expected, element.matches(selector), message); |
| 19 |
| 20 if (qsRoot) { |
| 21 assert_equals(expected, element === qsRoot.querySelector(selector), |
| 22 message + " in querySelector()"); |
| 23 var qsa = qsRoot.querySelectorAll(selector); |
| 24 assert_equals(expected, !!qsa.length && element === qsa[0], |
| 25 message + " in querySelectorAll()"); |
| 26 } |
| 27 } |
| 28 } |
| 29 |
| 30 var rootOfSubtreeSelectors = [ |
| 31 [ ":first-child", true ], |
| 32 [ ":last-child", true ], |
| 33 [ ":only-child", true ], |
| 34 [ ":first-of-type", true ], |
| 35 [ ":last-of-type", true ], |
| 36 [ ":only-of-type", true ], |
| 37 [ ":nth-child(1)", true ], |
| 38 [ ":nth-child(n)", true ], |
| 39 [ ":nth-last-child(1)", true ], |
| 40 [ ":nth-last-child(n)", true ], |
| 41 [ ":nth-of-type(1)", true ], |
| 42 [ ":nth-of-type(n)", true ], |
| 43 [ ":nth-last-of-type(1)", true ], |
| 44 [ ":nth-last-of-type(n)", true ], |
| 45 [ ":nth-child(2)", false ], |
| 46 [ ":nth-last-child(2)", false], |
| 47 [ ":nth-of-type(2)", false ], |
| 48 [ ":nth-last-of-type(2)", false], |
| 49 ]; |
| 50 |
| 51 check(document.documentElement, rootOfSubtreeSelectors, document); |
| 52 check(document.createElement('div'), rootOfSubtreeSelectors); |
| 53 |
| 54 var fragment = document.createDocumentFragment(); |
| 55 var div = document.createElement('div'); |
| 56 fragment.appendChild(div); |
| 57 check(div, rootOfSubtreeSelectors, fragment); |
| 58 }, "child-indexed pseudo-classes should match without a parent") |
| 59 </script> |
OLD | NEW |