tor-browser

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

child-indexed-pseudo-classes-in-has.html (4788B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8" />
      3 <title>CSS Selectors Invalidation: child-indexed pseudo classes in :has() argument</title>
      4 <link rel="author" title="Byungwoo Lee" href="blee@igalia.com">
      5 <link rel="help" href="https://drafts.csswg.org/selectors/#relational">
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <style>
      9  #container ~ div { color: grey }
     10  #container:has(:only-child) ~ #only_child { color: red }
     11  #container:has(.orange:first-child) ~ #first_child { color: orange }
     12  #container:has(.yellow:first-child) ~ #first_child { color: yellow }
     13  #container:has(.green:first-child) ~ #first_child { color: green }
     14  #container:has(.orange:last-child) ~ #last_child { color: orange }
     15  #container:has(.yellow:last-child) ~ #last_child { color: yellow }
     16  #container:has(.green:last-child) ~ #last_child { color: green }
     17  #container:has(.orange:nth-child(3n)) ~ #nth_child_3n { color: orange }
     18  #container:has(.yellow:nth-child(3n)) ~ #nth_child_3n { color: yellow }
     19  #container:has(.green:nth-child(3n)) ~ #nth_child_3n { color: green }
     20  #container:has(.orange:nth-child(3n+1)) ~ #nth_child_3n_1 { color: orange }
     21  #container:has(.yellow:nth-child(3n+1)) ~ #nth_child_3n_1 { color: yellow }
     22  #container:has(.green:nth-child(3n+1)) ~ #nth_child_3n_1 { color: green }
     23  #container:has(.orange:nth-child(3n+2)) ~ #nth_child_3n_2 { color: orange }
     24  #container:has(.yellow:nth-child(3n+2)) ~ #nth_child_3n_2 { color: yellow }
     25  #container:has(.green:nth-child(3n+2)) ~ #nth_child_3n_2 { color: green }
     26  #container:has(.orange:nth-child(3n)) ~ #nth_child_3n { color: orange }
     27  #container:has(.yellow:nth-child(3n)) ~ #nth_child_3n { color: yellow }
     28  #container:has(.green:nth-child(3n)) ~ #nth_child_3n { color: green }
     29 </style>
     30 <div id="container">
     31 </div>
     32 <div id="only_child"></div>
     33 <div id="first_child"></div>
     34 <div id="last_child"></div>
     35 <div id="nth_child_3n_1"></div>
     36 <div id="nth_child_3n_2"></div>
     37 <div id="nth_child_3n"></div>
     38 <script>
     39 const grey = "rgb(128, 128, 128)";
     40 const red = "rgb(255, 0, 0)";
     41 const orange = "rgb(255, 165, 0)";
     42 const yellow = "rgb(255, 255, 0)";
     43 const green = "rgb(0, 128, 0)";
     44 
     45 function testColors(test_name,
     46                    only_child_color,
     47                    first_child_color,
     48                    last_child_color,
     49                    nth_child_3n_1_color,
     50                    nth_child_3n_2_color,
     51                    nth_child_3n_color) {
     52  test(function() {
     53      assert_equals(getComputedStyle(only_child).color, only_child_color);
     54  }, test_name + ": #only_child");
     55  test(function() {
     56      assert_equals(getComputedStyle(first_child).color, first_child_color);
     57  }, test_name + ": #first_child");
     58  test(function() {
     59      assert_equals(getComputedStyle(last_child).color, last_child_color);
     60  }, test_name + ": #last_child");
     61  test(function() {
     62      assert_equals(getComputedStyle(nth_child_3n_1).color, nth_child_3n_1_color);
     63  }, test_name + ": #nth_child_3n_1");
     64  test(function() {
     65      assert_equals(getComputedStyle(nth_child_3n_2).color, nth_child_3n_2_color);
     66  }, test_name + ": #nth_child_3n_2");
     67  test(function() {
     68      assert_equals(getComputedStyle(nth_child_3n).color, nth_child_3n_color);
     69  }, test_name + ": #nth_child_3n");
     70 }
     71 
     72 testColors("Initial colors", grey, grey, grey, grey, grey, grey);
     73 
     74 let div1 = document.createElement("div");
     75 div1.id = "div1";
     76 div1.classList.add("green");
     77 container.insertBefore(div1, container.firstChild);
     78 testColors("Prepend #div1.green", red, green, green, green, grey, grey);
     79 
     80 let div2 = document.createElement("div");
     81 div2.id = "div2";
     82 div2.classList.add("yellow");
     83 container.insertBefore(div2, container.firstChild);
     84 testColors("Prepend #div2.yellow", grey, yellow, green, yellow, green, grey);
     85 
     86 let div3 = document.createElement("div");
     87 div3.id = "div3";
     88 div3.classList.add("orange");
     89 container.insertBefore(div3, container.firstChild);
     90 testColors("Prepend #div3.orange", grey, orange, green, orange, yellow, green);
     91 
     92 let div4 = document.createElement("div");
     93 div4.id = "div4";
     94 container.insertBefore(div4, container.firstChild);
     95 testColors("Prepend #div4", grey, grey, green, green, orange, yellow);
     96 
     97 let div5 = document.createElement("div");
     98 div5.id = "div5";
     99 container.insertBefore(div5, container.firstChild);
    100 testColors("Prepend #div5", grey, grey, green, yellow, green, orange);
    101 
    102 div1.remove();
    103 testColors("Remove #div1", grey, grey, yellow, yellow, grey, orange);
    104 
    105 div2.remove();
    106 testColors("Remove #div2", grey, grey, orange, grey, grey, orange);
    107 
    108 div3.remove();
    109 testColors("Remove #div3", grey, grey, grey, grey, grey, grey);
    110 
    111 div4.remove();
    112 testColors("Remove #div4", red, grey, grey, grey, grey, grey);
    113 
    114 div5.remove();
    115 testColors("Remove #div5", grey, grey, grey, grey, grey, grey);
    116 </script>