Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / dom / bindings / parser / tests / test_bytestring.py
blob248d2716f3647d3a7b0713ab0db107ddc0ea5da4
1 # -*- coding: UTF-8 -*-
3 import WebIDL
6 def WebIDLTest(parser, harness):
7 parser.parse(
8 """
9 interface TestByteString {
10 attribute ByteString bs;
11 attribute DOMString ds;
13 """
16 results = parser.finish()
18 harness.ok(True, "TestByteString interface parsed without error.")
20 harness.check(len(results), 1, "Should be one production")
21 harness.ok(isinstance(results[0], WebIDL.IDLInterface), "Should be an IDLInterface")
22 iface = results[0]
23 harness.check(
24 iface.identifier.QName(), "::TestByteString", "Interface has the right QName"
26 harness.check(
27 iface.identifier.name, "TestByteString", "Interface has the right name"
29 harness.check(iface.parent, None, "Interface has no parent")
31 members = iface.members
32 harness.check(len(members), 2, "Should be two productions")
34 attr = members[0]
35 harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Should be an IDLAttribute")
36 harness.check(
37 attr.identifier.QName(), "::TestByteString::bs", "Attr has correct QName"
39 harness.check(attr.identifier.name, "bs", "Attr has correct name")
40 harness.check(str(attr.type), "ByteString", "Attr type is the correct name")
41 harness.ok(attr.type.isByteString(), "Should be ByteString type")
42 harness.ok(attr.type.isString(), "Should be String collective type")
43 harness.ok(not attr.type.isDOMString(), "Should be not be DOMString type")
45 # now check we haven't broken DOMStrings in the process.
46 attr = members[1]
47 harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Should be an IDLAttribute")
48 harness.check(
49 attr.identifier.QName(), "::TestByteString::ds", "Attr has correct QName"
51 harness.check(attr.identifier.name, "ds", "Attr has correct name")
52 harness.check(str(attr.type), "String", "Attr type is the correct name")
53 harness.ok(attr.type.isDOMString(), "Should be DOMString type")
54 harness.ok(attr.type.isString(), "Should be String collective type")
55 harness.ok(not attr.type.isByteString(), "Should be not be ByteString type")
57 # Cannot represent constant ByteString in IDL.
58 threw = False
59 try:
60 parser.parse(
61 """
62 interface ConstByteString {
63 const ByteString foo = "hello"
65 """
67 except WebIDL.WebIDLError:
68 threw = True
69 harness.ok(
70 threw, "Should have thrown a WebIDL error for ByteString default in interface"
73 # Can have optional ByteStrings with default values
74 try:
75 parser.parse(
76 """
77 interface OptionalByteString {
78 undefined passByteString(optional ByteString arg = "hello");
80 """
82 parser.finish()
83 except WebIDL.WebIDLError as e:
84 harness.ok(
85 False,
86 "Should not have thrown a WebIDL error for ByteString "
87 "default in dictionary. " + str(e),
90 # Can have a default ByteString value in a dictionary
91 try:
92 parser.parse(
93 """
94 dictionary OptionalByteStringDict {
95 ByteString item = "some string";
97 """
99 parser.finish()
100 except WebIDL.WebIDLError as e:
101 harness.ok(
102 False,
103 "Should not have thrown a WebIDL error for ByteString "
104 "default in dictionary. " + str(e),
107 # Don't allow control characters in ByteString literals
108 threw = False
109 try:
110 parser.parse(
112 dictionary OptionalByteStringDict2 {
113 ByteString item = "\x03";
117 parser.finish()
118 except WebIDL.WebIDLError:
119 threw = True
121 harness.ok(
122 threw,
123 "Should have thrown a WebIDL error for invalid ByteString "
124 "default in dictionary",