aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/parser/tests
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/bindings/codegen/parser/tests')
-rw-r--r--components/script/dom/bindings/codegen/parser/tests/test_argument_keywords.py17
-rw-r--r--components/script/dom/bindings/codegen/parser/tests/test_attributes_on_types.py12
-rw-r--r--components/script/dom/bindings/codegen/parser/tests/test_constructor.py207
-rw-r--r--components/script/dom/bindings/codegen/parser/tests/test_constructor_global.py18
-rw-r--r--components/script/dom/bindings/codegen/parser/tests/test_constructor_no_interface_object.py18
-rw-r--r--components/script/dom/bindings/codegen/parser/tests/test_dictionary.py74
-rw-r--r--components/script/dom/bindings/codegen/parser/tests/test_distinguishability.py8
-rw-r--r--components/script/dom/bindings/codegen/parser/tests/test_interface.py8
-rw-r--r--components/script/dom/bindings/codegen/parser/tests/test_interface_maplikesetlikeiterable.py16
9 files changed, 265 insertions, 113 deletions
diff --git a/components/script/dom/bindings/codegen/parser/tests/test_argument_keywords.py b/components/script/dom/bindings/codegen/parser/tests/test_argument_keywords.py
new file mode 100644
index 00000000000..e190f617e26
--- /dev/null
+++ b/components/script/dom/bindings/codegen/parser/tests/test_argument_keywords.py
@@ -0,0 +1,17 @@
+def WebIDLTest(parser, harness):
+ parser.parse("""
+ interface Foo {
+ void foo(object constructor);
+ };
+ """)
+
+ results = parser.finish()
+ harness.check(len(results), 1, "Should have an interface");
+ iface = results[0];
+ harness.check(len(iface.members), 1, "Should have an operation");
+ operation = iface.members[0];
+ harness.check(len(operation.signatures()), 1, "Should have one signature");
+ (retval, args) = operation.signatures()[0];
+ harness.check(len(args), 1, "Should have an argument");
+ harness.check(args[0].identifier.name, "constructor",
+ "Should have an identifier named 'constructor'");
diff --git a/components/script/dom/bindings/codegen/parser/tests/test_attributes_on_types.py b/components/script/dom/bindings/codegen/parser/tests/test_attributes_on_types.py
index 1128d58317a..43daca3c453 100644
--- a/components/script/dom/bindings/codegen/parser/tests/test_attributes_on_types.py
+++ b/components/script/dom/bindings/codegen/parser/tests/test_attributes_on_types.py
@@ -209,6 +209,18 @@ def WebIDLTest(parser, harness):
threw = False
try:
parser.parse("""
+ typedef [TreatNullAs=EmptyString] JSString Foo;
+ """)
+ parser.finish()
+ except:
+ threw = True
+
+ harness.ok(threw, "Should not allow [TreatNullAs] on JSString")
+
+ parser = parser.reset()
+ threw = False
+ try:
+ parser.parse("""
interface Foo {
void foo([Clamp] Bar arg);
};
diff --git a/components/script/dom/bindings/codegen/parser/tests/test_constructor.py b/components/script/dom/bindings/codegen/parser/tests/test_constructor.py
index c722d7bc5c7..20eb152cdab 100644
--- a/components/script/dom/bindings/codegen/parser/tests/test_constructor.py
+++ b/components/script/dom/bindings/codegen/parser/tests/test_constructor.py
@@ -43,45 +43,55 @@ def WebIDLTest(parser, harness):
(QName, name, type, optional, variadic) = expectedArgs[i]
checkArgument(gotArgs[i], QName, name, type, optional, variadic)
+ def checkResults(results):
+ harness.check(len(results), 3, "Should be three productions")
+ harness.ok(isinstance(results[0], WebIDL.IDLInterface),
+ "Should be an IDLInterface")
+ harness.ok(isinstance(results[1], WebIDL.IDLInterface),
+ "Should be an IDLInterface")
+ harness.ok(isinstance(results[2], WebIDL.IDLInterface),
+ "Should be an IDLInterface")
+
+ checkMethod(results[0].ctor(), "::TestConstructorNoArgs::constructor",
+ "constructor", [("TestConstructorNoArgs (Wrapper)", [])])
+ harness.check(len(results[0].members), 0,
+ "TestConstructorNoArgs should not have members")
+ checkMethod(results[1].ctor(), "::TestConstructorWithArgs::constructor",
+ "constructor",
+ [("TestConstructorWithArgs (Wrapper)",
+ [("::TestConstructorWithArgs::constructor::name", "name", "String", False, False)])])
+ harness.check(len(results[1].members), 0,
+ "TestConstructorWithArgs should not have members")
+ checkMethod(results[2].ctor(), "::TestConstructorOverloads::constructor",
+ "constructor",
+ [("TestConstructorOverloads (Wrapper)",
+ [("::TestConstructorOverloads::constructor::foo", "foo", "Object", False, False)]),
+ ("TestConstructorOverloads (Wrapper)",
+ [("::TestConstructorOverloads::constructor::bar", "bar", "Boolean", False, False)])])
+ harness.check(len(results[2].members), 0,
+ "TestConstructorOverloads should not have members")
+
parser.parse("""
- [Constructor]
interface TestConstructorNoArgs {
+ constructor();
};
- [Constructor(DOMString name)]
interface TestConstructorWithArgs {
+ constructor(DOMString name);
};
- [Constructor(object foo), Constructor(boolean bar)]
interface TestConstructorOverloads {
+ constructor(object foo);
+ constructor(boolean bar);
};
""")
results = parser.finish()
- harness.check(len(results), 3, "Should be three productions")
- harness.ok(isinstance(results[0], WebIDL.IDLInterface),
- "Should be an IDLInterface")
- harness.ok(isinstance(results[1], WebIDL.IDLInterface),
- "Should be an IDLInterface")
- harness.ok(isinstance(results[2], WebIDL.IDLInterface),
- "Should be an IDLInterface")
-
- checkMethod(results[0].ctor(), "::TestConstructorNoArgs::constructor",
- "constructor", [("TestConstructorNoArgs (Wrapper)", [])])
- checkMethod(results[1].ctor(), "::TestConstructorWithArgs::constructor",
- "constructor",
- [("TestConstructorWithArgs (Wrapper)",
- [("::TestConstructorWithArgs::constructor::name", "name", "String", False, False)])])
- checkMethod(results[2].ctor(), "::TestConstructorOverloads::constructor",
- "constructor",
- [("TestConstructorOverloads (Wrapper)",
- [("::TestConstructorOverloads::constructor::foo", "foo", "Object", False, False)]),
- ("TestConstructorOverloads (Wrapper)",
- [("::TestConstructorOverloads::constructor::bar", "bar", "Boolean", False, False)])])
+ checkResults(results)
parser = parser.reset()
parser.parse("""
- [ChromeConstructor()]
- interface TestChromeConstructor {
+ interface TestChromeOnlyConstructor {
+ [ChromeOnly] constructor();
};
""")
results = parser.finish()
@@ -89,8 +99,8 @@ def WebIDLTest(parser, harness):
harness.ok(isinstance(results[0], WebIDL.IDLInterface),
"Should be an IDLInterface")
- checkMethod(results[0].ctor(), "::TestChromeConstructor::constructor",
- "constructor", [("TestChromeConstructor (Wrapper)", [])],
+ checkMethod(results[0].ctor(), "::TestChromeOnlyConstructor::constructor",
+ "constructor", [("TestChromeOnlyConstructor (Wrapper)", [])],
chromeOnly=True)
parser = parser.reset()
@@ -112,16 +122,16 @@ def WebIDLTest(parser, harness):
threw = False
try:
parser.parse("""
- [Constructor(),
- ChromeConstructor(DOMString a)]
- interface TestChromeConstructor {
+ interface TestChromeOnlyConstructor {
+ constructor()
+ [ChromeOnly] constructor(DOMString a);
};
""")
results = parser.finish()
except:
threw = True
- harness.ok(threw, "Can't have both a Constructor and a ChromeConstructor")
+ harness.ok(threw, "Can't have both a constructor and a ChromeOnly constructor")
# Test HTMLConstructor with argument
parser = parser.reset()
@@ -153,120 +163,197 @@ def WebIDLTest(parser, harness):
harness.ok(threw, "HTMLConstructor can't be used on a callback interface")
- # Test HTMLConstructor and Constructor
+ # Test HTMLConstructor and constructor operation
+ parser = parser.reset()
+ threw = False
+ try:
+ parser.parse("""
+ [HTMLConstructor]
+ interface TestHTMLConstructorAndConstructor {
+ constructor();
+ };
+ """)
+ results = parser.finish()
+ except:
+ threw = True
+
+ harness.ok(threw, "Can't have both a constructor and a HTMLConstructor")
+
+ parser = parser.reset()
+ threw = False
+ try:
+ parser.parse("""
+ [HTMLConstructor]
+ interface TestHTMLConstructorAndConstructor {
+ [Throws]
+ constructor();
+ };
+ """)
+ results = parser.finish()
+ except:
+ threw = True
+
+ harness.ok(threw,
+ "Can't have both a throwing constructor and a HTMLConstructor")
+
+ parser = parser.reset()
+ threw = False
+ try:
+ parser.parse("""
+ [HTMLConstructor]
+ interface TestHTMLConstructorAndConstructor {
+ constructor(DOMString a);
+ };
+ """)
+ results = parser.finish()
+ except:
+ threw = True
+
+ harness.ok(threw,
+ "Can't have both a HTMLConstructor and a constructor operation")
+
parser = parser.reset()
threw = False
try:
parser.parse("""
- [Constructor,
- HTMLConstructor]
+ [HTMLConstructor]
interface TestHTMLConstructorAndConstructor {
+ [Throws]
+ constructor(DOMString a);
};
""")
results = parser.finish()
except:
threw = True
- harness.ok(threw, "Can't have both a Constructor and a HTMLConstructor")
+ harness.ok(threw,
+ "Can't have both a HTMLConstructor and a throwing constructor "
+ "operation")
+ # Test HTMLConstructor and [ChromeOnly] constructor operation
parser = parser.reset()
threw = False
try:
parser.parse("""
- [HTMLConstructor,
- Constructor]
+ [HTMLConstructor]
interface TestHTMLConstructorAndConstructor {
+ [ChromeOnly]
+ constructor();
};
""")
results = parser.finish()
except:
threw = True
- harness.ok(threw, "Can't have both a HTMLConstructor and a Constructor")
+ harness.ok(threw,
+ "Can't have both a ChromeOnly constructor and a HTMLConstructor")
parser = parser.reset()
threw = False
try:
parser.parse("""
- [HTMLConstructor,
- Constructor(DOMString a)]
+ [HTMLConstructor]
interface TestHTMLConstructorAndConstructor {
+ [Throws, ChromeOnly]
+ constructor();
};
""")
+ results = parser.finish()
except:
threw = True
- harness.ok(threw, "Can't have both a HTMLConstructor and a Constructor")
+ harness.ok(threw,
+ "Can't have both a throwing chromeonly constructor and a "
+ "HTMLConstructor")
parser = parser.reset()
threw = False
try:
parser.parse("""
- [Constructor(DOMString a),
- HTMLConstructor]
+ [HTMLConstructor]
interface TestHTMLConstructorAndConstructor {
+ [ChromeOnly]
+ constructor(DOMString a);
};
""")
+ results = parser.finish()
except:
threw = True
- harness.ok(threw, "Can't have both a HTMLConstructor and a Constructor")
+ harness.ok(threw,
+ "Can't have both a HTMLConstructor and a chromeonly constructor "
+ "operation")
- # Test HTMLConstructor and ChromeConstructor
parser = parser.reset()
threw = False
try:
parser.parse("""
- [ChromeConstructor,
- HTMLConstructor]
- interface TestHTMLConstructorAndChromeConstructor {
+ [HTMLConstructor]
+ interface TestHTMLConstructorAndConstructor {
+ [Throws, ChromeOnly]
+ constructor(DOMString a);
};
""")
results = parser.finish()
except:
threw = True
- harness.ok(threw, "Can't have both a HTMLConstructor and a ChromeConstructor")
+ harness.ok(threw,
+ "Can't have both a HTMLConstructor and a throwing chromeonly "
+ "constructor operation")
parser = parser.reset()
threw = False
try:
parser.parse("""
- [HTMLConstructor,
- ChromeConstructor]
- interface TestHTMLConstructorAndChromeConstructor {
+ [NoInterfaceObject]
+ interface InterfaceWithoutInterfaceObject {
+ constructor();
};
""")
results = parser.finish()
except:
threw = True
- harness.ok(threw, "Can't have both a HTMLConstructor and a ChromeConstructor")
+ harness.ok(threw,
+ "Can't have a constructor operation on a [NoInterfaceObject] "
+ "interface")
parser = parser.reset()
threw = False
try:
parser.parse("""
- [ChromeConstructor(DOMString a),
- HTMLConstructor]
- interface TestHTMLConstructorAndChromeConstructor {
+ interface InterfaceWithPartial {
+ };
+
+ partial interface InterfaceWithPartial {
+ constructor();
};
""")
results = parser.finish()
except:
threw = True
+ harness.ok(threw,
+ "Can't have a constructor operation on a partial interface")
+
parser = parser.reset()
threw = False
try:
parser.parse("""
- [HTMLConstructor,
- ChromeConstructor(DOMString a)]
- interface TestHTMLConstructorAndChromeConstructor {
+ interface InterfaceWithMixin {
};
+
+ interface mixin Mixin {
+ constructor();
+ };
+
+ InterfaceWithMixin includes Mixin
""")
results = parser.finish()
except:
threw = True
- harness.ok(threw, "Can't have both a HTMLConstructor and a ChromeConstructor")
+ harness.ok(threw,
+ "Can't have a constructor operation on a mixin")
+
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
index 14d42caf09c..c469d56e817 100644
--- a/components/script/dom/bindings/codegen/parser/tests/test_constructor_global.py
+++ b/components/script/dom/bindings/codegen/parser/tests/test_constructor_global.py
@@ -2,23 +2,9 @@ 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]
+ [Global]
interface TestConstructorGlobal {
+ constructor();
};
""")
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 e5413350a28..d4175094911 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
@@ -2,23 +2,9 @@ def WebIDLTest(parser, harness):
threw = False
try:
parser.parse("""
- [Constructor, NoInterfaceObject]
- interface TestConstructorNoInterfaceObject {
- };
- """)
-
- results = parser.finish()
- except:
- threw = True
-
- harness.ok(threw, "Should have thrown.")
-
- parser = parser.reset()
- threw = False
- try:
- parser.parse("""
- [NoInterfaceObject, Constructor]
+ [NoInterfaceObject]
interface TestConstructorNoInterfaceObject {
+ constructor();
};
""")
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 770f76b22f0..cff049bea15 100644
--- a/components/script/dom/bindings/codegen/parser/tests/test_dictionary.py
+++ b/components/script/dom/bindings/codegen/parser/tests/test_dictionary.py
@@ -320,14 +320,36 @@ def WebIDLTest(parser, harness):
dictionary A {
};
interface X {
- void doFoo(optional A? arg1);
+ void doFoo(optional A? arg1 = {});
};
""")
results = parser.finish()
- except:
- threw = True
+ except Exception as x:
+ threw = x
+
+ harness.ok(threw, "Optional dictionary arg must not be nullable")
+ harness.ok("nullable" in str(threw),
+ "Must have the expected exception for optional nullable dictionary arg")
+
+ parser = parser.reset()
+ threw = False
+ try:
+ parser.parse("""
+ dictionary A {
+ required long x;
+ };
+ interface X {
+ void doFoo(A? arg1);
+ };
+ """)
+ results = parser.finish()
+ except Exception as x:
+ threw = x
- harness.ok(threw, "Dictionary arg must not be nullable")
+ harness.ok(threw, "Required dictionary arg must not be nullable")
+ harness.ok("nullable" in str(threw),
+ "Must have the expected exception for required nullable "
+ "dictionary arg")
parser = parser.reset()
threw = False
@@ -336,14 +358,54 @@ def WebIDLTest(parser, harness):
dictionary A {
};
interface X {
- void doFoo(optional (A or long)? arg1);
+ void doFoo(optional (A or long)? arg1 = {});
+ };
+ """)
+ results = parser.finish()
+ except Exception as x:
+ threw = x
+
+ harness.ok(threw, "Dictionary arg must not be in an optional nullable union")
+ harness.ok("nullable" in str(threw),
+ "Must have the expected exception for optional nullable union "
+ "arg containing dictionary")
+
+ parser = parser.reset()
+ threw = False
+ try:
+ parser.parse("""
+ dictionary A {
+ required long x;
+ };
+ interface X {
+ void doFoo((A or long)? arg1);
+ };
+ """)
+ results = parser.finish()
+ except Exception as x:
+ threw = x
+
+ harness.ok(threw, "Dictionary arg must not be in a required nullable union")
+ harness.ok("nullable" in str(threw),
+ "Must have the expected exception for required nullable union "
+ "arg containing dictionary")
+
+ parser = parser.reset()
+ threw = False
+ try:
+ parser.parse("""
+ dictionary A {
+ };
+ interface X {
+ void doFoo(sequence<A?> arg1);
};
""")
results = parser.finish()
except:
threw = True
- harness.ok(threw, "Dictionary arg must not be in a nullable union")
+ harness.ok(not threw,
+ "Nullable union should be allowed in a sequence argument")
parser = parser.reset()
threw = False
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 e88c2b50d98..8d18b26cf2d 100644
--- a/components/script/dom/bindings/codegen/parser/tests/test_distinguishability.py
+++ b/components/script/dom/bindings/codegen/parser/tests/test_distinguishability.py
@@ -166,7 +166,7 @@ def WebIDLTest(parser, harness):
"record<ByteString, long>",
"Date", "Date?", "any",
"Promise<any>", "Promise<any>?",
- "USVString", "ArrayBuffer", "ArrayBufferView", "SharedArrayBuffer",
+ "USVString", "JSString", "ArrayBuffer", "ArrayBufferView", "SharedArrayBuffer",
"Uint8Array", "Uint16Array",
"(long or Callback)", "(long or Dict)",
]
@@ -183,7 +183,7 @@ def WebIDLTest(parser, harness):
primitives = numerics + booleans
nonNumerics = allBut(argTypes, numerics + unions)
nonBooleans = allBut(argTypes, booleans)
- strings = [ "DOMString", "ByteString", "Enum", "Enum2", "USVString" ]
+ strings = [ "DOMString", "ByteString", "Enum", "Enum2", "USVString", "JSString" ]
nonStrings = allBut(argTypes, strings)
nonObjects = primitives + strings
objects = allBut(argTypes, nonObjects )
@@ -202,7 +202,7 @@ def WebIDLTest(parser, harness):
notRelatedInterfaces = (nonObjects + ["UnrelatedInterface"] +
otherObjects + dates + sequences + bufferSourceTypes + sharedBufferSourceTypes)
records = [ "record<DOMString, object>", "record<USVString, Dict>",
- "record<ByteString, long>" ]
+ "record<ByteString, long>" ] # JSString not supported in records
# Build a representation of the distinguishability table as a dict
# of dicts, holding True values where needed, holes elsewhere.
@@ -222,6 +222,7 @@ def WebIDLTest(parser, harness):
setDistinguishable("DOMString", nonStrings)
setDistinguishable("ByteString", nonStrings)
setDistinguishable("USVString", nonStrings)
+ setDistinguishable("JSString", nonStrings)
setDistinguishable("Enum", nonStrings)
setDistinguishable("Enum2", nonStrings)
setDistinguishable("Interface", notRelatedInterfaces)
@@ -244,6 +245,7 @@ def WebIDLTest(parser, harness):
allBut(argTypes, sequences + ["object"]))
setDistinguishable("record<DOMString, object>", nonUserObjects)
setDistinguishable("record<USVString, Dict>", nonUserObjects)
+ # JSString not supported in records
setDistinguishable("record<ByteString, long>", nonUserObjects)
setDistinguishable("Date", allBut(argTypes, dates + ["object"]))
setDistinguishable("Date?", allBut(argTypes, dates + nullables + ["object"]))
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 ea3e842907a..28e6af94597 100644
--- a/components/script/dom/bindings/codegen/parser/tests/test_interface.py
+++ b/components/script/dom/bindings/codegen/parser/tests/test_interface.py
@@ -189,12 +189,12 @@ def WebIDLTest(parser, harness):
parser = parser.reset()
parser.parse("""
- [Constructor(long arg)]
interface A {
+ constructor();
+ constructor(long arg);
readonly attribute boolean x;
void foo();
};
- [Constructor]
partial interface A {
readonly attribute boolean y;
void foo(long arg);
@@ -219,13 +219,13 @@ def WebIDLTest(parser, harness):
parser = parser.reset()
parser.parse("""
- [Constructor]
partial interface A {
readonly attribute boolean y;
void foo(long arg);
};
- [Constructor(long arg)]
interface A {
+ constructor();
+ constructor(long arg);
readonly attribute boolean x;
void foo();
};
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 72aa7617b84..5de2e02af7e 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
@@ -264,18 +264,18 @@ def WebIDLTest(parser, harness):
shouldPass("JS Implemented maplike interface",
"""
- [JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1",
- Constructor()]
+ [JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1"]
interface Foo1 {
+ constructor();
setlike<long>;
};
""", setRWChromeMembers)
shouldPass("JS Implemented maplike interface",
"""
- [JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1",
- Constructor()]
+ [JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1"]
interface Foo1 {
+ constructor();
maplike<long, long>;
};
""", mapRWChromeMembers)
@@ -655,9 +655,9 @@ def WebIDLTest(parser, harness):
shouldPass("JS Implemented read-only interface with readonly allowable overrides",
"""
- [JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1",
- Constructor()]
+ [JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1"]
interface Foo1 {
+ constructor();
readonly setlike<long>;
readonly attribute boolean clear;
};
@@ -665,9 +665,9 @@ def WebIDLTest(parser, harness):
shouldFail("JS Implemented read-write interface with non-readwrite allowable overrides",
"""
- [JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1",
- Constructor()]
+ [JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1"]
interface Foo1 {
+ constructor();
setlike<long>;
readonly attribute boolean clear;
};