tor-browser

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

test_global_extended_attr.py (3276B)


      1 import WebIDL
      2 
      3 
      4 def WebIDLTest(parser, harness):
      5    parser.parse(
      6        """
      7      [Global=Foo, Exposed=Foo]
      8      interface Foo : Bar {
      9        getter any(DOMString name);
     10      };
     11      [Exposed=Foo]
     12      interface Bar {};
     13    """
     14    )
     15 
     16    results = parser.finish()
     17 
     18    harness.ok(
     19        results[0].isOnGlobalProtoChain(),
     20        "[Global] interface should be on global's proto chain",
     21    )
     22    harness.ok(
     23        results[1].isOnGlobalProtoChain(),
     24        "[Global] interface should be on global's proto chain",
     25    )
     26 
     27    parser = parser.reset()
     28    threw = False
     29    try:
     30        parser.parse(
     31            """
     32          [Global=Foo, Exposed=Foo]
     33          interface Foo {
     34            getter any(DOMString name);
     35            setter undefined(DOMString name, any arg);
     36          };
     37        """
     38        )
     39        parser.finish()
     40    except WebIDL.WebIDLError:
     41        threw = True
     42 
     43    harness.ok(
     44        threw,
     45        "Should have thrown for [Global] used on an interface with a named setter",
     46    )
     47 
     48    parser = parser.reset()
     49    threw = False
     50    try:
     51        parser.parse(
     52            """
     53          [Global=Foo, Exposed=Foo]
     54          interface Foo {
     55            getter any(DOMString name);
     56            deleter undefined(DOMString name);
     57          };
     58        """
     59        )
     60        parser.finish()
     61    except WebIDL.WebIDLError:
     62        threw = True
     63 
     64    harness.ok(
     65        threw,
     66        "Should have thrown for [Global] used on an interface with a named deleter",
     67    )
     68 
     69    parser = parser.reset()
     70    threw = False
     71    try:
     72        parser.parse(
     73            """
     74          [Global=Foo, LegacyOverrideBuiltIns, Exposed=Foo]
     75          interface Foo {
     76          };
     77        """
     78        )
     79        parser.finish()
     80    except WebIDL.WebIDLError:
     81        threw = True
     82 
     83    harness.ok(
     84        threw,
     85        "Should have thrown for [Global] used on an interface with a "
     86        "[LegacyOverrideBuiltIns]",
     87    )
     88 
     89    parser = parser.reset()
     90    threw = False
     91    try:
     92        parser.parse(
     93            """
     94          [Global=Foo, Exposed=Foo]
     95          interface Foo : Bar {
     96          };
     97          [LegacyOverrideBuiltIns, Exposed=Foo]
     98          interface Bar {
     99          };
    100        """
    101        )
    102        parser.finish()
    103    except WebIDL.WebIDLError:
    104        threw = True
    105 
    106    harness.ok(
    107        threw,
    108        "Should have thrown for [Global] used on an interface with an "
    109        "[LegacyOverrideBuiltIns] ancestor",
    110    )
    111 
    112    parser = parser.reset()
    113    threw = False
    114    try:
    115        parser.parse(
    116            """
    117          [Global=Foo, Exposed=Foo]
    118          interface Foo {
    119          };
    120          [Exposed=Foo]
    121          interface Bar : Foo {
    122          };
    123        """
    124        )
    125        parser.finish()
    126    except WebIDL.WebIDLError:
    127        threw = True
    128 
    129    harness.ok(
    130        threw,
    131        "Should have thrown for [Global] used on an interface with a descendant",
    132    )
    133 
    134    parser = parser.reset()
    135    threw = False
    136    try:
    137        parser.parse(
    138            """
    139          [Global, Exposed=Foo]
    140          interface Foo {
    141          };
    142        """
    143        )
    144        parser.finish()
    145    except WebIDL.WebIDLError:
    146        threw = True
    147 
    148    harness.ok(
    149        threw,
    150        "Should have thrown for [Global] without a right hand side value",
    151    )