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")
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")
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()
32 interface QNameDerived : QNameBase {
33 attribute long long foo;
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")
48 base
.members
[0].identifier
.QName(),
50 "Member has the right QName",
53 derived
.members
[0].identifier
.QName(),
54 "::QNameDerived::foo",
55 "Member has the right QName",
58 derived
.members
[1].identifier
.QName(),
59 "::QNameDerived::bar",
60 "Member has the right QName",
63 parser
= parser
.reset()
72 results
= parser
.finish()
73 except WebIDL
.WebIDLError
:
76 harness
.ok(threw
, "Should not allow cycles in interface inheritance chains")
78 parser
= parser
.reset()
88 results
= parser
.finish()
89 except WebIDL
.WebIDLError
:
93 threw
, "Should not allow indirect cycles in interface inheritance chains"
96 parser
= parser
.reset()
105 results
= parser
.finish()
106 except WebIDL
.WebIDLError
:
111 "Should not allow inheriting from an interface that is only forward declared",
114 parser
= parser
.reset()
119 constructor(long arg);
120 readonly attribute boolean x;
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")
133 len(iface
.members
), 3, "Should have three members with partial interface"
136 iface
.members
[0].identifier
.name
,
138 "First member should be x with partial interface",
141 iface
.members
[1].identifier
.name
,
143 "Second member should be foo with partial interface",
146 len(iface
.members
[1].signatures()),
148 "Should have two foo signatures with partial interface",
151 iface
.members
[2].identifier
.name
,
153 "Third member should be y with partial interface",
156 len(iface
.ctor().signatures()),
158 "Should have two constructors with partial interface",
161 parser
= parser
.reset()
164 partial interface A {
165 readonly attribute boolean y;
166 undefined foo(long arg);
170 constructor(long arg);
171 readonly attribute boolean x;
176 results
= parser
.finish()
178 len(results
), 2, "Should have two results with reversed partial interface"
184 "Should have three members with reversed partial interface",
187 iface
.members
[0].identifier
.name
,
189 "First member should be x with reversed partial interface",
192 iface
.members
[1].identifier
.name
,
194 "Second member should be foo with reversed partial interface",
197 len(iface
.members
[1].signatures()),
199 "Should have two foo signatures with reversed partial interface",
202 iface
.members
[2].identifier
.name
,
204 "Third member should be y with reversed partial interface",
207 len(iface
.ctor().signatures()),
209 "Should have two constructors with reversed partial interface",
212 parser
= parser
.reset()
218 readonly attribute boolean x;
221 readonly attribute boolean y;
225 results
= parser
.finish()
226 except WebIDL
.WebIDLError
:
228 harness
.ok(threw
, "Should not allow two non-partial interfaces with the same name")
230 parser
= parser
.reset()
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
:
246 harness
.ok(threw
, "Must have a non-partial interface for a given name")
248 parser
= parser
.reset()
256 partial interface A {
257 readonly attribute boolean y;
261 results
= parser
.finish()
262 except WebIDL
.WebIDLError
:
266 "Should not allow a name collision between partial interface "
270 parser
= parser
.reset()
279 readonly attribute boolean y;
283 results
= parser
.finish()
284 except WebIDL
.WebIDLError
:
287 threw
, "Should not allow a name collision between interface " "and other object"
290 parser
= parser
.reset()
301 results
= parser
.finish()
302 except WebIDL
.WebIDLError
:
306 "Should not allow a name collision between external interface "
310 parser
= parser
.reset()
316 readonly attribute boolean x;
321 results
= parser
.finish()
322 except WebIDL
.WebIDLError
:
326 "Should not allow a name collision between external interface " "and interface",
329 parser
= parser
.reset()
336 results
= parser
.finish()
338 len(results
) == 1 and isinstance(results
[0], WebIDL
.IDLExternalInterface
),
339 "Should allow name collisions between external interface " "declarations",
342 parser
= parser
.reset()
347 [SomeRandomAnnotation]
349 readonly attribute boolean y;
353 results
= parser
.finish()
354 except WebIDL
.WebIDLError
:
356 harness
.ok(threw
, "Should not allow unknown extended attributes on interfaces")
358 parser
= parser
.reset()
361 [Global=Window, Exposed=Window] interface Window {};
362 [Exposed=Window, LegacyWindowAlias=A]
364 [Exposed=Window, LegacyWindowAlias=(C, D)]
368 results
= parser
.finish()
370 results
[1].legacyWindowAliases
, ["A"], "Should support a single identifier"
373 results
[2].legacyWindowAliases
, ["C", "D"], "Should support an identifier list"
376 parser
= parser
.reset()
385 results
= parser
.finish()
386 except WebIDL
.WebIDLError
:
388 harness
.ok(threw
, "Should not allow [LegacyWindowAlias] with no value")
390 parser
= parser
.reset()
395 [Exposed=Worker, LegacyWindowAlias=B]
399 results
= parser
.finish()
400 except WebIDL
.WebIDLError
:
402 harness
.ok(threw
, "Should not allow [LegacyWindowAlias] without Window exposure")
404 parser
= parser
.reset()
409 [Global=Window, Exposed=Window] interface Window {};
412 [Exposed=Window, LegacyWindowAlias=A]
416 results
= parser
.finish()
417 except WebIDL
.WebIDLError
:
420 threw
, "Should not allow [LegacyWindowAlias] to conflict with other identifiers"
423 parser
= parser
.reset()
428 [Global=Window, Exposed=Window] interface Window {};
429 [Exposed=Window, LegacyWindowAlias=A]
435 results
= parser
.finish()
436 except WebIDL
.WebIDLError
:
439 threw
, "Should not allow [LegacyWindowAlias] to conflict with other identifiers"
442 parser
= parser
.reset()
447 [Global=Window, Exposed=Window] interface Window {};
448 [Exposed=Window, LegacyWindowAlias=A]
450 [Exposed=Window, LegacyWindowAlias=A]
454 results
= parser
.finish()
455 except WebIDL
.WebIDLError
:
458 threw
, "Should not allow [LegacyWindowAlias] to conflict with other identifiers"