test_union_callback_dict.py (3999B)
1 import WebIDL 2 3 4 def WebIDLTest(parser, harness): 5 parser = parser.reset() 6 threw = False 7 try: 8 parser.parse( 9 """ 10 dictionary TestDict { 11 DOMString member; 12 }; 13 [LegacyTreatNonObjectAsNull] callback TestCallback = undefined (); 14 typedef (TestCallback or TestDict) TestUnionCallbackDict; 15 """ 16 ) 17 results = parser.finish() 18 except WebIDL.WebIDLError: 19 threw = True 20 harness.ok( 21 threw, 22 "Should not allow Dict/Callback union where callback is [LegacyTreatNonObjectAsNull]", 23 ) 24 25 parser = parser.reset() 26 27 threw = False 28 try: 29 parser.parse( 30 """ 31 dictionary TestDict { 32 DOMString member; 33 }; 34 [LegacyTreatNonObjectAsNull] callback TestCallback = undefined (); 35 typedef (TestDict or TestCallback) TestUnionCallbackDict; 36 """ 37 ) 38 results = parser.finish() 39 except WebIDL.WebIDLError: 40 threw = True 41 harness.ok( 42 threw, 43 "Should not allow Dict/Callback union where callback is [LegacyTreatNonObjectAsNull]", 44 ) 45 46 parser = parser.reset() 47 48 parser.parse( 49 """ 50 dictionary TestDict { 51 DOMString member; 52 }; 53 callback TestCallback = undefined (); 54 typedef (TestCallback or TestDict) TestUnionCallbackDict; 55 """ 56 ) 57 results = parser.finish() 58 59 harness.ok(True, "TestUnionCallbackDict interface parsed without error") 60 harness.check(len(results), 3, "Document should have 3 types") 61 62 myDict = results[0] 63 harness.ok(isinstance(myDict, WebIDL.IDLDictionary), "Expect an IDLDictionary") 64 65 myCallback = results[1] 66 harness.ok(isinstance(myCallback, WebIDL.IDLCallback), "Expect an IDLCallback") 67 68 myUnion = results[2] 69 harness.ok(isinstance(myUnion, WebIDL.IDLTypedef), "Expect a IDLTypedef") 70 harness.ok( 71 isinstance(myUnion.innerType, WebIDL.IDLUnionType), "Expect a IDLUnionType" 72 ) 73 harness.ok( 74 isinstance(myUnion.innerType.memberTypes[0], WebIDL.IDLCallbackType), 75 "Expect a IDLCallbackType", 76 ) 77 harness.ok( 78 isinstance(myUnion.innerType.memberTypes[1], WebIDL.IDLWrapperType), 79 "Expect a IDLDictionary", 80 ) 81 harness.ok( 82 (myUnion.innerType.memberTypes[0].callback == myCallback), 83 "Expect left Union member to be MyCallback", 84 ) 85 harness.ok( 86 (myUnion.innerType.memberTypes[1].inner == myDict), 87 "Expect right Union member to be MyDict", 88 ) 89 90 parser = parser.reset() 91 92 parser.parse( 93 """ 94 dictionary TestDict { 95 DOMString member; 96 }; 97 callback TestCallback = undefined (); 98 typedef (TestDict or TestCallback) TestUnionCallbackDict; 99 """ 100 ) 101 results = parser.finish() 102 103 harness.ok(True, "TestUnionCallbackDict interface parsed without error") 104 harness.check(len(results), 3, "Document should have 3 types") 105 106 myDict = results[0] 107 harness.ok(isinstance(myDict, WebIDL.IDLDictionary), "Expect an IDLDictionary") 108 109 myCallback = results[1] 110 harness.ok(isinstance(myCallback, WebIDL.IDLCallback), "Expect an IDLCallback") 111 112 myUnion = results[2] 113 harness.ok(isinstance(myUnion, WebIDL.IDLTypedef), "Expect a IDLTypedef") 114 harness.ok( 115 isinstance(myUnion.innerType, WebIDL.IDLUnionType), "Expect a IDLUnionType" 116 ) 117 harness.ok( 118 isinstance(myUnion.innerType.memberTypes[0], WebIDL.IDLWrapperType), 119 "Expect a IDLDictionary", 120 ) 121 harness.ok( 122 isinstance(myUnion.innerType.memberTypes[1], WebIDL.IDLCallbackType), 123 "Expect a IDLCallbackType", 124 ) 125 harness.ok( 126 (myUnion.innerType.memberTypes[0].inner == myDict), 127 "Expect right Union member to be MyDict", 128 ) 129 harness.ok( 130 (myUnion.innerType.memberTypes[1].callback == myCallback), 131 "Expect left Union member to be MyCallback", 132 )