aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/parser/tests
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2019-03-02 11:48:31 +0530
committerManish Goregaokar <manishsmail@gmail.com>2019-03-04 14:03:31 +0530
commit7b48df53a142507f6f11b9645b605be816db5ab1 (patch)
tree6d99a826f6c81b011c398c6aeeaa2c16e4cc5b04 /components/script/dom/bindings/codegen/parser/tests
parent5fa80a8be0a2cdbb5e84856da6a041958aacc238 (diff)
downloadservo-7b48df53a142507f6f11b9645b605be816db5ab1.tar.gz
servo-7b48df53a142507f6f11b9645b605be816db5ab1.zip
Update WebIDL.py to 4166cae81546
https://hg.mozilla.org/integration/autoland/rev/4166cae81546f54accae807413f806d20bf30920 Pulls in changes from https://bugzilla.mozilla.org/show_bug.cgi?id=1359269
Diffstat (limited to 'components/script/dom/bindings/codegen/parser/tests')
-rw-r--r--components/script/dom/bindings/codegen/parser/tests/test_attributes_on_types.py238
-rw-r--r--components/script/dom/bindings/codegen/parser/tests/test_extended_attributes.py8
-rw-r--r--components/script/dom/bindings/codegen/parser/tests/test_typedef_identifier_conflict.py16
3 files changed, 258 insertions, 4 deletions
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
new file mode 100644
index 00000000000..1128d58317a
--- /dev/null
+++ b/components/script/dom/bindings/codegen/parser/tests/test_attributes_on_types.py
@@ -0,0 +1,238 @@
+# Import the WebIDL module, so we can do isinstance checks and whatnot
+import WebIDL
+
+def WebIDLTest(parser, harness):
+ # Basic functionality
+ threw = False
+ try:
+ parser.parse("""
+ typedef [EnforceRange] long Foo;
+ typedef [Clamp] long Bar;
+ typedef [TreatNullAs=EmptyString] DOMString Baz;
+ dictionary A {
+ required [EnforceRange] long a;
+ required [Clamp] long b;
+ [ChromeOnly, EnforceRange] long c;
+ Foo d;
+ };
+ interface B {
+ attribute Foo typedefFoo;
+ attribute [EnforceRange] long foo;
+ attribute [Clamp] long bar;
+ attribute [TreatNullAs=EmptyString] DOMString baz;
+ void method([EnforceRange] long foo, [Clamp] long bar,
+ [TreatNullAs=EmptyString] DOMString baz);
+ void method2(optional [EnforceRange] long foo, optional [Clamp] long bar,
+ optional [TreatNullAs=EmptyString] DOMString baz);
+ };
+ interface Setlike {
+ setlike<[Clamp] long>;
+ };
+ interface Maplike {
+ maplike<[Clamp] long, [EnforceRange] long>;
+ };
+ interface Iterable {
+ iterable<[Clamp] long, [EnforceRange] long>;
+ };
+ """)
+ results = parser.finish()
+ except:
+ threw = True
+
+ harness.ok(not threw, "Should not have thrown on parsing normal")
+ if not threw:
+ harness.check(results[0].innerType.enforceRange, True, "Foo is [EnforceRange]")
+ harness.check(results[1].innerType.clamp, True, "Bar is [Clamp]")
+ harness.check(results[2].innerType.treatNullAsEmpty, True, "Baz is [TreatNullAs=EmptyString]")
+ A = results[3]
+ harness.check(A.members[0].type.enforceRange, True, "A.a is [EnforceRange]")
+ harness.check(A.members[1].type.clamp, True, "A.b is [Clamp]")
+ harness.check(A.members[2].type.enforceRange, True, "A.c is [EnforceRange]")
+ harness.check(A.members[3].type.enforceRange, True, "A.d is [EnforceRange]")
+ B = results[4]
+ harness.check(B.members[0].type.enforceRange, True, "B.typedefFoo is [EnforceRange]")
+ harness.check(B.members[1].type.enforceRange, True, "B.foo is [EnforceRange]")
+ harness.check(B.members[2].type.clamp, True, "B.bar is [Clamp]")
+ harness.check(B.members[3].type.treatNullAsEmpty, True, "B.baz is [TreatNullAs=EmptyString]")
+ method = B.members[4].signatures()[0][1]
+ harness.check(method[0].type.enforceRange, True, "foo argument of method is [EnforceRange]")
+ harness.check(method[1].type.clamp, True, "bar argument of method is [Clamp]")
+ harness.check(method[2].type.treatNullAsEmpty, True, "baz argument of method is [TreatNullAs=EmptyString]")
+ method2 = B.members[5].signatures()[0][1]
+ harness.check(method[0].type.enforceRange, True, "foo argument of method2 is [EnforceRange]")
+ harness.check(method[1].type.clamp, True, "bar argument of method2 is [Clamp]")
+ harness.check(method[2].type.treatNullAsEmpty, True, "baz argument of method2 is [TreatNullAs=EmptyString]")
+
+ ATTRIBUTES = [("[Clamp]", "long"), ("[EnforceRange]", "long"), ("[TreatNullAs=EmptyString]", "DOMString")]
+ TEMPLATES = [
+ ("required dictionary members", """
+ dictionary Foo {
+ %s required %s foo;
+ };
+ """),
+ ("optional arguments", """
+ interface Foo {
+ void foo(%s optional %s foo);
+ };
+ """),
+ ("typedefs", """
+ %s typedef %s foo;
+ """),
+ ("attributes", """
+ interface Foo {
+ %s attribute %s foo;
+ };
+ """),
+ ("readonly attributes", """
+ interface Foo {
+ readonly attribute %s %s foo;
+ };
+ """),
+ ("readonly unresolved attributes", """
+ interface Foo {
+ readonly attribute Bar baz;
+ };
+ typedef %s %s Bar;
+ """)
+ ];
+
+ for (name, template) in TEMPLATES:
+ parser = parser.reset()
+ threw = False
+ try:
+ parser.parse(template % ("", "long"))
+ parser.finish()
+ except:
+ threw = True
+ harness.ok(not threw, "Template for %s parses without attributes" % name)
+ for (attribute, type) in ATTRIBUTES:
+ parser = parser.reset()
+ threw = False
+ try:
+ parser.parse(template % (attribute, type))
+ parser.finish()
+ except:
+ threw = True
+ harness.ok(threw,
+ "Should not allow %s on %s" % (attribute, name))
+
+ parser = parser.reset()
+ threw = False
+ try:
+ parser.parse("""
+ typedef [Clamp, EnforceRange] long Foo;
+ """)
+ parser.finish()
+ except:
+ threw = True
+
+ harness.ok(threw, "Should not allow mixing [Clamp] and [EnforceRange]")
+
+ parser = parser.reset()
+ threw = False
+ try:
+ parser.parse("""
+ typedef [EnforceRange, Clamp] long Foo;
+ """)
+ parser.finish()
+ except:
+ threw = True
+
+ harness.ok(threw, "Should not allow mixing [Clamp] and [EnforceRange]")
+
+
+ parser = parser.reset()
+ threw = False
+ try:
+ parser.parse("""
+ typedef [Clamp] long Foo;
+ typedef [EnforceRange] Foo bar;
+ """)
+ parser.finish()
+ except:
+ threw = True
+
+ harness.ok(threw, "Should not allow mixing [Clamp] and [EnforceRange] via typedefs")
+
+ parser = parser.reset()
+ threw = False
+ try:
+ parser.parse("""
+ typedef [EnforceRange] long Foo;
+ typedef [Clamp] Foo bar;
+ """)
+ parser.finish()
+ except:
+ threw = True
+
+ harness.ok(threw, "Should not allow mixing [Clamp] and [EnforceRange] via typedefs")
+
+ parser = parser.reset()
+ threw = False
+ try:
+ parser.parse("""
+ typedef [Clamp] DOMString Foo;
+ """)
+ parser.finish()
+ except:
+ threw = True
+
+ harness.ok(threw, "Should not allow [Clamp] on DOMString")
+
+
+ parser = parser.reset()
+ threw = False
+ try:
+ parser.parse("""
+ typedef [EnforceRange] DOMString Foo;
+ """)
+ parser.finish()
+ except:
+ threw = True
+
+ harness.ok(threw, "Should not allow [EnforceRange] on DOMString")
+
+
+ parser = parser.reset()
+ threw = False
+ try:
+ parser.parse("""
+ typedef [TreatNullAs=EmptyString] long Foo;
+ """)
+ parser.finish()
+ except:
+ threw = True
+
+ harness.ok(threw, "Should not allow [TreatNullAs] on long")
+
+ parser = parser.reset()
+ threw = False
+ try:
+ parser.parse("""
+ interface Foo {
+ void foo([Clamp] Bar arg);
+ };
+ typedef long Bar;
+ """)
+ results = parser.finish()
+ except:
+ threw = True
+ harness.ok(not threw, "Should allow type attributes on unresolved types")
+ harness.check(results[0].members[0].signatures()[0][1][0].type.clamp, True,
+ "Unresolved types with type attributes should correctly resolve with attributes")
+
+ parser = parser.reset()
+ threw = False
+ try:
+ parser.parse("""
+ interface Foo {
+ void foo(Bar arg);
+ };
+ typedef [Clamp] long Bar;
+ """)
+ results = parser.finish()
+ except:
+ threw = True
+ harness.ok(not threw, "Should allow type attributes on typedefs")
+ harness.check(results[0].members[0].signatures()[0][1][0].type.clamp, True,
+ "Unresolved types that resolve to typedefs with attributes should correctly resolve with attributes")
diff --git a/components/script/dom/bindings/codegen/parser/tests/test_extended_attributes.py b/components/script/dom/bindings/codegen/parser/tests/test_extended_attributes.py
index 85a70d98f2c..97184ec2478 100644
--- a/components/script/dom/bindings/codegen/parser/tests/test_extended_attributes.py
+++ b/components/script/dom/bindings/codegen/parser/tests/test_extended_attributes.py
@@ -56,9 +56,9 @@ def WebIDLTest(parser, harness):
results = parser.finish()
# Pull out the first argument out of the arglist of the first (and
# only) signature.
- harness.ok(results[0].members[0].signatures()[0][1][0].clamp,
+ harness.ok(results[0].members[0].signatures()[0][1][0].type.clamp,
"Should be clamped")
- harness.ok(not results[0].members[1].signatures()[0][1][0].clamp,
+ harness.ok(not results[0].members[1].signatures()[0][1][0].type.clamp,
"Should not be clamped")
parser = parser.reset()
@@ -86,9 +86,9 @@ def WebIDLTest(parser, harness):
results = parser.finish()
# Pull out the first argument out of the arglist of the first (and
# only) signature.
- harness.ok(results[0].members[0].signatures()[0][1][0].enforceRange,
+ harness.ok(results[0].members[0].signatures()[0][1][0].type.enforceRange,
"Should be enforceRange")
- harness.ok(not results[0].members[1].signatures()[0][1][0].enforceRange,
+ harness.ok(not results[0].members[1].signatures()[0][1][0].type.enforceRange,
"Should not be enforceRange")
parser = parser.reset()
diff --git a/components/script/dom/bindings/codegen/parser/tests/test_typedef_identifier_conflict.py b/components/script/dom/bindings/codegen/parser/tests/test_typedef_identifier_conflict.py
new file mode 100644
index 00000000000..0ea38ce437b
--- /dev/null
+++ b/components/script/dom/bindings/codegen/parser/tests/test_typedef_identifier_conflict.py
@@ -0,0 +1,16 @@
+def WebIDLTest(parser, harness):
+ exception = None
+ try:
+ parser.parse(
+ """
+ typedef long foo;
+ typedef long foo;
+ """)
+
+ results = parser.finish()
+ except Exception as e:
+ exception = e
+
+ harness.ok(exception, "Should have thrown.")
+ harness.ok("Multiple unresolvable definitions of identifier 'foo'" in str(exception),
+ "Should have a sane exception message")