tor-browser

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

layer-important.html (3332B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <title>CSS Cascade Layers: !important </title>
      5 <meta name="assert" content="!important functionality of CSS Cascade Layers">
      6 <link rel="author" title="Romain Menke" href="mailto:romainmenke@gmail.com">
      7 <link rel="help" href="https://www.w3.org/TR/css-cascade-5/#cascade-layering">
      8 <script src="/resources/testharness.js"></script>
      9 <script src="/resources/testharnessreport.js"></script>
     10 </head>
     11 <body>
     12 <target class="first"></target>
     13 <target class="second"></target>
     14 <div id="log"></div>
     15 <script>
     16 
     17 // In all test cases, the rule specified as "color: green" should win.
     18 var testCases = [
     19    {
     20        title: 'A1 Unlayered !important style',
     21        style: `
     22            target { color: green !important; }
     23            target { color: red; }
     24        `
     25    },
     26    {
     27        title: 'B1 Same specificity, layered !important first',
     28        style: `
     29            @layer { target { color: green !important; } }
     30            target { color: red; }
     31        `,
     32    },
     33    {
     34        title: 'C1 Same specificity, layered !important second',
     35        style: `
     36            target { color: red; }
     37            @layer { target { color: green !important; } }
     38        `,
     39    },
     40    {
     41        title: 'D1 Same specificity, all !important',
     42        style: `
     43            @layer { target { color: green !important; } }
     44            @layer { target { color: red !important; } }
     45            target { color: red !important; }
     46        `,
     47    },
     48    {
     49        title: 'D2 Same specificity, all !important',
     50        style: `
     51            @layer { target { color: green !important; } }
     52            target { color: red !important; }
     53            @layer { target { color: red !important; } }
     54        `,
     55    },
     56    {
     57        title: 'D3 Same specificity, all !important',
     58        style: `
     59            target { color: red !important; }
     60            @layer { target { color: green !important; } }
     61            @layer { target { color: red !important; } }
     62        `,
     63    },
     64    {
     65        title: 'D4 Same specificity, all !important',
     66        style: `
     67            @layer A, B;
     68            @layer B { target { color: red !important; } }
     69            @layer A { target { color: green !important; } }
     70            target { color: red !important; }
     71        `,
     72    },
     73    {
     74        title: 'E1 Different specificity, all !important',
     75        style: `
     76            @layer { target { color: green !important; } }
     77            @layer { target { color: red !important; } }
     78            target.first { color: red !important; }
     79        `,
     80    },
     81    {
     82        title: 'E2 Different specificity, all !important',
     83        style: `
     84            @layer { target { color: green !important; } }
     85            @layer { target.first { color: red !important; } }
     86            target { color: red !important; }
     87        `,
     88    },
     89 ];
     90 
     91 for (let testCase of testCases) {
     92    const styleElement = document.createElement('style');
     93    styleElement.textContent = testCase['style'];
     94    document.head.append(styleElement);
     95 
     96    test(function () {
     97        var targets = document.querySelectorAll('target');
     98        for (target of targets)
     99            assert_equals(window.getComputedStyle(target).color, 'rgb(0, 128, 0)',
    100                      testCase['title'] + ", target '" + target.classList[0] + "'");
    101    }, testCase['title']);
    102 
    103    styleElement.remove();
    104 }
    105 </script>
    106 </body>
    107 </html>