tor-browser

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

test_lenientSetter.py (2156B)


      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 import WebIDL
      6 
      7 
      8 def should_throw(parser, harness, message, code):
      9    parser = parser.reset()
     10    threw = False
     11    try:
     12        parser.parse(code)
     13        parser.finish()
     14    except WebIDL.WebIDLError:
     15        threw = True
     16 
     17    harness.ok(threw, "Should have thrown: %s" % message)
     18 
     19 
     20 def WebIDLTest(parser, harness):
     21    # The [LegacyLenientSetter] extended attribute MUST take no arguments.
     22    should_throw(
     23        parser,
     24        harness,
     25        "no arguments",
     26        """
     27        interface I {
     28          [LegacyLenientSetter=X] readonly attribute long A;
     29        };
     30    """,
     31    )
     32 
     33    # An attribute with the [LegacyLenientSetter] extended attribute MUST NOT
     34    # also be declared with the [PutForwards] extended attribute.
     35    should_throw(
     36        parser,
     37        harness,
     38        "PutForwards",
     39        """
     40        interface I {
     41          [PutForwards=B, LegacyLenientSetter] readonly attribute J A;
     42        };
     43        interface J {
     44          attribute long B;
     45        };
     46    """,
     47    )
     48 
     49    # An attribute with the [LegacyLenientSetter] extended attribute MUST NOT
     50    # also be declared with the [Replaceable] extended attribute.
     51    should_throw(
     52        parser,
     53        harness,
     54        "Replaceable",
     55        """
     56        interface I {
     57          [Replaceable, LegacyLenientSetter] readonly attribute J A;
     58        };
     59    """,
     60    )
     61 
     62    # The [LegacyLenientSetter] extended attribute MUST NOT be used on an
     63    # attribute that is not read only.
     64    should_throw(
     65        parser,
     66        harness,
     67        "writable attribute",
     68        """
     69        interface I {
     70          [LegacyLenientSetter] attribute long A;
     71        };
     72    """,
     73    )
     74 
     75    # The [LegacyLenientSetter] extended attribute MUST NOT be used on a
     76    # static attribute.
     77    should_throw(
     78        parser,
     79        harness,
     80        "static attribute",
     81        """
     82        interface I {
     83          [LegacyLenientSetter] static readonly attribute long A;
     84        };
     85    """,
     86    )