tor-browser

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

page-rule-declarations-004.html (1966B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>CSS Paged Media: parsing invalid @page selectors</title>
      4 <link rel="author" title="Mozilla" href="https://mozilla.org"/>
      5 <link rel="help" href="https://drafts.csswg.org/css-page/#page-selectors"/>
      6 <meta name="assert" content="Test that @page selectors are parsed correctly.">
      7 <script src="/resources/testharness.js"></script>
      8 <script src="/resources/testharnessreport.js"></script>
      9 
     10 <style>
     11    @page 1 {
     12        size: 1in;
     13    }
     14    @page -3 {
     15        size: 2in;
     16    }
     17    @page --a {
     18        size: 3in;
     19    }
     20    @page 7cm {
     21        size: 4in;
     22    }
     23    @page 0.17 {
     24        size: 5in;
     25    }
     26    @page a, 123 {
     27        size: 6in;
     28    }
     29 </style>
     30 
     31 <script>
     32    const invalidSelectorTexts = [
     33        "1",
     34        "-3",
     35        "--a",
     36        "7cm",
     37        "0.17",
     38        "a, 123",
     39    ];
     40 
     41    let styleSheets = document.styleSheets;
     42    for (let sheet of styleSheets) {
     43        for (let rule of sheet.cssRules) {
     44            test(function(){
     45                assert_not_equals(rule.type, CSSRule.PAGE_RULE,
     46                    "no @page rule should have been parsed");
     47            }, "rule with invalid selector ['" + rule.selectorText + "']");
     48        }
     49    }
     50 
     51    let ruleIndex = styleSheets[0].insertRule("@page{}");
     52    let rule = styleSheets[0].cssRules[ruleIndex];
     53    test(function() {
     54        assert_equals(rule.selectorText, "", "Initial selector text should have been empty");
     55        assert_equals(rule.type, CSSRule.PAGE_RULE, "unexpected rule type (not @page)");
     56    }, "adding a blank @page rule");
     57    for (let selectorText of invalidSelectorTexts){
     58        test(function() {
     59            // Clear the selector first
     60            rule.selectorText = "";
     61            rule.selectorText = selectorText;
     62            assert_equals(rule.selectorText, "",
     63                "should not be able to assign an invalid selector");
     64        }, "assigning invalid selector text ['" + selectorText + "']");
     65    }
     66 </script>