Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / dom / bindings / parser / tests / test_interface.py
blob5b32a27f4d326e254c1e1a64c8edd031fb5c8b4f
1 import WebIDL
4 def WebIDLTest(parser, harness):
5 parser.parse("interface Foo { };")
6 results = parser.finish()
7 harness.ok(True, "Empty interface parsed without error.")
8 harness.check(len(results), 1, "Should be one production")
9 harness.ok(isinstance(results[0], WebIDL.IDLInterface), "Should be an IDLInterface")
10 iface = results[0]
11 harness.check(iface.identifier.QName(), "::Foo", "Interface has the right QName")
12 harness.check(iface.identifier.name, "Foo", "Interface has the right name")
13 harness.check(iface.parent, None, "Interface has no parent")
15 parser.parse("interface Bar : Foo { };")
16 results = parser.finish()
17 harness.ok(True, "Empty interface parsed without error.")
18 harness.check(len(results), 2, "Should be two productions")
19 harness.ok(isinstance(results[1], WebIDL.IDLInterface), "Should be an IDLInterface")
20 iface = results[1]
21 harness.check(iface.identifier.QName(), "::Bar", "Interface has the right QName")
22 harness.check(iface.identifier.name, "Bar", "Interface has the right name")
23 harness.ok(isinstance(iface.parent, WebIDL.IDLInterface), "Interface has a parent")
25 parser = parser.reset()
26 parser.parse(
27 """
28 interface QNameBase {
29 attribute long foo;
32 interface QNameDerived : QNameBase {
33 attribute long long foo;
34 attribute byte bar;
36 """
38 results = parser.finish()
39 harness.check(len(results), 2, "Should be two productions")
40 harness.ok(isinstance(results[0], WebIDL.IDLInterface), "Should be an IDLInterface")
41 harness.ok(isinstance(results[1], WebIDL.IDLInterface), "Should be an IDLInterface")
42 harness.check(results[1].parent, results[0], "Inheritance chain is right")
43 harness.check(len(results[0].members), 1, "Expect 1 productions")
44 harness.check(len(results[1].members), 2, "Expect 2 productions")
45 base = results[0]
46 derived = results[1]
47 harness.check(
48 base.members[0].identifier.QName(),
49 "::QNameBase::foo",
50 "Member has the right QName",
52 harness.check(
53 derived.members[0].identifier.QName(),
54 "::QNameDerived::foo",
55 "Member has the right QName",
57 harness.check(
58 derived.members[1].identifier.QName(),
59 "::QNameDerived::bar",
60 "Member has the right QName",
63 parser = parser.reset()
64 threw = False
65 try:
66 parser.parse(
67 """
68 interface A : B {};
69 interface B : A {};
70 """
72 results = parser.finish()
73 except WebIDL.WebIDLError:
74 threw = True
76 harness.ok(threw, "Should not allow cycles in interface inheritance chains")
78 parser = parser.reset()
79 threw = False
80 try:
81 parser.parse(
82 """
83 interface A : C {};
84 interface C : B {};
85 interface B : A {};
86 """
88 results = parser.finish()
89 except WebIDL.WebIDLError:
90 threw = True
92 harness.ok(
93 threw, "Should not allow indirect cycles in interface inheritance chains"
96 parser = parser.reset()
97 threw = False
98 try:
99 parser.parse(
101 interface A;
102 interface B : A {};
105 results = parser.finish()
106 except WebIDL.WebIDLError:
107 threw = True
109 harness.ok(
110 threw,
111 "Should not allow inheriting from an interface that is only forward declared",
114 parser = parser.reset()
115 parser.parse(
117 interface A {
118 constructor();
119 constructor(long arg);
120 readonly attribute boolean x;
121 undefined foo();
123 partial interface A {
124 readonly attribute boolean y;
125 undefined foo(long arg);
129 results = parser.finish()
130 harness.check(len(results), 2, "Should have two results with partial interface")
131 iface = results[0]
132 harness.check(
133 len(iface.members), 3, "Should have three members with partial interface"
135 harness.check(
136 iface.members[0].identifier.name,
137 "x",
138 "First member should be x with partial interface",
140 harness.check(
141 iface.members[1].identifier.name,
142 "foo",
143 "Second member should be foo with partial interface",
145 harness.check(
146 len(iface.members[1].signatures()),
148 "Should have two foo signatures with partial interface",
150 harness.check(
151 iface.members[2].identifier.name,
152 "y",
153 "Third member should be y with partial interface",
155 harness.check(
156 len(iface.ctor().signatures()),
158 "Should have two constructors with partial interface",
161 parser = parser.reset()
162 parser.parse(
164 partial interface A {
165 readonly attribute boolean y;
166 undefined foo(long arg);
168 interface A {
169 constructor();
170 constructor(long arg);
171 readonly attribute boolean x;
172 undefined foo();
176 results = parser.finish()
177 harness.check(
178 len(results), 2, "Should have two results with reversed partial interface"
180 iface = results[1]
181 harness.check(
182 len(iface.members),
184 "Should have three members with reversed partial interface",
186 harness.check(
187 iface.members[0].identifier.name,
188 "x",
189 "First member should be x with reversed partial interface",
191 harness.check(
192 iface.members[1].identifier.name,
193 "foo",
194 "Second member should be foo with reversed partial interface",
196 harness.check(
197 len(iface.members[1].signatures()),
199 "Should have two foo signatures with reversed partial interface",
201 harness.check(
202 iface.members[2].identifier.name,
203 "y",
204 "Third member should be y with reversed partial interface",
206 harness.check(
207 len(iface.ctor().signatures()),
209 "Should have two constructors with reversed partial interface",
212 parser = parser.reset()
213 threw = False
214 try:
215 parser.parse(
217 interface A {
218 readonly attribute boolean x;
220 interface A {
221 readonly attribute boolean y;
225 results = parser.finish()
226 except WebIDL.WebIDLError:
227 threw = True
228 harness.ok(threw, "Should not allow two non-partial interfaces with the same name")
230 parser = parser.reset()
231 threw = False
232 try:
233 parser.parse(
235 partial interface A {
236 readonly attribute boolean x;
238 partial interface A {
239 readonly attribute boolean y;
243 results = parser.finish()
244 except WebIDL.WebIDLError:
245 threw = True
246 harness.ok(threw, "Must have a non-partial interface for a given name")
248 parser = parser.reset()
249 threw = False
250 try:
251 parser.parse(
253 dictionary A {
254 boolean x;
256 partial interface A {
257 readonly attribute boolean y;
261 results = parser.finish()
262 except WebIDL.WebIDLError:
263 threw = True
264 harness.ok(
265 threw,
266 "Should not allow a name collision between partial interface "
267 "and other object",
270 parser = parser.reset()
271 threw = False
272 try:
273 parser.parse(
275 dictionary A {
276 boolean x;
278 interface A {
279 readonly attribute boolean y;
283 results = parser.finish()
284 except WebIDL.WebIDLError:
285 threw = True
286 harness.ok(
287 threw, "Should not allow a name collision between interface " "and other object"
290 parser = parser.reset()
291 threw = False
292 try:
293 parser.parse(
295 dictionary A {
296 boolean x;
298 interface A;
301 results = parser.finish()
302 except WebIDL.WebIDLError:
303 threw = True
304 harness.ok(
305 threw,
306 "Should not allow a name collision between external interface "
307 "and other object",
310 parser = parser.reset()
311 threw = False
312 try:
313 parser.parse(
315 interface A {
316 readonly attribute boolean x;
318 interface A;
321 results = parser.finish()
322 except WebIDL.WebIDLError:
323 threw = True
324 harness.ok(
325 threw,
326 "Should not allow a name collision between external interface " "and interface",
329 parser = parser.reset()
330 parser.parse(
332 interface A;
333 interface A;
336 results = parser.finish()
337 harness.ok(
338 len(results) == 1 and isinstance(results[0], WebIDL.IDLExternalInterface),
339 "Should allow name collisions between external interface " "declarations",
342 parser = parser.reset()
343 threw = False
344 try:
345 parser.parse(
347 [SomeRandomAnnotation]
348 interface A {
349 readonly attribute boolean y;
353 results = parser.finish()
354 except WebIDL.WebIDLError:
355 threw = True
356 harness.ok(threw, "Should not allow unknown extended attributes on interfaces")
358 parser = parser.reset()
359 parser.parse(
361 [Global=Window, Exposed=Window] interface Window {};
362 [Exposed=Window, LegacyWindowAlias=A]
363 interface B {};
364 [Exposed=Window, LegacyWindowAlias=(C, D)]
365 interface E {};
368 results = parser.finish()
369 harness.check(
370 results[1].legacyWindowAliases, ["A"], "Should support a single identifier"
372 harness.check(
373 results[2].legacyWindowAliases, ["C", "D"], "Should support an identifier list"
376 parser = parser.reset()
377 threw = False
378 try:
379 parser.parse(
381 [LegacyWindowAlias]
382 interface A {};
385 results = parser.finish()
386 except WebIDL.WebIDLError:
387 threw = True
388 harness.ok(threw, "Should not allow [LegacyWindowAlias] with no value")
390 parser = parser.reset()
391 threw = False
392 try:
393 parser.parse(
395 [Exposed=Worker, LegacyWindowAlias=B]
396 interface A {};
399 results = parser.finish()
400 except WebIDL.WebIDLError:
401 threw = True
402 harness.ok(threw, "Should not allow [LegacyWindowAlias] without Window exposure")
404 parser = parser.reset()
405 threw = False
406 try:
407 parser.parse(
409 [Global=Window, Exposed=Window] interface Window {};
410 [Exposed=Window]
411 interface A {};
412 [Exposed=Window, LegacyWindowAlias=A]
413 interface B {};
416 results = parser.finish()
417 except WebIDL.WebIDLError:
418 threw = True
419 harness.ok(
420 threw, "Should not allow [LegacyWindowAlias] to conflict with other identifiers"
423 parser = parser.reset()
424 threw = False
425 try:
426 parser.parse(
428 [Global=Window, Exposed=Window] interface Window {};
429 [Exposed=Window, LegacyWindowAlias=A]
430 interface B {};
431 [Exposed=Window]
432 interface A {};
435 results = parser.finish()
436 except WebIDL.WebIDLError:
437 threw = True
438 harness.ok(
439 threw, "Should not allow [LegacyWindowAlias] to conflict with other identifiers"
442 parser = parser.reset()
443 threw = False
444 try:
445 parser.parse(
447 [Global=Window, Exposed=Window] interface Window {};
448 [Exposed=Window, LegacyWindowAlias=A]
449 interface B {};
450 [Exposed=Window, LegacyWindowAlias=A]
451 interface C {};
454 results = parser.finish()
455 except WebIDL.WebIDLError:
456 threw = True
457 harness.ok(
458 threw, "Should not allow [LegacyWindowAlias] to conflict with other identifiers"