tor-browser

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

test_special_methods.py (3270B)


      1 import WebIDL
      2 
      3 
      4 def WebIDLTest(parser, harness):
      5    parser.parse(
      6        """
      7        interface SpecialMethods {
      8          getter long long (unsigned long index);
      9          setter undefined (unsigned long index, long long value);
     10          getter boolean (DOMString name);
     11          setter undefined (DOMString name, boolean value);
     12          deleter undefined (DOMString name);
     13          readonly attribute unsigned long length;
     14        };
     15    """
     16    )
     17 
     18    results = parser.finish()
     19 
     20    def checkMethod(
     21        method,
     22        QName,
     23        name,
     24        static=False,
     25        getter=False,
     26        setter=False,
     27        deleter=False,
     28        legacycaller=False,
     29        stringifier=False,
     30    ):
     31        harness.ok(isinstance(method, WebIDL.IDLMethod), "Should be an IDLMethod")
     32        harness.check(method.identifier.QName(), QName, "Method has the right QName")
     33        harness.check(method.identifier.name, name, "Method has the right name")
     34        harness.check(method.isStatic(), static, "Method has the correct static value")
     35        harness.check(method.isGetter(), getter, "Method has the correct getter value")
     36        harness.check(method.isSetter(), setter, "Method has the correct setter value")
     37        harness.check(
     38            method.isDeleter(), deleter, "Method has the correct deleter value"
     39        )
     40        harness.check(
     41            method.isLegacycaller(),
     42            legacycaller,
     43            "Method has the correct legacycaller value",
     44        )
     45        harness.check(
     46            method.isStringifier(),
     47            stringifier,
     48            "Method has the correct stringifier value",
     49        )
     50 
     51    harness.check(len(results), 1, "Expect 1 interface")
     52 
     53    iface = results[0]
     54    harness.check(len(iface.members), 6, "Expect 6 members")
     55 
     56    checkMethod(
     57        iface.members[0],
     58        "::SpecialMethods::__indexedgetter",
     59        "__indexedgetter",
     60        getter=True,
     61    )
     62    checkMethod(
     63        iface.members[1],
     64        "::SpecialMethods::__indexedsetter",
     65        "__indexedsetter",
     66        setter=True,
     67    )
     68    checkMethod(
     69        iface.members[2],
     70        "::SpecialMethods::__namedgetter",
     71        "__namedgetter",
     72        getter=True,
     73    )
     74    checkMethod(
     75        iface.members[3],
     76        "::SpecialMethods::__namedsetter",
     77        "__namedsetter",
     78        setter=True,
     79    )
     80    checkMethod(
     81        iface.members[4],
     82        "::SpecialMethods::__nameddeleter",
     83        "__nameddeleter",
     84        deleter=True,
     85    )
     86 
     87    parser = parser.reset()
     88 
     89    threw = False
     90    try:
     91        parser.parse(
     92            """
     93            interface SpecialMethodsCombination {
     94              getter deleter boolean (DOMString name);
     95            };
     96            """
     97        )
     98        parser.finish()
     99    except WebIDL.WebIDLError:
    100        threw = True
    101 
    102    harness.ok(
    103        threw, "Should not allow combining a getter and a deleter in a single operation"
    104    )
    105 
    106    parser = parser.reset()
    107 
    108    threw = False
    109    try:
    110        parser.parse(
    111            """
    112            interface IndexedDeleter {
    113              deleter undefined(unsigned long index);
    114            };
    115            """
    116        )
    117        parser.finish()
    118    except WebIDL.WebIDLError:
    119        threw = True
    120 
    121    harness.ok(threw, "There are no indexed deleters")