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

Side by Side Diff: net/base/layered_network_delegate_unittest.cc

Issue 1680893002: Moving proxy resolution logic out of NetworkDelegate and into ProxyDelegate for DataReductionProxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 10 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
« no previous file with comments | « net/base/layered_network_delegate.cc ('k') | net/base/network_delegate.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/base/layered_network_delegate.h" 5 #include "net/base/layered_network_delegate.h"
6 6
7 #include <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "net/base/auth.h" 15 #include "net/base/auth.h"
16 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
17 #include "net/base/network_delegate_impl.h" 17 #include "net/base/network_delegate_impl.h"
18 #include "net/base/request_priority.h" 18 #include "net/base/request_priority.h"
19 #include "net/base/test_completion_callback.h" 19 #include "net/base/test_completion_callback.h"
20 #include "net/http/http_response_headers.h" 20 #include "net/http/http_response_headers.h"
21 #include "net/proxy/proxy_config_service.h" 21 #include "net/proxy/proxy_config_service.h"
22 #include "net/proxy/proxy_info.h" 22 #include "net/proxy/proxy_info.h"
23 #include "net/proxy/proxy_service.h"
24 #include "net/url_request/url_request.h" 23 #include "net/url_request/url_request.h"
25 #include "net/url_request/url_request_test_util.h" 24 #include "net/url_request/url_request_test_util.h"
26 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
27 #include "url/gurl.h" 26 #include "url/gurl.h"
28 27
29 namespace net { 28 namespace net {
30 namespace { 29 namespace {
31 30
32 typedef std::map<const char*, int> CountersMap; 31 typedef std::map<const char*, int> CountersMap;
33 32
34 class TestNetworkDelegateImpl : public NetworkDelegateImpl { 33 class TestNetworkDelegateImpl : public NetworkDelegateImpl {
35 public: 34 public:
36 TestNetworkDelegateImpl(CountersMap* layered_network_delegate_counters) 35 TestNetworkDelegateImpl(CountersMap* layered_network_delegate_counters)
37 : layered_network_delegate_counters_(layered_network_delegate_counters) {} 36 : layered_network_delegate_counters_(layered_network_delegate_counters) {}
38 37
39 ~TestNetworkDelegateImpl() override {} 38 ~TestNetworkDelegateImpl() override {}
40 39
41 // NetworkDelegateImpl implementation: 40 // NetworkDelegateImpl implementation:
42 int OnBeforeURLRequest(URLRequest* request, 41 int OnBeforeURLRequest(URLRequest* request,
43 const CompletionCallback& callback, 42 const CompletionCallback& callback,
44 GURL* new_url) override { 43 GURL* new_url) override {
45 IncrementAndCompareCounter("on_before_url_request_count"); 44 IncrementAndCompareCounter("on_before_url_request_count");
46 return OK; 45 return OK;
47 } 46 }
48 47
49 void OnResolveProxy(const GURL& url,
50 int load_flags,
51 const ProxyService& proxy_service,
52 ProxyInfo* result) override {
53 IncrementAndCompareCounter("on_resolve_proxy_count");
54 }
55
56 void OnProxyFallback(const ProxyServer& bad_proxy, int net_error) override {
57 IncrementAndCompareCounter("on_proxy_fallback_count");
58 }
59
60 int OnBeforeSendHeaders(URLRequest* request, 48 int OnBeforeSendHeaders(URLRequest* request,
61 const CompletionCallback& callback, 49 const CompletionCallback& callback,
62 HttpRequestHeaders* headers) override { 50 HttpRequestHeaders* headers) override {
63 IncrementAndCompareCounter("on_before_send_headers_count"); 51 IncrementAndCompareCounter("on_before_send_headers_count");
64 return OK; 52 return OK;
65 } 53 }
66 54
67 void OnBeforeSendProxyHeaders(URLRequest* request, 55 void OnBeforeSendProxyHeaders(URLRequest* request,
68 const ProxyInfo& proxy_info, 56 const ProxyInfo& proxy_info,
69 HttpRequestHeaders* headers) override { 57 HttpRequestHeaders* headers) override {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 ~TestLayeredNetworkDelegate() override {} 172 ~TestLayeredNetworkDelegate() override {}
185 173
186 void CallAndVerify() { 174 void CallAndVerify() {
187 scoped_refptr<AuthChallengeInfo> auth_challenge(new AuthChallengeInfo()); 175 scoped_refptr<AuthChallengeInfo> auth_challenge(new AuthChallengeInfo());
188 scoped_ptr<URLRequest> request = 176 scoped_ptr<URLRequest> request =
189 context_.CreateRequest(GURL(), IDLE, &delegate_); 177 context_.CreateRequest(GURL(), IDLE, &delegate_);
190 scoped_ptr<HttpRequestHeaders> request_headers(new HttpRequestHeaders()); 178 scoped_ptr<HttpRequestHeaders> request_headers(new HttpRequestHeaders());
191 scoped_refptr<HttpResponseHeaders> response_headers( 179 scoped_refptr<HttpResponseHeaders> response_headers(
192 new HttpResponseHeaders("")); 180 new HttpResponseHeaders(""));
193 TestCompletionCallback completion_callback; 181 TestCompletionCallback completion_callback;
194 scoped_ptr<ProxyService> proxy_service(ProxyService::CreateDirect());
195 scoped_ptr<ProxyInfo> proxy_info(new ProxyInfo());
196 182
197 EXPECT_EQ(OK, OnBeforeURLRequest(request.get(), 183 EXPECT_EQ(OK, OnBeforeURLRequest(request.get(),
198 completion_callback.callback(), NULL)); 184 completion_callback.callback(), NULL));
199 OnResolveProxy(GURL(), 0, *proxy_service, proxy_info.get());
200 OnProxyFallback(ProxyServer(), 0);
201 EXPECT_EQ(OK, OnBeforeSendHeaders(NULL, completion_callback.callback(), 185 EXPECT_EQ(OK, OnBeforeSendHeaders(NULL, completion_callback.callback(),
202 request_headers.get())); 186 request_headers.get()));
203 OnBeforeSendProxyHeaders(NULL, ProxyInfo(), request_headers.get()); 187 OnBeforeSendProxyHeaders(NULL, ProxyInfo(), request_headers.get());
204 OnSendHeaders(NULL, *request_headers); 188 OnSendHeaders(NULL, *request_headers);
205 OnNetworkBytesSent(request.get(), 42); 189 OnNetworkBytesSent(request.get(), 42);
206 EXPECT_EQ(OK, OnHeadersReceived(NULL, completion_callback.callback(), 190 EXPECT_EQ(OK, OnHeadersReceived(NULL, completion_callback.callback(),
207 response_headers.get(), NULL, NULL)); 191 response_headers.get(), NULL, NULL));
208 OnResponseStarted(request.get()); 192 OnResponseStarted(request.get());
209 OnNetworkBytesReceived(request.get(), 42); 193 OnNetworkBytesReceived(request.get(), 42);
210 OnCompleted(request.get(), false); 194 OnCompleted(request.get(), false);
(...skipping 11 matching lines...) Expand all
222 } 206 }
223 207
224 protected: 208 protected:
225 void OnBeforeURLRequestInternal(URLRequest* request, 209 void OnBeforeURLRequestInternal(URLRequest* request,
226 const CompletionCallback& callback, 210 const CompletionCallback& callback,
227 GURL* new_url) override { 211 GURL* new_url) override {
228 ++(*counters_)["on_before_url_request_count"]; 212 ++(*counters_)["on_before_url_request_count"];
229 EXPECT_EQ(1, (*counters_)["on_before_url_request_count"]); 213 EXPECT_EQ(1, (*counters_)["on_before_url_request_count"]);
230 } 214 }
231 215
232 void OnResolveProxyInternal(const GURL& url,
233 int load_flags,
234 const ProxyService& proxy_service,
235 ProxyInfo* result) override {
236 ++(*counters_)["on_resolve_proxy_count"];
237 EXPECT_EQ(1, (*counters_)["on_resolve_proxy_count"]);
238 }
239
240 void OnProxyFallbackInternal(const ProxyServer& bad_proxy,
241 int net_error) override {
242 ++(*counters_)["on_proxy_fallback_count"];
243 EXPECT_EQ(1, (*counters_)["on_proxy_fallback_count"]);
244 }
245
246 void OnBeforeSendHeadersInternal(URLRequest* request, 216 void OnBeforeSendHeadersInternal(URLRequest* request,
247 const CompletionCallback& callback, 217 const CompletionCallback& callback,
248 HttpRequestHeaders* headers) override { 218 HttpRequestHeaders* headers) override {
249 ++(*counters_)["on_before_send_headers_count"]; 219 ++(*counters_)["on_before_send_headers_count"];
250 EXPECT_EQ(1, (*counters_)["on_before_send_headers_count"]); 220 EXPECT_EQ(1, (*counters_)["on_before_send_headers_count"]);
251 } 221 }
252 222
253 void OnBeforeSendProxyHeadersInternal(URLRequest* request, 223 void OnBeforeSendProxyHeadersInternal(URLRequest* request,
254 const ProxyInfo& proxy_info, 224 const ProxyInfo& proxy_info,
255 HttpRequestHeaders* headers) override { 225 HttpRequestHeaders* headers) override {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 CountersMap layered_network_delegate_counters; 352 CountersMap layered_network_delegate_counters;
383 TestNetworkDelegateImpl* test_network_delegate_; 353 TestNetworkDelegateImpl* test_network_delegate_;
384 scoped_ptr<TestLayeredNetworkDelegate> layered_network_delegate_; 354 scoped_ptr<TestLayeredNetworkDelegate> layered_network_delegate_;
385 }; 355 };
386 356
387 TEST_F(LayeredNetworkDelegateTest, VerifyLayeredNetworkDelegateInternal) { 357 TEST_F(LayeredNetworkDelegateTest, VerifyLayeredNetworkDelegateInternal) {
388 layered_network_delegate_->CallAndVerify(); 358 layered_network_delegate_->CallAndVerify();
389 } 359 }
390 360
391 } // namespace net 361 } // namespace net
OLDNEW
« no previous file with comments | « net/base/layered_network_delegate.cc ('k') | net/base/network_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698