test_unforgeable.py (7623B)
1 import WebIDL 2 3 4 def WebIDLTest(parser, harness): 5 parser.parse( 6 """ 7 interface Child : Parent { 8 }; 9 interface Parent { 10 [LegacyUnforgeable] readonly attribute long foo; 11 }; 12 """ 13 ) 14 15 results = parser.finish() 16 harness.check( 17 len(results), 18 2, 19 "Should be able to inherit from an interface with " 20 "[LegacyUnforgeable] properties.", 21 ) 22 23 parser = parser.reset() 24 parser.parse( 25 """ 26 interface Child : Parent { 27 const short foo = 10; 28 }; 29 interface Parent { 30 [LegacyUnforgeable] readonly attribute long foo; 31 }; 32 """ 33 ) 34 35 results = parser.finish() 36 harness.check( 37 len(results), 38 2, 39 "Should be able to inherit from an interface with " 40 "[LegacyUnforgeable] properties even if we have a constant with " 41 "the same name.", 42 ) 43 44 parser = parser.reset() 45 parser.parse( 46 """ 47 interface Child : Parent { 48 static attribute short foo; 49 }; 50 interface Parent { 51 [LegacyUnforgeable] readonly attribute long foo; 52 }; 53 """ 54 ) 55 56 results = parser.finish() 57 harness.check( 58 len(results), 59 2, 60 "Should be able to inherit from an interface with " 61 "[LegacyUnforgeable] properties even if we have a static attribute " 62 "with the same name.", 63 ) 64 65 parser = parser.reset() 66 parser.parse( 67 """ 68 interface Child : Parent { 69 static undefined foo(); 70 }; 71 interface Parent { 72 [LegacyUnforgeable] readonly attribute long foo; 73 }; 74 """ 75 ) 76 77 results = parser.finish() 78 harness.check( 79 len(results), 80 2, 81 "Should be able to inherit from an interface with " 82 "[LegacyUnforgeable] properties even if we have a static operation " 83 "with the same name.", 84 ) 85 86 parser = parser.reset() 87 threw = False 88 try: 89 parser.parse( 90 """ 91 interface Child : Parent { 92 undefined foo(); 93 }; 94 interface Parent { 95 [LegacyUnforgeable] readonly attribute long foo; 96 }; 97 """ 98 ) 99 100 results = parser.finish() 101 except WebIDL.WebIDLError: 102 threw = True 103 harness.ok( 104 threw, 105 "Should have thrown when shadowing unforgeable attribute on " 106 "parent with operation.", 107 ) 108 109 parser = parser.reset() 110 threw = False 111 try: 112 parser.parse( 113 """ 114 interface Child : Parent { 115 undefined foo(); 116 }; 117 interface Parent { 118 [LegacyUnforgeable] undefined foo(); 119 }; 120 """ 121 ) 122 123 results = parser.finish() 124 except WebIDL.WebIDLError: 125 threw = True 126 harness.ok( 127 threw, 128 "Should have thrown when shadowing unforgeable operation on " 129 "parent with operation.", 130 ) 131 132 parser = parser.reset() 133 threw = False 134 try: 135 parser.parse( 136 """ 137 interface Child : Parent { 138 attribute short foo; 139 }; 140 interface Parent { 141 [LegacyUnforgeable] readonly attribute long foo; 142 }; 143 """ 144 ) 145 146 results = parser.finish() 147 except WebIDL.WebIDLError: 148 threw = True 149 harness.ok( 150 threw, 151 "Should have thrown when shadowing unforgeable attribute on " 152 "parent with attribute.", 153 ) 154 155 parser = parser.reset() 156 threw = False 157 try: 158 parser.parse( 159 """ 160 interface Child : Parent { 161 attribute short foo; 162 }; 163 interface Parent { 164 [LegacyUnforgeable] undefined foo(); 165 }; 166 """ 167 ) 168 169 results = parser.finish() 170 except WebIDL.WebIDLError: 171 threw = True 172 harness.ok( 173 threw, 174 "Should have thrown when shadowing unforgeable operation on " 175 "parent with attribute.", 176 ) 177 178 parser = parser.reset() 179 parser.parse( 180 """ 181 interface Child : Parent { 182 }; 183 interface Parent {}; 184 interface mixin Mixin { 185 [LegacyUnforgeable] readonly attribute long foo; 186 }; 187 Parent includes Mixin; 188 """ 189 ) 190 191 results = parser.finish() 192 harness.check( 193 len(results), 194 4, 195 "Should be able to inherit from an interface with a " 196 "mixin with [LegacyUnforgeable] properties.", 197 ) 198 199 parser = parser.reset() 200 threw = False 201 try: 202 parser.parse( 203 """ 204 interface Child : Parent { 205 undefined foo(); 206 }; 207 interface Parent {}; 208 interface mixin Mixin { 209 [LegacyUnforgeable] readonly attribute long foo; 210 }; 211 Parent includes Mixin; 212 """ 213 ) 214 215 results = parser.finish() 216 except WebIDL.WebIDLError: 217 threw = True 218 219 harness.ok( 220 threw, 221 "Should have thrown when shadowing unforgeable attribute " 222 "of parent's consequential interface.", 223 ) 224 225 parser = parser.reset() 226 threw = False 227 try: 228 parser.parse( 229 """ 230 interface Child : Parent { 231 }; 232 interface Parent : GrandParent {}; 233 interface GrandParent {}; 234 interface mixin Mixin { 235 [LegacyUnforgeable] readonly attribute long foo; 236 }; 237 GrandParent includes Mixin; 238 interface mixin ChildMixin { 239 undefined foo(); 240 }; 241 Child includes ChildMixin; 242 """ 243 ) 244 245 results = parser.finish() 246 except WebIDL.WebIDLError: 247 threw = True 248 249 harness.ok( 250 threw, 251 "Should have thrown when our consequential interface shadows unforgeable attribute " 252 "of ancestor's consequential interface.", 253 ) 254 255 parser = parser.reset() 256 threw = False 257 try: 258 parser.parse( 259 """ 260 interface Child : Parent { 261 }; 262 interface Parent : GrandParent {}; 263 interface GrandParent {}; 264 interface mixin Mixin { 265 [LegacyUnforgeable] undefined foo(); 266 }; 267 GrandParent includes Mixin; 268 interface mixin ChildMixin { 269 undefined foo(); 270 }; 271 Child includes ChildMixin; 272 """ 273 ) 274 275 results = parser.finish() 276 except WebIDL.WebIDLError: 277 threw = True 278 279 harness.ok( 280 threw, 281 "Should have thrown when our consequential interface shadows unforgeable operation " 282 "of ancestor's consequential interface.", 283 ) 284 285 parser = parser.reset() 286 parser.parse( 287 """ 288 interface iface { 289 [LegacyUnforgeable] attribute long foo; 290 }; 291 """ 292 ) 293 294 results = parser.finish() 295 harness.check( 296 len(results), 1, "Should allow writable [LegacyUnforgeable] attribute." 297 ) 298 299 parser = parser.reset() 300 threw = False 301 try: 302 parser.parse( 303 """ 304 interface iface { 305 [LegacyUnforgeable] static readonly attribute long foo; 306 }; 307 """ 308 ) 309 310 results = parser.finish() 311 except WebIDL.WebIDLError: 312 threw = True 313 314 harness.ok(threw, "Should have thrown for static [LegacyUnforgeable] attribute.")