| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 """Generator script for proxy tests. |
| 7 |
| 8 See AndroidProxySelectorTest.java |
| 9 and net/proxy/proxy_config_service_android_unittest.cc |
| 10 |
| 11 To generate C++, run this script without arguments. |
| 12 To generate Java, run this script with -j argument. |
| 13 |
| 14 Note that this generator is not run as part of the build process because |
| 15 we are assuming that these test cases will not change often. |
| 16 """ |
| 17 |
| 18 import optparse |
| 19 |
| 20 test_cases = [ |
| 21 { |
| 22 "name": "NoProxy", |
| 23 "description" : "Test direct mapping when no proxy defined.", |
| 24 "properties" : { |
| 25 }, |
| 26 "mappings" : { |
| 27 "http://example.com/" : "", |
| 28 "ftp://example.com/" : "", |
| 29 "https://example.com/" : "", |
| 30 } |
| 31 }, |
| 32 { |
| 33 "name": "HttpProxyHostAndPort", |
| 34 "description" : "Test http.proxyHost and http.proxyPort works.", |
| 35 "properties" : { |
| 36 "http.proxyHost" : "httpproxy.com", |
| 37 "http.proxyPort" : "8080", |
| 38 }, |
| 39 "mappings" : { |
| 40 "http://example.com/" : "httpproxy.com:8080", |
| 41 "ftp://example.com/" : "", |
| 42 "https://example.com/" : "", |
| 43 } |
| 44 }, |
| 45 { |
| 46 "name": "HttpProxyHostOnly", |
| 47 "description" : "We should get the default port (80) for proxied hosts.", |
| 48 "properties" : { |
| 49 "http.proxyHost" : "httpproxy.com", |
| 50 }, |
| 51 "mappings" : { |
| 52 "http://example.com/" : "httpproxy.com:80", |
| 53 "ftp://example.com/" : "", |
| 54 "https://example.com/" : "", |
| 55 } |
| 56 }, |
| 57 { |
| 58 "name": "HttpProxyPortOnly", |
| 59 "description" : |
| 60 "http.proxyPort only should not result in any hosts being proxied.", |
| 61 "properties" : { |
| 62 "http.proxyPort" : "8080", |
| 63 }, |
| 64 "mappings" : { |
| 65 "http://example.com/" : "", |
| 66 "ftp://example.com/" : "", |
| 67 "https://example.com/" : "" |
| 68 } |
| 69 }, |
| 70 { |
| 71 "name": "HttpNonProxyHosts1", |
| 72 "description" : "Test that HTTP non proxy hosts are mapped correctly", |
| 73 "properties" : { |
| 74 "http.nonProxyHosts" : "slashdot.org", |
| 75 "http.proxyHost" : "httpproxy.com", |
| 76 "http.proxyPort" : "8080", |
| 77 }, |
| 78 "mappings" : { |
| 79 "http://example.com/" : "httpproxy.com:8080", |
| 80 "http://slashdot.org/" : "", |
| 81 } |
| 82 }, |
| 83 { |
| 84 "name": "HttpNonProxyHosts2", |
| 85 "description" : "Test that | pattern works.", |
| 86 "properties" : { |
| 87 "http.nonProxyHosts" : "slashdot.org|freecode.net", |
| 88 "http.proxyHost" : "httpproxy.com", |
| 89 "http.proxyPort" : "8080", |
| 90 }, |
| 91 "mappings" : { |
| 92 "http://example.com/" : "httpproxy.com:8080", |
| 93 "http://slashdot.org/" : "", |
| 94 "http://freecode.net/" : "", |
| 95 } |
| 96 }, |
| 97 { |
| 98 "name": "HttpNonProxyHosts3", |
| 99 "description" : "Test that * pattern works.", |
| 100 "properties" : { |
| 101 "http.nonProxyHosts" : "*example.com", |
| 102 "http.proxyHost" : "httpproxy.com", |
| 103 "http.proxyPort" : "8080", |
| 104 }, |
| 105 "mappings" : { |
| 106 "http://example.com/" : "", |
| 107 "http://www.example.com/" : "", |
| 108 "http://slashdot.org/" : "httpproxy.com:8080", |
| 109 } |
| 110 }, |
| 111 { |
| 112 "name": "FtpNonProxyHosts", |
| 113 "description" : "Test that FTP non proxy hosts are mapped correctly", |
| 114 "properties" : { |
| 115 "ftp.nonProxyHosts" : "slashdot.org", |
| 116 "ftp.proxyHost" : "httpproxy.com", |
| 117 "ftp.proxyPort" : "8080", |
| 118 }, |
| 119 "mappings" : { |
| 120 "http://example.com/" : "", |
| 121 "ftp://example.com/" : "httpproxy.com:8080", |
| 122 } |
| 123 }, |
| 124 { |
| 125 "name": "FtpProxyHostAndPort", |
| 126 "description" : "Test ftp.proxyHost and ftp.proxyPort works.", |
| 127 "properties" : { |
| 128 "ftp.proxyHost" : "httpproxy.com", |
| 129 "ftp.proxyPort" : "8080", |
| 130 }, |
| 131 "mappings" : { |
| 132 "ftp://example.com/" : "httpproxy.com:8080", |
| 133 "http://example.com/" : "", |
| 134 "https://example.com/" : "", |
| 135 } |
| 136 }, |
| 137 { |
| 138 "name": "FtpProxyHostOnly", |
| 139 "description" : "Test ftp.proxyHost and default port.", |
| 140 "properties" : { |
| 141 "ftp.proxyHost" : "httpproxy.com", |
| 142 }, |
| 143 "mappings" : { |
| 144 "ftp://example.com/" : "httpproxy.com:80", |
| 145 "http://example.com/" : "", |
| 146 "https://example.com/" : "", |
| 147 } |
| 148 }, |
| 149 { |
| 150 "name": "HttpsProxyHostAndPort", |
| 151 "description" : "Test https.proxyHost and https.proxyPort works.", |
| 152 "properties" : { |
| 153 "https.proxyHost" : "httpproxy.com", |
| 154 "https.proxyPort" : "8080", |
| 155 }, |
| 156 "mappings" : { |
| 157 "https://example.com/" : "httpproxy.com:8080", |
| 158 "http://example.com/" : "", |
| 159 "ftp://example.com/" : "", |
| 160 } |
| 161 }, |
| 162 { |
| 163 "name": "HttpsProxyHostOnly", |
| 164 "description" : "Test https.proxyHost and default port.", |
| 165 "properties" : { |
| 166 "https.proxyHost" : "httpproxy.com", |
| 167 }, |
| 168 "mappings" : { |
| 169 "https://example.com/" : "httpproxy.com:443", |
| 170 "http://example.com/" : "", |
| 171 "ftp://example.com/" : "", |
| 172 } |
| 173 }, |
| 174 { |
| 175 "name": "DefaultProxyExplictPort", |
| 176 "description" : |
| 177 "Default http proxy is used if a scheme-specific one is not found.", |
| 178 "properties" : { |
| 179 "proxyHost" : "defaultproxy.com", |
| 180 "proxyPort" : "8080", |
| 181 "ftp.proxyHost" : "httpproxy.com", |
| 182 "ftp.proxyPort" : "8080", |
| 183 }, |
| 184 "mappings" : { |
| 185 "http://example.com/" : "defaultproxy.com:8080", |
| 186 "https://example.com/" : "defaultproxy.com:8080", |
| 187 "ftp://example.com/" : "httpproxy.com:8080", |
| 188 } |
| 189 }, |
| 190 { |
| 191 "name": "DefaultProxyDefaultPort", |
| 192 "description" : "Check that the default proxy port is as expected.", |
| 193 "properties" : { |
| 194 "proxyHost" : "defaultproxy.com", |
| 195 }, |
| 196 "mappings" : { |
| 197 "http://example.com/" : "defaultproxy.com:80", |
| 198 "https://example.com/" : "defaultproxy.com:443", |
| 199 } |
| 200 }, |
| 201 { |
| 202 "name": "FallbackToSocks", |
| 203 "description" : "SOCKS proxy is used if scheme-specific one is not found.", |
| 204 "properties" : { |
| 205 "http.proxyHost" : "defaultproxy.com", |
| 206 "socksProxyHost" : "socksproxy.com" |
| 207 }, |
| 208 "mappings" : { |
| 209 "http://example.com/" : "defaultproxy.com:80", |
| 210 "https://example.com/" : "socksproxy.com:1080", |
| 211 "ftp://example.com" : "socksproxy.com:1080", |
| 212 } |
| 213 }, |
| 214 { |
| 215 "name": "SocksExplicitPort", |
| 216 "description" : "SOCKS proxy port is used if specified", |
| 217 "properties" : { |
| 218 "socksProxyHost" : "socksproxy.com", |
| 219 "socksProxyPort" : "9000", |
| 220 }, |
| 221 "mappings" : { |
| 222 "http://example.com/" : "socksproxy.com:9000", |
| 223 } |
| 224 }, |
| 225 { |
| 226 "name": "HttpProxySupercedesSocks", |
| 227 "description" : "SOCKS proxy is ignored if default HTTP proxy defined.", |
| 228 "properties" : { |
| 229 "proxyHost" : "defaultproxy.com", |
| 230 "socksProxyHost" : "socksproxy.com", |
| 231 "socksProxyPort" : "9000", |
| 232 }, |
| 233 "mappings" : { |
| 234 "http://example.com/" : "defaultproxy.com:80", |
| 235 } |
| 236 }, |
| 237 ] |
| 238 |
| 239 class GenerateCPlusPlus: |
| 240 """Generate C++ test cases""" |
| 241 |
| 242 def Generate(self): |
| 243 for test_case in test_cases: |
| 244 print ("TEST_F(ProxyConfigServiceAndroidTest, %s) {" % test_case["name"]) |
| 245 if "description" in test_case: |
| 246 self._GenerateDescription(test_case["description"]); |
| 247 self._GenerateConfiguration(test_case["properties"]) |
| 248 self._GenerateMappings(test_case["mappings"]) |
| 249 print "}" |
| 250 print "" |
| 251 |
| 252 def _GenerateDescription(self, description): |
| 253 print " // %s" % description |
| 254 |
| 255 def _GenerateConfiguration(self, properties): |
| 256 for key in sorted(properties.iterkeys()): |
| 257 print " configuration_[\"%s\"] = \"%s\";" % (key, properties[key]) |
| 258 print " delegate_->SetProperties(configuration_);" |
| 259 |
| 260 def _GenerateMappings(self, mappings): |
| 261 for url in sorted(mappings.iterkeys()): |
| 262 print " TestMapping(\"%s\", \"%s\");" % (url, mappings[url]) |
| 263 |
| 264 |
| 265 class GenerateJava: |
| 266 """Generate Java test cases""" |
| 267 |
| 268 def Generate(self): |
| 269 for test_case in test_cases: |
| 270 if "description" in test_case: |
| 271 self._GenerateDescription(test_case["description"]); |
| 272 print " @SmallTest" |
| 273 print " public void test%s() throws Exception {" % test_case["name"] |
| 274 self._GenerateConfiguration(test_case["properties"]) |
| 275 self._GenerateMappings(test_case["mappings"]) |
| 276 print " }" |
| 277 print "" |
| 278 |
| 279 def _GenerateDescription(self, description): |
| 280 print " /**" |
| 281 print " * %s" % description |
| 282 print " *" |
| 283 print " * @throws Exception" |
| 284 print " */" |
| 285 |
| 286 def _GenerateConfiguration(self, properties): |
| 287 for key in sorted(properties.iterkeys()): |
| 288 print " System.setProperty(\"%s\", \"%s\");" % ( |
| 289 key, properties[key]) |
| 290 |
| 291 def _GenerateMappings(self, mappings): |
| 292 for url in sorted(mappings.iterkeys()): |
| 293 print " checkMapping(\"%s\", \"%s\");" % (url, mappings[url]) |
| 294 |
| 295 |
| 296 def main(): |
| 297 parser = optparse.OptionParser() |
| 298 parser.add_option("-j", "--java", |
| 299 action="store_true", dest="java"); |
| 300 (options, args) = parser.parse_args(); |
| 301 if options.java: |
| 302 generator = GenerateJava() |
| 303 else: |
| 304 generator = GenerateCPlusPlus() |
| 305 generator.Generate() |
| 306 |
| 307 if __name__ == '__main__': |
| 308 main() |
| OLD | NEW |