4 def WebIDLTest(parser
, harness
):
5 def checkArgument(argument
, QName
, name
, type, optional
, variadic
):
6 harness
.ok(isinstance(argument
, WebIDL
.IDLArgument
), "Should be an IDLArgument")
8 argument
.identifier
.QName(), QName
, "Argument has the right QName"
10 harness
.check(argument
.identifier
.name
, name
, "Argument has the right name")
11 harness
.check(str(argument
.type), type, "Argument has the right return type")
13 argument
.optional
, optional
, "Argument has the right optional value"
16 argument
.variadic
, variadic
, "Argument has the right variadic value"
31 htmlConstructor
=False,
36 harness
.ok(isinstance(method
, WebIDL
.IDLMethod
), "Should be an IDLMethod")
37 harness
.ok(method
.isMethod(), "Method is a method")
38 harness
.ok(not method
.isAttr(), "Method is not an attr")
39 harness
.ok(not method
.isConst(), "Method is not a const")
40 harness
.check(method
.identifier
.QName(), QName
, "Method has the right QName")
41 harness
.check(method
.identifier
.name
, name
, "Method has the right name")
42 harness
.check(method
.isStatic(), static
, "Method has the correct static value")
43 harness
.check(method
.isGetter(), getter
, "Method has the correct getter value")
44 harness
.check(method
.isSetter(), setter
, "Method has the correct setter value")
46 method
.isDeleter(), deleter
, "Method has the correct deleter value"
49 method
.isLegacycaller(),
51 "Method has the correct legacycaller value",
54 method
.isStringifier(),
56 "Method has the correct stringifier value",
59 method
.getExtendedAttribute("ChromeOnly") is not None,
61 "Method has the correct value for ChromeOnly",
64 method
.isHTMLConstructor(),
66 "Method has the correct htmlConstructor value",
69 len(method
.signatures()),
71 "Method has the correct number of signatures",
74 method
.getExtendedAttribute("Pref"),
76 "Method has the correct pref value",
79 method
.getExtendedAttribute("Func"),
81 "Method has the correct func value",
84 method
.getExtendedAttribute("SecureContext") is not None,
86 "Method has the correct SecureContext value",
89 sigpairs
= zip(method
.signatures(), signatures
)
90 for gotSignature
, expectedSignature
in sigpairs
:
91 (gotRetType
, gotArgs
) = gotSignature
92 (expectedRetType
, expectedArgs
) = expectedSignature
95 str(gotRetType
), expectedRetType
, "Method has the expected return type."
98 for i
in range(0, len(gotArgs
)):
99 (QName
, name
, type, optional
, variadic
) = expectedArgs
[i
]
100 checkArgument(gotArgs
[i
], QName
, name
, type, optional
, variadic
)
102 def checkResults(results
):
103 harness
.check(len(results
), 3, "Should be three productions")
105 isinstance(results
[0], WebIDL
.IDLInterface
), "Should be an IDLInterface"
108 isinstance(results
[1], WebIDL
.IDLInterface
), "Should be an IDLInterface"
111 isinstance(results
[2], WebIDL
.IDLInterface
), "Should be an IDLInterface"
116 "::TestConstructorNoArgs::constructor",
118 [("TestConstructorNoArgs (Wrapper)", [])],
121 len(results
[0].members
), 0, "TestConstructorNoArgs should not have members"
125 "::TestConstructorWithArgs::constructor",
129 "TestConstructorWithArgs (Wrapper)",
132 "::TestConstructorWithArgs::constructor::name",
143 len(results
[1].members
),
145 "TestConstructorWithArgs should not have members",
149 "::TestConstructorOverloads::constructor",
153 "TestConstructorOverloads (Wrapper)",
156 "::TestConstructorOverloads::constructor::foo",
165 "TestConstructorOverloads (Wrapper)",
168 "::TestConstructorOverloads::constructor::bar",
179 len(results
[2].members
),
181 "TestConstructorOverloads should not have members",
186 interface TestConstructorNoArgs {
190 interface TestConstructorWithArgs {
191 constructor(DOMString name);
194 interface TestConstructorOverloads {
195 constructor(object foo);
196 constructor(boolean bar);
200 results
= parser
.finish()
201 checkResults(results
)
203 parser
= parser
.reset()
206 interface TestPrefConstructor {
207 [Pref="dom.webidl.test1"] constructor();
211 results
= parser
.finish()
212 harness
.check(len(results
), 1, "Should be one production")
213 harness
.ok(isinstance(results
[0], WebIDL
.IDLInterface
), "Should be an IDLInterface")
217 "::TestPrefConstructor::constructor",
219 [("TestPrefConstructor (Wrapper)", [])],
220 pref
=["dom.webidl.test1"],
223 parser
= parser
.reset()
226 interface TestChromeOnlyConstructor {
227 [ChromeOnly] constructor();
231 results
= parser
.finish()
232 harness
.check(len(results
), 1, "Should be one production")
233 harness
.ok(isinstance(results
[0], WebIDL
.IDLInterface
), "Should be an IDLInterface")
237 "::TestChromeOnlyConstructor::constructor",
239 [("TestChromeOnlyConstructor (Wrapper)", [])],
243 parser
= parser
.reset()
246 interface TestSCConstructor {
247 [SecureContext] constructor();
251 results
= parser
.finish()
252 harness
.check(len(results
), 1, "Should be one production")
253 harness
.ok(isinstance(results
[0], WebIDL
.IDLInterface
), "Should be an IDLInterface")
257 "::TestSCConstructor::constructor",
259 [("TestSCConstructor (Wrapper)", [])],
263 parser
= parser
.reset()
266 interface TestFuncConstructor {
267 [Func="IsNotUAWidget"] constructor();
271 results
= parser
.finish()
272 harness
.check(len(results
), 1, "Should be one production")
273 harness
.ok(isinstance(results
[0], WebIDL
.IDLInterface
), "Should be an IDLInterface")
277 "::TestFuncConstructor::constructor",
279 [("TestFuncConstructor (Wrapper)", [])],
280 func
=["IsNotUAWidget"],
283 parser
= parser
.reset()
287 " interface TestPrefChromeOnlySCFuncConstructor {\n"
288 ' [ChromeOnly, Pref="dom.webidl.test1", SecureContext, '
289 'Func="IsNotUAWidget"]\n'
294 results
= parser
.finish()
295 harness
.check(len(results
), 1, "Should be one production")
296 harness
.ok(isinstance(results
[0], WebIDL
.IDLInterface
), "Should be an IDLInterface")
300 "::TestPrefChromeOnlySCFuncConstructor::constructor",
302 [("TestPrefChromeOnlySCFuncConstructor (Wrapper)", [])],
303 func
=["IsNotUAWidget"],
304 pref
=["dom.webidl.test1"],
309 parser
= parser
.reset()
312 interface TestHTMLConstructor {
313 [HTMLConstructor] constructor();
317 results
= parser
.finish()
318 harness
.check(len(results
), 1, "Should be one production")
319 harness
.ok(isinstance(results
[0], WebIDL
.IDLInterface
), "Should be an IDLInterface")
323 "::TestHTMLConstructor::constructor",
325 [("TestHTMLConstructor (Wrapper)", [])],
326 htmlConstructor
=True,
329 parser
= parser
.reset()
334 interface TestChromeOnlyConstructor {
336 [ChromeOnly] constructor(DOMString a);
340 results
= parser
.finish()
341 except WebIDL
.WebIDLError
:
344 harness
.ok(threw
, "Can't have both a constructor and a ChromeOnly constructor")
346 # Test HTMLConstructor with argument
347 parser
= parser
.reset()
352 interface TestHTMLConstructorWithArgs {
353 [HTMLConstructor] constructor(DOMString a);
357 results
= parser
.finish()
358 except WebIDL
.WebIDLError
:
361 harness
.ok(threw
, "HTMLConstructor should take no argument")
363 # Test HTMLConstructor on a callback interface
364 parser
= parser
.reset()
369 callback interface TestHTMLConstructorOnCallbackInterface {
370 [HTMLConstructor] constructor();
374 results
= parser
.finish()
375 except WebIDL
.WebIDLError
:
378 harness
.ok(threw
, "HTMLConstructor can't be used on a callback interface")
380 # Test HTMLConstructor and constructor operation
381 parser
= parser
.reset()
386 interface TestHTMLConstructorAndConstructor {
388 [HTMLConstructor] constructor();
392 results
= parser
.finish()
393 except WebIDL
.WebIDLError
:
396 harness
.ok(threw
, "Can't have both a constructor and a HTMLConstructor")
398 parser
= parser
.reset()
403 interface TestHTMLConstructorAndConstructor {
406 [HTMLConstructor] constructor();
410 results
= parser
.finish()
411 except WebIDL
.WebIDLError
:
414 harness
.ok(threw
, "Can't have both a throwing constructor and a HTMLConstructor")
416 parser
= parser
.reset()
421 interface TestHTMLConstructorAndConstructor {
422 constructor(DOMString a);
423 [HTMLConstructor] constructor();
427 results
= parser
.finish()
428 except WebIDL
.WebIDLError
:
431 harness
.ok(threw
, "Can't have both a HTMLConstructor and a constructor operation")
433 parser
= parser
.reset()
438 interface TestHTMLConstructorAndConstructor {
440 constructor(DOMString a);
441 [HTMLConstructor] constructor();
445 results
= parser
.finish()
446 except WebIDL
.WebIDLError
:
451 "Can't have both a HTMLConstructor and a throwing constructor " "operation",
454 # Test HTMLConstructor and [ChromeOnly] constructor operation
455 parser
= parser
.reset()
460 interface TestHTMLConstructorAndConstructor {
463 [HTMLConstructor] constructor();
467 results
= parser
.finish()
468 except WebIDL
.WebIDLError
:
471 harness
.ok(threw
, "Can't have both a ChromeOnly constructor and a HTMLConstructor")
473 parser
= parser
.reset()
478 interface TestHTMLConstructorAndConstructor {
481 [HTMLConstructor] constructor();
485 results
= parser
.finish()
486 except WebIDL
.WebIDLError
:
491 "Can't have both a throwing chromeonly constructor and a " "HTMLConstructor",
494 parser
= parser
.reset()
499 interface TestHTMLConstructorAndConstructor {
501 constructor(DOMString a);
502 [HTMLConstructor] constructor();
506 results
= parser
.finish()
507 except WebIDL
.WebIDLError
:
512 "Can't have both a HTMLConstructor and a chromeonly constructor " "operation",
515 parser
= parser
.reset()
520 interface TestHTMLConstructorAndConstructor {
522 constructor(DOMString a);
523 [HTMLConstructor] constructor();
527 results
= parser
.finish()
528 except WebIDL
.WebIDLError
:
533 "Can't have both a HTMLConstructor and a throwing chromeonly "
534 "constructor operation",
537 parser
= parser
.reset()
542 [LegacyNoInterfaceObject]
543 interface InterfaceWithoutInterfaceObject {
548 results
= parser
.finish()
549 except WebIDL
.WebIDLError
:
554 "Can't have a constructor operation on a [LegacyNoInterfaceObject] "
558 parser
= parser
.reset()
563 interface InterfaceWithPartial {
566 partial interface InterfaceWithPartial {
571 results
= parser
.finish()
572 except WebIDL
.WebIDLError
:
575 harness
.ok(threw
, "Can't have a constructor operation on a partial interface")
577 parser
= parser
.reset()
582 interface InterfaceWithMixin {
585 interface mixin Mixin {
589 InterfaceWithMixin includes Mixin
592 results
= parser
.finish()
593 except WebIDL
.WebIDLError
:
596 harness
.ok(threw
, "Can't have a constructor operation on a mixin")