OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/proxy/proxy_service.h" | 5 #include "net/proxy/proxy_service.h" |
6 | 6 |
7 #include <cstdarg> | 7 #include <cstdarg> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
19 #include "net/base/proxy_delegate.h" | 19 #include "net/base/proxy_delegate.h" |
20 #include "net/base/test_completion_callback.h" | 20 #include "net/base/test_completion_callback.h" |
21 #include "net/log/net_log.h" | 21 #include "net/log/net_log.h" |
22 #include "net/log/net_log_event_type.h" | |
22 #include "net/log/test_net_log.h" | 23 #include "net/log/test_net_log.h" |
23 #include "net/log/test_net_log_entry.h" | 24 #include "net/log/test_net_log_entry.h" |
24 #include "net/log/test_net_log_util.h" | 25 #include "net/log/test_net_log_util.h" |
25 #include "net/proxy/dhcp_proxy_script_fetcher.h" | 26 #include "net/proxy/dhcp_proxy_script_fetcher.h" |
26 #include "net/proxy/mock_proxy_resolver.h" | 27 #include "net/proxy/mock_proxy_resolver.h" |
27 #include "net/proxy/mock_proxy_script_fetcher.h" | 28 #include "net/proxy/mock_proxy_script_fetcher.h" |
28 #include "net/proxy/proxy_config_service.h" | 29 #include "net/proxy/proxy_config_service.h" |
29 #include "net/proxy/proxy_resolver.h" | 30 #include "net/proxy/proxy_resolver.h" |
30 #include "net/proxy/proxy_script_fetcher.h" | 31 #include "net/proxy/proxy_script_fetcher.h" |
31 #include "net/test/gtest_util.h" | 32 #include "net/test/gtest_util.h" |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 EXPECT_TRUE(info.is_direct()); | 380 EXPECT_TRUE(info.is_direct()); |
380 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); | 381 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); |
381 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); | 382 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); |
382 | 383 |
383 // Check the NetLog was filled correctly. | 384 // Check the NetLog was filled correctly. |
384 TestNetLogEntry::List entries; | 385 TestNetLogEntry::List entries; |
385 log.GetEntries(&entries); | 386 log.GetEntries(&entries); |
386 | 387 |
387 EXPECT_EQ(3u, entries.size()); | 388 EXPECT_EQ(3u, entries.size()); |
388 EXPECT_TRUE(LogContainsBeginEvent( | 389 EXPECT_TRUE(LogContainsBeginEvent( |
389 entries, 0, NetLog::TYPE_PROXY_SERVICE)); | 390 entries, 0, NetLogEventType::PROXY_SERVICE)); |
390 EXPECT_TRUE(LogContainsEvent( | 391 EXPECT_TRUE(LogContainsEvent( |
391 entries, 1, NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, | 392 entries, 1, NetLogEventType::PROXY_SERVICE_RESOLVED_PROXY_LIST, |
392 NetLog::PHASE_NONE)); | 393 NetLogEventPhase::NONE)); |
393 EXPECT_TRUE(LogContainsEndEvent( | 394 EXPECT_TRUE(LogContainsEndEvent( |
394 entries, 2, NetLog::TYPE_PROXY_SERVICE)); | 395 entries, 2, NetLogEventType::PROXY_SERVICE)); |
395 } | 396 } |
396 | 397 |
397 TEST_F(ProxyServiceTest, OnResolveProxyCallbackAddProxy) { | 398 TEST_F(ProxyServiceTest, OnResolveProxyCallbackAddProxy) { |
398 ProxyConfig config; | 399 ProxyConfig config; |
399 config.proxy_rules().ParseFromString("foopy1:8080"); | 400 config.proxy_rules().ParseFromString("foopy1:8080"); |
400 config.set_auto_detect(false); | 401 config.set_auto_detect(false); |
401 config.proxy_rules().bypass_rules.ParseFromString("*.org"); | 402 config.proxy_rules().bypass_rules.ParseFromString("*.org"); |
402 | 403 |
403 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 404 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
404 nullptr, nullptr); | 405 nullptr, nullptr); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 537 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
537 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 538 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
538 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 539 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
539 | 540 |
540 // Check the NetLog was filled correctly. | 541 // Check the NetLog was filled correctly. |
541 TestNetLogEntry::List entries; | 542 TestNetLogEntry::List entries; |
542 log.GetEntries(&entries); | 543 log.GetEntries(&entries); |
543 | 544 |
544 EXPECT_EQ(5u, entries.size()); | 545 EXPECT_EQ(5u, entries.size()); |
545 EXPECT_TRUE(LogContainsBeginEvent( | 546 EXPECT_TRUE(LogContainsBeginEvent( |
546 entries, 0, NetLog::TYPE_PROXY_SERVICE)); | 547 entries, 0, NetLogEventType::PROXY_SERVICE)); |
547 EXPECT_TRUE(LogContainsBeginEvent( | 548 EXPECT_TRUE(LogContainsBeginEvent( |
548 entries, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); | 549 entries, 1, NetLogEventType::PROXY_SERVICE_WAITING_FOR_INIT_PAC)); |
549 EXPECT_TRUE(LogContainsEndEvent( | 550 EXPECT_TRUE(LogContainsEndEvent( |
550 entries, 2, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); | 551 entries, 2, NetLogEventType::PROXY_SERVICE_WAITING_FOR_INIT_PAC)); |
551 EXPECT_TRUE(LogContainsEndEvent( | 552 EXPECT_TRUE(LogContainsEndEvent( |
552 entries, 4, NetLog::TYPE_PROXY_SERVICE)); | 553 entries, 4, NetLogEventType::PROXY_SERVICE)); |
553 } | 554 } |
554 | 555 |
555 // Test that the proxy resolver does not see the URL's username/password | 556 // Test that the proxy resolver does not see the URL's username/password |
556 // or its reference section. | 557 // or its reference section. |
557 TEST_F(ProxyServiceTest, PAC_NoIdentityOrHash) { | 558 TEST_F(ProxyServiceTest, PAC_NoIdentityOrHash) { |
558 MockProxyConfigService* config_service = | 559 MockProxyConfigService* config_service = |
559 new MockProxyConfigService("http://foopy/proxy.pac"); | 560 new MockProxyConfigService("http://foopy/proxy.pac"); |
560 | 561 |
561 MockAsyncProxyResolver resolver; | 562 MockAsyncProxyResolver resolver; |
562 MockAsyncProxyResolverFactory* factory = | 563 MockAsyncProxyResolverFactory* factory = |
(...skipping 1675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2238 | 2239 |
2239 EXPECT_FALSE(callback1.have_result()); // Cancelled. | 2240 EXPECT_FALSE(callback1.have_result()); // Cancelled. |
2240 EXPECT_FALSE(callback2.have_result()); // Cancelled. | 2241 EXPECT_FALSE(callback2.have_result()); // Cancelled. |
2241 | 2242 |
2242 TestNetLogEntry::List entries1; | 2243 TestNetLogEntry::List entries1; |
2243 log1.GetEntries(&entries1); | 2244 log1.GetEntries(&entries1); |
2244 | 2245 |
2245 // Check the NetLog for request 1 (which was cancelled) got filled properly. | 2246 // Check the NetLog for request 1 (which was cancelled) got filled properly. |
2246 EXPECT_EQ(4u, entries1.size()); | 2247 EXPECT_EQ(4u, entries1.size()); |
2247 EXPECT_TRUE(LogContainsBeginEvent( | 2248 EXPECT_TRUE(LogContainsBeginEvent( |
2248 entries1, 0, NetLog::TYPE_PROXY_SERVICE)); | 2249 entries1, 0, NetLogEventType::PROXY_SERVICE)); |
2249 EXPECT_TRUE(LogContainsBeginEvent( | 2250 EXPECT_TRUE(LogContainsBeginEvent( |
2250 entries1, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); | 2251 entries1, 1, NetLogEventType::PROXY_SERVICE_WAITING_FOR_INIT_PAC)); |
2251 // Note that TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC is never completed before | 2252 // Note that TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC is never completed before |
eroman
2016/09/06 19:32:20
Please update this comment.
mikecirone
2016/09/07 21:35:41
Done.
| |
2252 // the cancellation occured. | 2253 // the cancellation occured. |
2253 EXPECT_TRUE(LogContainsEvent( | 2254 EXPECT_TRUE(LogContainsEvent( |
2254 entries1, 2, NetLog::TYPE_CANCELLED, NetLog::PHASE_NONE)); | 2255 entries1, 2, NetLogEventType::CANCELLED, NetLogEventPhase::NONE)); |
2255 EXPECT_TRUE(LogContainsEndEvent( | 2256 EXPECT_TRUE(LogContainsEndEvent( |
2256 entries1, 3, NetLog::TYPE_PROXY_SERVICE)); | 2257 entries1, 3, NetLogEventType::PROXY_SERVICE)); |
2257 } | 2258 } |
2258 | 2259 |
2259 // Test that if auto-detect fails, we fall-back to the custom pac. | 2260 // Test that if auto-detect fails, we fall-back to the custom pac. |
2260 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { | 2261 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { |
2261 const GURL url1("http://request1"); | 2262 const GURL url1("http://request1"); |
2262 const GURL url2("http://request2"); | 2263 const GURL url2("http://request2"); |
2263 ProxyConfig config; | 2264 ProxyConfig config; |
2264 config.set_auto_detect(true); | 2265 config.set_auto_detect(true); |
2265 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 2266 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
2266 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. | 2267 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2789 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 2790 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
2790 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2791 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2791 | 2792 |
2792 // Check that the expected events were output to the log stream. In particular | 2793 // Check that the expected events were output to the log stream. In particular |
2793 // PROXY_CONFIG_CHANGED should have only been emitted once (for the initial | 2794 // PROXY_CONFIG_CHANGED should have only been emitted once (for the initial |
2794 // setup), and NOT a second time when the IP address changed. | 2795 // setup), and NOT a second time when the IP address changed. |
2795 TestNetLogEntry::List entries; | 2796 TestNetLogEntry::List entries; |
2796 log.GetEntries(&entries); | 2797 log.GetEntries(&entries); |
2797 | 2798 |
2798 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, | 2799 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, |
2799 NetLog::TYPE_PROXY_CONFIG_CHANGED)); | 2800 NetLogEventType::PROXY_CONFIG_CHANGED)); |
2800 ASSERT_EQ(9u, entries.size()); | 2801 ASSERT_EQ(9u, entries.size()); |
2801 for (size_t i = 1; i < entries.size(); ++i) | 2802 for (size_t i = 1; i < entries.size(); ++i) |
2802 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); | 2803 EXPECT_NE(NetLogEventType::PROXY_CONFIG_CHANGED, entries[i].type); |
2803 } | 2804 } |
2804 | 2805 |
2805 // This test verifies that the PAC script specified by the settings is | 2806 // This test verifies that the PAC script specified by the settings is |
2806 // periodically polled for changes. Specifically, if the initial fetch fails due | 2807 // periodically polled for changes. Specifically, if the initial fetch fails due |
2807 // to a network error, we will eventually re-configure the service to use the | 2808 // to a network error, we will eventually re-configure the service to use the |
2808 // script once it becomes available. | 2809 // script once it becomes available. |
2809 TEST_F(ProxyServiceTest, PACScriptRefetchAfterFailure) { | 2810 TEST_F(ProxyServiceTest, PACScriptRefetchAfterFailure) { |
2810 // Change the retry policy to wait a mere 1 ms before retrying, so the test | 2811 // Change the retry policy to wait a mere 1 ms before retrying, so the test |
2811 // runs quickly. | 2812 // runs quickly. |
2812 ImmediatePollPolicy poll_policy; | 2813 ImmediatePollPolicy poll_policy; |
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3665 GURL(test.sanitized_url_unstripped), | 3666 GURL(test.sanitized_url_unstripped), |
3666 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::UNSAFE)); | 3667 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::UNSAFE)); |
3667 | 3668 |
3668 EXPECT_EQ( | 3669 EXPECT_EQ( |
3669 GURL(test.sanitized_url), | 3670 GURL(test.sanitized_url), |
3670 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::SAFE)); | 3671 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::SAFE)); |
3671 } | 3672 } |
3672 } | 3673 } |
3673 | 3674 |
3674 } // namespace net | 3675 } // namespace net |
OLD | NEW |