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