Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / dom / bindings / parser / tests / test_constructor.py
blob1a08a828fd149f5925cbd7e85056ec2dc16ea97a
1 import WebIDL
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")
7 harness.check(
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")
12 harness.check(
13 argument.optional, optional, "Argument has the right optional value"
15 harness.check(
16 argument.variadic, variadic, "Argument has the right variadic value"
19 def checkMethod(
20 method,
21 QName,
22 name,
23 signatures,
24 static=True,
25 getter=False,
26 setter=False,
27 deleter=False,
28 legacycaller=False,
29 stringifier=False,
30 chromeOnly=False,
31 htmlConstructor=False,
32 secureContext=False,
33 pref=None,
34 func=None,
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")
45 harness.check(
46 method.isDeleter(), deleter, "Method has the correct deleter value"
48 harness.check(
49 method.isLegacycaller(),
50 legacycaller,
51 "Method has the correct legacycaller value",
53 harness.check(
54 method.isStringifier(),
55 stringifier,
56 "Method has the correct stringifier value",
58 harness.check(
59 method.getExtendedAttribute("ChromeOnly") is not None,
60 chromeOnly,
61 "Method has the correct value for ChromeOnly",
63 harness.check(
64 method.isHTMLConstructor(),
65 htmlConstructor,
66 "Method has the correct htmlConstructor value",
68 harness.check(
69 len(method.signatures()),
70 len(signatures),
71 "Method has the correct number of signatures",
73 harness.check(
74 method.getExtendedAttribute("Pref"),
75 pref,
76 "Method has the correct pref value",
78 harness.check(
79 method.getExtendedAttribute("Func"),
80 func,
81 "Method has the correct func value",
83 harness.check(
84 method.getExtendedAttribute("SecureContext") is not None,
85 secureContext,
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
94 harness.check(
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")
104 harness.ok(
105 isinstance(results[0], WebIDL.IDLInterface), "Should be an IDLInterface"
107 harness.ok(
108 isinstance(results[1], WebIDL.IDLInterface), "Should be an IDLInterface"
110 harness.ok(
111 isinstance(results[2], WebIDL.IDLInterface), "Should be an IDLInterface"
114 checkMethod(
115 results[0].ctor(),
116 "::TestConstructorNoArgs::constructor",
117 "constructor",
118 [("TestConstructorNoArgs (Wrapper)", [])],
120 harness.check(
121 len(results[0].members), 0, "TestConstructorNoArgs should not have members"
123 checkMethod(
124 results[1].ctor(),
125 "::TestConstructorWithArgs::constructor",
126 "constructor",
129 "TestConstructorWithArgs (Wrapper)",
132 "::TestConstructorWithArgs::constructor::name",
133 "name",
134 "String",
135 False,
136 False,
142 harness.check(
143 len(results[1].members),
145 "TestConstructorWithArgs should not have members",
147 checkMethod(
148 results[2].ctor(),
149 "::TestConstructorOverloads::constructor",
150 "constructor",
153 "TestConstructorOverloads (Wrapper)",
156 "::TestConstructorOverloads::constructor::foo",
157 "foo",
158 "Object",
159 False,
160 False,
165 "TestConstructorOverloads (Wrapper)",
168 "::TestConstructorOverloads::constructor::bar",
169 "bar",
170 "Boolean",
171 False,
172 False,
178 harness.check(
179 len(results[2].members),
181 "TestConstructorOverloads should not have members",
184 parser.parse(
186 interface TestConstructorNoArgs {
187 constructor();
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()
204 parser.parse(
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")
215 checkMethod(
216 results[0].ctor(),
217 "::TestPrefConstructor::constructor",
218 "constructor",
219 [("TestPrefConstructor (Wrapper)", [])],
220 pref=["dom.webidl.test1"],
223 parser = parser.reset()
224 parser.parse(
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")
235 checkMethod(
236 results[0].ctor(),
237 "::TestChromeOnlyConstructor::constructor",
238 "constructor",
239 [("TestChromeOnlyConstructor (Wrapper)", [])],
240 chromeOnly=True,
243 parser = parser.reset()
244 parser.parse(
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")
255 checkMethod(
256 results[0].ctor(),
257 "::TestSCConstructor::constructor",
258 "constructor",
259 [("TestSCConstructor (Wrapper)", [])],
260 secureContext=True,
263 parser = parser.reset()
264 parser.parse(
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")
275 checkMethod(
276 results[0].ctor(),
277 "::TestFuncConstructor::constructor",
278 "constructor",
279 [("TestFuncConstructor (Wrapper)", [])],
280 func=["IsNotUAWidget"],
283 parser = parser.reset()
284 parser.parse(
286 "\n"
287 " interface TestPrefChromeOnlySCFuncConstructor {\n"
288 ' [ChromeOnly, Pref="dom.webidl.test1", SecureContext, '
289 'Func="IsNotUAWidget"]\n'
290 " constructor();\n"
291 " };\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")
298 checkMethod(
299 results[0].ctor(),
300 "::TestPrefChromeOnlySCFuncConstructor::constructor",
301 "constructor",
302 [("TestPrefChromeOnlySCFuncConstructor (Wrapper)", [])],
303 func=["IsNotUAWidget"],
304 pref=["dom.webidl.test1"],
305 chromeOnly=True,
306 secureContext=True,
309 parser = parser.reset()
310 parser.parse(
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")
321 checkMethod(
322 results[0].ctor(),
323 "::TestHTMLConstructor::constructor",
324 "constructor",
325 [("TestHTMLConstructor (Wrapper)", [])],
326 htmlConstructor=True,
329 parser = parser.reset()
330 threw = False
331 try:
332 parser.parse(
334 interface TestChromeOnlyConstructor {
335 constructor()
336 [ChromeOnly] constructor(DOMString a);
340 results = parser.finish()
341 except WebIDL.WebIDLError:
342 threw = True
344 harness.ok(threw, "Can't have both a constructor and a ChromeOnly constructor")
346 # Test HTMLConstructor with argument
347 parser = parser.reset()
348 threw = False
349 try:
350 parser.parse(
352 interface TestHTMLConstructorWithArgs {
353 [HTMLConstructor] constructor(DOMString a);
357 results = parser.finish()
358 except WebIDL.WebIDLError:
359 threw = True
361 harness.ok(threw, "HTMLConstructor should take no argument")
363 # Test HTMLConstructor on a callback interface
364 parser = parser.reset()
365 threw = False
366 try:
367 parser.parse(
369 callback interface TestHTMLConstructorOnCallbackInterface {
370 [HTMLConstructor] constructor();
374 results = parser.finish()
375 except WebIDL.WebIDLError:
376 threw = True
378 harness.ok(threw, "HTMLConstructor can't be used on a callback interface")
380 # Test HTMLConstructor and constructor operation
381 parser = parser.reset()
382 threw = False
383 try:
384 parser.parse(
386 interface TestHTMLConstructorAndConstructor {
387 constructor();
388 [HTMLConstructor] constructor();
392 results = parser.finish()
393 except WebIDL.WebIDLError:
394 threw = True
396 harness.ok(threw, "Can't have both a constructor and a HTMLConstructor")
398 parser = parser.reset()
399 threw = False
400 try:
401 parser.parse(
403 interface TestHTMLConstructorAndConstructor {
404 [Throws]
405 constructor();
406 [HTMLConstructor] constructor();
410 results = parser.finish()
411 except WebIDL.WebIDLError:
412 threw = True
414 harness.ok(threw, "Can't have both a throwing constructor and a HTMLConstructor")
416 parser = parser.reset()
417 threw = False
418 try:
419 parser.parse(
421 interface TestHTMLConstructorAndConstructor {
422 constructor(DOMString a);
423 [HTMLConstructor] constructor();
427 results = parser.finish()
428 except WebIDL.WebIDLError:
429 threw = True
431 harness.ok(threw, "Can't have both a HTMLConstructor and a constructor operation")
433 parser = parser.reset()
434 threw = False
435 try:
436 parser.parse(
438 interface TestHTMLConstructorAndConstructor {
439 [Throws]
440 constructor(DOMString a);
441 [HTMLConstructor] constructor();
445 results = parser.finish()
446 except WebIDL.WebIDLError:
447 threw = True
449 harness.ok(
450 threw,
451 "Can't have both a HTMLConstructor and a throwing constructor " "operation",
454 # Test HTMLConstructor and [ChromeOnly] constructor operation
455 parser = parser.reset()
456 threw = False
457 try:
458 parser.parse(
460 interface TestHTMLConstructorAndConstructor {
461 [ChromeOnly]
462 constructor();
463 [HTMLConstructor] constructor();
467 results = parser.finish()
468 except WebIDL.WebIDLError:
469 threw = True
471 harness.ok(threw, "Can't have both a ChromeOnly constructor and a HTMLConstructor")
473 parser = parser.reset()
474 threw = False
475 try:
476 parser.parse(
478 interface TestHTMLConstructorAndConstructor {
479 [Throws, ChromeOnly]
480 constructor();
481 [HTMLConstructor] constructor();
485 results = parser.finish()
486 except WebIDL.WebIDLError:
487 threw = True
489 harness.ok(
490 threw,
491 "Can't have both a throwing chromeonly constructor and a " "HTMLConstructor",
494 parser = parser.reset()
495 threw = False
496 try:
497 parser.parse(
499 interface TestHTMLConstructorAndConstructor {
500 [ChromeOnly]
501 constructor(DOMString a);
502 [HTMLConstructor] constructor();
506 results = parser.finish()
507 except WebIDL.WebIDLError:
508 threw = True
510 harness.ok(
511 threw,
512 "Can't have both a HTMLConstructor and a chromeonly constructor " "operation",
515 parser = parser.reset()
516 threw = False
517 try:
518 parser.parse(
520 interface TestHTMLConstructorAndConstructor {
521 [Throws, ChromeOnly]
522 constructor(DOMString a);
523 [HTMLConstructor] constructor();
527 results = parser.finish()
528 except WebIDL.WebIDLError:
529 threw = True
531 harness.ok(
532 threw,
533 "Can't have both a HTMLConstructor and a throwing chromeonly "
534 "constructor operation",
537 parser = parser.reset()
538 threw = False
539 try:
540 parser.parse(
542 [LegacyNoInterfaceObject]
543 interface InterfaceWithoutInterfaceObject {
544 constructor();
548 results = parser.finish()
549 except WebIDL.WebIDLError:
550 threw = True
552 harness.ok(
553 threw,
554 "Can't have a constructor operation on a [LegacyNoInterfaceObject] "
555 "interface",
558 parser = parser.reset()
559 threw = False
560 try:
561 parser.parse(
563 interface InterfaceWithPartial {
566 partial interface InterfaceWithPartial {
567 constructor();
571 results = parser.finish()
572 except WebIDL.WebIDLError:
573 threw = True
575 harness.ok(threw, "Can't have a constructor operation on a partial interface")
577 parser = parser.reset()
578 threw = False
579 try:
580 parser.parse(
582 interface InterfaceWithMixin {
585 interface mixin Mixin {
586 constructor();
589 InterfaceWithMixin includes Mixin
592 results = parser.finish()
593 except WebIDL.WebIDLError:
594 threw = True
596 harness.ok(threw, "Can't have a constructor operation on a mixin")