summaryrefslogtreecommitdiffstats
path: root/dom/bindings/parser/tests/test_unforgeable.py
blob: 3787e8c6af1ece280ebda02ac2669e71567c50ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
def WebIDLTest(parser, harness):
    parser.parse("""
            interface Child : Parent {
            };
            interface Parent {
              [Unforgeable] readonly attribute long foo;
            };
        """)

    results = parser.finish()
    harness.check(len(results), 2,
                  "Should be able to inherit from an interface with "
                  "[Unforgeable] properties.")

    parser = parser.reset();
    parser.parse("""
            interface Child : Parent {
              const short foo = 10;
            };
            interface Parent {
              [Unforgeable] readonly attribute long foo;
            };
        """)

    results = parser.finish()
    harness.check(len(results), 2,
                  "Should be able to inherit from an interface with "
                  "[Unforgeable] properties even if we have a constant with "
                  "the same name.")

    parser = parser.reset();
    parser.parse("""
            interface Child : Parent {
              static attribute short foo;
            };
            interface Parent {
              [Unforgeable] readonly attribute long foo;
            };
        """)

    results = parser.finish()
    harness.check(len(results), 2,
                  "Should be able to inherit from an interface with "
                  "[Unforgeable] properties even if we have a static attribute "
                  "with the same name.")

    parser = parser.reset();
    parser.parse("""
            interface Child : Parent {
              static void foo();
            };
            interface Parent {
              [Unforgeable] readonly attribute long foo;
            };
        """)

    results = parser.finish()
    harness.check(len(results), 2,
                  "Should be able to inherit from an interface with "
                  "[Unforgeable] properties even if we have a static operation "
                  "with the same name.")

    parser = parser.reset();
    threw = False
    try:
        parser.parse("""
            interface Child : Parent {
              void foo();
            };
            interface Parent {
              [Unforgeable] readonly attribute long foo;
            };
        """)

        results = parser.finish()
    except:
        threw = True
    harness.ok(threw,
               "Should have thrown when shadowing unforgeable attribute on "
               "parent with operation.")

    parser = parser.reset();
    threw = False
    try:
        parser.parse("""
            interface Child : Parent {
              void foo();
            };
            interface Parent {
              [Unforgeable] void foo();
            };
        """)

        results = parser.finish()
    except:
        threw = True
    harness.ok(threw,
               "Should have thrown when shadowing unforgeable operation on "
               "parent with operation.")

    parser = parser.reset();
    threw = False
    try:
        parser.parse("""
            interface Child : Parent {
              attribute short foo;
            };
            interface Parent {
              [Unforgeable] readonly attribute long foo;
            };
        """)

        results = parser.finish()
    except Exception,x:
        threw = True
    harness.ok(threw,
               "Should have thrown when shadowing unforgeable attribute on "
               "parent with attribute.")

    parser = parser.reset();
    threw = False
    try:
        parser.parse("""
            interface Child : Parent {
              attribute short foo;
            };
            interface Parent {
              [Unforgeable] void foo();
            };
        """)

        results = parser.finish()
    except Exception,x:
        threw = True
    harness.ok(threw,
               "Should have thrown when shadowing unforgeable operation on "
               "parent with attribute.")

    parser = parser.reset();
    parser.parse("""
            interface Child : Parent {
            };
            interface Parent {};
            interface Consequential {
              [Unforgeable] readonly attribute long foo;
            };
            Parent implements Consequential;
        """)

    results = parser.finish()
    harness.check(len(results), 4,
                  "Should be able to inherit from an interface with a "
                  "consequential interface with [Unforgeable] properties.")

    parser = parser.reset();
    threw = False
    try:
        parser.parse("""
            interface Child : Parent {
              void foo();
            };
            interface Parent {};
            interface Consequential {
              [Unforgeable] readonly attribute long foo;
            };
            Parent implements Consequential;
        """)

        results = parser.finish()
    except:
        threw = True

    harness.ok(threw,
               "Should have thrown when shadowing unforgeable attribute "
               "of parent's consequential interface.")

    parser = parser.reset();
    threw = False
    try:
        parser.parse("""
            interface Child : Parent {
            };
            interface Parent : GrandParent {};
            interface GrandParent {};
            interface Consequential {
              [Unforgeable] readonly attribute long foo;
            };
            GrandParent implements Consequential;
            interface ChildConsequential {
              void foo();
            };
            Child implements ChildConsequential;
        """)

        results = parser.finish()
    except:
        threw = True

    harness.ok(threw,
               "Should have thrown when our consequential interface shadows unforgeable attribute "
               "of ancestor's consequential interface.")

    parser = parser.reset();
    threw = False
    try:
        parser.parse("""
            interface Child : Parent {
            };
            interface Parent : GrandParent {};
            interface GrandParent {};
            interface Consequential {
              [Unforgeable] void foo();
            };
            GrandParent implements Consequential;
            interface ChildConsequential {
              void foo();
            };
            Child implements ChildConsequential;
        """)

        results = parser.finish()
    except:
        threw = True

    harness.ok(threw,
               "Should have thrown when our consequential interface shadows unforgeable operation "
               "of ancestor's consequential interface.")

    parser = parser.reset();
    parser.parse("""
        interface iface {
          [Unforgeable] attribute long foo;
        };
    """)

    results = parser.finish()
    harness.check(len(results), 1,
                  "Should allow writable [Unforgeable] attribute.")

    parser = parser.reset();
    threw = False
    try:
        parser.parse("""
            interface iface {
              [Unforgeable] static readonly attribute long foo;
            };
        """)

        results = parser.finish()
    except:
        threw = True

    harness.ok(threw, "Should have thrown for static [Unforgeable] attribute.")