diff options
Diffstat (limited to 'components/script/dom/bindings/codegen/parser/tests')
27 files changed, 484 insertions, 75 deletions
diff --git a/components/script/dom/bindings/codegen/parser/tests/test_attr.py b/components/script/dom/bindings/codegen/parser/tests/test_attr.py index ad7aabc1918..35f680aaa82 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_attr.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_attr.py @@ -133,7 +133,7 @@ def WebIDLTest(parser, harness): }; """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should not allow [SetterThrows] on readonly attributes") @@ -146,7 +146,7 @@ def WebIDLTest(parser, harness): }; """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should spell [Throws] correctly") @@ -159,7 +159,7 @@ def WebIDLTest(parser, harness): }; """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should not allow [SameObject] on attributes not of interface type") @@ -172,6 +172,6 @@ def WebIDLTest(parser, harness): }; """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(not threw, "Should allow [SameObject] on attributes of interface type") diff --git a/components/script/dom/bindings/codegen/parser/tests/test_callback.py b/components/script/dom/bindings/codegen/parser/tests/test_callback.py index 4dfda1c3c76..c304d085ce5 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_callback.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_callback.py @@ -32,3 +32,6 @@ def WebIDLTest(parser, harness): harness.ok(not isinstance(t, WebIDL.IDLWrapperType), "Attr has the right type") harness.ok(isinstance(t, WebIDL.IDLNullableType), "Attr has the right type") harness.ok(t.isCallback(), "Attr has the right type") + + callback = results[1] + harness.ok(not callback.isConstructor(), "callback is not constructor") diff --git a/components/script/dom/bindings/codegen/parser/tests/test_callback_constructor.py b/components/script/dom/bindings/codegen/parser/tests/test_callback_constructor.py new file mode 100644 index 00000000000..4999deef623 --- /dev/null +++ b/components/script/dom/bindings/codegen/parser/tests/test_callback_constructor.py @@ -0,0 +1,63 @@ +import WebIDL + +def WebIDLTest(parser, harness): + parser.parse(""" + interface TestCallbackConstructor { + attribute CallbackConstructorType? constructorAttribute; + }; + + callback constructor CallbackConstructorType = TestCallbackConstructor (unsigned long arg); + """) + + results = parser.finish() + + harness.ok(True, "TestCallbackConstructor interface parsed without error.") + harness.check(len(results), 2, "Should be two productions.") + iface = results[0] + harness.ok(isinstance(iface, WebIDL.IDLInterface), + "Should be an IDLInterface") + harness.check(iface.identifier.QName(), "::TestCallbackConstructor", "Interface has the right QName") + harness.check(iface.identifier.name, "TestCallbackConstructor", "Interface has the right name") + harness.check(len(iface.members), 1, "Expect %s members" % 1) + + attr = iface.members[0] + harness.ok(isinstance(attr, WebIDL.IDLAttribute), + "Should be an IDLAttribute") + harness.ok(attr.isAttr(), "Should be an attribute") + harness.ok(not attr.isMethod(), "Attr is not an method") + harness.ok(not attr.isConst(), "Attr is not a const") + harness.check(attr.identifier.QName(), "::TestCallbackConstructor::constructorAttribute", "Attr has the right QName") + harness.check(attr.identifier.name, "constructorAttribute", "Attr has the right name") + t = attr.type + harness.ok(not isinstance(t, WebIDL.IDLWrapperType), "Attr has the right type") + harness.ok(isinstance(t, WebIDL.IDLNullableType), "Attr has the right type") + harness.ok(t.isCallback(), "Attr has the right type") + + callback = results[1] + harness.ok(callback.isConstructor(), "Callback is constructor") + + parser.reset() + threw = False + try: + parser.parse(""" + [TreatNonObjectAsNull] + callback constructor CallbackConstructorType = object (); + """) + results = parser.finish() + except: + threw = True + + harness.ok(threw, "Should throw on TreatNonObjectAsNull callback constructors") + + parser.reset() + threw = False + try: + parser.parse(""" + [MOZ_CAN_RUN_SCRIPT_BOUNDARY] + callback constructor CallbackConstructorType = object (); + """) + results = parser.finish() + except: + threw = True + + harness.ok(threw, "Should not permit MOZ_CAN_RUN_SCRIPT_BOUNDARY callback constructors") diff --git a/components/script/dom/bindings/codegen/parser/tests/test_cereactions.py b/components/script/dom/bindings/codegen/parser/tests/test_cereactions.py index dba16f53302..f726907c2fc 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_cereactions.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_cereactions.py @@ -38,7 +38,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception, e: + except Exception as e: harness.ok(False, "Shouldn't have thrown for [CEReactions] used on writable attribute. %s" % e) threw = True @@ -52,7 +52,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception, e: + except Exception as e: harness.ok(False, "Shouldn't have thrown for [CEReactions] used on regular operations. %s" % e) threw = True diff --git a/components/script/dom/bindings/codegen/parser/tests/test_conditional_dictionary_member.py b/components/script/dom/bindings/codegen/parser/tests/test_conditional_dictionary_member.py index 433b7e501a4..066300e8bb4 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_conditional_dictionary_member.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_conditional_dictionary_member.py @@ -44,7 +44,7 @@ def WebIDLTest(parser, harness): }; """) results = parser.finish() - except Exception, exception: + except Exception as exception: pass harness.ok(exception, "Should have thrown.") @@ -70,7 +70,7 @@ def WebIDLTest(parser, harness): }; """) results = parser.finish() - except Exception, exception: + except Exception as exception: pass harness.ok(exception, "Should have thrown (2).") @@ -100,7 +100,7 @@ def WebIDLTest(parser, harness): }; """) results = parser.finish() - except Exception, exception: + except Exception as exception: pass harness.ok(exception, "Should have thrown (3).") diff --git a/components/script/dom/bindings/codegen/parser/tests/test_const.py b/components/script/dom/bindings/codegen/parser/tests/test_const.py index 80b6fb0e9c8..918f284a226 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_const.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_const.py @@ -12,9 +12,6 @@ expected = [ ("::TestConsts::ll", "ll", "LongLong", -8), ("::TestConsts::t", "t", "Boolean", True), ("::TestConsts::f", "f", "Boolean", False), - ("::TestConsts::n", "n", "BooleanOrNull", None), - ("::TestConsts::nt", "nt", "BooleanOrNull", True), - ("::TestConsts::nf", "nf", "BooleanOrNull", False), ("::TestConsts::fl", "fl", "Float", 0.2), ("::TestConsts::db", "db", "Double", 0.2), ("::TestConsts::ufl", "ufl", "UnrestrictedFloat", 0.2), @@ -39,9 +36,6 @@ def WebIDLTest(parser, harness): const long long ll = -010; const boolean t = true; const boolean f = false; - const boolean? n = null; - const boolean? nt = true; - const boolean? nf = false; const float fl = 0.2; const double db = 0.2; const unrestricted float ufl = 0.2; @@ -78,3 +72,16 @@ def WebIDLTest(parser, harness): "Const's value has the same type as the type") harness.check(const.value.value, value, "Const value has the right value.") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + interface TestConsts { + const boolean? zero = 0; + }; + """) + parser.finish() + except: + threw = True + harness.ok(threw, "Nullable types are not allowed for consts.") diff --git a/components/script/dom/bindings/codegen/parser/tests/test_constructor_global.py b/components/script/dom/bindings/codegen/parser/tests/test_constructor_global.py new file mode 100644 index 00000000000..14d42caf09c --- /dev/null +++ b/components/script/dom/bindings/codegen/parser/tests/test_constructor_global.py @@ -0,0 +1,87 @@ +def WebIDLTest(parser, harness): + threw = False + try: + parser.parse(""" + [Constructor, Global] + interface TestConstructorGlobal { + }; + """) + + results = parser.finish() + except: + threw = True + + harness.ok(threw, "Should have thrown.") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + [Global, Constructor] + interface TestConstructorGlobal { + }; + """) + + results = parser.finish() + except: + threw = True + + harness.ok(threw, "Should have thrown.") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + [Global, NamedConstructor=FooBar] + interface TestNamedConstructorGlobal { + }; + """) + results = parser.finish() + except: + threw = True + + harness.ok(threw, "Should have thrown.") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + [NamedConstructor=FooBar, Global] + interface TestNamedConstructorGlobal { + }; + """) + results = parser.finish() + except: + threw = True + + harness.ok(threw, "Should have thrown.") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + [Global, HTMLConstructor] + interface TestHTMLConstructorGlobal { + }; + """) + + results = parser.finish() + except: + threw = True + + harness.ok(threw, "Should have thrown.") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + [HTMLConstructor, Global] + interface TestHTMLConstructorGlobal { + }; + """) + + results = parser.finish() + except: + threw = True + + harness.ok(threw, "Should have thrown.") diff --git a/components/script/dom/bindings/codegen/parser/tests/test_constructor_no_interface_object.py b/components/script/dom/bindings/codegen/parser/tests/test_constructor_no_interface_object.py index 40708e7870e..e5413350a28 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_constructor_no_interface_object.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_constructor_no_interface_object.py @@ -13,6 +13,7 @@ def WebIDLTest(parser, harness): harness.ok(threw, "Should have thrown.") + parser = parser.reset() threw = False try: parser.parse(""" diff --git a/components/script/dom/bindings/codegen/parser/tests/test_dictionary.py b/components/script/dom/bindings/codegen/parser/tests/test_dictionary.py index 361b83ea52b..770f76b22f0 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_dictionary.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_dictionary.py @@ -174,6 +174,22 @@ def WebIDLTest(parser, harness): dictionary A { }; interface X { + void doFoo(optional A arg); + }; + """) + results = parser.finish() + except: + threw = True + + harness.ok(threw, "Trailing dictionary arg must have a default value") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + dictionary A { + }; + interface X { void doFoo((A or DOMString) arg); }; """) @@ -191,6 +207,23 @@ def WebIDLTest(parser, harness): dictionary A { }; interface X { + void doFoo(optional (A or DOMString) arg); + }; + """) + results = parser.finish() + except: + threw = True + + harness.ok(threw, + "Trailing union arg containing a dictionary must have a default value") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + dictionary A { + }; + interface X { void doFoo(A arg1, optional long arg2); }; """) @@ -207,6 +240,22 @@ def WebIDLTest(parser, harness): dictionary A { }; interface X { + void doFoo(optional A arg1, optional long arg2); + }; + """) + results = parser.finish() + except: + threw = True + + harness.ok(threw, "Dictionary arg followed by optional arg must have default value") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + dictionary A { + }; + interface X { void doFoo(A arg1, optional long arg2, long arg3); }; """) @@ -236,6 +285,24 @@ def WebIDLTest(parser, harness): "be optional") parser = parser.reset() + threw = False + try: + parser.parse(""" + dictionary A { + }; + interface X { + void doFoo(optional (A or DOMString) arg1, optional long arg2); + }; + """) + results = parser.finish() + except: + threw = True + + harness.ok(threw, + "Union arg containing dictionary followed by optional arg must " + "have a default value") + + parser = parser.reset() parser.parse(""" dictionary A { }; @@ -326,7 +393,7 @@ def WebIDLTest(parser, harness): dictionary A { }; interface X { - void doFoo(optional A arg); + void doFoo(optional A arg = {}); }; """) results = parser.finish() @@ -337,13 +404,24 @@ def WebIDLTest(parser, harness): dictionary A { }; interface X { - void doFoo(optional (A or DOMString) arg); + void doFoo(optional (A or DOMString) arg = {}); }; """) results = parser.finish() harness.ok(True, "Union arg containing a dictionary should actually parse") parser = parser.reset() + parser.parse(""" + dictionary A { + }; + interface X { + void doFoo(optional (A or DOMString) arg = "abc"); + }; + """) + results = parser.finish() + harness.ok(True, "Union arg containing a dictionary with string default should actually parse") + + parser = parser.reset() threw = False try: parser.parse(""" diff --git a/components/script/dom/bindings/codegen/parser/tests/test_distinguishability.py b/components/script/dom/bindings/codegen/parser/tests/test_distinguishability.py index 73a32b0acfb..e88c2b50d98 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_distinguishability.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_distinguishability.py @@ -3,13 +3,16 @@ def firstArgType(method): def WebIDLTest(parser, harness): parser.parse(""" + // Give our dictionary a required member so we don't need to + // mess with optional and default values. dictionary Dict { + required long member; }; callback interface Foo { }; interface Bar { // Bit of a pain to get things that have dictionary types - void passDict(optional Dict arg); + void passDict(Dict arg); void passFoo(Foo arg); void passNullableUnion((object? or DOMString) arg); void passNullable(Foo? arg); @@ -156,8 +159,8 @@ def WebIDLTest(parser, harness): "AncestorInterface", "UnrelatedInterface", "ImplementedInterface", "CallbackInterface", "CallbackInterface?", "CallbackInterface2", - "object", "Callback", "Callback2", "optional Dict", - "optional Dict2", "sequence<long>", "sequence<short>", + "object", "Callback", "Callback2", "Dict", + "Dict2", "sequence<long>", "sequence<short>", "record<DOMString, object>", "record<USVString, Dict>", "record<ByteString, long>", @@ -165,7 +168,7 @@ def WebIDLTest(parser, harness): "Promise<any>", "Promise<any>?", "USVString", "ArrayBuffer", "ArrayBufferView", "SharedArrayBuffer", "Uint8Array", "Uint16Array", - "(long or Callback)", "optional (long or Dict)", + "(long or Callback)", "(long or Dict)", ] # When we can parse Date, we need to add it here. # XXXbz we can, and should really do that... @@ -174,7 +177,7 @@ def WebIDLTest(parser, harness): def allBut(list1, list2): return [a for a in list1 if a not in list2 and (a != "any" and a != "Promise<any>" and a != "Promise<any>?")] - unions = [ "(long or Callback)", "optional (long or Dict)" ] + unions = [ "(long or Callback)", "(long or Dict)" ] numerics = [ "long", "short", "long?", "short?" ] booleans = [ "boolean", "boolean?" ] primitives = numerics + booleans @@ -189,7 +192,7 @@ def WebIDLTest(parser, harness): interfaces = [ "Interface", "Interface?", "AncestorInterface", "UnrelatedInterface", "ImplementedInterface" ] + bufferSourceTypes + sharedBufferSourceTypes nullables = (["long?", "short?", "boolean?", "Interface?", - "CallbackInterface?", "optional Dict", "optional Dict2", + "CallbackInterface?", "Dict", "Dict2", "Date?", "any", "Promise<any>?"] + allBut(unions, [ "(long or Callback)" ])) dates = [ "Date", "Date?" ] @@ -233,8 +236,8 @@ def WebIDLTest(parser, harness): setDistinguishable("object", nonObjects) setDistinguishable("Callback", nonUserObjects) setDistinguishable("Callback2", nonUserObjects) - setDistinguishable("optional Dict", allBut(nonUserObjects, nullables)) - setDistinguishable("optional Dict2", allBut(nonUserObjects, nullables)) + setDistinguishable("Dict", allBut(nonUserObjects, nullables)) + setDistinguishable("Dict2", allBut(nonUserObjects, nullables)) setDistinguishable("sequence<long>", allBut(argTypes, sequences + ["object"])) setDistinguishable("sequence<short>", @@ -254,7 +257,7 @@ def WebIDLTest(parser, harness): setDistinguishable("SharedArrayBuffer", allBut(argTypes, ["SharedArrayBuffer", "object"])) setDistinguishable("(long or Callback)", allBut(nonUserObjects, numerics)) - setDistinguishable("optional (long or Dict)", + setDistinguishable("(long or Dict)", allBut(nonUserObjects, numerics + nullables)) def areDistinguishable(type1, type2): @@ -273,8 +276,10 @@ def WebIDLTest(parser, harness): callback interface CallbackInterface2 {}; callback Callback = any(); callback Callback2 = long(short arg); - dictionary Dict {}; - dictionary Dict2 {}; + // Give our dictionaries required members so we don't need to + // mess with optional and default values. + dictionary Dict { required long member; }; + dictionary Dict2 { required long member; }; interface TestInterface {%s }; """ diff --git a/components/script/dom/bindings/codegen/parser/tests/test_empty_sequence_default_value.py b/components/script/dom/bindings/codegen/parser/tests/test_empty_sequence_default_value.py index 350ae72f022..a713266c88e 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_empty_sequence_default_value.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_empty_sequence_default_value.py @@ -10,7 +10,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception,x: + except Exception as x: threw = True harness.ok(threw, "Constant cannot have [] as a default value") diff --git a/components/script/dom/bindings/codegen/parser/tests/test_error_colno.py b/components/script/dom/bindings/codegen/parser/tests/test_error_colno.py index ca0674aec04..7afd15513c6 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_error_colno.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_error_colno.py @@ -8,7 +8,7 @@ def WebIDLTest(parser, harness): try: parser.parse(input) results = parser.finish() - except WebIDL.WebIDLError, e: + except WebIDL.WebIDLError as e: threw = True lines = str(e).split('\n') diff --git a/components/script/dom/bindings/codegen/parser/tests/test_error_lineno.py b/components/script/dom/bindings/codegen/parser/tests/test_error_lineno.py index f11222e7a4d..70bb1883682 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_error_lineno.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_error_lineno.py @@ -14,7 +14,7 @@ interface ?""" try: parser.parse(input) results = parser.finish() - except WebIDL.WebIDLError, e: + except WebIDL.WebIDLError as e: threw = True lines = str(e).split('\n') diff --git a/components/script/dom/bindings/codegen/parser/tests/test_exposed_extended_attribute.py b/components/script/dom/bindings/codegen/parser/tests/test_exposed_extended_attribute.py index 48957098bfe..a6c04e30caf 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_exposed_extended_attribute.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_exposed_extended_attribute.py @@ -124,7 +124,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception,x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown on invalid Exposed value on interface.") @@ -140,7 +140,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception,x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown on invalid Exposed value on attribute.") @@ -156,7 +156,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception,x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown on invalid Exposed value on operation.") @@ -172,7 +172,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception,x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown on invalid Exposed value on constant.") @@ -192,7 +192,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception,x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown on member exposed where its interface is not.") @@ -216,7 +216,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception,x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown on LHS of implements being exposed where RHS is not.") diff --git a/components/script/dom/bindings/codegen/parser/tests/test_float_types.py b/components/script/dom/bindings/codegen/parser/tests/test_float_types.py index 718f09c114b..b7325cf9d26 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_float_types.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_float_types.py @@ -68,7 +68,7 @@ def WebIDLTest(parser, harness): long m(float arg); }; """) - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "[LenientFloat] only allowed on void methods") @@ -81,7 +81,7 @@ def WebIDLTest(parser, harness): void m(unrestricted float arg); }; """) - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "[LenientFloat] only allowed on methods with unrestricted float args") @@ -94,7 +94,7 @@ def WebIDLTest(parser, harness): void m(sequence<unrestricted float> arg); }; """) - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "[LenientFloat] only allowed on methods with unrestricted float args (2)") @@ -107,7 +107,7 @@ def WebIDLTest(parser, harness): void m((unrestricted float or FloatTypes) arg); }; """) - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "[LenientFloat] only allowed on methods with unrestricted float args (3)") @@ -120,6 +120,6 @@ def WebIDLTest(parser, harness): readonly attribute float foo; }; """) - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "[LenientFloat] only allowed on writable attributes") diff --git a/components/script/dom/bindings/codegen/parser/tests/test_identifier_conflict.py b/components/script/dom/bindings/codegen/parser/tests/test_identifier_conflict.py index b510a30c044..0e9a6654aa7 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_identifier_conflict.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_identifier_conflict.py @@ -9,7 +9,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() harness.ok(False, "Should fail to parse") - except Exception, e: + except Exception as e: harness.ok("Name collision" in e.message, "Should have name collision for interface") @@ -21,7 +21,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() harness.ok(False, "Should fail to parse") - except Exception, e: + except Exception as e: harness.ok("Name collision" in e.message, "Should have name collision for dictionary") @@ -33,7 +33,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() harness.ok(False, "Should fail to parse") - except Exception, e: + except Exception as e: harness.ok("Multiple unresolvable definitions" in e.message, "Should have name collision for dictionary") diff --git a/components/script/dom/bindings/codegen/parser/tests/test_interface.py b/components/script/dom/bindings/codegen/parser/tests/test_interface.py index a23243abe61..ea3e842907a 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_interface.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_interface.py @@ -374,3 +374,89 @@ def WebIDLTest(parser, harness): threw = True harness.ok(threw, "Should not allow unknown extended attributes on interfaces") + + parser = parser.reset() + parser.parse(""" + [Global] interface Window {}; + [Exposed=Window, LegacyWindowAlias=A] + interface B {}; + [Exposed=Window, LegacyWindowAlias=(C, D)] + interface E {}; + """); + results = parser.finish(); + harness.check(results[1].legacyWindowAliases, ["A"], + "Should support a single identifier") + harness.check(results[2].legacyWindowAliases, ["C", "D"], + "Should support an identifier list") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + [LegacyWindowAlias] + interface A {}; + """) + results = parser.finish() + except: + threw = True + harness.ok(threw, + "Should not allow [LegacyWindowAlias] with no value") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + [Exposed=Worker, LegacyWindowAlias=B] + interface A {}; + """) + results = parser.finish() + except: + threw = True + harness.ok(threw, + "Should not allow [LegacyWindowAlias] without Window exposure") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + [Global] interface Window {}; + interface A {}; + [Exposed=Window, LegacyWindowAlias=A] + interface B {}; + """) + results = parser.finish() + except: + threw = True + harness.ok(threw, + "Should not allow [LegacyWindowAlias] to conflict with other identifiers") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + [Global] interface Window {}; + [Exposed=Window, LegacyWindowAlias=A] + interface B {}; + interface A {}; + """) + results = parser.finish() + except: + threw = True + harness.ok(threw, + "Should not allow [LegacyWindowAlias] to conflict with other identifiers") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + [Global] interface Window {}; + [Exposed=Window, LegacyWindowAlias=A] + interface B {}; + [Exposed=Window, LegacyWindowAlias=A] + interface C {}; + """) + results = parser.finish() + except: + threw = True + harness.ok(threw, + "Should not allow [LegacyWindowAlias] to conflict with other identifiers") diff --git a/components/script/dom/bindings/codegen/parser/tests/test_interface_maplikesetlikeiterable.py b/components/script/dom/bindings/codegen/parser/tests/test_interface_maplikesetlikeiterable.py index ee5d870c200..72aa7617b84 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_interface_maplikesetlikeiterable.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_interface_maplikesetlikeiterable.py @@ -37,10 +37,10 @@ def WebIDLTest(parser, harness): p.finish() harness.ok(False, prefix + " - Interface passed when should've failed") - except WebIDL.WebIDLError, e: + except WebIDL.WebIDLError as e: harness.ok(True, prefix + " - Interface failed as expected") - except Exception, e: + except Exception as e: harness.ok(False, prefix + " - Interface failed but not as a WebIDLError exception: %s" % e) diff --git a/components/script/dom/bindings/codegen/parser/tests/test_lenientSetter.py b/components/script/dom/bindings/codegen/parser/tests/test_lenientSetter.py index 50e9df658e9..78a9ffe9eaa 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_lenientSetter.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_lenientSetter.py @@ -1,6 +1,6 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# file, You can obtain one at http://mozilla.org/MPL/2.0/. def should_throw(parser, harness, message, code): parser = parser.reset(); diff --git a/components/script/dom/bindings/codegen/parser/tests/test_method.py b/components/script/dom/bindings/codegen/parser/tests/test_method.py index 29e6d6b25b7..88ee874386c 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_method.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_method.py @@ -120,7 +120,7 @@ def WebIDLTest(parser, harness): }; """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(not threw, "Should allow integer to float type corecion") @@ -133,7 +133,7 @@ def WebIDLTest(parser, harness): }; """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should not allow [GetterThrows] on methods") @@ -146,7 +146,7 @@ def WebIDLTest(parser, harness): }; """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should not allow [SetterThrows] on methods") @@ -159,7 +159,7 @@ def WebIDLTest(parser, harness): }; """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should spell [Throws] correctly on methods") @@ -172,6 +172,85 @@ def WebIDLTest(parser, harness): }; """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should not allow __noSuchMethod__ methods") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + interface A { + [Throws, LenientFloat] + void foo(float myFloat); + [Throws] + void foo(); + }; + """) + results = parser.finish() + except Exception as x: + threw = True + harness.ok(not threw, "Should allow LenientFloat to be only in a specific overload") + + parser = parser.reset() + parser.parse(""" + interface A { + [Throws] + void foo(); + [Throws, LenientFloat] + void foo(float myFloat); + }; + """) + results = parser.finish() + iface = results[0] + methods = iface.members + lenientFloat = methods[0].getExtendedAttribute("LenientFloat") + harness.ok(lenientFloat is not None, "LenientFloat in overloads must be added to the method") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + interface A { + [Throws, LenientFloat] + void foo(float myFloat); + [Throws] + void foo(float myFloat, float yourFloat); + }; + """) + results = parser.finish() + except Exception as x: + threw = True + harness.ok(threw, "Should prevent overloads from getting different restricted float behavior") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + interface A { + [Throws] + void foo(float myFloat, float yourFloat); + [Throws, LenientFloat] + void foo(float myFloat); + }; + """) + results = parser.finish() + except Exception as x: + threw = True + harness.ok(threw, "Should prevent overloads from getting different restricted float behavior (2)") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + interface A { + [Throws, LenientFloat] + void foo(float myFloat); + [Throws, LenientFloat] + void foo(short myShort); + }; + """) + results = parser.finish() + except Exception as x: + threw = True + harness.ok(threw, "Should prevent overloads from getting redundant [LenientFloat]") diff --git a/components/script/dom/bindings/codegen/parser/tests/test_namespace.py b/components/script/dom/bindings/codegen/parser/tests/test_namespace.py index 74533a1770e..62edb270c63 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_namespace.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_namespace.py @@ -70,7 +70,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown.") @@ -85,7 +85,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown.") @@ -104,7 +104,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown.") @@ -123,7 +123,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown.") @@ -142,7 +142,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown.") @@ -161,7 +161,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown.") @@ -180,7 +180,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown.") @@ -199,7 +199,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown.") @@ -218,6 +218,6 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown.") diff --git a/components/script/dom/bindings/codegen/parser/tests/test_record.py b/components/script/dom/bindings/codegen/parser/tests/test_record.py index c3fe29fa060..d50572caf07 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_record.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_record.py @@ -33,7 +33,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception,x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown because record can't have void as value type.") @@ -47,7 +47,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception,x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown on dictionary containing itself via record.") diff --git a/components/script/dom/bindings/codegen/parser/tests/test_replaceable.py b/components/script/dom/bindings/codegen/parser/tests/test_replaceable.py index 78b1bf7e60b..93ee42ed919 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_replaceable.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_replaceable.py @@ -1,6 +1,6 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# file, You can obtain one at http://mozilla.org/MPL/2.0/. def should_throw(parser, harness, message, code): parser = parser.reset(); diff --git a/components/script/dom/bindings/codegen/parser/tests/test_typedef.py b/components/script/dom/bindings/codegen/parser/tests/test_typedef.py index 8921985c5ca..b5fc1c68890 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_typedef.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_typedef.py @@ -4,15 +4,15 @@ def WebIDLTest(parser, harness): typedef long? mynullablelong; interface Foo { const mylong X = 5; - const mynullablelong Y = 7; - const mynullablelong Z = null; - void foo(mylong arg); + void foo(optional mynullablelong arg = 7); + void bar(optional mynullablelong arg = null); + void baz(mylong arg); }; """) results = parser.finish() - harness.check(results[2].members[1].type.name, "LongOrNull", + harness.check(results[2].members[1].signatures()[0][1][0].type.name, "LongOrNull", "Should expand typedefs") parser = parser.reset() diff --git a/components/script/dom/bindings/codegen/parser/tests/test_unenumerable_own_properties.py b/components/script/dom/bindings/codegen/parser/tests/test_unenumerable_own_properties.py index d017d5ce092..d28cc1ec052 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_unenumerable_own_properties.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_unenumerable_own_properties.py @@ -24,7 +24,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown.") @@ -39,7 +39,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown.") @@ -59,6 +59,6 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception, x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown.") diff --git a/components/script/dom/bindings/codegen/parser/tests/test_unforgeable.py b/components/script/dom/bindings/codegen/parser/tests/test_unforgeable.py index 3787e8c6af1..44a168670ed 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_unforgeable.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_unforgeable.py @@ -111,7 +111,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception,x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown when shadowing unforgeable attribute on " @@ -130,7 +130,7 @@ def WebIDLTest(parser, harness): """) results = parser.finish() - except Exception,x: + except Exception as x: threw = True harness.ok(threw, "Should have thrown when shadowing unforgeable operation on " diff --git a/components/script/dom/bindings/codegen/parser/tests/test_union.py b/components/script/dom/bindings/codegen/parser/tests/test_union.py index 9c4f2a56ab6..801314fd0bd 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_union.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_union.py @@ -17,7 +17,7 @@ def combinations(iterable, r): n = len(pool) if r > n: return - indices = range(r) + indices = list(range(r)) yield tuple(pool[i] for i in indices) while True: for i in reversed(range(r)): |