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

Side by Side Diff: chrome/browser/chromeos/proxy_config_service_impl_unittest.cc

Issue 8102019: redesign and reimplement proxy config service and tracker, revise proxy ui on cros (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/proxy_config_service_impl.h" 5 #include "chrome/browser/chromeos/proxy_config_service_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 30 matching lines...) Expand all
41 #define MK_MODE(mode) ProxyConfigServiceImpl::ProxyConfig::MODE_##mode 41 #define MK_MODE(mode) ProxyConfigServiceImpl::ProxyConfig::MODE_##mode
42 #define MK_SRC(src) ProxyConfigServiceImpl::ProxyConfig::SOURCE_##src 42 #define MK_SRC(src) ProxyConfigServiceImpl::ProxyConfig::SOURCE_##src
43 #define MK_SCHM(scheme) net::ProxyServer::SCHEME_##scheme 43 #define MK_SCHM(scheme) net::ProxyServer::SCHEME_##scheme
44 44
45 // Inspired from net/proxy/proxy_config_service_linux_unittest.cc. 45 // Inspired from net/proxy/proxy_config_service_linux_unittest.cc.
46 const struct { 46 const struct {
47 // Short description to identify the test 47 // Short description to identify the test
48 std::string description; 48 std::string description;
49 49
50 bool is_valid; 50 bool is_valid;
51 bool test_read_write_access; 51 bool test_modifiable;
52 52
53 Input input; 53 Input input;
54 54
55 // Expected outputs from fields of net::ProxyConfig (via IO). 55 // Expected outputs from fields of net::ProxyConfig (via IO).
56 bool auto_detect; 56 bool auto_detect;
57 GURL pac_url; 57 GURL pac_url;
58 net::ProxyRulesExpectation proxy_rules; 58 net::ProxyRulesExpectation proxy_rules;
59 } tests[] = { 59 } tests[] = {
60 { 60 {
61 TEST_DESC("No proxying"), 61 TEST_DESC("No proxying"),
62 62
63 true, // is_valid 63 true, // is_valid
64 true, // test_read_write_access 64 true, // test_modifiable
65 65
66 { // Input. 66 { // Input.
67 MK_MODE(DIRECT), // mode 67 MK_MODE(DIRECT), // mode
68 }, 68 },
69 69
70 // Expected result. 70 // Expected result.
71 false, // auto_detect 71 false, // auto_detect
72 GURL(), // pac_url 72 GURL(), // pac_url
73 net::ProxyRulesExpectation::Empty(), // proxy_rules 73 net::ProxyRulesExpectation::Empty(), // proxy_rules
74 }, 74 },
75 75
76 { 76 {
77 TEST_DESC("Auto detect"), 77 TEST_DESC("Auto detect"),
78 78
79 true, // is_valid 79 true, // is_valid
80 true, // test_read_write_access 80 true, // test_modifiable
81 81
82 { // Input. 82 { // Input.
83 MK_MODE(AUTO_DETECT), // mode 83 MK_MODE(AUTO_DETECT), // mode
84 }, 84 },
85 85
86 // Expected result. 86 // Expected result.
87 true, // auto_detect 87 true, // auto_detect
88 GURL(), // pac_url 88 GURL(), // pac_url
89 net::ProxyRulesExpectation::Empty(), // proxy_rules 89 net::ProxyRulesExpectation::Empty(), // proxy_rules
90 }, 90 },
91 91
92 { 92 {
93 TEST_DESC("Valid PAC URL"), 93 TEST_DESC("Valid PAC URL"),
94 94
95 true, // is_valid 95 true, // is_valid
96 true, // test_read_write_access 96 true, // test_modifiable
97 97
98 { // Input. 98 { // Input.
99 MK_MODE(PAC_SCRIPT), // mode 99 MK_MODE(PAC_SCRIPT), // mode
100 "http://wpad/wpad.dat", // pac_url 100 "http://wpad/wpad.dat", // pac_url
101 }, 101 },
102 102
103 // Expected result. 103 // Expected result.
104 false, // auto_detect 104 false, // auto_detect
105 GURL("http://wpad/wpad.dat"), // pac_url 105 GURL("http://wpad/wpad.dat"), // pac_url
106 net::ProxyRulesExpectation::Empty(), // proxy_rules 106 net::ProxyRulesExpectation::Empty(), // proxy_rules
107 }, 107 },
108 108
109 { 109 {
110 TEST_DESC("Invalid PAC URL"), 110 TEST_DESC("Invalid PAC URL"),
111 111
112 false, // is_valid 112 false, // is_valid
113 false, // test_read_write_access 113 false, // test_modifiable
114 114
115 { // Input. 115 { // Input.
116 MK_MODE(PAC_SCRIPT), // mode 116 MK_MODE(PAC_SCRIPT), // mode
117 "wpad.dat", // pac_url 117 "wpad.dat", // pac_url
118 }, 118 },
119 119
120 // Expected result. 120 // Expected result.
121 false, // auto_detect 121 false, // auto_detect
122 GURL(), // pac_url 122 GURL(), // pac_url
123 net::ProxyRulesExpectation::Empty(), // proxy_rules 123 net::ProxyRulesExpectation::Empty(), // proxy_rules
124 }, 124 },
125 125
126 { 126 {
127 TEST_DESC("Single-host in proxy list"), 127 TEST_DESC("Single-host in proxy list"),
128 128
129 true, // is_valid 129 true, // is_valid
130 true, // test_read_write_access 130 true, // test_modifiable
131 131
132 { // Input. 132 { // Input.
133 MK_MODE(SINGLE_PROXY), // mode 133 MK_MODE(SINGLE_PROXY), // mode
134 NULL, // pac_url 134 NULL, // pac_url
135 "www.google.com", // single_uri 135 "www.google.com", // single_uri
136 }, 136 },
137 137
138 // Expected result. 138 // Expected result.
139 false, // auto_detect 139 false, // auto_detect
140 GURL(), // pac_url 140 GURL(), // pac_url
141 net::ProxyRulesExpectation::Single( // proxy_rules 141 net::ProxyRulesExpectation::Single( // proxy_rules
142 "www.google.com:80", // single proxy 142 "www.google.com:80", // single proxy
143 ""), // bypass rules 143 ""), // bypass rules
144 }, 144 },
145 145
146 { 146 {
147 TEST_DESC("Single-host, different port"), 147 TEST_DESC("Single-host, different port"),
148 148
149 true, // is_valid 149 true, // is_valid
150 false, // test_read_write_access 150 false, // test_modifiable
151 151
152 { // Input. 152 { // Input.
153 MK_MODE(SINGLE_PROXY), // mode 153 MK_MODE(SINGLE_PROXY), // mode
154 NULL, // pac_url 154 NULL, // pac_url
155 "www.google.com:99", // single_uri 155 "www.google.com:99", // single_uri
156 }, 156 },
157 157
158 // Expected result. 158 // Expected result.
159 false, // auto_detect 159 false, // auto_detect
160 GURL(), // pac_url 160 GURL(), // pac_url
161 net::ProxyRulesExpectation::Single( // proxy_rules 161 net::ProxyRulesExpectation::Single( // proxy_rules
162 "www.google.com:99", // single 162 "www.google.com:99", // single
163 ""), // bypass rules 163 ""), // bypass rules
164 }, 164 },
165 165
166 { 166 {
167 TEST_DESC("Tolerate a scheme"), 167 TEST_DESC("Tolerate a scheme"),
168 168
169 true, // is_valid 169 true, // is_valid
170 false, // test_read_write_access 170 false, // test_modifiable
171 171
172 { // Input. 172 { // Input.
173 MK_MODE(SINGLE_PROXY), // mode 173 MK_MODE(SINGLE_PROXY), // mode
174 NULL, // pac_url 174 NULL, // pac_url
175 "http://www.google.com:99", // single_uri 175 "http://www.google.com:99", // single_uri
176 }, 176 },
177 177
178 // Expected result. 178 // Expected result.
179 false, // auto_detect 179 false, // auto_detect
180 GURL(), // pac_url 180 GURL(), // pac_url
181 net::ProxyRulesExpectation::Single( // proxy_rules 181 net::ProxyRulesExpectation::Single( // proxy_rules
182 "www.google.com:99", // single proxy 182 "www.google.com:99", // single proxy
183 ""), // bypass rules 183 ""), // bypass rules
184 }, 184 },
185 185
186 { 186 {
187 TEST_DESC("Per-scheme proxy rules"), 187 TEST_DESC("Per-scheme proxy rules"),
188 188
189 true, // is_valid 189 true, // is_valid
190 true, // test_read_write_access 190 true, // test_modifiable
191 191
192 { // Input. 192 { // Input.
193 MK_MODE(PROXY_PER_SCHEME), // mode 193 MK_MODE(PROXY_PER_SCHEME), // mode
194 NULL, // pac_url 194 NULL, // pac_url
195 NULL, // single_uri 195 NULL, // single_uri
196 "www.google.com:80", // http_uri 196 "www.google.com:80", // http_uri
197 "www.foo.com:110", // https_uri 197 "www.foo.com:110", // https_uri
198 "ftp.foo.com:121", // ftp_uri 198 "ftp.foo.com:121", // ftp_uri
199 "socks.com:888", // socks_uri 199 "socks.com:888", // socks_uri
200 }, 200 },
201 201
202 // Expected result. 202 // Expected result.
203 false, // auto_detect 203 false, // auto_detect
204 GURL(), // pac_url 204 GURL(), // pac_url
205 net::ProxyRulesExpectation::PerSchemeWithSocks( // proxy_rules 205 net::ProxyRulesExpectation::PerSchemeWithSocks( // proxy_rules
206 "www.google.com:80", // http 206 "www.google.com:80", // http
207 "https://www.foo.com:110", // https 207 "https://www.foo.com:110", // https
208 "ftp.foo.com:121", // ftp 208 "ftp.foo.com:121", // ftp
209 "socks5://socks.com:888", // fallback proxy 209 "socks5://socks.com:888", // fallback proxy
210 ""), // bypass rules 210 ""), // bypass rules
211 }, 211 },
212 212
213 { 213 {
214 TEST_DESC("Bypass rules"), 214 TEST_DESC("Bypass rules"),
215 215
216 true, // is_valid 216 true, // is_valid
217 true, // test_read_write_access 217 true, // test_modifiable
218 218
219 { // Input. 219 { // Input.
220 MK_MODE(SINGLE_PROXY), // mode 220 MK_MODE(SINGLE_PROXY), // mode
221 NULL, // pac_url 221 NULL, // pac_url
222 "www.google.com", // single_uri 222 "www.google.com", // single_uri
223 NULL, NULL, NULL, NULL, // per-proto 223 NULL, NULL, NULL, NULL, // per-proto
224 "*.google.com, *foo.com:99, 1.2.3.4:22, 127.0.0.1/8", // bypass_rules 224 "*.google.com, *foo.com:99, 1.2.3.4:22, 127.0.0.1/8", // bypass_rules
225 }, 225 },
226 226
227 // Expected result. 227 // Expected result.
(...skipping 26 matching lines...) Expand all
254 config_service_->SetTesting(); 254 config_service_->SetTesting();
255 } 255 }
256 256
257 void SetAutomaticProxy( 257 void SetAutomaticProxy(
258 ProxyConfigServiceImpl::ProxyConfig::Mode mode, 258 ProxyConfigServiceImpl::ProxyConfig::Mode mode,
259 ProxyConfigServiceImpl::ProxyConfig::Source source, 259 ProxyConfigServiceImpl::ProxyConfig::Source source,
260 const char* pac_url, 260 const char* pac_url,
261 ProxyConfigServiceImpl::ProxyConfig* config, 261 ProxyConfigServiceImpl::ProxyConfig* config,
262 ProxyConfigServiceImpl::ProxyConfig::AutomaticProxy* automatic_proxy) { 262 ProxyConfigServiceImpl::ProxyConfig::AutomaticProxy* automatic_proxy) {
263 config->mode = mode; 263 config->mode = mode;
264 automatic_proxy->source = source; 264 config->source = source;
265 if (pac_url) 265 if (pac_url)
266 automatic_proxy->pac_url = GURL(pac_url); 266 automatic_proxy->pac_url = GURL(pac_url);
267 } 267 }
268 268
269 void SetManualProxy( 269 void SetManualProxy(
270 ProxyConfigServiceImpl::ProxyConfig::Mode mode, 270 ProxyConfigServiceImpl::ProxyConfig::Mode mode,
271 ProxyConfigServiceImpl::ProxyConfig::Source source, 271 ProxyConfigServiceImpl::ProxyConfig::Source source,
272 const char* server_uri, 272 const char* server_uri,
273 net::ProxyServer::Scheme scheme, 273 net::ProxyServer::Scheme scheme,
274 ProxyConfigServiceImpl::ProxyConfig* config, 274 ProxyConfigServiceImpl::ProxyConfig* config,
275 ProxyConfigServiceImpl::ProxyConfig::ManualProxy* manual_proxy) { 275 ProxyConfigServiceImpl::ProxyConfig::ManualProxy* manual_proxy) {
276 if (!server_uri) 276 if (!server_uri)
277 return; 277 return;
278 config->mode = mode; 278 config->mode = mode;
279 manual_proxy->source = source; 279 config->source = source;
280 manual_proxy->server = net::ProxyServer::FromURI(server_uri, scheme); 280 manual_proxy->server = net::ProxyServer::FromURI(server_uri, scheme);
281 } 281 }
282 282
283 void InitConfigWithTestInput( 283 void InitConfigWithTestInput(
284 const Input& input, ProxyConfigServiceImpl::ProxyConfig::Source source, 284 const Input& input, ProxyConfigServiceImpl::ProxyConfig::Source source,
285 ProxyConfigServiceImpl::ProxyConfig* init_config) { 285 ProxyConfigServiceImpl::ProxyConfig* init_config) {
286 switch (input.mode) { 286 switch (input.mode) {
287 case MK_MODE(DIRECT): 287 case MK_MODE(DIRECT):
288 case MK_MODE(AUTO_DETECT): 288 case MK_MODE(AUTO_DETECT):
289 case MK_MODE(PAC_SCRIPT): 289 case MK_MODE(PAC_SCRIPT):
(...skipping 13 matching lines...) Expand all
303 init_config, &init_config->ftp_proxy); 303 init_config, &init_config->ftp_proxy);
304 SetManualProxy(input.mode, source, input.socks_uri, MK_SCHM(SOCKS5), 304 SetManualProxy(input.mode, source, input.socks_uri, MK_SCHM(SOCKS5),
305 init_config, &init_config->socks_proxy); 305 init_config, &init_config->socks_proxy);
306 break; 306 break;
307 } 307 }
308 if (input.bypass_rules) { 308 if (input.bypass_rules) {
309 init_config->bypass_rules.ParseFromString(input.bypass_rules); 309 init_config->bypass_rules.ParseFromString(input.bypass_rules);
310 } 310 }
311 } 311 }
312 312
313 void TestReadWriteAccessForMode(const Input& input, 313 void TestModifiable(const Input& input,
314 ProxyConfigServiceImpl::ProxyConfig::Source source) { 314 ProxyConfigServiceImpl::ProxyConfig::Source source,
315 bool expected_modifiable) {
315 // Init config from |source|. 316 // Init config from |source|.
316 ProxyConfigServiceImpl::ProxyConfig init_config; 317 ProxyConfigServiceImpl::ProxyConfig init_config;
317 InitConfigWithTestInput(input, source, &init_config); 318 InitConfigWithTestInput(input, source, &init_config);
318 CreateConfigService(init_config); 319 CreateConfigService(init_config);
319 320
320 ProxyConfigServiceImpl::ProxyConfig config; 321 ProxyConfigServiceImpl::ProxyConfig config;
321 config_service()->UIGetProxyConfig(&config); 322 config_service()->UIGetProxyConfig(&config);
322 323
323 // For owner, write access to config should be equal CanBeWrittenByOwner(). 324 EXPECT_EQ(expected_modifiable, config.IsUserModifiable());
324 // For non-owner, config is never writeable.
325 bool expected_writeable_by_owner = CanBeWrittenByOwner(source);
326 if (config.mode == MK_MODE(PROXY_PER_SCHEME)) {
327 if (input.http_uri) {
328 EXPECT_EQ(expected_writeable_by_owner,
329 config.CanBeWrittenByUser(true, "http"));
330 EXPECT_FALSE(config.CanBeWrittenByUser(false, "http"));
331 }
332 if (input.https_uri) {
333 EXPECT_EQ(expected_writeable_by_owner,
334 config.CanBeWrittenByUser(true, "http"));
335 EXPECT_FALSE(config.CanBeWrittenByUser(false, "https"));
336 }
337 if (input.ftp_uri) {
338 EXPECT_EQ(expected_writeable_by_owner,
339 config.CanBeWrittenByUser(true, "http"));
340 EXPECT_FALSE(config.CanBeWrittenByUser(false, "ftp"));
341 }
342 if (input.socks_uri) {
343 EXPECT_EQ(expected_writeable_by_owner,
344 config.CanBeWrittenByUser(true, "http"));
345 EXPECT_FALSE(config.CanBeWrittenByUser(false, "socks"));
346 }
347 } else {
348 EXPECT_EQ(expected_writeable_by_owner,
349 config.CanBeWrittenByUser(true, std::string()));
350 EXPECT_FALSE(config.CanBeWrittenByUser(false, std::string()));
351 }
352 }
353
354 void TestReadWriteAccessForScheme(
355 ProxyConfigServiceImpl::ProxyConfig::Source source,
356 const char* server_uri,
357 const std::string& scheme) {
358 // Init with manual |scheme| proxy.
359 ProxyConfigServiceImpl::ProxyConfig init_config;
360 ProxyConfigServiceImpl::ProxyConfig::ManualProxy* proxy =
361 init_config.MapSchemeToProxy(scheme);
362 net::ProxyServer::Scheme net_scheme = MK_SCHM(HTTP);
363 if (scheme == "http" || scheme == "ftp")
364 net_scheme = MK_SCHM(HTTP);
365 else if (scheme == "https")
366 net_scheme = MK_SCHM(HTTPS);
367 else if (scheme == "socks")
368 net_scheme = MK_SCHM(SOCKS4);
369 SetManualProxy(MK_MODE(PROXY_PER_SCHEME), source, server_uri, net_scheme,
370 &init_config, proxy);
371 CreateConfigService(init_config);
372
373 ProxyConfigServiceImpl::ProxyConfig config;
374 config_service()->UIGetProxyConfig(&config);
375
376 // For owner, write access to config should be equal CanBeWrittenByOwner().
377 // For non-owner, config is never writeable.
378 bool expected_writeable_by_owner = CanBeWrittenByOwner(source);
379 EXPECT_EQ(expected_writeable_by_owner,
380 config.CanBeWrittenByUser(true, scheme));
381 EXPECT_FALSE(config.CanBeWrittenByUser(false, scheme));
382
383 const char* all_schemes[] = {
384 "http", "https", "ftp", "socks",
385 };
386
387 // Rest of protos should be writeable by owner, but not writeable by
388 // non-owner.
389 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(all_schemes); ++i) {
390 if (scheme == all_schemes[i])
391 continue;
392 EXPECT_TRUE(config.CanBeWrittenByUser(true, all_schemes[i]));
393 EXPECT_FALSE(config.CanBeWrittenByUser(false, all_schemes[i]));
394 }
395 } 325 }
396 326
397 // Synchronously gets the latest proxy config. 327 // Synchronously gets the latest proxy config.
398 bool SyncGetLatestProxyConfig(net::ProxyConfig* config) { 328 bool SyncGetLatestProxyConfig(net::ProxyConfig* config) {
399 // Let message loop process all messages. 329 // Let message loop process all messages.
400 MessageLoop::current()->RunAllPending(); 330 MessageLoop::current()->RunAllPending();
401 // Calls IOGetProxyConfig (which is called from 331 // Calls IOGetProxyConfig (which is called from
402 // ProxyConfigService::GetLatestProxyConfig), running on faked IO thread. 332 // ProxyConfigService::GetLatestProxyConfig), running on faked IO thread.
403 return config_service_->IOGetProxyConfig(config); 333 return config_service_->IOGetProxyConfig(config);
404 } 334 }
405 335
406 ProxyConfigServiceImpl* config_service() const { 336 ProxyConfigServiceImpl* config_service() const {
407 return config_service_; 337 return config_service_;
408 } 338 }
409 339
410 private: 340 private:
411 bool CanBeWrittenByOwner(
412 ProxyConfigServiceImpl::ProxyConfig::Source source) const {
413 return source == MK_SRC(POLICY) ? false : true;
414 }
415
416 ScopedStubCrosEnabler stub_cros_enabler_; 341 ScopedStubCrosEnabler stub_cros_enabler_;
417 MessageLoop message_loop_; 342 MessageLoop message_loop_;
418 BrowserThread ui_thread_; 343 BrowserThread ui_thread_;
419 BrowserThread io_thread_; 344 BrowserThread io_thread_;
420 345
421 scoped_refptr<ProxyConfigServiceImpl> config_service_; 346 scoped_refptr<ProxyConfigServiceImpl> config_service_;
422 }; 347 };
423 348
424 TEST_F(ProxyConfigServiceImplTest, ChromeosProxyConfigToNetProxyConfig) { 349 TEST_F(ProxyConfigServiceImplTest, ChromeosProxyConfigToNetProxyConfig) {
425 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 350 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
426 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, 351 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i,
427 tests[i].description.c_str())); 352 tests[i].description.c_str()));
428 353
429 ProxyConfigServiceImpl::ProxyConfig init_config; 354 ProxyConfigServiceImpl::ProxyConfig init_config;
430 InitConfigWithTestInput(tests[i].input, MK_SRC(OWNER), &init_config); 355 InitConfigWithTestInput(tests[i].input, MK_SRC(NETWORK), &init_config);
431 CreateConfigService(init_config); 356 CreateConfigService(init_config);
432 357
433 net::ProxyConfig config; 358 net::ProxyConfig config;
434 SyncGetLatestProxyConfig(&config); 359 SyncGetLatestProxyConfig(&config);
435 360
436 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); 361 EXPECT_EQ(tests[i].auto_detect, config.auto_detect());
437 EXPECT_EQ(tests[i].pac_url, config.pac_url()); 362 EXPECT_EQ(tests[i].pac_url, config.pac_url());
438 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); 363 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules()));
439 } 364 }
440 } 365 }
441 366
442 TEST_F(ProxyConfigServiceImplTest, ModifyFromUI) { 367 TEST_F(ProxyConfigServiceImplTest, ModifyFromUI) {
443 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 368 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
444 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, 369 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i,
445 tests[i].description.c_str())); 370 tests[i].description.c_str()));
446 371
447 // Init with direct. 372 // Init with direct.
448 ProxyConfigServiceImpl::ProxyConfig init_config; 373 ProxyConfigServiceImpl::ProxyConfig init_config;
449 SetAutomaticProxy(MK_MODE(DIRECT), MK_SRC(OWNER), NULL, &init_config, 374 SetAutomaticProxy(MK_MODE(DIRECT), MK_SRC(NETWORK), NULL, &init_config,
450 &init_config.automatic_proxy); 375 &init_config.automatic_proxy);
451 CreateConfigService(init_config); 376 CreateConfigService(init_config);
452 377
453 // Set config to tests[i].input via UI. 378 // Set config to tests[i].input via UI.
454 net::ProxyBypassRules bypass_rules; 379 net::ProxyBypassRules bypass_rules;
455 const Input& input = tests[i].input; 380 const Input& input = tests[i].input;
456 switch (input.mode) { 381 switch (input.mode) {
457 case MK_MODE(DIRECT) : 382 case MK_MODE(DIRECT) :
458 config_service()->UISetProxyConfigToDirect(); 383 config_service()->UISetProxyConfigToDirect();
459 break; 384 break;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 availability_ = availability; 484 availability_ = availability;
560 } 485 }
561 486
562 scoped_refptr<ProxyConfigServiceImpl> config_service_; 487 scoped_refptr<ProxyConfigServiceImpl> config_service_;
563 net::ProxyConfigService::ConfigAvailability availability_; 488 net::ProxyConfigService::ConfigAvailability availability_;
564 net::ProxyConfig config_; 489 net::ProxyConfig config_;
565 }; 490 };
566 491
567 // Init with direct. 492 // Init with direct.
568 ProxyConfigServiceImpl::ProxyConfig init_config; 493 ProxyConfigServiceImpl::ProxyConfig init_config;
569 SetAutomaticProxy(MK_MODE(DIRECT), MK_SRC(OWNER), NULL, &init_config, 494 SetAutomaticProxy(MK_MODE(DIRECT), MK_SRC(NETWORK), NULL, &init_config,
570 &init_config.automatic_proxy); 495 &init_config.automatic_proxy);
571 CreateConfigService(init_config); 496 CreateConfigService(init_config);
572 497
573 ProxyChangedObserver observer(config_service()); 498 ProxyChangedObserver observer(config_service());
574 499
575 // Set to pac script from UI. 500 // Set to pac script from UI.
576 EXPECT_TRUE(config_service()->UISetProxyConfigToPACScript( 501 EXPECT_TRUE(config_service()->UISetProxyConfigToPACScript(
577 GURL("http://wpad.dat"))); 502 GURL("http://wpad.dat")));
578 // Retrieve config from IO thread. 503 // Retrieve config from IO thread.
579 net::ProxyConfig io_config; 504 net::ProxyConfig io_config;
580 SyncGetLatestProxyConfig(&io_config); 505 SyncGetLatestProxyConfig(&io_config);
581 506
582 // Observer should have gotten the same new proxy config. 507 // Observer should have gotten the same new proxy config.
583 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, observer.availability()); 508 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, observer.availability());
584 EXPECT_TRUE(io_config.Equals(observer.config())); 509 EXPECT_TRUE(io_config.Equals(observer.config()));
585 } 510 }
586 511
587 TEST_F(ProxyConfigServiceImplTest, SerializeAndDeserializeForNetwork) { 512 TEST_F(ProxyConfigServiceImplTest, SerializeAndDeserializeForNetwork) {
588 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 513 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
589 if (!tests[i].is_valid) 514 if (!tests[i].is_valid)
590 continue; 515 continue;
591 516
592 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, 517 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i,
593 tests[i].description.c_str())); 518 tests[i].description.c_str()));
594 519
595 ProxyConfigServiceImpl::ProxyConfig source_config; 520 ProxyConfigServiceImpl::ProxyConfig source_config;
596 InitConfigWithTestInput(tests[i].input, MK_SRC(OWNER), &source_config); 521 InitConfigWithTestInput(tests[i].input, MK_SRC(NETWORK), &source_config);
597 522
598 // Serialize source_config into std::string. 523 // Serialize source_config into std::string.
599 std::string serialized_value; 524 std::string serialized_value;
600 EXPECT_TRUE(source_config.SerializeForNetwork(&serialized_value)); 525 EXPECT_TRUE(source_config.SerializeForNetwork(&serialized_value));
601 526
602 // Deserialize std:string into target_config. 527 // Deserialize std:string into target_config.
603 ProxyConfigServiceImpl::ProxyConfig target_config; 528 ProxyConfigServiceImpl::ProxyConfig target_config;
604 EXPECT_TRUE(target_config.DeserializeForNetwork(serialized_value)); 529 EXPECT_TRUE(target_config.DeserializeForNetwork(serialized_value));
605 530
606 // Compare the configs after serialization and deserialization. 531 // Compare the configs after serialization and deserialization.
607 net::ProxyConfig net_src_cfg; 532 net::ProxyConfig net_src_cfg;
608 net::ProxyConfig net_tgt_cfg; 533 net::ProxyConfig net_tgt_cfg;
609 source_config.ToNetProxyConfig(&net_src_cfg); 534 source_config.ToNetProxyConfig(&net_src_cfg);
610 target_config.ToNetProxyConfig(&net_tgt_cfg); 535 target_config.ToNetProxyConfig(&net_tgt_cfg);
611 #if !defined(NDEBUG) 536 #if !defined(NDEBUG)
612 if (!net_src_cfg.Equals(net_tgt_cfg)) { 537 if (!net_src_cfg.Equals(net_tgt_cfg)) {
613 std::string src_output, tgt_output; 538 std::string src_output, tgt_output;
614 JSONStringValueSerializer src_serializer(&src_output); 539 JSONStringValueSerializer src_serializer(&src_output);
615 src_serializer.Serialize(*net_src_cfg.ToValue()); 540 src_serializer.Serialize(*net_src_cfg.ToValue());
616 JSONStringValueSerializer tgt_serializer(&tgt_output); 541 JSONStringValueSerializer tgt_serializer(&tgt_output);
617 tgt_serializer.Serialize(*net_tgt_cfg.ToValue()); 542 tgt_serializer.Serialize(*net_tgt_cfg.ToValue());
618 VLOG(1) << "source:\n" << src_output 543 VLOG(1) << "source:\n" << src_output
619 << "\ntarget:\n" << tgt_output; 544 << "\ntarget:\n" << tgt_output;
620 } 545 }
621 #endif // !defined(NDEBUG) 546 #endif // !defined(NDEBUG)
622 EXPECT_TRUE(net_src_cfg.Equals(net_tgt_cfg)); 547 EXPECT_TRUE(net_src_cfg.Equals(net_tgt_cfg));
623 } 548 }
624 } 549 }
625 550
626 TEST_F(ProxyConfigServiceImplTest, ReadWriteAccessForPolicySource) { 551 TEST_F(ProxyConfigServiceImplTest, Modifiable) {
627 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 552 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
628 if (!tests[i].test_read_write_access) 553 if (!tests[i].test_modifiable)
629 continue; 554 continue;
630 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, 555 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i,
631 tests[i].description.c_str())); 556 tests[i].description.c_str()));
632 TestReadWriteAccessForMode(tests[i].input, MK_SRC(POLICY)); 557 TestModifiable(tests[i].input, MK_SRC(NONE), true);
558 TestModifiable(tests[i].input, MK_SRC(NONE_DISABLED), false);
559 TestModifiable(tests[i].input, MK_SRC(POLICY), false);
560 TestModifiable(tests[i].input, MK_SRC(EXTENSION), false);
561 TestModifiable(tests[i].input, MK_SRC(NETWORK), true);
562 TestModifiable(tests[i].input, MK_SRC(NETWORK_DISABLED), false);
563 TestModifiable(tests[i].input, MK_SRC(RECOMMENDED), true);
564 TestModifiable(tests[i].input, MK_SRC(RECOMMENDED_DISABLED), false);
633 } 565 }
634 } 566 }
635 567
636 TEST_F(ProxyConfigServiceImplTest, ReadWriteAccessForOwnerSource) {
637 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
638 if (!tests[i].test_read_write_access)
639 continue;
640 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i,
641 tests[i].description.c_str()));
642 TestReadWriteAccessForMode(tests[i].input, MK_SRC(OWNER));
643 }
644 }
645
646 TEST_F(ProxyConfigServiceImplTest, ReadWriteAccessForMixedSchemes) {
647 const char* http_uri = "www.google.com:80";
648 const char* https_uri = "www.foo.com:110";
649 const char* ftp_uri = "ftp.foo.com:121";
650 const char* socks_uri = "socks.com:888";
651
652 // Init with policy source.
653 TestReadWriteAccessForScheme(MK_SRC(POLICY), http_uri, "http");
654 TestReadWriteAccessForScheme(MK_SRC(POLICY), https_uri, "https");
655 TestReadWriteAccessForScheme(MK_SRC(POLICY), ftp_uri, "ftp");
656 TestReadWriteAccessForScheme(MK_SRC(POLICY), socks_uri, "socks");
657
658 // Init with owner source.
659 TestReadWriteAccessForScheme(MK_SRC(OWNER), http_uri, "http");
660 TestReadWriteAccessForScheme(MK_SRC(OWNER), https_uri, "https");
661 TestReadWriteAccessForScheme(MK_SRC(OWNER), ftp_uri, "ftp");
662 TestReadWriteAccessForScheme(MK_SRC(OWNER), socks_uri, "socks");
663 }
664
665 } // namespace chromeos 568 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698