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

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: Add proxy_test_cases.py Created 8 years, 7 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
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/" : "",
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(ProxyConfigServiceAndroidMappingTest, %s) {" %
245 test_case["name"])
246 if "description" in test_case:
247 self._GenerateDescription(test_case["description"]);
248 self._GenerateConfiguration(test_case["properties"])
249 self._GenerateMappings(test_case["mappings"])
250 print "}"
251 print ""
252
253 def _GenerateDescription(self, description):
254 print " // %s" % description
255
256 def _GenerateConfiguration(self, properties):
257 for key in sorted(properties.iterkeys()):
258 print " configuration_[\"%s\"] = \"%s\";" % (key, properties[key])
259 print " delegate_->SetProperties(configuration_);"
260
261 def _GenerateMappings(self, mappings):
262 for url in sorted(mappings.iterkeys()):
263 print " TestMapping(\"%s\", \"%s\");" % (url, mappings[url])
264
265
266 class GenerateJava:
267 """Generate Java test cases"""
268
269 def Generate(self):
270 for test_case in test_cases:
271 if "description" in test_case:
272 self._GenerateDescription(test_case["description"]);
273 print " @SmallTest"
274 print " public void test%s() throws Exception {" % test_case["name"]
275 self._GenerateConfiguration(test_case["properties"])
276 self._GenerateMappings(test_case["mappings"])
277 print " }"
278 print ""
279
280 def _GenerateDescription(self, description):
281 print " /**"
282 print " * %s" % description
283 print " *"
284 print " * @throws Exception"
285 print " */"
286
287 def _GenerateConfiguration(self, properties):
288 for key in sorted(properties.iterkeys()):
289 print " System.setProperty(\"%s\", \"%s\");" % (
290 key, properties[key])
291
292 def _GenerateMappings(self, mappings):
293 for url in sorted(mappings.iterkeys()):
294 print " checkMapping(\"%s\", \"%s\");" % (url, mappings[url])
295
296
297 def main():
298 parser = optparse.OptionParser()
299 parser.add_option("-j", "--java",
300 action="store_true", dest="java");
301 (options, args) = parser.parse_args();
302 if options.java:
303 generator = GenerateJava()
304 else:
305 generator = GenerateCPlusPlus()
306 generator.Generate()
307
308 if __name__ == '__main__':
309 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698