Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Side by Side Diff: net/android/tools/proxy_test_cases.py

Issue 10206014: Upstream Android proxy config service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Marcus' comments Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/android/net_jni_registrar.cc ('k') | net/net.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/" : "DIRECT",
28 "ftp://example.com/" : "DIRECT",
29 "https://example.com/" : "DIRECT",
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/" : "PROXY httpproxy.com:8080",
41 "ftp://example.com/" : "DIRECT",
42 "https://example.com/" : "DIRECT",
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/" : "PROXY httpproxy.com:80",
53 "ftp://example.com/" : "DIRECT",
54 "https://example.com/" : "DIRECT",
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/" : "DIRECT",
66 "ftp://example.com/" : "DIRECT",
67 "https://example.com/" : "DIRECT"
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/" : "PROXY httpproxy.com:8080",
80 "http://slashdot.org/" : "DIRECT",
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/" : "PROXY httpproxy.com:8080",
93 "http://slashdot.org/" : "DIRECT",
94 "http://freecode.net/" : "DIRECT",
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/" : "DIRECT",
107 "http://www.example.com/" : "DIRECT",
108 "http://slashdot.org/" : "PROXY 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/" : "DIRECT",
121 "ftp://example.com/" : "PROXY 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/" : "PROXY httpproxy.com:8080",
133 "http://example.com/" : "DIRECT",
134 "https://example.com/" : "DIRECT",
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/" : "PROXY httpproxy.com:80",
145 "http://example.com/" : "DIRECT",
146 "https://example.com/" : "DIRECT",
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/" : "HTTPS httpproxy.com:8080",
158 "http://example.com/" : "DIRECT",
159 "ftp://example.com/" : "DIRECT",
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/" : "HTTPS httpproxy.com:443",
170 "http://example.com/" : "DIRECT",
171 "ftp://example.com/" : "DIRECT",
172 }
173 },
174 {
175 "name": "HttpProxyHostIPv6",
176 "description" : "Test IPv6 https.proxyHost and default port.",
177 "properties" : {
178 "http.proxyHost" : "a:b:c::d:1",
179 },
180 "mappings" : {
181 "http://example.com/" : "PROXY [a:b:c::d:1]:80",
182 "ftp://example.com/" : "DIRECT",
183 }
184 },
185 {
186 "name": "HttpProxyHostAndPortIPv6",
187 "description" : "Test IPv6 http.proxyHost and http.proxyPort works.",
188 "properties" : {
189 "http.proxyHost" : "a:b:c::d:1",
190 "http.proxyPort" : "8080",
191 },
192 "mappings" : {
193 "http://example.com/" : "PROXY [a:b:c::d:1]:8080",
194 "ftp://example.com/" : "DIRECT",
195 }
196 },
197 {
198 "name": "HttpProxyHostAndInvalidPort",
199 "description" : "Test invalid http.proxyPort does not crash.",
200 "properties" : {
201 "http.proxyHost" : "a:b:c::d:1",
202 "http.proxyPort" : "65536",
203 },
204 "mappings" : {
205 "http://example.com/" : "DIRECT",
206 "ftp://example.com/" : "DIRECT",
207 }
208 },
209 {
210 "name": "DefaultProxyExplictPort",
211 "description" :
212 "Default http proxy is used if a scheme-specific one is not found.",
213 "properties" : {
214 "proxyHost" : "defaultproxy.com",
215 "proxyPort" : "8080",
216 "ftp.proxyHost" : "httpproxy.com",
217 "ftp.proxyPort" : "8080",
218 },
219 "mappings" : {
220 "http://example.com/" : "PROXY defaultproxy.com:8080",
221 "https://example.com/" : "HTTPS defaultproxy.com:8080",
222 "ftp://example.com/" : "PROXY httpproxy.com:8080",
223 }
224 },
225 {
226 "name": "DefaultProxyDefaultPort",
227 "description" : "Check that the default proxy port is as expected.",
228 "properties" : {
229 "proxyHost" : "defaultproxy.com",
230 },
231 "mappings" : {
232 "http://example.com/" : "PROXY defaultproxy.com:80",
233 "https://example.com/" : "HTTPS defaultproxy.com:443",
234 }
235 },
236 {
237 "name": "FallbackToSocks",
238 "description" : "SOCKS proxy is used if scheme-specific one is not found.",
239 "properties" : {
240 "http.proxyHost" : "defaultproxy.com",
241 "socksProxyHost" : "socksproxy.com"
242 },
243 "mappings" : {
244 "http://example.com/" : "PROXY defaultproxy.com:80",
245 "https://example.com/" : "SOCKS5 socksproxy.com:1080",
246 "ftp://example.com" : "SOCKS5 socksproxy.com:1080",
247 }
248 },
249 {
250 "name": "SocksExplicitPort",
251 "description" : "SOCKS proxy port is used if specified",
252 "properties" : {
253 "socksProxyHost" : "socksproxy.com",
254 "socksProxyPort" : "9000",
255 },
256 "mappings" : {
257 "http://example.com/" : "SOCKS5 socksproxy.com:9000",
258 }
259 },
260 {
261 "name": "HttpProxySupercedesSocks",
262 "description" : "SOCKS proxy is ignored if default HTTP proxy defined.",
263 "properties" : {
264 "proxyHost" : "defaultproxy.com",
265 "socksProxyHost" : "socksproxy.com",
266 "socksProxyPort" : "9000",
267 },
268 "mappings" : {
269 "http://example.com/" : "PROXY defaultproxy.com:80",
270 }
271 },
272 ]
273
274 class GenerateCPlusPlus:
275 """Generate C++ test cases"""
276
277 def Generate(self):
278 for test_case in test_cases:
279 print ("TEST_F(ProxyConfigServiceAndroidTest, %s) {" % test_case["name"])
280 if "description" in test_case:
281 self._GenerateDescription(test_case["description"]);
282 self._GenerateConfiguration(test_case["properties"])
283 self._GenerateMappings(test_case["mappings"])
284 print "}"
285 print ""
286
287 def _GenerateDescription(self, description):
288 print " // %s" % description
289
290 def _GenerateConfiguration(self, properties):
291 for key in sorted(properties.iterkeys()):
292 print " AddProperty(\"%s\", \"%s\");" % (key, properties[key])
293 print " ProxySettingsChanged();"
294
295 def _GenerateMappings(self, mappings):
296 for url in sorted(mappings.iterkeys()):
297 print " TestMapping(\"%s\", \"%s\");" % (url, mappings[url])
298
299
300 class GenerateJava:
301 """Generate Java test cases"""
302
303 def Generate(self):
304 for test_case in test_cases:
305 if "description" in test_case:
306 self._GenerateDescription(test_case["description"]);
307 print " @SmallTest"
308 print " public void test%s() throws Exception {" % test_case["name"]
309 self._GenerateConfiguration(test_case["properties"])
310 self._GenerateMappings(test_case["mappings"])
311 print " }"
312 print ""
313
314 def _GenerateDescription(self, description):
315 print " /**"
316 print " * %s" % description
317 print " *"
318 print " * @throws Exception"
319 print " */"
320
321 def _GenerateConfiguration(self, properties):
322 for key in sorted(properties.iterkeys()):
323 print " System.setProperty(\"%s\", \"%s\");" % (
324 key, properties[key])
325
326 def _GenerateMappings(self, mappings):
327 for url in sorted(mappings.iterkeys()):
328 print " checkMapping(\"%s\", \"%s\");" % (url, mappings[url])
329
330
331 def main():
332 parser = optparse.OptionParser()
333 parser.add_option("-j", "--java",
334 action="store_true", dest="java");
335 (options, args) = parser.parse_args();
336 if options.java:
337 generator = GenerateJava()
338 else:
339 generator = GenerateCPlusPlus()
340 generator.Generate()
341
342 if __name__ == '__main__':
343 main()
OLDNEW
« no previous file with comments | « net/android/net_jni_registrar.cc ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698