tor-browser

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

test_observableArray.py (6871B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 
      5 
      6 def WebIDLTest(parser, harness):
      7    # Test dictionary as inner type
      8    harness.should_throw(
      9        parser,
     10        """
     11        dictionary A {
     12          boolean member;
     13        };
     14        interface B {
     15          attribute ObservableArray<A> foo;
     16        };
     17        """,
     18        "use dictionary as inner type",
     19    )
     20 
     21    # Test sequence as inner type
     22    harness.should_throw(
     23        parser,
     24        """
     25        interface A {
     26          attribute ObservableArray<sequence<boolean>> foo;
     27        };
     28        """,
     29        "use sequence as inner type",
     30    )
     31 
     32    # Test sequence<dictionary> as inner type
     33    harness.should_throw(
     34        parser,
     35        """
     36        dictionary A {
     37            boolean member;
     38        };
     39        interface B {
     40          attribute ObservableArray<sequence<A>> foo;
     41        };
     42        """,
     43        "use sequence<dictionary> as inner type",
     44    )
     45 
     46    # Test record as inner type
     47    harness.should_throw(
     48        parser,
     49        """
     50        interface A {
     51          attribute ObservableArray<record<DOMString, boolean>> foo;
     52        };
     53        """,
     54        "use record as inner type",
     55    )
     56 
     57    # Test record<dictionary> as inner type
     58    harness.should_throw(
     59        parser,
     60        """
     61        dictionary A {
     62            boolean member;
     63        };
     64        interface B {
     65          attribute ObservableArray<record<DOMString, A>> foo;
     66        };
     67        """,
     68        "use record<dictionary> as inner type",
     69    )
     70 
     71    # Test observable array as inner type
     72    harness.should_throw(
     73        parser,
     74        """
     75        interface A {
     76          attribute ObservableArray<ObservableArray<boolean>> foo;
     77        };
     78        """,
     79        "use ObservableArray as inner type",
     80    )
     81 
     82    # Test nullable attribute
     83    harness.should_throw(
     84        parser,
     85        """
     86        interface A {
     87          attribute ObservableArray<boolean>? foo;
     88        };
     89        """,
     90        "nullable",
     91    )
     92 
     93    # Test sequence
     94    harness.should_throw(
     95        parser,
     96        """
     97        interface A {
     98          undefined foo(sequence<ObservableArray<boolean>> foo);
     99        };
    100        """,
    101        "used in sequence",
    102    )
    103 
    104    # Test record
    105    harness.should_throw(
    106        parser,
    107        """
    108        interface A {
    109          undefined foo(record<DOMString, ObservableArray<boolean>> foo);
    110        };
    111        """,
    112        "used in record",
    113    )
    114 
    115    # Test promise
    116    harness.should_throw(
    117        parser,
    118        """
    119        interface A {
    120          Promise<ObservableArray<boolean>> foo();
    121        };
    122        """,
    123        "used in promise",
    124    )
    125 
    126    # Test union
    127    harness.should_throw(
    128        parser,
    129        """
    130        interface A {
    131          attribute (DOMString or ObservableArray<boolean>>) foo;
    132        };
    133        """,
    134        "used in union",
    135    )
    136 
    137    # Test dictionary member
    138    harness.should_throw(
    139        parser,
    140        """
    141        dictionary A {
    142          ObservableArray<boolean> foo;
    143        };
    144        """,
    145        "used on dictionary member type",
    146    )
    147 
    148    # Test argument
    149    harness.should_throw(
    150        parser,
    151        """
    152        interface A {
    153          undefined foo(ObservableArray<boolean> foo);
    154        };
    155        """,
    156        "used on argument",
    157    )
    158 
    159    # Test static attribute
    160    harness.should_throw(
    161        parser,
    162        """
    163        interface A {
    164          static attribute ObservableArray<boolean> foo;
    165        };
    166        """,
    167        "used on static attribute type",
    168    )
    169 
    170    # Test iterable
    171    harness.should_throw(
    172        parser,
    173        """
    174        interface A {
    175          iterable<ObservableArray<boolean>>;
    176        };
    177        """,
    178        "used in iterable",
    179    )
    180 
    181    # Test maplike
    182    harness.should_throw(
    183        parser,
    184        """
    185        interface A {
    186          maplike<long, ObservableArray<boolean>>;
    187        };
    188        """,
    189        "used in maplike",
    190    )
    191 
    192    # Test setlike
    193    harness.should_throw(
    194        parser,
    195        """
    196        interface A {
    197          setlike<ObservableArray<boolean>>;
    198        };
    199        """,
    200        "used in setlike",
    201    )
    202 
    203    # Test JS implemented interface
    204    harness.should_throw(
    205        parser,
    206        """
    207        [JSImplementation="@mozilla.org/dom/test-interface-js;1"]
    208        interface A {
    209          readonly attribute ObservableArray<boolean> foo;
    210        };
    211        """,
    212        "used in JS implemented interface",
    213    )
    214 
    215    # Test namespace
    216    harness.should_throw(
    217        parser,
    218        """
    219        namespace A {
    220          readonly attribute ObservableArray<boolean> foo;
    221        };
    222        """,
    223        "used in namespaces",
    224    )
    225 
    226    # Test [Cached] extended attribute
    227    harness.should_throw(
    228        parser,
    229        """
    230        interface A {
    231          [Cached, Pure]
    232          readonly attribute ObservableArray<boolean> foo;
    233        };
    234        """,
    235        "have Cached extended attribute",
    236    )
    237 
    238    # Test [StoreInSlot] extended attribute
    239    harness.should_throw(
    240        parser,
    241        """
    242        interface A {
    243          [StoreInSlot, Pure]
    244          readonly attribute ObservableArray<boolean> foo;
    245        };
    246        """,
    247        "have StoreInSlot extended attribute",
    248    )
    249 
    250    # Test regular attribute
    251    parser = parser.reset()
    252    parser.parse(
    253        """
    254        interface A {
    255          readonly attribute ObservableArray<boolean> foo;
    256          attribute ObservableArray<[Clamp] octet> bar;
    257          attribute ObservableArray<long?> baz;
    258          attribute ObservableArray<(boolean or long)> qux;
    259        };
    260        """
    261    )
    262    results = parser.finish()
    263    A = results[0]
    264    foo = A.members[0]
    265    harness.ok(foo.readonly, "A.foo is readonly attribute")
    266    harness.ok(foo.type.isObservableArray(), "A.foo is ObservableArray type")
    267    harness.check(
    268        foo.slotIndices[A.identifier.name], 0, "A.foo should be stored in slot"
    269    )
    270    bar = A.members[1]
    271    harness.ok(bar.type.isObservableArray(), "A.bar is ObservableArray type")
    272    harness.check(
    273        bar.slotIndices[A.identifier.name], 1, "A.bar should be stored in slot"
    274    )
    275    harness.ok(bar.type.inner.hasClamp(), "A.bar's inner type should be clamped")
    276    baz = A.members[2]
    277    harness.ok(baz.type.isObservableArray(), "A.baz is ObservableArray type")
    278    harness.check(
    279        baz.slotIndices[A.identifier.name], 2, "A.baz should be stored in slot"
    280    )
    281    harness.ok(baz.type.inner.nullable(), "A.baz's inner type should be nullable")
    282    qux = A.members[3]
    283    harness.ok(qux.type.isObservableArray(), "A.qux is ObservableArray type")
    284    harness.check(
    285        qux.slotIndices[A.identifier.name], 3, "A.qux should be stored in slot"
    286    )
    287    harness.ok(qux.type.inner.isUnion(), "A.qux's inner type should be union")