test_cereactions.py (3534B)
1 import WebIDL 2 3 4 def WebIDLTest(parser, harness): 5 threw = False 6 try: 7 parser.parse( 8 """ 9 interface Foo { 10 [CEReactions(DOMString a)] undefined foo(boolean arg2); 11 }; 12 """ 13 ) 14 15 parser.finish() 16 except WebIDL.WebIDLError: 17 threw = True 18 19 harness.ok(threw, "Should have thrown for [CEReactions] with an argument") 20 21 parser = parser.reset() 22 threw = False 23 try: 24 parser.parse( 25 """ 26 interface Foo { 27 [CEReactions(DOMString b)] readonly attribute boolean bar; 28 }; 29 """ 30 ) 31 32 parser.finish() 33 except WebIDL.WebIDLError: 34 threw = True 35 36 harness.ok(threw, "Should have thrown for [CEReactions] with an argument") 37 38 parser = parser.reset() 39 threw = False 40 try: 41 parser.parse( 42 """ 43 interface Foo { 44 [CEReactions] attribute boolean bar; 45 }; 46 """ 47 ) 48 49 parser.finish() 50 except Exception as e: 51 harness.ok( 52 False, 53 "Shouldn't have thrown for [CEReactions] used on writable attribute. %s" 54 % e, 55 ) 56 threw = True 57 58 parser = parser.reset() 59 threw = False 60 try: 61 parser.parse( 62 """ 63 interface Foo { 64 [CEReactions] undefined foo(boolean arg2); 65 }; 66 """ 67 ) 68 69 parser.finish() 70 except Exception as e: 71 harness.ok( 72 False, 73 "Shouldn't have thrown for [CEReactions] used on regular operations. %s" 74 % e, 75 ) 76 threw = True 77 78 parser = parser.reset() 79 threw = False 80 try: 81 parser.parse( 82 """ 83 interface Foo { 84 [CEReactions] readonly attribute boolean A; 85 }; 86 """ 87 ) 88 89 parser.finish() 90 except WebIDL.WebIDLError: 91 threw = True 92 93 harness.ok( 94 threw, "Should have thrown for [CEReactions] used on a readonly attribute" 95 ) 96 97 parser = parser.reset() 98 threw = False 99 try: 100 parser.parse( 101 """ 102 [CEReactions] 103 interface Foo { 104 } 105 """ 106 ) 107 108 parser.finish() 109 except WebIDL.WebIDLError: 110 threw = True 111 112 harness.ok(threw, "Should have thrown for [CEReactions] used on a interface") 113 114 parser = parser.reset() 115 threw = False 116 try: 117 parser.parse( 118 """ 119 interface Foo { 120 [CEReactions] getter any(DOMString name); 121 }; 122 """ 123 ) 124 parser.finish() 125 except WebIDL.WebIDLError: 126 threw = True 127 128 harness.ok(threw, "Should have thrown for [CEReactions] used on a named getter") 129 130 parser = parser.reset() 131 threw = False 132 try: 133 parser.parse( 134 """ 135 interface Foo { 136 [CEReactions] legacycaller double compute(double x); 137 }; 138 """ 139 ) 140 parser.finish() 141 except WebIDL.WebIDLError: 142 threw = True 143 144 harness.ok(threw, "Should have thrown for [CEReactions] used on a legacycaller") 145 146 parser = parser.reset() 147 threw = False 148 try: 149 parser.parse( 150 """ 151 interface Foo { 152 [CEReactions] stringifier DOMString (); 153 }; 154 """ 155 ) 156 parser.finish() 157 except WebIDL.WebIDLError: 158 threw = True 159 160 harness.ok(threw, "Should have thrown for [CEReactions] used on a stringifier")