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

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: 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
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" 23 #include "net/proxy/proxy_service.h"
bengr 2016/02/08 23:23:30 You don't need this anymore.
RyanSturm 2016/02/09 00:46:03 Done.
24 #include "net/url_request/url_request.h" 24 #include "net/url_request/url_request.h"
25 #include "net/url_request/url_request_test_util.h" 25 #include "net/url_request/url_request_test_util.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "url/gurl.h" 27 #include "url/gurl.h"
28 28
29 namespace net { 29 namespace net {
30 namespace { 30 namespace {
31 31
32 typedef std::map<const char*, int> CountersMap; 32 typedef std::map<const char*, int> CountersMap;
33 33
34 class TestNetworkDelegateImpl : public NetworkDelegateImpl { 34 class TestNetworkDelegateImpl : public NetworkDelegateImpl {
35 public: 35 public:
36 TestNetworkDelegateImpl(CountersMap* layered_network_delegate_counters) 36 TestNetworkDelegateImpl(CountersMap* layered_network_delegate_counters)
37 : layered_network_delegate_counters_(layered_network_delegate_counters) {} 37 : layered_network_delegate_counters_(layered_network_delegate_counters) {}
38 38
39 ~TestNetworkDelegateImpl() override {} 39 ~TestNetworkDelegateImpl() override {}
40 40
41 // NetworkDelegateImpl implementation: 41 // NetworkDelegateImpl implementation:
42 int OnBeforeURLRequest(URLRequest* request, 42 int OnBeforeURLRequest(URLRequest* request,
43 const CompletionCallback& callback, 43 const CompletionCallback& callback,
44 GURL* new_url) override { 44 GURL* new_url) override {
45 IncrementAndCompareCounter("on_before_url_request_count"); 45 IncrementAndCompareCounter("on_before_url_request_count");
46 return OK; 46 return OK;
47 } 47 }
48 48
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, 49 int OnBeforeSendHeaders(URLRequest* request,
61 const CompletionCallback& callback, 50 const CompletionCallback& callback,
62 HttpRequestHeaders* headers) override { 51 HttpRequestHeaders* headers) override {
63 IncrementAndCompareCounter("on_before_send_headers_count"); 52 IncrementAndCompareCounter("on_before_send_headers_count");
64 return OK; 53 return OK;
65 } 54 }
66 55
67 void OnBeforeSendProxyHeaders(URLRequest* request, 56 void OnBeforeSendProxyHeaders(URLRequest* request,
68 const ProxyInfo& proxy_info, 57 const ProxyInfo& proxy_info,
69 HttpRequestHeaders* headers) override { 58 HttpRequestHeaders* headers) override {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 ~TestLayeredNetworkDelegate() override {} 173 ~TestLayeredNetworkDelegate() override {}
185 174
186 void CallAndVerify() { 175 void CallAndVerify() {
187 scoped_refptr<AuthChallengeInfo> auth_challenge(new AuthChallengeInfo()); 176 scoped_refptr<AuthChallengeInfo> auth_challenge(new AuthChallengeInfo());
188 scoped_ptr<URLRequest> request = 177 scoped_ptr<URLRequest> request =
189 context_.CreateRequest(GURL(), IDLE, &delegate_); 178 context_.CreateRequest(GURL(), IDLE, &delegate_);
190 scoped_ptr<HttpRequestHeaders> request_headers(new HttpRequestHeaders()); 179 scoped_ptr<HttpRequestHeaders> request_headers(new HttpRequestHeaders());
191 scoped_refptr<HttpResponseHeaders> response_headers( 180 scoped_refptr<HttpResponseHeaders> response_headers(
192 new HttpResponseHeaders("")); 181 new HttpResponseHeaders(""));
193 TestCompletionCallback completion_callback; 182 TestCompletionCallback completion_callback;
194 scoped_ptr<ProxyService> proxy_service(ProxyService::CreateDirect());
195 scoped_ptr<ProxyInfo> proxy_info(new ProxyInfo());
196 183
197 EXPECT_EQ(OK, OnBeforeURLRequest(request.get(), 184 EXPECT_EQ(OK, OnBeforeURLRequest(request.get(),
198 completion_callback.callback(), NULL)); 185 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(), 186 EXPECT_EQ(OK, OnBeforeSendHeaders(NULL, completion_callback.callback(),
202 request_headers.get())); 187 request_headers.get()));
203 OnBeforeSendProxyHeaders(NULL, ProxyInfo(), request_headers.get()); 188 OnBeforeSendProxyHeaders(NULL, ProxyInfo(), request_headers.get());
204 OnSendHeaders(NULL, *request_headers); 189 OnSendHeaders(NULL, *request_headers);
205 OnNetworkBytesSent(request.get(), 42); 190 OnNetworkBytesSent(request.get(), 42);
206 EXPECT_EQ(OK, OnHeadersReceived(NULL, completion_callback.callback(), 191 EXPECT_EQ(OK, OnHeadersReceived(NULL, completion_callback.callback(),
207 response_headers.get(), NULL, NULL)); 192 response_headers.get(), NULL, NULL));
208 OnResponseStarted(request.get()); 193 OnResponseStarted(request.get());
209 OnNetworkBytesReceived(request.get(), 42); 194 OnNetworkBytesReceived(request.get(), 42);
210 OnCompleted(request.get(), false); 195 OnCompleted(request.get(), false);
(...skipping 11 matching lines...) Expand all
222 } 207 }
223 208
224 protected: 209 protected:
225 void OnBeforeURLRequestInternal(URLRequest* request, 210 void OnBeforeURLRequestInternal(URLRequest* request,
226 const CompletionCallback& callback, 211 const CompletionCallback& callback,
227 GURL* new_url) override { 212 GURL* new_url) override {
228 ++(*counters_)["on_before_url_request_count"]; 213 ++(*counters_)["on_before_url_request_count"];
229 EXPECT_EQ(1, (*counters_)["on_before_url_request_count"]); 214 EXPECT_EQ(1, (*counters_)["on_before_url_request_count"]);
230 } 215 }
231 216
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, 217 void OnBeforeSendHeadersInternal(URLRequest* request,
247 const CompletionCallback& callback, 218 const CompletionCallback& callback,
248 HttpRequestHeaders* headers) override { 219 HttpRequestHeaders* headers) override {
249 ++(*counters_)["on_before_send_headers_count"]; 220 ++(*counters_)["on_before_send_headers_count"];
250 EXPECT_EQ(1, (*counters_)["on_before_send_headers_count"]); 221 EXPECT_EQ(1, (*counters_)["on_before_send_headers_count"]);
251 } 222 }
252 223
253 void OnBeforeSendProxyHeadersInternal(URLRequest* request, 224 void OnBeforeSendProxyHeadersInternal(URLRequest* request,
254 const ProxyInfo& proxy_info, 225 const ProxyInfo& proxy_info,
255 HttpRequestHeaders* headers) override { 226 HttpRequestHeaders* headers) override {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 CountersMap layered_network_delegate_counters; 353 CountersMap layered_network_delegate_counters;
383 TestNetworkDelegateImpl* test_network_delegate_; 354 TestNetworkDelegateImpl* test_network_delegate_;
384 scoped_ptr<TestLayeredNetworkDelegate> layered_network_delegate_; 355 scoped_ptr<TestLayeredNetworkDelegate> layered_network_delegate_;
385 }; 356 };
386 357
387 TEST_F(LayeredNetworkDelegateTest, VerifyLayeredNetworkDelegateInternal) { 358 TEST_F(LayeredNetworkDelegateTest, VerifyLayeredNetworkDelegateInternal) {
388 layered_network_delegate_->CallAndVerify(); 359 layered_network_delegate_->CallAndVerify();
389 } 360 }
390 361
391 } // namespace net 362 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698