tor-browser

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

test_reflected_attribute.py (5778B)


      1 import WebIDL
      2 
      3 
      4 def WebIDLTest(parser, harness):
      5    def parseWithNode(test):
      6        parser.parse(
      7            """
      8            interface Node {};
      9            interface Document : Node {};
     10            interface Element : Node {};
     11            interface HTMLElement : Element {};
     12            """
     13            + test
     14        )
     15 
     16    def parseFrozenArrayAttribute(innerType):
     17        parseWithNode(
     18            """
     19            interface ReflectedAttribute {
     20               [Frozen, ReflectedHTMLAttributeReturningFrozenArray]
     21               attribute sequence<%s>? reflectedHTMLAttribute;
     22            };
     23            """
     24            % innerType
     25        )
     26 
     27        results = parser.finish()
     28 
     29        harness.check(len(results), 5, "Should know about one thing")
     30        harness.ok(
     31            isinstance(results[4], WebIDL.IDLInterface), "Should have an interface here"
     32        )
     33        members = results[4].members
     34        harness.check(len(members), 1, "Should have one member")
     35        harness.ok(members[0].isAttr(), "Should have attribute")
     36        harness.ok(
     37            members[0].getExtendedAttribute(
     38                "ReflectedHTMLAttributeReturningFrozenArray"
     39            )
     40            is not None,
     41            "Should have extended attribute",
     42        )
     43 
     44    parseFrozenArrayAttribute("Element")
     45 
     46    parser = parser.reset()
     47    parseFrozenArrayAttribute("HTMLElement")
     48 
     49    parser = parser.reset()
     50    threw = False
     51    try:
     52        parseWithNode(
     53            """
     54            interface ReflectedAttribute {
     55              [ReflectedHTMLAttributeReturningFrozenArray]
     56              attribute Element? reflectedHTMLAttribute;
     57            };
     58            """
     59        )
     60 
     61        parser.finish()
     62    except WebIDL.WebIDLError:
     63        threw = True
     64    harness.ok(
     65        threw,
     66        "Should have thrown because [ReflectedHTMLAttributeReturningFrozenArray] "
     67        "should only be used on attributes with a sequence<*Element> type.",
     68    )
     69 
     70    parser = parser.reset()
     71    threw = False
     72    try:
     73        parseWithNode(
     74            """
     75            interface ReflectedAttribute {
     76              [Frozen, ReflectedHTMLAttributeReturningFrozenArray]
     77              attribute sequence<long> reflectedHTMLAttribute;
     78            };
     79            """
     80        )
     81 
     82        parser.finish()
     83    except WebIDL.WebIDLError:
     84        threw = True
     85    harness.ok(
     86        threw,
     87        "Should have thrown because [ReflectedHTMLAttributeReturningFrozenArray] "
     88        "should only be used on attributes with a sequence<*Element> type.",
     89    )
     90 
     91    parser = parser.reset()
     92    threw = False
     93    try:
     94        parseWithNode(
     95            """
     96            interface ReflectedAttribute {
     97              [Frozen, ReflectedHTMLAttributeReturningFrozenArray]
     98              attribute sequence<Document> reflectedHTMLAttribute;
     99            };
    100            """
    101        )
    102 
    103        parser.finish()
    104    except WebIDL.WebIDLError:
    105        threw = True
    106    harness.ok(
    107        threw,
    108        "Should have thrown because [ReflectedHTMLAttributeReturningFrozenArray] "
    109        "should only be used on attributes with a sequence<*Element> type.",
    110    )
    111 
    112    parser = parser.reset()
    113    threw = False
    114    try:
    115        parseWithNode(
    116            """
    117            interface ReflectedAttribute {
    118              [ReflectedHTMLAttributeReturningFrozenArray]
    119              sequence<Element>? reflectedHTMLAttribute();
    120            };
    121            """
    122        )
    123 
    124        parser.finish()
    125    except WebIDL.WebIDLError:
    126        threw = True
    127    harness.ok(
    128        threw,
    129        "Should have thrown because [ReflectedHTMLAttributeReturningFrozenArray] "
    130        "should only be used on attributes with a sequence<*Element> type.",
    131    )
    132 
    133    parser = parser.reset()
    134    threw = False
    135    try:
    136        parseWithNode(
    137            """
    138            interface ReflectedAttribute {
    139              [Frozen, ReflectedHTMLAttributeReturningFrozenArray, Cached, Pure]
    140              attribute sequence<Element>? reflectedHTMLAttribute;
    141            };
    142            """
    143        )
    144 
    145        parser.finish()
    146    except WebIDL.WebIDLError:
    147        threw = True
    148    harness.ok(
    149        threw,
    150        "Should have thrown because [ReflectedHTMLAttributeReturningFrozenArray] "
    151        "should not be used together with [Cached].",
    152    )
    153 
    154    parser = parser.reset()
    155    threw = False
    156    try:
    157        parseWithNode(
    158            """
    159            interface ReflectedAttribute {
    160              [Frozen, ReflectedHTMLAttributeReturningFrozenArray, StoreInSlot, Pure]
    161              attribute sequence<Element>? reflectedHTMLAttribute;
    162            };
    163            """
    164        )
    165 
    166        parser.finish()
    167    except WebIDL.WebIDLError:
    168        threw = True
    169    harness.ok(
    170        threw,
    171        "Should have thrown because [ReflectedHTMLAttributeReturningFrozenArray] "
    172        "should not be used together with [Cached].",
    173    )
    174 
    175    parser = parser.reset()
    176    threw = False
    177    try:
    178        parseWithNode(
    179            """
    180            interface ReflectedAttributeBase {
    181              [Frozen, ReflectedHTMLAttributeReturningFrozenArray]
    182              attribute sequence<Element>? reflectedHTMLAttributeBase;
    183            };
    184            interface ReflectedAttribute : ReflectedAttributeBase {
    185              [Frozen, ReflectedHTMLAttributeReturningFrozenArray]
    186              attribute sequence<Element>? reflectedHTMLAttribute;
    187            };
    188            """
    189        )
    190 
    191        parser.finish()
    192    except WebIDL.WebIDLError:
    193        threw = True
    194    harness.ok(
    195        threw,
    196        "Should have thrown because [ReflectedHTMLAttributeReturningFrozenArray] "
    197        "should not be used on the attribute of an interface that inherits from "
    198        "an interface that also has an attribute with "
    199        "[ReflectedHTMLAttributeReturningFrozenArray].",
    200    )