tor-browser

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

selectorSerialize.html (7888B)


      1 <!DOCTYPE html>
      2 <html>
      3    <head>
      4        <title>CSSOM Test: test serialized selector which is only one simple selector in the sequence of simple selectors</title>
      5        <link rel="author" title="T.Nishitani" href="mailto:lequinharay@gmail.com">
      6        <link rel="reviewer" title="L. David Baron" href="https://dbaron.org/">
      7        <link rel="help" href="https://drafts.csswg.org/cssom-1/#serializing-selectors">
      8        <meta name="flags" content="dom">
      9        <meta charset="utf-8">
     10        <script src="/resources/testharness.js"></script>
     11        <script src="/resources/testharnessreport.js"></script>
     12        <style id="teststyles">
     13        </style>
     14    </head>
     15    <body>
     16        <div id="log"></div>
     17        <script>
     18            function assert_selector_serializes_to(source, expected_result) {
     19              var style_element = document.getElementById("teststyles");
     20              style_element.firstChild.data = source + "{ font-size: 1em; }";
     21              var sheet = style_element.sheet;
     22              assert_equals(sheet.cssRules[sheet.cssRules.length - 1].selectorText, expected_result);
     23            }
     24 
     25            function run_tests_on_anplusb_selector(source) {
     26                assert_selector_serializes_to(source + '( even   )', source + '(2n)');
     27                assert_selector_serializes_to(source + '(   odd )', source + '(2n+1)');
     28                assert_selector_serializes_to(source + '( +10  )', source + '(10)');
     29                assert_selector_serializes_to(source + '(   -10 )', source + '(-10)');
     30                assert_selector_serializes_to(source + '( +4n  )', source + '(4n)');
     31                assert_selector_serializes_to(source + '( -3n   )', source + '(-3n)');
     32                assert_selector_serializes_to(source + '( 1n + 5  )', source + '(n+5)');
     33                assert_selector_serializes_to(source + '( -1n +     5 )', source + '(-n+5)');
     34                assert_selector_serializes_to(source + '( -1n     - 5 )', source + '(-n-5)');
     35            }
     36 
     37            test(function() {
     38              assert_selector_serializes_to(":nth-child(  3n - 0)", ":nth-child(3n)");
     39              assert_selector_serializes_to(":nth-child(  1n - 0)", ":nth-child(n)");
     40            }, ":nth-child serialization produces canonical form");
     41 
     42 
     43            /* for universal selecter with default namespace */
     44            test(function(){
     45                /* this is single universal selector */
     46                assert_selector_serializes_to('*', '*');
     47                assert_selector_serializes_to(' * ', '*');
     48            }, 'single universal selector shows \'*\' when serialized.')
     49 
     50            test(function(){
     51                assert_selector_serializes_to('div', 'div');
     52                assert_selector_serializes_to(' div ', 'div');
     53            }, 'single type (simple) selector in the sequence of simple selectors that is not a universal selector')
     54 
     55            test(function(){
     56                assert_selector_serializes_to('.class', '.class');
     57                assert_selector_serializes_to(' .class    ', '.class');
     58            }, 'single class (simple) selector in the sequence of simple selectors that is not a universal selector')
     59 
     60            test(function(){
     61                assert_selector_serializes_to('#id', '#id');
     62                assert_selector_serializes_to('     #id ', '#id');
     63            }, 'single id (simple) selector in the sequence of simple selectors that is not a universal selector')
     64 
     65            test(function(){
     66                assert_selector_serializes_to(':hover', ':hover');
     67                assert_selector_serializes_to('    :hover    ', ':hover');
     68            }, 'single pseudo (simple) selector which does not accept arguments in the sequence of simple selectors that is not a universal selector')
     69 
     70            test(function(){
     71                assert_selector_serializes_to(':lang(ja)', ':lang(ja)');
     72                assert_selector_serializes_to(':lang( ja )', ':lang(ja)');
     73                assert_selector_serializes_to(':lang( j\\ a )', ':lang(j\\ a)');
     74            }, 'single pseudo (simple) selector "lang" which accepts arguments in the sequence of simple selectors that is not a universal selector')
     75 
     76 
     77            test(function(){
     78                run_tests_on_anplusb_selector(':nth-child');
     79            }, 'single pseudo (simple) selector "nth-child" which accepts arguments in the sequence of simple selectors that is not a universal selector')
     80 
     81            test(function(){
     82                run_tests_on_anplusb_selector(':nth-last-child');
     83            }, 'single pseudo (simple) selector "nth-last-child" which accepts arguments in the sequence of simple selectors that is not a universal selector')
     84 
     85            test(function(){
     86                run_tests_on_anplusb_selector(':nth-of-type');
     87            }, 'single pseudo (simple) selector "nth-of-child" which accepts arguments in the sequence of simple selectors that is not a universal selector')
     88 
     89            test(function(){
     90                run_tests_on_anplusb_selector(':nth-last-of-type');
     91            }, 'single pseudo (simple) selector ":nth-last-of-type" which accepts arguments in the sequence of simple selectors that is not a universal selector')
     92 
     93            test(function(){
     94                assert_selector_serializes_to(' :not( abc ) ', ':not(abc)');
     95                assert_selector_serializes_to(' :not(  .head ) ', ':not(.head)');
     96                assert_selector_serializes_to(' :not(  #head   ) ', ':not(#head)');
     97                assert_selector_serializes_to(' :not(  :hover   ) ', ':not(:hover)');
     98            }, 'single pseudo (simple) selector ":not" which accepts arguments in the sequence of simple selectors that is not a universal selector')
     99 
    100            const escaped_ns_rule = "@namespace ns\\:odd url(ns);";
    101            test(function() {
    102                assert_selector_serializes_to("[ns\\:foo]", "[ns\\:foo]");
    103            }, "escaped character in attribute name");
    104            test(function() {
    105                assert_selector_serializes_to("[\\30zonk]", "[\\30 zonk]");
    106            }, "escaped character as code point in attribute name");
    107            test(function() {
    108                assert_selector_serializes_to("[\\@]", "[\\@]");
    109            }, "escaped character (@) in attribute name");
    110            test(function() {
    111                assert_selector_serializes_to("[*|ns\\:foo]", "[*|ns\\:foo]");
    112            }, "escaped character in attribute name with any namespace");
    113            test(function() {
    114                assert_selector_serializes_to(escaped_ns_rule + "[ns\\:odd|foo]", "[ns\\:odd|foo]");
    115            }, "escaped character in attribute prefix");
    116            test(function() {
    117                assert_selector_serializes_to(escaped_ns_rule + "[ns\\:odd|odd\\:name]", "[ns\\:odd|odd\\:name]");
    118            }, "escaped character in both attribute prefix and name");
    119 
    120            test(() => {
    121              assert_selector_serializes_to("\\\\", "\\\\");
    122            }, "escaped character (\\) in element name");
    123            test(() => {
    124              assert_selector_serializes_to("*|\\\\", "\\\\");
    125            }, "escaped character (\\) in element name with any namespace without default");
    126            test(() => {
    127              assert_selector_serializes_to("@namespace 'blah'; *|\\\\", "*|\\\\");
    128            }, "escaped character (\\) in element name with any namespace with default");
    129            test(() => {
    130              assert_selector_serializes_to("|\\\\", "|\\\\");
    131            }, "escaped character (\\) in element name with no namespace");
    132 
    133            const element_escaped_ns_rule = "@namespace x\\* 'blah';";
    134            test(() => {
    135              assert_selector_serializes_to(element_escaped_ns_rule + "x\\*|test", "x\\*|test");
    136            }, "escaped character (*) in element prefix");
    137 
    138            // TODO: https://github.com/w3c/csswg-drafts/issues/8911
    139        </script>
    140    </body>
    141 </html>