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

Side by Side Diff: net/proxy/proxy_service_unittest.cc

Issue 2315613002: Extracted NetLog class's inner enum types into their own enum classes and (Closed)
Patch Set: Ran "git cl format" on code. Much formatting ensued. Created 4 years, 3 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
OLDNEW
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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 379
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(
389 entries, 0, NetLog::TYPE_PROXY_SERVICE)); 390 LogContainsBeginEvent(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(entries, 2, NetLogEventType::PROXY_SERVICE));
394 entries, 2, NetLog::TYPE_PROXY_SERVICE));
395 } 395 }
396 396
397 TEST_F(ProxyServiceTest, OnResolveProxyCallbackAddProxy) { 397 TEST_F(ProxyServiceTest, OnResolveProxyCallbackAddProxy) {
398 ProxyConfig config; 398 ProxyConfig config;
399 config.proxy_rules().ParseFromString("foopy1:8080"); 399 config.proxy_rules().ParseFromString("foopy1:8080");
400 config.set_auto_detect(false); 400 config.set_auto_detect(false);
401 config.proxy_rules().bypass_rules.ParseFromString("*.org"); 401 config.proxy_rules().bypass_rules.ParseFromString("*.org");
402 402
403 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), 403 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)),
404 nullptr, nullptr); 404 nullptr, nullptr);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 535
536 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); 536 EXPECT_FALSE(info.proxy_resolve_start_time().is_null());
537 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); 537 EXPECT_FALSE(info.proxy_resolve_end_time().is_null());
538 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); 538 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time());
539 539
540 // Check the NetLog was filled correctly. 540 // Check the NetLog was filled correctly.
541 TestNetLogEntry::List entries; 541 TestNetLogEntry::List entries;
542 log.GetEntries(&entries); 542 log.GetEntries(&entries);
543 543
544 EXPECT_EQ(5u, entries.size()); 544 EXPECT_EQ(5u, entries.size());
545 EXPECT_TRUE(
546 LogContainsBeginEvent(entries, 0, NetLogEventType::PROXY_SERVICE));
545 EXPECT_TRUE(LogContainsBeginEvent( 547 EXPECT_TRUE(LogContainsBeginEvent(
546 entries, 0, NetLog::TYPE_PROXY_SERVICE)); 548 entries, 1, NetLogEventType::PROXY_SERVICE_WAITING_FOR_INIT_PAC));
547 EXPECT_TRUE(LogContainsBeginEvent(
548 entries, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC));
549 EXPECT_TRUE(LogContainsEndEvent( 549 EXPECT_TRUE(LogContainsEndEvent(
550 entries, 2, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); 550 entries, 2, NetLogEventType::PROXY_SERVICE_WAITING_FOR_INIT_PAC));
551 EXPECT_TRUE(LogContainsEndEvent( 551 EXPECT_TRUE(LogContainsEndEvent(entries, 4, NetLogEventType::PROXY_SERVICE));
552 entries, 4, NetLog::TYPE_PROXY_SERVICE));
553 } 552 }
554 553
555 // Test that the proxy resolver does not see the URL's username/password 554 // Test that the proxy resolver does not see the URL's username/password
556 // or its reference section. 555 // or its reference section.
557 TEST_F(ProxyServiceTest, PAC_NoIdentityOrHash) { 556 TEST_F(ProxyServiceTest, PAC_NoIdentityOrHash) {
558 MockProxyConfigService* config_service = 557 MockProxyConfigService* config_service =
559 new MockProxyConfigService("http://foopy/proxy.pac"); 558 new MockProxyConfigService("http://foopy/proxy.pac");
560 559
561 MockAsyncProxyResolver resolver; 560 MockAsyncProxyResolver resolver;
562 MockAsyncProxyResolverFactory* factory = 561 MockAsyncProxyResolverFactory* factory =
(...skipping 1674 matching lines...) Expand 10 before | Expand all | Expand 10 after
2237 EXPECT_TRUE(resolver.cancelled_requests().empty()); 2236 EXPECT_TRUE(resolver.cancelled_requests().empty());
2238 2237
2239 EXPECT_FALSE(callback1.have_result()); // Cancelled. 2238 EXPECT_FALSE(callback1.have_result()); // Cancelled.
2240 EXPECT_FALSE(callback2.have_result()); // Cancelled. 2239 EXPECT_FALSE(callback2.have_result()); // Cancelled.
2241 2240
2242 TestNetLogEntry::List entries1; 2241 TestNetLogEntry::List entries1;
2243 log1.GetEntries(&entries1); 2242 log1.GetEntries(&entries1);
2244 2243
2245 // Check the NetLog for request 1 (which was cancelled) got filled properly. 2244 // Check the NetLog for request 1 (which was cancelled) got filled properly.
2246 EXPECT_EQ(4u, entries1.size()); 2245 EXPECT_EQ(4u, entries1.size());
2246 EXPECT_TRUE(
2247 LogContainsBeginEvent(entries1, 0, NetLogEventType::PROXY_SERVICE));
2247 EXPECT_TRUE(LogContainsBeginEvent( 2248 EXPECT_TRUE(LogContainsBeginEvent(
2248 entries1, 0, NetLog::TYPE_PROXY_SERVICE)); 2249 entries1, 1, NetLogEventType::PROXY_SERVICE_WAITING_FOR_INIT_PAC));
2249 EXPECT_TRUE(LogContainsBeginEvent( 2250 // Note that PROXY_SERVICE_WAITING_FOR_INIT_PAC is never completed before
2250 entries1, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC));
2251 // Note that TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC is never completed before
2252 // the cancellation occured. 2251 // the cancellation occured.
2253 EXPECT_TRUE(LogContainsEvent( 2252 EXPECT_TRUE(LogContainsEvent(entries1, 2, NetLogEventType::CANCELLED,
2254 entries1, 2, NetLog::TYPE_CANCELLED, NetLog::PHASE_NONE)); 2253 NetLogEventPhase::NONE));
2255 EXPECT_TRUE(LogContainsEndEvent( 2254 EXPECT_TRUE(LogContainsEndEvent(entries1, 3, NetLogEventType::PROXY_SERVICE));
2256 entries1, 3, NetLog::TYPE_PROXY_SERVICE));
2257 } 2255 }
2258 2256
2259 // Test that if auto-detect fails, we fall-back to the custom pac. 2257 // Test that if auto-detect fails, we fall-back to the custom pac.
2260 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { 2258 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomPac) {
2261 const GURL url1("http://request1"); 2259 const GURL url1("http://request1");
2262 const GURL url2("http://request2"); 2260 const GURL url2("http://request2");
2263 ProxyConfig config; 2261 ProxyConfig config;
2264 config.set_auto_detect(true); 2262 config.set_auto_detect(true);
2265 config.set_pac_url(GURL("http://foopy/proxy.pac")); 2263 config.set_pac_url(GURL("http://foopy/proxy.pac"));
2266 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. 2264 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used.
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
2789 EXPECT_THAT(callback2.WaitForResult(), IsOk()); 2787 EXPECT_THAT(callback2.WaitForResult(), IsOk());
2790 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); 2788 EXPECT_EQ("request2:80", info2.proxy_server().ToURI());
2791 2789
2792 // Check that the expected events were output to the log stream. In particular 2790 // 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 2791 // PROXY_CONFIG_CHANGED should have only been emitted once (for the initial
2794 // setup), and NOT a second time when the IP address changed. 2792 // setup), and NOT a second time when the IP address changed.
2795 TestNetLogEntry::List entries; 2793 TestNetLogEntry::List entries;
2796 log.GetEntries(&entries); 2794 log.GetEntries(&entries);
2797 2795
2798 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, 2796 EXPECT_TRUE(LogContainsEntryWithType(entries, 0,
2799 NetLog::TYPE_PROXY_CONFIG_CHANGED)); 2797 NetLogEventType::PROXY_CONFIG_CHANGED));
2800 ASSERT_EQ(9u, entries.size()); 2798 ASSERT_EQ(9u, entries.size());
2801 for (size_t i = 1; i < entries.size(); ++i) 2799 for (size_t i = 1; i < entries.size(); ++i)
2802 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); 2800 EXPECT_NE(NetLogEventType::PROXY_CONFIG_CHANGED, entries[i].type);
2803 } 2801 }
2804 2802
2805 // This test verifies that the PAC script specified by the settings is 2803 // This test verifies that the PAC script specified by the settings is
2806 // periodically polled for changes. Specifically, if the initial fetch fails due 2804 // 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 2805 // to a network error, we will eventually re-configure the service to use the
2808 // script once it becomes available. 2806 // script once it becomes available.
2809 TEST_F(ProxyServiceTest, PACScriptRefetchAfterFailure) { 2807 TEST_F(ProxyServiceTest, PACScriptRefetchAfterFailure) {
2810 // Change the retry policy to wait a mere 1 ms before retrying, so the test 2808 // Change the retry policy to wait a mere 1 ms before retrying, so the test
2811 // runs quickly. 2809 // runs quickly.
2812 ImmediatePollPolicy poll_policy; 2810 ImmediatePollPolicy poll_policy;
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
3665 GURL(test.sanitized_url_unstripped), 3663 GURL(test.sanitized_url_unstripped),
3666 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::UNSAFE)); 3664 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::UNSAFE));
3667 3665
3668 EXPECT_EQ( 3666 EXPECT_EQ(
3669 GURL(test.sanitized_url), 3667 GURL(test.sanitized_url),
3670 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::SAFE)); 3668 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::SAFE));
3671 } 3669 }
3672 } 3670 }
3673 3671
3674 } // namespace net 3672 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_service_mojo_unittest.cc ('k') | net/quic/chromium/bidirectional_stream_quic_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698