tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

child-indexed-pseudo-class.html (1951B)


      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 var check = function(element, selectors, qsRoot) {
     10  for (var i = 0; i < selectors.length; ++i) {
     11    var selector = selectors[i][0];
     12    var expected = selectors[i][1];
     13    test(function() {
     14      assert_equals(expected, element.matches(selector));
     15 
     16      if (qsRoot) {
     17        assert_equals(expected, element === qsRoot.querySelector(selector));
     18        var qsa = qsRoot.querySelectorAll(selector);
     19        assert_equals(expected, !!qsa.length && element === qsa[0]);
     20      }
     21    }, "Expected " + element.tagName + " element to " +
     22         (expected ? "match " : "not match ") + selector + " with matches" +
     23         (qsRoot ? ", querySelector(), and querySelectorAll()" : ""));
     24  }
     25 }
     26 
     27 var rootOfSubtreeSelectors = [
     28  [ ":first-child", true ],
     29  [ ":last-child", true ],
     30  [ ":only-child", true ],
     31  [ ":first-of-type", true ],
     32  [ ":last-of-type", true ],
     33  [ ":only-of-type", true ],
     34  [ ":nth-child(1)", true ],
     35  [ ":nth-child(n)", true ],
     36  [ ":nth-last-child(1)", true ],
     37  [ ":nth-last-child(n)", true ],
     38  [ ":nth-of-type(1)", true ],
     39  [ ":nth-of-type(n)", true ],
     40  [ ":nth-last-of-type(1)", true ],
     41  [ ":nth-last-of-type(n)", true ],
     42  [ ":nth-child(2)", false ],
     43  [ ":nth-last-child(2)", false],
     44  [ ":nth-of-type(2)", false ],
     45  [ ":nth-last-of-type(2)", false],
     46 ];
     47 
     48 check(document.documentElement, rootOfSubtreeSelectors, document);
     49 check(document.createElement('div'), rootOfSubtreeSelectors);
     50 
     51 var fragment = document.createDocumentFragment();
     52 var div = document.createElement('div');
     53 fragment.appendChild(div);
     54 check(div, rootOfSubtreeSelectors, fragment);
     55 </script>