Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 import WebIDL
3 def WebIDLTest(parser, harness):
4 testData = [("::TestAttr%s::b", "b", "Byte%s", False),
5 ("::TestAttr%s::rb", "rb", "Byte%s", True),
6 ("::TestAttr%s::o", "o", "Octet%s", False),
7 ("::TestAttr%s::ro", "ro", "Octet%s", True),
8 ("::TestAttr%s::s", "s", "Short%s", False),
9 ("::TestAttr%s::rs", "rs", "Short%s", True),
10 ("::TestAttr%s::us", "us", "UnsignedShort%s", False),
11 ("::TestAttr%s::rus", "rus", "UnsignedShort%s", True),
12 ("::TestAttr%s::l", "l", "Long%s", False),
13 ("::TestAttr%s::rl", "rl", "Long%s", True),
14 ("::TestAttr%s::ul", "ul", "UnsignedLong%s", False),
15 ("::TestAttr%s::rul", "rul", "UnsignedLong%s", True),
16 ("::TestAttr%s::ll", "ll", "LongLong%s", False),
17 ("::TestAttr%s::rll", "rll", "LongLong%s", True),
18 ("::TestAttr%s::ull", "ull", "UnsignedLongLong%s", False),
19 ("::TestAttr%s::rull", "rull", "UnsignedLongLong%s", True),
20 ("::TestAttr%s::str", "str", "String%s", False),
21 ("::TestAttr%s::rstr", "rstr", "String%s", True),
22 ("::TestAttr%s::obj", "obj", "Object%s", False),
23 ("::TestAttr%s::robj", "robj", "Object%s", True),
24 ("::TestAttr%s::object", "object", "Object%s", False),
25 ("::TestAttr%s::f", "f", "Float%s", False),
26 ("::TestAttr%s::rf", "rf", "Float%s", True)]
28 parser.parse("""
29 interface TestAttr {
30 attribute byte b;
31 readonly attribute byte rb;
32 attribute octet o;
33 readonly attribute octet ro;
34 attribute short s;
35 readonly attribute short rs;
36 attribute unsigned short us;
37 readonly attribute unsigned short rus;
38 attribute long l;
39 readonly attribute long rl;
40 attribute unsigned long ul;
41 readonly attribute unsigned long rul;
42 attribute long long ll;
43 readonly attribute long long rll;
44 attribute unsigned long long ull;
45 readonly attribute unsigned long long rull;
46 attribute DOMString str;
47 readonly attribute DOMString rstr;
48 attribute object obj;
49 readonly attribute object robj;
50 attribute object _object;
51 attribute float f;
52 readonly attribute float rf;
53 };
55 interface TestAttrNullable {
56 attribute byte? b;
57 readonly attribute byte? rb;
58 attribute octet? o;
59 readonly attribute octet? ro;
60 attribute short? s;
61 readonly attribute short? rs;
62 attribute unsigned short? us;
63 readonly attribute unsigned short? rus;
64 attribute long? l;
65 readonly attribute long? rl;
66 attribute unsigned long? ul;
67 readonly attribute unsigned long? rul;
68 attribute long long? ll;
69 readonly attribute long long? rll;
70 attribute unsigned long long? ull;
71 readonly attribute unsigned long long? rull;
72 attribute DOMString? str;
73 readonly attribute DOMString? rstr;
74 attribute object? obj;
75 readonly attribute object? robj;
76 attribute object? _object;
77 attribute float? f;
78 readonly attribute float? rf;
79 };
81 interface TestAttrArray {
82 attribute byte[] b;
83 readonly attribute byte[] rb;
84 attribute octet[] o;
85 readonly attribute octet[] ro;
86 attribute short[] s;
87 readonly attribute short[] rs;
88 attribute unsigned short[] us;
89 readonly attribute unsigned short[] rus;
90 attribute long[] l;
91 readonly attribute long[] rl;
92 attribute unsigned long[] ul;
93 readonly attribute unsigned long[] rul;
94 attribute long long[] ll;
95 readonly attribute long long[] rll;
96 attribute unsigned long long[] ull;
97 readonly attribute unsigned long long[] rull;
98 attribute DOMString[] str;
99 readonly attribute DOMString[] rstr;
100 attribute object[] obj;
101 readonly attribute object[] robj;
102 attribute object[] _object;
103 attribute float[] f;
104 readonly attribute float[] rf;
105 };
107 interface TestAttrNullableArray {
108 attribute byte[]? b;
109 readonly attribute byte[]? rb;
110 attribute octet[]? o;
111 readonly attribute octet[]? ro;
112 attribute short[]? s;
113 readonly attribute short[]? rs;
114 attribute unsigned short[]? us;
115 readonly attribute unsigned short[]? rus;
116 attribute long[]? l;
117 readonly attribute long[]? rl;
118 attribute unsigned long[]? ul;
119 readonly attribute unsigned long[]? rul;
120 attribute long long[]? ll;
121 readonly attribute long long[]? rll;
122 attribute unsigned long long[]? ull;
123 readonly attribute unsigned long long[]? rull;
124 attribute DOMString[]? str;
125 readonly attribute DOMString[]? rstr;
126 attribute object[]? obj;
127 readonly attribute object[]? robj;
128 attribute object[]? _object;
129 attribute float[]? f;
130 readonly attribute float[]? rf;
131 };
133 interface TestAttrArrayOfNullableTypes {
134 attribute byte?[] b;
135 readonly attribute byte?[] rb;
136 attribute octet?[] o;
137 readonly attribute octet?[] ro;
138 attribute short?[] s;
139 readonly attribute short?[] rs;
140 attribute unsigned short?[] us;
141 readonly attribute unsigned short?[] rus;
142 attribute long?[] l;
143 readonly attribute long?[] rl;
144 attribute unsigned long?[] ul;
145 readonly attribute unsigned long?[] rul;
146 attribute long long?[] ll;
147 readonly attribute long long?[] rll;
148 attribute unsigned long long?[] ull;
149 readonly attribute unsigned long long?[] rull;
150 attribute DOMString?[] str;
151 readonly attribute DOMString?[] rstr;
152 attribute object?[] obj;
153 readonly attribute object?[] robj;
154 attribute object?[] _object;
155 attribute float?[] f;
156 readonly attribute float?[] rf;
157 };
159 interface TestAttrNullableArrayOfNullableTypes {
160 attribute byte?[]? b;
161 readonly attribute byte?[]? rb;
162 attribute octet?[]? o;
163 readonly attribute octet?[]? ro;
164 attribute short?[]? s;
165 readonly attribute short?[]? rs;
166 attribute unsigned short?[]? us;
167 readonly attribute unsigned short?[]? rus;
168 attribute long?[]? l;
169 readonly attribute long?[]? rl;
170 attribute unsigned long?[]? ul;
171 readonly attribute unsigned long?[]? rul;
172 attribute long long?[]? ll;
173 readonly attribute long long?[]? rll;
174 attribute unsigned long long?[]? ull;
175 readonly attribute unsigned long long?[]? rull;
176 attribute DOMString?[]? str;
177 readonly attribute DOMString?[]? rstr;
178 attribute object?[]? obj;
179 readonly attribute object?[]? robj;
180 attribute object?[]? _object;
181 attribute float?[]? f;
182 readonly attribute float?[]? rf;
183 };
184 """)
186 results = parser.finish()
188 def checkAttr(attr, QName, name, type, readonly):
189 harness.ok(isinstance(attr, WebIDL.IDLAttribute),
190 "Should be an IDLAttribute")
191 harness.ok(attr.isAttr(), "Attr is an Attr")
192 harness.ok(not attr.isMethod(), "Attr is not an method")
193 harness.ok(not attr.isConst(), "Attr is not a const")
194 harness.check(attr.identifier.QName(), QName, "Attr has the right QName")
195 harness.check(attr.identifier.name, name, "Attr has the right name")
196 harness.check(str(attr.type), type, "Attr has the right type")
197 harness.check(attr.readonly, readonly, "Attr's readonly state is correct")
199 harness.ok(True, "TestAttr interface parsed without error.")
200 harness.check(len(results), 6, "Should be six productions.")
201 iface = results[0]
202 harness.ok(isinstance(iface, WebIDL.IDLInterface),
203 "Should be an IDLInterface")
204 harness.check(iface.identifier.QName(), "::TestAttr", "Interface has the right QName")
205 harness.check(iface.identifier.name, "TestAttr", "Interface has the right name")
206 harness.check(len(iface.members), len(testData), "Expect %s members" % len(testData))
208 attrs = iface.members
210 for i in range(len(attrs)):
211 data = testData[i]
212 attr = attrs[i]
213 (QName, name, type, readonly) = data
214 checkAttr(attr, QName % "", name, type % "", readonly)
216 iface = results[1]
217 harness.ok(isinstance(iface, WebIDL.IDLInterface),
218 "Should be an IDLInterface")
219 harness.check(iface.identifier.QName(), "::TestAttrNullable", "Interface has the right QName")
220 harness.check(iface.identifier.name, "TestAttrNullable", "Interface has the right name")
221 harness.check(len(iface.members), len(testData), "Expect %s members" % len(testData))
223 attrs = iface.members
225 for i in range(len(attrs)):
226 data = testData[i]
227 attr = attrs[i]
228 (QName, name, type, readonly) = data
229 checkAttr(attr, QName % "Nullable", name, type % "OrNull", readonly)
231 iface = results[2]
232 harness.ok(isinstance(iface, WebIDL.IDLInterface),
233 "Should be an IDLInterface")
234 harness.check(iface.identifier.QName(), "::TestAttrArray", "Interface has the right QName")
235 harness.check(iface.identifier.name, "TestAttrArray", "Interface has the right name")
236 harness.check(len(iface.members), len(testData), "Expect %s members" % len(testData))
238 attrs = iface.members
240 for i in range(len(attrs)):
241 data = testData[i]
242 attr = attrs[i]
243 (QName, name, type, readonly) = data
244 checkAttr(attr, QName % "Array", name, type % "Array", readonly)
246 iface = results[3]
247 harness.ok(isinstance(iface, WebIDL.IDLInterface),
248 "Should be an IDLInterface")
249 harness.check(iface.identifier.QName(), "::TestAttrNullableArray", "Interface has the right QName")
250 harness.check(iface.identifier.name, "TestAttrNullableArray", "Interface has the right name")
251 harness.check(len(iface.members), len(testData), "Expect %s members" % len(testData))
253 attrs = iface.members
255 for i in range(len(attrs)):
256 data = testData[i]
257 attr = attrs[i]
258 (QName, name, type, readonly) = data
259 checkAttr(attr, QName % "NullableArray", name, type % "ArrayOrNull", readonly)
261 iface = results[4]
262 harness.ok(isinstance(iface, WebIDL.IDLInterface),
263 "Should be an IDLInterface")
264 harness.check(iface.identifier.QName(), "::TestAttrArrayOfNullableTypes", "Interface has the right QName")
265 harness.check(iface.identifier.name, "TestAttrArrayOfNullableTypes", "Interface has the right name")
266 harness.check(len(iface.members), len(testData), "Expect %s members" % len(testData))
268 attrs = iface.members
270 for i in range(len(attrs)):
271 data = testData[i]
272 attr = attrs[i]
273 (QName, name, type, readonly) = data
274 checkAttr(attr, QName % "ArrayOfNullableTypes", name, type % "OrNullArray", readonly)
276 iface = results[5]
277 harness.ok(isinstance(iface, WebIDL.IDLInterface),
278 "Should be an IDLInterface")
279 harness.check(iface.identifier.QName(), "::TestAttrNullableArrayOfNullableTypes", "Interface has the right QName")
280 harness.check(iface.identifier.name, "TestAttrNullableArrayOfNullableTypes", "Interface has the right name")
281 harness.check(len(iface.members), len(testData), "Expect %s members" % len(testData))
283 attrs = iface.members
285 for i in range(len(attrs)):
286 data = testData[i]
287 attr = attrs[i]
288 (QName, name, type, readonly) = data
289 checkAttr(attr, QName % "NullableArrayOfNullableTypes", name, type % "OrNullArrayOrNull", readonly)
291 parser = parser.reset()
292 threw = False
293 try:
294 parser.parse("""
295 interface A {
296 [SetterThrows] readonly attribute boolean foo;
297 };
298 """)
299 results = parser.finish()
300 except Exception, x:
301 threw = True
302 harness.ok(threw, "Should not allow [SetterThrows] on readonly attributes")
304 parser = parser.reset()
305 threw = False
306 try:
307 parser.parse("""
308 interface A {
309 [Throw] readonly attribute boolean foo;
310 };
311 """)
312 results = parser.finish()
313 except Exception, x:
314 threw = True
315 harness.ok(threw, "Should spell [Throws] correctly")
317 parser = parser.reset()
318 threw = False
319 try:
320 parser.parse("""
321 interface A {
322 [SameObject] readonly attribute boolean foo;
323 };
324 """)
325 results = parser.finish()
326 except Exception, x:
327 threw = True
328 harness.ok(threw, "Should not allow [SameObject] on attributes not of interface type")
330 parser = parser.reset()
331 threw = False
332 try:
333 parser.parse("""
334 interface A {
335 [SameObject] readonly attribute A foo;
336 };
337 """)
338 results = parser.finish()
339 except Exception, x:
340 threw = True
341 harness.ok(not threw, "Should allow [SameObject] on attributes of interface type")