dom/bindings/parser/tests/test_unforgeable.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/bindings/parser/tests/test_unforgeable.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,193 @@
     1.4 +def WebIDLTest(parser, harness):
     1.5 +    parser.parse("""
     1.6 +            interface Child : Parent {
     1.7 +            };
     1.8 +            interface Parent {
     1.9 +              [Unforgeable] readonly attribute long foo;
    1.10 +            };
    1.11 +        """)
    1.12 +
    1.13 +    results = parser.finish()
    1.14 +    harness.check(len(results), 2,
    1.15 +                  "Should be able to inherit from an interface with "
    1.16 +                  "[Unforgeable] properties.")
    1.17 +
    1.18 +    parser = parser.reset();
    1.19 +    parser.parse("""
    1.20 +            interface Child : Parent {
    1.21 +              const short foo = 10;
    1.22 +            };
    1.23 +            interface Parent {
    1.24 +              [Unforgeable] readonly attribute long foo;
    1.25 +            };
    1.26 +        """)
    1.27 +
    1.28 +    results = parser.finish()
    1.29 +    harness.check(len(results), 2,
    1.30 +                  "Should be able to inherit from an interface with "
    1.31 +                  "[Unforgeable] properties even if we have a constant with "
    1.32 +                  "the same name.")
    1.33 +
    1.34 +    parser = parser.reset();
    1.35 +    parser.parse("""
    1.36 +            interface Child : Parent {
    1.37 +              static attribute short foo;
    1.38 +            };
    1.39 +            interface Parent {
    1.40 +              [Unforgeable] readonly attribute long foo;
    1.41 +            };
    1.42 +        """)
    1.43 +
    1.44 +    results = parser.finish()
    1.45 +    harness.check(len(results), 2,
    1.46 +                  "Should be able to inherit from an interface with "
    1.47 +                  "[Unforgeable] properties even if we have a static attribute "
    1.48 +                  "with the same name.")
    1.49 +
    1.50 +    parser = parser.reset();
    1.51 +    parser.parse("""
    1.52 +            interface Child : Parent {
    1.53 +              static void foo();
    1.54 +            };
    1.55 +            interface Parent {
    1.56 +              [Unforgeable] readonly attribute long foo;
    1.57 +            };
    1.58 +        """)
    1.59 +
    1.60 +    results = parser.finish()
    1.61 +    harness.check(len(results), 2,
    1.62 +                  "Should be able to inherit from an interface with "
    1.63 +                  "[Unforgeable] properties even if we have a static operation "
    1.64 +                  "with the same name.")
    1.65 +
    1.66 +    parser = parser.reset();
    1.67 +    threw = False
    1.68 +    try:
    1.69 +        parser.parse("""
    1.70 +            interface Child : Parent {
    1.71 +              void foo();
    1.72 +            };
    1.73 +            interface Parent {
    1.74 +              [Unforgeable] readonly attribute long foo;
    1.75 +            };
    1.76 +        """)
    1.77 +
    1.78 +        results = parser.finish()
    1.79 +    except:
    1.80 +        threw = True
    1.81 +    harness.ok(threw,
    1.82 +               "Should have thrown when shadowing unforgeable attribute on "
    1.83 +               "parent with operation.")
    1.84 +
    1.85 +    parser = parser.reset();
    1.86 +    threw = False
    1.87 +    try:
    1.88 +        parser.parse("""
    1.89 +            interface Child : Parent {
    1.90 +              attribute short foo;
    1.91 +            };
    1.92 +            interface Parent {
    1.93 +              [Unforgeable] readonly attribute long foo;
    1.94 +            };
    1.95 +        """)
    1.96 +
    1.97 +        results = parser.finish()
    1.98 +    except Exception,x:
    1.99 +        threw = True
   1.100 +    harness.ok(threw,
   1.101 +               "Should have thrown when shadowing unforgeable attribute on "
   1.102 +               "parent with attribute.")
   1.103 +
   1.104 +    parser = parser.reset();
   1.105 +    parser.parse("""
   1.106 +            interface Child : Parent {
   1.107 +            };
   1.108 +            interface Parent {};
   1.109 +            interface Consequential {
   1.110 +              [Unforgeable] readonly attribute long foo;
   1.111 +            };
   1.112 +            Parent implements Consequential;
   1.113 +        """)
   1.114 +
   1.115 +    results = parser.finish()
   1.116 +    harness.check(len(results), 4,
   1.117 +                  "Should be able to inherit from an interface with a "
   1.118 +                  "consequential interface with [Unforgeable] properties.")
   1.119 +
   1.120 +    parser = parser.reset();
   1.121 +    threw = False
   1.122 +    try:
   1.123 +        parser.parse("""
   1.124 +            interface Child : Parent {
   1.125 +              void foo();
   1.126 +            };
   1.127 +            interface Parent {};
   1.128 +            interface Consequential {
   1.129 +              [Unforgeable] readonly attribute long foo;
   1.130 +            };
   1.131 +            Parent implements Consequential;
   1.132 +        """)
   1.133 +
   1.134 +        results = parser.finish()
   1.135 +    except:
   1.136 +        threw = True
   1.137 +
   1.138 +    harness.ok(threw,
   1.139 +               "Should have thrown when shadowing unforgeable attribute "
   1.140 +               "of parent's consequential interface.")
   1.141 +
   1.142 +    parser = parser.reset();
   1.143 +    threw = False
   1.144 +    try:
   1.145 +        parser.parse("""
   1.146 +            interface Child : Parent {
   1.147 +            };
   1.148 +            interface Parent : GrandParent {};
   1.149 +            interface GrandParent {};
   1.150 +            interface Consequential {
   1.151 +              [Unforgeable] readonly attribute long foo;
   1.152 +            };
   1.153 +            GrandParent implements Consequential;
   1.154 +            interface ChildConsequential {
   1.155 +              void foo();
   1.156 +            };
   1.157 +            Child implements ChildConsequential;
   1.158 +        """)
   1.159 +
   1.160 +        results = parser.finish()
   1.161 +    except:
   1.162 +        threw = True
   1.163 +
   1.164 +    harness.ok(threw,
   1.165 +               "Should have thrown when our consequential interface shadows unforgeable attribute "
   1.166 +               "of ancestor's consequential interface.")
   1.167 +
   1.168 +    parser = parser.reset();
   1.169 +    threw = False
   1.170 +    try:
   1.171 +        parser.parse("""
   1.172 +            interface iface {
   1.173 +              [Unforgeable] attribute long foo;
   1.174 +            };
   1.175 +        """)
   1.176 +
   1.177 +        results = parser.finish()
   1.178 +    except:
   1.179 +        threw = True
   1.180 +
   1.181 +    harness.ok(threw, "Should have thrown for writable [Unforgeable] attribute.")
   1.182 +
   1.183 +    parser = parser.reset();
   1.184 +    threw = False
   1.185 +    try:
   1.186 +        parser.parse("""
   1.187 +            interface iface {
   1.188 +              [Unforgeable] static readonly attribute long foo;
   1.189 +            };
   1.190 +        """)
   1.191 +
   1.192 +        results = parser.finish()
   1.193 +    except:
   1.194 +        threw = True
   1.195 +
   1.196 +    harness.ok(threw, "Should have thrown for static [Unforgeable] attribute.")

mercurial