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

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

Issue 848006: Generalize the net module's LoadLog facility from a passive container, to an event stream (NetLog). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Split up RequestTracker into ConnectJobTracker+RequestTracker+RequestTrackerBase, address comments Created 10 years, 9 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
« no previous file with comments | « net/proxy/proxy_service.cc ('k') | net/proxy/single_threaded_proxy_resolver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <vector> 7 #include <vector>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
13 #include "net/base/load_log.h" 13 #include "net/base/net_log.h"
14 #include "net/base/load_log_unittest.h" 14 #include "net/base/net_log_unittest.h"
15 #include "net/base/mock_network_change_notifier.h" 15 #include "net/base/mock_network_change_notifier.h"
16 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
17 #include "net/base/test_completion_callback.h" 17 #include "net/base/test_completion_callback.h"
18 #include "net/proxy/mock_proxy_resolver.h" 18 #include "net/proxy/mock_proxy_resolver.h"
19 #include "net/proxy/proxy_config_service.h" 19 #include "net/proxy/proxy_config_service.h"
20 #include "net/proxy/proxy_resolver.h" 20 #include "net/proxy/proxy_resolver.h"
21 #include "net/proxy/proxy_script_fetcher.h" 21 #include "net/proxy/proxy_script_fetcher.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 23
24 // TODO(eroman): Write a test which exercises 24 // TODO(eroman): Write a test which exercises
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 TEST(ProxyServiceTest, Direct) { 92 TEST(ProxyServiceTest, Direct) {
93 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 93 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
94 scoped_refptr<ProxyService> service( 94 scoped_refptr<ProxyService> service(
95 new ProxyService(new MockProxyConfigService, resolver, NULL)); 95 new ProxyService(new MockProxyConfigService, resolver, NULL));
96 96
97 GURL url("http://www.google.com/"); 97 GURL url("http://www.google.com/");
98 98
99 ProxyInfo info; 99 ProxyInfo info;
100 TestCompletionCallback callback; 100 TestCompletionCallback callback;
101 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); 101 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
102 int rv = service->ResolveProxy(url, &info, &callback, NULL, log); 102 int rv = service->ResolveProxy(url, &info, &callback, NULL, log.bound());
103 EXPECT_EQ(OK, rv); 103 EXPECT_EQ(OK, rv);
104 EXPECT_TRUE(resolver->pending_requests().empty()); 104 EXPECT_TRUE(resolver->pending_requests().empty());
105 EXPECT_TRUE(NULL == service->init_proxy_resolver_log());
106 105
107 EXPECT_TRUE(info.is_direct()); 106 EXPECT_TRUE(info.is_direct());
108 107
109 // Check the LoadLog was filled correctly. 108 // Check the NetLog was filled correctly.
110 EXPECT_EQ(5u, log->entries().size()); 109 EXPECT_EQ(5u, log.entries().size());
111 EXPECT_TRUE(LogContainsBeginEvent(*log, 0, LoadLog::TYPE_PROXY_SERVICE)); 110 EXPECT_TRUE(LogContainsBeginEvent(
112 EXPECT_TRUE(LogContainsEndEvent(*log, 4, LoadLog::TYPE_PROXY_SERVICE)); 111 log.entries(), 0, NetLog::TYPE_PROXY_SERVICE));
112 EXPECT_TRUE(LogContainsEndEvent(
113 log.entries(), 4, NetLog::TYPE_PROXY_SERVICE));
113 } 114 }
114 115
115 TEST(ProxyServiceTest, PAC) { 116 TEST(ProxyServiceTest, PAC) {
116 MockProxyConfigService* config_service = 117 MockProxyConfigService* config_service =
117 new MockProxyConfigService("http://foopy/proxy.pac"); 118 new MockProxyConfigService("http://foopy/proxy.pac");
118 119
119 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 120 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
120 121
121 scoped_refptr<ProxyService> service( 122 scoped_refptr<ProxyService> service(
122 new ProxyService(config_service, resolver, NULL)); 123 new ProxyService(config_service, resolver, NULL));
123 124
124 GURL url("http://www.google.com/"); 125 GURL url("http://www.google.com/");
125 126
126 ProxyInfo info; 127 ProxyInfo info;
127 TestCompletionCallback callback; 128 TestCompletionCallback callback;
128 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); 129 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
129 int rv = service->ResolveProxy(url, &info, &callback, NULL, log); 130
131 int rv = service->ResolveProxy(url, &info, &callback, NULL, log.bound());
130 EXPECT_EQ(ERR_IO_PENDING, rv); 132 EXPECT_EQ(ERR_IO_PENDING, rv);
131 133
132 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 134 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
133 resolver->pending_set_pac_script_request()->pac_url()); 135 resolver->pending_set_pac_script_request()->pac_url());
134 EXPECT_FALSE(NULL == service->init_proxy_resolver_log());
135 resolver->pending_set_pac_script_request()->CompleteNow(OK); 136 resolver->pending_set_pac_script_request()->CompleteNow(OK);
136 137
137 ASSERT_EQ(1u, resolver->pending_requests().size()); 138 ASSERT_EQ(1u, resolver->pending_requests().size());
138 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 139 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
139 140
140 // Set the result in proxy resolver. 141 // Set the result in proxy resolver.
141 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy"); 142 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy");
142 resolver->pending_requests()[0]->CompleteNow(OK); 143 resolver->pending_requests()[0]->CompleteNow(OK);
143 144
144 EXPECT_EQ(OK, callback.WaitForResult()); 145 EXPECT_EQ(OK, callback.WaitForResult());
145 EXPECT_FALSE(info.is_direct()); 146 EXPECT_FALSE(info.is_direct());
146 EXPECT_EQ("foopy:80", info.proxy_server().ToURI()); 147 EXPECT_EQ("foopy:80", info.proxy_server().ToURI());
147 148
148 // Check the LoadLog was filled correctly. 149 // Check the NetLog was filled correctly.
149 EXPECT_EQ(7u, log->entries().size()); 150 EXPECT_EQ(7u, log.entries().size());
150 EXPECT_TRUE(LogContainsBeginEvent(*log, 0, LoadLog::TYPE_PROXY_SERVICE));
151 EXPECT_TRUE(LogContainsBeginEvent( 151 EXPECT_TRUE(LogContainsBeginEvent(
152 *log, 3, LoadLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); 152 log.entries(), 0, NetLog::TYPE_PROXY_SERVICE));
153 EXPECT_TRUE(LogContainsBeginEvent(
154 log.entries(), 3, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC));
153 EXPECT_TRUE(LogContainsEndEvent( 155 EXPECT_TRUE(LogContainsEndEvent(
154 *log, 4, LoadLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); 156 log.entries(), 4, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC));
155 EXPECT_TRUE(LogContainsEndEvent(*log, 6, LoadLog::TYPE_PROXY_SERVICE)); 157 EXPECT_TRUE(LogContainsEndEvent(
158 log.entries(), 6, NetLog::TYPE_PROXY_SERVICE));
156 } 159 }
157 160
158 // Test that the proxy resolver does not see the URL's username/password 161 // Test that the proxy resolver does not see the URL's username/password
159 // or its reference section. 162 // or its reference section.
160 TEST(ProxyServiceTest, PAC_NoIdentityOrHash) { 163 TEST(ProxyServiceTest, PAC_NoIdentityOrHash) {
161 MockProxyConfigService* config_service = 164 MockProxyConfigService* config_service =
162 new MockProxyConfigService("http://foopy/proxy.pac"); 165 new MockProxyConfigService("http://foopy/proxy.pac");
163 166
164 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 167 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
165 168
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 scoped_refptr<ProxyService> service( 1032 scoped_refptr<ProxyService> service(
1030 new ProxyService(config_service, resolver, NULL)); 1033 new ProxyService(config_service, resolver, NULL));
1031 1034
1032 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 1035 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1033 service->SetProxyScriptFetcher(fetcher); 1036 service->SetProxyScriptFetcher(fetcher);
1034 1037
1035 // Start 3 requests. 1038 // Start 3 requests.
1036 ProxyInfo info1; 1039 ProxyInfo info1;
1037 TestCompletionCallback callback1; 1040 TestCompletionCallback callback1;
1038 ProxyService::PacRequest* request1; 1041 ProxyService::PacRequest* request1;
1039 scoped_refptr<LoadLog> log1(new LoadLog(LoadLog::kUnbounded)); 1042 CapturingBoundNetLog log1(CapturingNetLog::kUnbounded);
1040 int rv = service->ResolveProxy( 1043 int rv = service->ResolveProxy(
1041 GURL("http://request1"), &info1, &callback1, &request1, log1); 1044 GURL("http://request1"), &info1, &callback1, &request1, log1.bound());
1042 EXPECT_EQ(ERR_IO_PENDING, rv); 1045 EXPECT_EQ(ERR_IO_PENDING, rv);
1043 1046
1044 // The first request should have triggered download of PAC script. 1047 // The first request should have triggered download of PAC script.
1045 EXPECT_TRUE(fetcher->has_pending_request()); 1048 EXPECT_TRUE(fetcher->has_pending_request());
1046 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 1049 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
1047 1050
1048 ProxyInfo info2; 1051 ProxyInfo info2;
1049 TestCompletionCallback callback2; 1052 TestCompletionCallback callback2;
1050 ProxyService::PacRequest* request2; 1053 ProxyService::PacRequest* request2;
1051 rv = service->ResolveProxy( 1054 rv = service->ResolveProxy(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 resolver->pending_requests()[0]->CompleteNow(OK); 1086 resolver->pending_requests()[0]->CompleteNow(OK);
1084 1087
1085 EXPECT_EQ(OK, callback3.WaitForResult()); 1088 EXPECT_EQ(OK, callback3.WaitForResult());
1086 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); 1089 EXPECT_EQ("request3:80", info3.proxy_server().ToURI());
1087 1090
1088 EXPECT_TRUE(resolver->cancelled_requests().empty()); 1091 EXPECT_TRUE(resolver->cancelled_requests().empty());
1089 1092
1090 EXPECT_FALSE(callback1.have_result()); // Cancelled. 1093 EXPECT_FALSE(callback1.have_result()); // Cancelled.
1091 EXPECT_FALSE(callback2.have_result()); // Cancelled. 1094 EXPECT_FALSE(callback2.have_result()); // Cancelled.
1092 1095
1093 // Check the LoadLog for request 1 (which was cancelled) got filled properly. 1096 // Check the NetLog for request 1 (which was cancelled) got filled properly.
1094 EXPECT_EQ(6u, log1->entries().size()); 1097 EXPECT_EQ(6u, log1.entries().size());
1095 EXPECT_TRUE(LogContainsBeginEvent(*log1, 0, LoadLog::TYPE_PROXY_SERVICE));
1096 EXPECT_TRUE(LogContainsBeginEvent( 1098 EXPECT_TRUE(LogContainsBeginEvent(
1097 *log1, 3, LoadLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); 1099 log1.entries(), 0, NetLog::TYPE_PROXY_SERVICE));
1100 EXPECT_TRUE(LogContainsBeginEvent(
1101 log1.entries(), 3, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC));
1098 // Note that TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC is never completed before 1102 // Note that TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC is never completed before
1099 // the cancellation occured. 1103 // the cancellation occured.
1100 EXPECT_TRUE(LogContainsEvent( 1104 EXPECT_TRUE(LogContainsEvent(
1101 *log1, 4, LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE)); 1105 log1.entries(), 4, NetLog::TYPE_CANCELLED, NetLog::PHASE_NONE));
1102 EXPECT_TRUE(LogContainsEndEvent(*log1, 5, LoadLog::TYPE_PROXY_SERVICE)); 1106 EXPECT_TRUE(LogContainsEndEvent(
1107 log1.entries(), 5, NetLog::TYPE_PROXY_SERVICE));
1103 } 1108 }
1104 1109
1105 // Test that if auto-detect fails, we fall-back to the custom pac. 1110 // Test that if auto-detect fails, we fall-back to the custom pac.
1106 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { 1111 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac) {
1107 ProxyConfig config; 1112 ProxyConfig config;
1108 config.set_auto_detect(true); 1113 config.set_auto_detect(true);
1109 config.set_pac_url(GURL("http://foopy/proxy.pac")); 1114 config.set_pac_url(GURL("http://foopy/proxy.pac"));
1110 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. 1115 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used.
1111 1116
1112 MockProxyConfigService* config_service = new MockProxyConfigService(config); 1117 MockProxyConfigService* config_service = new MockProxyConfigService(config);
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 // Complete the pending second request. 1660 // Complete the pending second request.
1656 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); 1661 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80");
1657 resolver->pending_requests()[0]->CompleteNow(OK); 1662 resolver->pending_requests()[0]->CompleteNow(OK);
1658 1663
1659 // Wait for completion callback, and verify that the request ran as expected. 1664 // Wait for completion callback, and verify that the request ran as expected.
1660 EXPECT_EQ(OK, callback2.WaitForResult()); 1665 EXPECT_EQ(OK, callback2.WaitForResult());
1661 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); 1666 EXPECT_EQ("request2:80", info2.proxy_server().ToURI());
1662 } 1667 }
1663 1668
1664 } // namespace net 1669 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_service.cc ('k') | net/proxy/single_threaded_proxy_resolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698