dom/bindings/parser/tests/test_callback_interface.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/bindings/parser/tests/test_callback_interface.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     1.4 +import WebIDL
     1.5 +
     1.6 +def WebIDLTest(parser, harness):
     1.7 +    parser.parse("""
     1.8 +        callback interface TestCallbackInterface {
     1.9 +          attribute boolean bool;
    1.10 +        };
    1.11 +    """)
    1.12 +
    1.13 +    results = parser.finish()
    1.14 +
    1.15 +    iface = results[0]
    1.16 +
    1.17 +    harness.ok(iface.isCallback(), "Interface should be a callback")
    1.18 +
    1.19 +    parser = parser.reset()
    1.20 +    threw = False
    1.21 +    try:
    1.22 +        parser.parse("""
    1.23 +            interface TestInterface {
    1.24 +            };
    1.25 +            callback interface TestCallbackInterface : TestInterface {
    1.26 +              attribute boolean bool;
    1.27 +            };
    1.28 +        """)
    1.29 +        results = parser.finish()
    1.30 +    except:
    1.31 +        threw = True
    1.32 +
    1.33 +    harness.ok(threw, "Should not allow non-callback parent of callback interface")
    1.34 +
    1.35 +    parser = parser.reset()
    1.36 +    threw = False
    1.37 +    try:
    1.38 +        parser.parse("""
    1.39 +            interface TestInterface : TestCallbackInterface {
    1.40 +            };
    1.41 +            callback interface TestCallbackInterface {
    1.42 +              attribute boolean bool;
    1.43 +            };
    1.44 +        """)
    1.45 +        results = parser.finish()
    1.46 +    except:
    1.47 +        threw = True
    1.48 +
    1.49 +    harness.ok(threw, "Should not allow callback parent of non-callback interface")
    1.50 +
    1.51 +    parser = parser.reset()
    1.52 +    parser.parse("""
    1.53 +        callback interface TestCallbackInterface1 {
    1.54 +          void foo();
    1.55 +        };
    1.56 +        callback interface TestCallbackInterface2 {
    1.57 +          void foo(DOMString arg);
    1.58 +          void foo(TestCallbackInterface1 arg);
    1.59 +        };
    1.60 +        callback interface TestCallbackInterface3 {
    1.61 +          void foo(DOMString arg);
    1.62 +          void foo(TestCallbackInterface1 arg);
    1.63 +          static void bar();
    1.64 +        };
    1.65 +        callback interface TestCallbackInterface4 {
    1.66 +          void foo(DOMString arg);
    1.67 +          void foo(TestCallbackInterface1 arg);
    1.68 +          static void bar();
    1.69 +          const long baz = 5;
    1.70 +        };
    1.71 +        callback interface TestCallbackInterface5 {
    1.72 +          static attribute boolean bool;
    1.73 +          void foo();
    1.74 +        };
    1.75 +        callback interface TestCallbackInterface6 {
    1.76 +          void foo(DOMString arg);
    1.77 +          void foo(TestCallbackInterface1 arg);
    1.78 +          void bar();
    1.79 +        };
    1.80 +        callback interface TestCallbackInterface7 {
    1.81 +          static attribute boolean bool;
    1.82 +        };
    1.83 +        callback interface TestCallbackInterface8 {
    1.84 +          attribute boolean bool;
    1.85 +        };
    1.86 +        callback interface TestCallbackInterface9 : TestCallbackInterface1 {
    1.87 +          void foo();
    1.88 +        };
    1.89 +        callback interface TestCallbackInterface10 : TestCallbackInterface1 {
    1.90 +          void bar();
    1.91 +        };
    1.92 +    """)
    1.93 +    results = parser.finish()
    1.94 +    for (i, iface) in enumerate(results):
    1.95 +      harness.check(iface.isSingleOperationInterface(), i < 4,
    1.96 +                    "Interface %s should be a single operation interface" %
    1.97 +                    iface.identifier.name)

mercurial