dom/bindings/parser/tests/test_implements.py

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 # Import the WebIDL module, so we can do isinstance checks and whatnot
michael@0 2 import WebIDL
michael@0 3
michael@0 4 def WebIDLTest(parser, harness):
michael@0 5 # Basic functionality
michael@0 6 threw = False
michael@0 7 try:
michael@0 8 parser.parse("""
michael@0 9 A implements B;
michael@0 10 interface B {
michael@0 11 attribute long x;
michael@0 12 };
michael@0 13 interface A {
michael@0 14 attribute long y;
michael@0 15 };
michael@0 16 """)
michael@0 17 results = parser.finish()
michael@0 18 except:
michael@0 19 threw = True
michael@0 20
michael@0 21 harness.ok(not threw, "Should not have thrown on implements statement "
michael@0 22 "before interfaces")
michael@0 23 harness.check(len(results), 3, "We have three statements")
michael@0 24 harness.ok(isinstance(results[1], WebIDL.IDLInterface), "B is an interface")
michael@0 25 harness.check(len(results[1].members), 1, "B has one member")
michael@0 26 A = results[2]
michael@0 27 harness.ok(isinstance(A, WebIDL.IDLInterface), "A is an interface")
michael@0 28 harness.check(len(A.members), 2, "A has two members")
michael@0 29 harness.check(A.members[0].identifier.name, "y", "First member is 'y'")
michael@0 30 harness.check(A.members[1].identifier.name, "x", "Second member is 'x'")
michael@0 31
michael@0 32 # Duplicated member names not allowed
michael@0 33 threw = False
michael@0 34 try:
michael@0 35 parser.parse("""
michael@0 36 C implements D;
michael@0 37 interface D {
michael@0 38 attribute long x;
michael@0 39 };
michael@0 40 interface C {
michael@0 41 attribute long x;
michael@0 42 };
michael@0 43 """)
michael@0 44 parser.finish()
michael@0 45 except:
michael@0 46 threw = True
michael@0 47
michael@0 48 harness.ok(threw, "Should have thrown on implemented interface duplicating "
michael@0 49 "a name on base interface")
michael@0 50
michael@0 51 # Same, but duplicated across implemented interfaces
michael@0 52 threw = False
michael@0 53 try:
michael@0 54 parser.parse("""
michael@0 55 E implements F;
michael@0 56 E implements G;
michael@0 57 interface F {
michael@0 58 attribute long x;
michael@0 59 };
michael@0 60 interface G {
michael@0 61 attribute long x;
michael@0 62 };
michael@0 63 interface E {};
michael@0 64 """)
michael@0 65 parser.finish()
michael@0 66 except:
michael@0 67 threw = True
michael@0 68
michael@0 69 harness.ok(threw, "Should have thrown on implemented interfaces "
michael@0 70 "duplicating each other's member names")
michael@0 71
michael@0 72 # Same, but duplicated across indirectly implemented interfaces
michael@0 73 threw = False
michael@0 74 try:
michael@0 75 parser.parse("""
michael@0 76 H implements I;
michael@0 77 H implements J;
michael@0 78 I implements K;
michael@0 79 interface K {
michael@0 80 attribute long x;
michael@0 81 };
michael@0 82 interface L {
michael@0 83 attribute long x;
michael@0 84 };
michael@0 85 interface I {};
michael@0 86 interface J : L {};
michael@0 87 interface H {};
michael@0 88 """)
michael@0 89 parser.finish()
michael@0 90 except:
michael@0 91 threw = True
michael@0 92
michael@0 93 harness.ok(threw, "Should have thrown on indirectly implemented interfaces "
michael@0 94 "duplicating each other's member names")
michael@0 95
michael@0 96 # Same, but duplicated across an implemented interface and its parent
michael@0 97 threw = False
michael@0 98 try:
michael@0 99 parser.parse("""
michael@0 100 M implements N;
michael@0 101 interface O {
michael@0 102 attribute long x;
michael@0 103 };
michael@0 104 interface N : O {
michael@0 105 attribute long x;
michael@0 106 };
michael@0 107 interface M {};
michael@0 108 """)
michael@0 109 parser.finish()
michael@0 110 except:
michael@0 111 threw = True
michael@0 112
michael@0 113 harness.ok(threw, "Should have thrown on implemented interface and its "
michael@0 114 "ancestor duplicating member names")
michael@0 115
michael@0 116 # Reset the parser so we can actually find things where we expect
michael@0 117 # them in the list
michael@0 118 parser = parser.reset()
michael@0 119
michael@0 120 # Diamonds should be allowed
michael@0 121 threw = False
michael@0 122 try:
michael@0 123 parser.parse("""
michael@0 124 P implements Q;
michael@0 125 P implements R;
michael@0 126 Q implements S;
michael@0 127 R implements S;
michael@0 128 interface Q {};
michael@0 129 interface R {};
michael@0 130 interface S {
michael@0 131 attribute long x;
michael@0 132 };
michael@0 133 interface P {};
michael@0 134 """)
michael@0 135 results = parser.finish()
michael@0 136 except:
michael@0 137 threw = True
michael@0 138
michael@0 139 harness.ok(not threw, "Diamond inheritance is fine")
michael@0 140 harness.check(results[6].identifier.name, "S", "We should be looking at 'S'")
michael@0 141 harness.check(len(results[6].members), 1, "S should have one member")
michael@0 142 harness.check(results[6].members[0].identifier.name, "x",
michael@0 143 "S's member should be 'x'")
michael@0 144
michael@0 145 parser = parser.reset()
michael@0 146 threw = False
michael@0 147 try:
michael@0 148 parser.parse("""
michael@0 149 interface TestInterface {
michael@0 150 };
michael@0 151 callback interface TestCallbackInterface {
michael@0 152 };
michael@0 153 TestInterface implements TestCallbackInterface;
michael@0 154 """)
michael@0 155 results = parser.finish()
michael@0 156 except:
michael@0 157 threw = True
michael@0 158
michael@0 159 harness.ok(threw,
michael@0 160 "Should not allow callback interfaces on the right-hand side "
michael@0 161 "of 'implements'")
michael@0 162
michael@0 163 parser = parser.reset()
michael@0 164 threw = False
michael@0 165 try:
michael@0 166 parser.parse("""
michael@0 167 interface TestInterface {
michael@0 168 };
michael@0 169 callback interface TestCallbackInterface {
michael@0 170 };
michael@0 171 TestCallbackInterface implements TestInterface;
michael@0 172 """)
michael@0 173 results = parser.finish()
michael@0 174 except:
michael@0 175 threw = True
michael@0 176
michael@0 177 harness.ok(threw,
michael@0 178 "Should not allow callback interfaces on the left-hand side of "
michael@0 179 "'implements'")
michael@0 180
michael@0 181 parser = parser.reset()
michael@0 182 threw = False
michael@0 183 try:
michael@0 184 parser.parse("""
michael@0 185 interface TestInterface {
michael@0 186 };
michael@0 187 dictionary Dict {
michael@0 188 };
michael@0 189 Dict implements TestInterface;
michael@0 190 """)
michael@0 191 results = parser.finish()
michael@0 192 except:
michael@0 193 threw = True
michael@0 194
michael@0 195 harness.ok(threw,
michael@0 196 "Should not allow non-interfaces on the left-hand side "
michael@0 197 "of 'implements'")
michael@0 198
michael@0 199 parser = parser.reset()
michael@0 200 threw = False
michael@0 201 try:
michael@0 202 parser.parse("""
michael@0 203 interface TestInterface {
michael@0 204 };
michael@0 205 dictionary Dict {
michael@0 206 };
michael@0 207 TestInterface implements Dict;
michael@0 208 """)
michael@0 209 results = parser.finish()
michael@0 210 except:
michael@0 211 threw = True
michael@0 212
michael@0 213 harness.ok(threw,
michael@0 214 "Should not allow non-interfaces on the right-hand side "
michael@0 215 "of 'implements'")
michael@0 216

mercurial