| OLD | NEW |
| 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/net/pref_proxy_config_tracker_impl.h" | 5 #include "chrome/browser/net/pref_proxy_config_tracker_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/prefs/pref_registry_simple.h" | 12 #include "base/prefs/pref_registry_simple.h" |
| 13 #include "base/prefs/testing_pref_service.h" | 13 #include "base/prefs/testing_pref_service.h" |
| 14 #include "base/test/histogram_tester.h" |
| 14 #include "chrome/browser/prefs/pref_service_mock_factory.h" | 15 #include "chrome/browser/prefs/pref_service_mock_factory.h" |
| 15 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 16 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
| 16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 18 #include "content/public/test/test_browser_thread.h" | 19 #include "content/public/test/test_browser_thread.h" |
| 19 #include "net/proxy/proxy_config_service_common_unittest.h" | 20 #include "net/proxy/proxy_config_service_common_unittest.h" |
| 20 #include "net/proxy/proxy_info.h" | 21 #include "net/proxy/proxy_info.h" |
| 21 #include "net/proxy/proxy_list.h" | 22 #include "net/proxy/proxy_list.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 EXPECT_TRUE(expected_result.proxy_list().Equals(result.proxy_list())) | 304 EXPECT_TRUE(expected_result.proxy_list().Equals(result.proxy_list())) |
| 304 << "expected: " << expected_result.proxy_list().ToPacString() | 305 << "expected: " << expected_result.proxy_list().ToPacString() |
| 305 << "\nactual: " << result.proxy_list().ToPacString(); | 306 << "\nactual: " << result.proxy_list().ToPacString(); |
| 306 } | 307 } |
| 307 | 308 |
| 308 TEST_F(PrefProxyConfigTrackerImplTest, ExcludeGooglezipDataReductionProxies) { | 309 TEST_F(PrefProxyConfigTrackerImplTest, ExcludeGooglezipDataReductionProxies) { |
| 309 const std::string kDataReductionProxies = | 310 const std::string kDataReductionProxies = |
| 310 "https://proxy.googlezip.net:443,compress.googlezip.net," | 311 "https://proxy.googlezip.net:443,compress.googlezip.net," |
| 311 "https://proxy-dev.googlezip.net:443,proxy-dev.googlezip.net," | 312 "https://proxy-dev.googlezip.net:443,proxy-dev.googlezip.net," |
| 312 "quic://proxy.googlezip.net"; | 313 "quic://proxy.googlezip.net"; |
| 314 const int kNumDataReductionProxies = 5; |
| 313 | 315 |
| 314 struct { | 316 struct { |
| 315 std::string initial_proxy_rules; | 317 std::string initial_proxy_rules; |
| 316 const char* http_proxy_info; | 318 const char* http_proxy_info; |
| 317 const char* https_proxy_info; | 319 const char* https_proxy_info; |
| 318 const char* ftp_proxy_info; | 320 const char* ftp_proxy_info; |
| 321 int expected_num_removed_proxies; |
| 319 } test_cases[] = { | 322 } test_cases[] = { |
| 320 {"http=foopyhttp," + kDataReductionProxies + | 323 {"http=foopyhttp," + kDataReductionProxies + |
| 321 ",direct://;https=foopyhttps," + kDataReductionProxies + | 324 ",direct://;https=foopyhttps," + kDataReductionProxies + |
| 322 ",direct://;ftp=foopyftp," + kDataReductionProxies + ",direct://", | 325 ",direct://;ftp=foopyftp," + kDataReductionProxies + ",direct://", |
| 323 "foopyhttp;direct://", | 326 "foopyhttp;direct://", |
| 324 "foopyhttps;direct://", | 327 "foopyhttps;direct://", |
| 325 "foopyftp;direct://"}, | 328 "foopyftp;direct://", |
| 329 kNumDataReductionProxies * 3}, |
| 326 | 330 |
| 327 {"foopy," + kDataReductionProxies + ",direct://", | 331 {"foopy," + kDataReductionProxies + ",direct://", |
| 328 "foopy;direct://", | 332 "foopy;direct://", |
| 329 "foopy;direct://", | 333 "foopy;direct://", |
| 330 "foopy;direct://"}, | 334 "foopy;direct://", |
| 335 kNumDataReductionProxies}, |
| 331 | 336 |
| 332 {"http=" + kDataReductionProxies + ";https=" + kDataReductionProxies + | 337 {"http=" + kDataReductionProxies + ";https=" + kDataReductionProxies + |
| 333 ";ftp=" + kDataReductionProxies, | 338 ";ftp=" + kDataReductionProxies, |
| 334 "direct://", | 339 "direct://", |
| 335 "direct://", | 340 "direct://", |
| 336 "direct://"}, | 341 "direct://", |
| 342 kNumDataReductionProxies * 3}, |
| 337 | 343 |
| 338 {"http=" + kDataReductionProxies + ",foopy,direct://", | 344 {"http=" + kDataReductionProxies + ",foopy,direct://", |
| 339 "foopy;direct://", | 345 "foopy;direct://", |
| 340 "direct://", | 346 "direct://", |
| 341 "direct://"}, | 347 "direct://", |
| 348 kNumDataReductionProxies}, |
| 349 |
| 350 {"foopy,direct://", |
| 351 "foopy;direct://", |
| 352 "foopy;direct://", |
| 353 "foopy;direct://", |
| 354 0}, |
| 355 |
| 356 {"direct://", |
| 357 "direct://", |
| 358 "direct://", |
| 359 "direct://", |
| 360 0}, |
| 342 }; | 361 }; |
| 343 | 362 |
| 344 // Test setting the proxy from a user pref. | 363 // Test setting the proxy from a user pref. |
| 345 for (const auto& test : test_cases) { | 364 for (const auto& test : test_cases) { |
| 365 base::HistogramTester histogram_tester; |
| 346 pref_service_->SetUserPref(prefs::kProxy, | 366 pref_service_->SetUserPref(prefs::kProxy, |
| 347 ProxyConfigDictionary::CreateFixedServers( | 367 ProxyConfigDictionary::CreateFixedServers( |
| 348 test.initial_proxy_rules, std::string())); | 368 test.initial_proxy_rules, std::string())); |
| 349 loop_.RunUntilIdle(); | 369 loop_.RunUntilIdle(); |
| 350 | 370 |
| 351 net::ProxyConfig config; | 371 net::ProxyConfig config; |
| 352 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, | 372 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, |
| 353 proxy_config_service_->GetLatestProxyConfig(&config)); | 373 proxy_config_service_->GetLatestProxyConfig(&config)); |
| 374 histogram_tester.ExpectUniqueSample( |
| 375 "Net.PrefProxyConfig.GooglezipProxyRemovalCount", |
| 376 test.expected_num_removed_proxies, 1); |
| 354 | 377 |
| 355 CheckResolvedProxyMatches(&config, GURL("http://google.com"), | 378 CheckResolvedProxyMatches(&config, GURL("http://google.com"), |
| 356 test.http_proxy_info); | 379 test.http_proxy_info); |
| 357 CheckResolvedProxyMatches(&config, GURL("https://google.com"), | 380 CheckResolvedProxyMatches(&config, GURL("https://google.com"), |
| 358 test.https_proxy_info); | 381 test.https_proxy_info); |
| 359 CheckResolvedProxyMatches(&config, GURL("ftp://google.com"), | 382 CheckResolvedProxyMatches(&config, GURL("ftp://google.com"), |
| 360 test.ftp_proxy_info); | 383 test.ftp_proxy_info); |
| 361 } | 384 } |
| 362 } | 385 } |
| 363 | 386 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 net::ProxyRulesExpectation::Empty(), | 570 net::ProxyRulesExpectation::Empty(), |
| 548 }, | 571 }, |
| 549 }; | 572 }; |
| 550 | 573 |
| 551 INSTANTIATE_TEST_CASE_P( | 574 INSTANTIATE_TEST_CASE_P( |
| 552 PrefProxyConfigTrackerImplCommandLineTestInstance, | 575 PrefProxyConfigTrackerImplCommandLineTestInstance, |
| 553 PrefProxyConfigTrackerImplCommandLineTest, | 576 PrefProxyConfigTrackerImplCommandLineTest, |
| 554 testing::ValuesIn(kCommandLineTestParams)); | 577 testing::ValuesIn(kCommandLineTestParams)); |
| 555 | 578 |
| 556 } // namespace | 579 } // namespace |
| OLD | NEW |