tor-browser

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

test_visited_style.html (2115B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      5 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
      6 <style>
      7 #target:visited, div {
      8  color: lime;
      9 }
     10 
     11 #target:link, div {
     12  color: pink;
     13 }
     14 </style>
     15 </head>
     16 <body>
     17  <a href="test" id="target">test-target</a>
     18 
     19  <script>
     20  const VISITED_SELECTOR = "#target:visited";
     21  const LINK_SELECTOR = "#target:link";
     22 
     23  const TEST_DATA = [
     24    {
     25      description: "Test for visited style",
     26      isVisitedTest: true,
     27      validSelector: VISITED_SELECTOR,
     28      invalidSelector: LINK_SELECTOR,
     29    },
     30    {
     31      description: "Test for unvisited style",
     32      isVisitedTest: false,
     33      validSelector: LINK_SELECTOR,
     34      invalidSelector: VISITED_SELECTOR,
     35    },
     36  ];
     37 
     38  function start() {
     39    const target = document.getElementById("target");
     40 
     41    for (const { description, isVisitedTest,
     42                 validSelector, invalidSelector } of TEST_DATA) {
     43      info(description);
     44 
     45      const rules =
     46        InspectorUtils.getMatchingCSSRules(target, undefined, isVisitedTest);
     47      ok(getRule(rules, validSelector),
     48         `Rule of ${validSelector} is in rules`);
     49      ok(!getRule(rules, invalidSelector),
     50         `Rule of ${invalidSelector} is not in rules`);
     51 
     52      const targetRule = getRule(rules, validSelector);
     53      const isTargetSelectorMatched = targetRule.selectorMatchesElement(0, target, undefined, isVisitedTest);
     54      const isDivSelectorMatched = targetRule.selectorMatchesElement(1, target, undefined, isVisitedTest);
     55      ok(isTargetSelectorMatched,
     56         `${validSelector} selector is matched for the rule`);
     57      ok(!isDivSelectorMatched,
     58         "div selector is not matched for the rule");
     59    }
     60 
     61    SimpleTest.finish();
     62  }
     63 
     64  function getRule(rules, selector) {
     65    for (const rule of rules) {
     66      if (rule.selectorText.startsWith(selector)) {
     67        return rule;
     68      }
     69    }
     70    return null;
     71  }
     72 
     73  SimpleTest.waitForExplicitFinish();
     74  document.addEventListener('DOMContentLoaded', start);
     75  </script>
     76 </body>
     77 </html>