tor-browser

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

test_exposed_extended_attribute.py (9989B)


      1 import WebIDL
      2 
      3 
      4 def WebIDLTest(parser, harness):
      5    parser.parse(
      6        """
      7      [Global=Foo, Exposed=Foo] interface Foo {};
      8      [Global=(Bar, Bar1,Bar2), Exposed=Bar] interface Bar {};
      9      [Global=(Baz, Baz2), Exposed=Baz] interface Baz {};
     10 
     11      [Exposed=(Foo,Bar1)]
     12      interface Iface {
     13        undefined method1();
     14 
     15        [Exposed=Bar1]
     16        readonly attribute any attr;
     17      };
     18 
     19      [Exposed=Foo]
     20      partial interface Iface {
     21        undefined method2();
     22      };
     23    """
     24    )
     25 
     26    results = parser.finish()
     27 
     28    harness.check(len(results), 5, "Should know about five things")
     29    iface = results[3]
     30    harness.ok(isinstance(iface, WebIDL.IDLInterface), "Should have an interface here")
     31    members = iface.members
     32    harness.check(len(members), 3, "Should have three members")
     33 
     34    harness.ok(
     35        members[0].exposureSet == set(["Foo", "Bar"]),
     36        "method1 should have the right exposure set",
     37    )
     38    harness.ok(
     39        members[0]._exposureGlobalNames == set(["Foo", "Bar1"]),
     40        "method1 should have the right exposure global names",
     41    )
     42 
     43    harness.ok(
     44        members[1].exposureSet == set(["Bar"]),
     45        "attr should have the right exposure set",
     46    )
     47    harness.ok(
     48        members[1]._exposureGlobalNames == set(["Bar1"]),
     49        "attr should have the right exposure global names",
     50    )
     51 
     52    harness.ok(
     53        members[2].exposureSet == set(["Foo"]),
     54        "method2 should have the right exposure set",
     55    )
     56    harness.ok(
     57        members[2]._exposureGlobalNames == set(["Foo"]),
     58        "method2 should have the right exposure global names",
     59    )
     60 
     61    harness.ok(
     62        iface.exposureSet == set(["Foo", "Bar"]),
     63        "Iface should have the right exposure set",
     64    )
     65    harness.ok(
     66        iface._exposureGlobalNames == set(["Foo", "Bar1"]),
     67        "Iface should have the right exposure global names",
     68    )
     69 
     70    parser = parser.reset()
     71    parser.parse(
     72        """
     73      [Global=Foo, Exposed=Foo] interface Foo {};
     74      [Global=(Bar, Bar1, Bar2), Exposed=Bar] interface Bar {};
     75      [Global=(Baz, Baz2), Exposed=Baz] interface Baz {};
     76 
     77      [Exposed=Foo]
     78      interface Iface2 {
     79        undefined method3();
     80      };
     81    """
     82    )
     83    results = parser.finish()
     84 
     85    harness.check(len(results), 4, "Should know about four things")
     86    iface = results[3]
     87    harness.ok(isinstance(iface, WebIDL.IDLInterface), "Should have an interface here")
     88    members = iface.members
     89    harness.check(len(members), 1, "Should have one member")
     90 
     91    harness.ok(
     92        members[0].exposureSet == set(["Foo"]),
     93        "method3 should have the right exposure set",
     94    )
     95    harness.ok(
     96        members[0]._exposureGlobalNames == set(["Foo"]),
     97        "method3 should have the right exposure global names",
     98    )
     99 
    100    harness.ok(
    101        iface.exposureSet == set(["Foo"]), "Iface2 should have the right exposure set"
    102    )
    103    harness.ok(
    104        iface._exposureGlobalNames == set(["Foo"]),
    105        "Iface2 should have the right exposure global names",
    106    )
    107 
    108    parser = parser.reset()
    109    parser.parse(
    110        """
    111      [Global=Foo, Exposed=Foo] interface Foo {};
    112      [Global=(Bar, Bar1, Bar2), Exposed=Bar] interface Bar {};
    113      [Global=(Baz, Baz2), Exposed=Baz] interface Baz {};
    114 
    115      [Exposed=Foo]
    116      interface Iface3 {
    117        undefined method4();
    118      };
    119 
    120      [Exposed=(Foo,Bar1)]
    121      interface mixin Mixin {
    122        undefined method5();
    123      };
    124 
    125      Iface3 includes Mixin;
    126    """
    127    )
    128    results = parser.finish()
    129    harness.check(len(results), 6, "Should know about six things")
    130    iface = results[3]
    131    harness.ok(isinstance(iface, WebIDL.IDLInterface), "Should have an interface here")
    132    members = iface.members
    133    harness.check(len(members), 2, "Should have two members")
    134 
    135    harness.ok(
    136        members[0].exposureSet == set(["Foo"]),
    137        "method4 should have the right exposure set",
    138    )
    139    harness.ok(
    140        members[0]._exposureGlobalNames == set(["Foo"]),
    141        "method4 should have the right exposure global names",
    142    )
    143 
    144    harness.ok(
    145        members[1].exposureSet == set(["Foo", "Bar"]),
    146        "method5 should have the right exposure set",
    147    )
    148    harness.ok(
    149        members[1]._exposureGlobalNames == set(["Foo", "Bar1"]),
    150        "method5 should have the right exposure global names",
    151    )
    152 
    153    parser = parser.reset()
    154    threw = False
    155    try:
    156        parser.parse(
    157            """
    158            [Exposed=Foo]
    159            interface Bar {
    160            };
    161        """
    162        )
    163 
    164        results = parser.finish()
    165    except WebIDL.WebIDLError:
    166        threw = True
    167 
    168    harness.ok(threw, "Should have thrown on invalid Exposed value on interface.")
    169 
    170    parser = parser.reset()
    171    threw = False
    172    try:
    173        parser.parse(
    174            """
    175            interface Bar {
    176              [Exposed=Foo]
    177              readonly attribute bool attr;
    178            };
    179        """
    180        )
    181 
    182        results = parser.finish()
    183    except WebIDL.WebIDLError:
    184        threw = True
    185 
    186    harness.ok(threw, "Should have thrown on invalid Exposed value on attribute.")
    187 
    188    parser = parser.reset()
    189    threw = False
    190    try:
    191        parser.parse(
    192            """
    193            interface Bar {
    194              [Exposed=Foo]
    195              undefined operation();
    196            };
    197        """
    198        )
    199 
    200        results = parser.finish()
    201    except WebIDL.WebIDLError:
    202        threw = True
    203 
    204    harness.ok(threw, "Should have thrown on invalid Exposed value on operation.")
    205 
    206    parser = parser.reset()
    207    threw = False
    208    try:
    209        parser.parse(
    210            """
    211            interface Bar {
    212              [Exposed=Foo]
    213              const long constant = 5;
    214            };
    215        """
    216        )
    217 
    218        results = parser.finish()
    219    except WebIDL.WebIDLError:
    220        threw = True
    221 
    222    harness.ok(threw, "Should have thrown on invalid Exposed value on constant.")
    223 
    224    parser = parser.reset()
    225    threw = False
    226    try:
    227        parser.parse(
    228            """
    229            [Global=Foo, Exposed=Foo] interface Foo {};
    230            [Global=Bar, Exposed=Bar] interface Bar {};
    231 
    232            [Exposed=Foo]
    233            interface Baz {
    234              [Exposed=Bar]
    235              undefined method();
    236            };
    237        """
    238        )
    239 
    240        results = parser.finish()
    241    except WebIDL.WebIDLError:
    242        threw = True
    243 
    244    harness.ok(
    245        threw, "Should have thrown on member exposed where its interface is not."
    246    )
    247 
    248    parser = parser.reset()
    249    parser.parse(
    250        """
    251        [Global=Foo, Exposed=Foo] interface Foo {};
    252        [Global=Bar, Exposed=Bar] interface Bar {};
    253 
    254        [Exposed=Foo]
    255        interface Baz {
    256          undefined method();
    257        };
    258 
    259        [Exposed=Bar]
    260        interface mixin Mixin {
    261          undefined otherMethod();
    262        };
    263 
    264        Baz includes Mixin;
    265    """
    266    )
    267 
    268    results = parser.finish()
    269 
    270    harness.check(len(results), 5, "Should know about five things")
    271    iface = results[2]
    272    harness.ok(isinstance(iface, WebIDL.IDLInterface), "Should have an interface here")
    273    members = iface.members
    274    harness.check(len(members), 2, "Should have two members")
    275 
    276    harness.ok(
    277        members[0].exposureSet == set(["Foo"]),
    278        "method should have the right exposure set",
    279    )
    280    harness.ok(
    281        members[0]._exposureGlobalNames == set(["Foo"]),
    282        "method should have the right exposure global names",
    283    )
    284 
    285    harness.ok(
    286        members[1].exposureSet == set(["Bar"]),
    287        "otherMethod should have the right exposure set",
    288    )
    289    harness.ok(
    290        members[1]._exposureGlobalNames == set(["Bar"]),
    291        "otherMethod should have the right exposure global names",
    292    )
    293 
    294    parser = parser.reset()
    295    parser.parse(
    296        """
    297        [Global=Foo, Exposed=Foo] interface Foo {};
    298        [Global=Bar, Exposed=Bar] interface Bar {};
    299 
    300        [Exposed=*]
    301        interface Baz {
    302          undefined methodWild();
    303        };
    304 
    305        [Exposed=Bar]
    306        interface mixin Mixin {
    307          undefined methodNotWild();
    308        };
    309 
    310        Baz includes Mixin;
    311    """
    312    )
    313 
    314    results = parser.finish()
    315 
    316    harness.check(len(results), 5, "Should know about five things")
    317    iface = results[2]
    318    harness.ok(isinstance(iface, WebIDL.IDLInterface), "Should have an interface here")
    319    members = iface.members
    320    harness.check(len(members), 2, "Should have two members")
    321 
    322    harness.ok(
    323        members[0].exposureSet == set(["Foo", "Bar"]),
    324        "methodWild should have the right exposure set",
    325    )
    326    harness.ok(
    327        members[0]._exposureGlobalNames == set(["Foo", "Bar"]),
    328        "methodWild should have the right exposure global names",
    329    )
    330 
    331    harness.ok(
    332        members[1].exposureSet == set(["Bar"]),
    333        "methodNotWild should have the right exposure set",
    334    )
    335    harness.ok(
    336        members[1]._exposureGlobalNames == set(["Bar"]),
    337        "methodNotWild should have the right exposure global names",
    338    )
    339 
    340    parser = parser.reset()
    341    threw = False
    342    try:
    343        parser.parse(
    344            """
    345            [Global=Foo, Exposed=Foo] interface Foo {};
    346            [Global=Bar, Exposed=Bar] interface Bar {};
    347 
    348            [Exposed=Foo]
    349            interface Baz {
    350              [Exposed=*]
    351              undefined method();
    352            };
    353        """
    354        )
    355 
    356        results = parser.finish()
    357    except WebIDL.WebIDLError:
    358        threw = True
    359 
    360    harness.ok(
    361        threw, "Should have thrown on member exposed where its interface is not."
    362    )
    363 
    364    parser = parser.reset()
    365    threw = False
    366    try:
    367        parser.parse(
    368            """
    369            [Global=Foo, Exposed=Foo] interface Foo {};
    370            [Global=Bar, Exposed=Bar] interface Bar {};
    371 
    372            [Exposed=(Foo,*)]
    373            interface Baz {
    374              undefined method();
    375            };
    376        """
    377        )
    378 
    379        results = parser.finish()
    380    except WebIDL.WebIDLError:
    381        threw = True
    382 
    383    harness.ok(threw, "Should have thrown on a wildcard in an identifier list.")