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

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_protocol_unittest.cc

Issue 407093011: Allow URLRequests from one context to have different NetworkDelegates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mojo Created 6 years, 4 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
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 "components/data_reduction_proxy/browser/data_reduction_proxy_protocol. h" 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol. h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // Starts a request with the given |method| and checks that the response 190 // Starts a request with the given |method| and checks that the response
191 // contains |content| and the the header |header|: |value|, if |header| is 191 // contains |content| and the the header |header|: |value|, if |header| is
192 // non-empty. Verifies that the request's URL chain is the right length 192 // non-empty. Verifies that the request's URL chain is the right length
193 // depending on whether or not a retry was expected (|expected_retry|). 193 // depending on whether or not a retry was expected (|expected_retry|).
194 void ExecuteRequestExpectingContentAndHeader(const std::string& method, 194 void ExecuteRequestExpectingContentAndHeader(const std::string& method,
195 const std::string& content, 195 const std::string& content,
196 const std::string& header, 196 const std::string& header,
197 const std::string& value, 197 const std::string& value,
198 bool expected_retry) { 198 bool expected_retry) {
199 TestDelegate d; 199 TestDelegate d;
200 URLRequest r(GURL("http://www.google.com/"), 200 scoped_ptr<URLRequest> r(context_->CreateRequest(
201 net::DEFAULT_PRIORITY, 201 GURL("http://www.google.com/"),
202 &d, 202 net::DEFAULT_PRIORITY,
203 context_.get()); 203 &d,
204 r.set_method(method); 204 NULL));
205 r.SetLoadFlags(net::LOAD_NORMAL); 205 r->set_method(method);
206 r->SetLoadFlags(net::LOAD_NORMAL);
206 207
207 r.Start(); 208 r->Start();
208 base::RunLoop().Run(); 209 base::RunLoop().Run();
209 210
210 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r.status().status()); 211 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r->status().status());
211 EXPECT_EQ(net::OK, r.status().error()); 212 EXPECT_EQ(net::OK, r->status().error());
212 if (expected_retry) 213 if (expected_retry)
213 EXPECT_EQ(2U, r.url_chain().size()); 214 EXPECT_EQ(2U, r->url_chain().size());
214 else 215 else
215 EXPECT_EQ(1U, r.url_chain().size()); 216 EXPECT_EQ(1U, r->url_chain().size());
216 217
217 if (!header.empty()) { 218 if (!header.empty()) {
218 // We also have a server header here that isn't set by the proxy. 219 // We also have a server header here that isn't set by the proxy.
219 EXPECT_TRUE(r.response_headers()->HasHeaderValue(header, value)); 220 EXPECT_TRUE(r->response_headers()->HasHeaderValue(header, value));
220 } 221 }
221 222
222 EXPECT_EQ(content, d.data_received()); 223 EXPECT_EQ(content, d.data_received());
223 } 224 }
224 225
225 // Returns the key to the |ProxyRetryInfoMap|. 226 // Returns the key to the |ProxyRetryInfoMap|.
226 std::string GetProxyKey(std::string proxy) { 227 std::string GetProxyKey(std::string proxy) {
227 GURL gurl(proxy); 228 GURL gurl(proxy);
228 std::string host_port = HostPortPair::FromURL(GURL(proxy)).ToString(); 229 std::string host_port = HostPortPair::FromURL(GURL(proxy)).ToString();
229 if (gurl.SchemeIs("https")) 230 if (gurl.SchemeIs("https"))
(...skipping 10 matching lines...) Expand all
240 const std::string& bad_proxy, 241 const std::string& bad_proxy,
241 const std::string& bad_proxy2) { 242 const std::string& bad_proxy2) {
242 const ProxyRetryInfoMap& retry_info = proxy_service_->proxy_retry_info(); 243 const ProxyRetryInfoMap& retry_info = proxy_service_->proxy_retry_info();
243 ASSERT_EQ(expected_num_bad_proxies, retry_info.size()); 244 ASSERT_EQ(expected_num_bad_proxies, retry_info.size());
244 245
245 base::TimeDelta expected_min_duration; 246 base::TimeDelta expected_min_duration;
246 base::TimeDelta expected_max_duration; 247 base::TimeDelta expected_max_duration;
247 if (duration_seconds == 0) { 248 if (duration_seconds == 0) {
248 expected_min_duration = base::TimeDelta::FromMinutes(1); 249 expected_min_duration = base::TimeDelta::FromMinutes(1);
249 expected_max_duration = base::TimeDelta::FromMinutes(5); 250 expected_max_duration = base::TimeDelta::FromMinutes(5);
250 } 251 } else {
251 else {
252 expected_min_duration = base::TimeDelta::FromSeconds(duration_seconds); 252 expected_min_duration = base::TimeDelta::FromSeconds(duration_seconds);
253 expected_max_duration = base::TimeDelta::FromSeconds(duration_seconds); 253 expected_max_duration = base::TimeDelta::FromSeconds(duration_seconds);
254 } 254 }
255 255
256 if (expected_num_bad_proxies >= 1u) { 256 if (expected_num_bad_proxies >= 1u) {
257 ProxyRetryInfoMap::const_iterator i = 257 ProxyRetryInfoMap::const_iterator i =
258 retry_info.find(GetProxyKey(bad_proxy)); 258 retry_info.find(GetProxyKey(bad_proxy));
259 ASSERT_TRUE(i != retry_info.end()); 259 ASSERT_TRUE(i != retry_info.end());
260 EXPECT_TRUE(expected_min_duration <= (*i).second.current_delay); 260 EXPECT_TRUE(expected_min_duration <= (*i).second.current_delay);
261 EXPECT_TRUE((*i).second.current_delay <= expected_max_duration); 261 EXPECT_TRUE((*i).second.current_delay <= expected_max_duration);
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 "Host: www.google.com\r\n" 620 "Host: www.google.com\r\n"
621 "Connection: keep-alive\r\n" 621 "Connection: keep-alive\r\n"
622 "User-Agent:\r\n" 622 "User-Agent:\r\n"
623 "Accept-Encoding: gzip,deflate\r\n\r\n"), 623 "Accept-Encoding: gzip,deflate\r\n\r\n"),
624 }; 624 };
625 StaticSocketDataProvider data1(data_reads, arraysize(data_reads), 625 StaticSocketDataProvider data1(data_reads, arraysize(data_reads),
626 data_writes, arraysize(data_writes)); 626 data_writes, arraysize(data_writes));
627 mock_socket_factory_.AddSocketDataProvider(&data1); 627 mock_socket_factory_.AddSocketDataProvider(&data1);
628 628
629 TestDelegate d; 629 TestDelegate d;
630 URLRequest r(GURL("http://www.google.com/"), 630 scoped_ptr<URLRequest> r(context_->CreateRequest(
631 net::DEFAULT_PRIORITY, 631 GURL("http://www.google.com/"),
632 &d, 632 net::DEFAULT_PRIORITY,
633 context_.get()); 633 &d,
634 r.set_method("GET"); 634 NULL));
635 r.SetLoadFlags(net::LOAD_NORMAL); 635 r->set_method("GET");
636 r->SetLoadFlags(net::LOAD_NORMAL);
636 637
637 r.Start(); 638 r->Start();
638 base::RunLoop().Run(); 639 base::RunLoop().Run();
639 640
640 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r.status().status()); 641 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r->status().status());
641 EXPECT_EQ(net::OK, r.status().error()); 642 EXPECT_EQ(net::OK, r->status().error());
642 643
643 EXPECT_EQ("Bypass message", d.data_received()); 644 EXPECT_EQ("Bypass message", d.data_received());
644 645
645 // We should have no entries in our bad proxy list. 646 // We should have no entries in our bad proxy list.
646 TestBadProxies(0, -1, "", ""); 647 TestBadProxies(0, -1, "", "");
647 } 648 }
648 649
649 class BadEntropyProvider : public base::FieldTrial::EntropyProvider { 650 class BadEntropyProvider : public base::FieldTrial::EntropyProvider {
650 public: 651 public:
651 virtual ~BadEntropyProvider() {} 652 virtual ~BadEntropyProvider() {}
(...skipping 25 matching lines...) Expand all
677 // Other proxy 678 // Other proxy
678 net::ProxyInfo info2; 679 net::ProxyInfo info2;
679 info2.UseNamedProxy("proxy.com"); 680 info2.UseNamedProxy("proxy.com");
680 EXPECT_FALSE(info2.is_empty()); 681 EXPECT_FALSE(info2.is_empty());
681 682
682 // Without DataCompressionProxyCriticalBypass Finch trial set, should never 683 // Without DataCompressionProxyCriticalBypass Finch trial set, should never
683 // bypass. 684 // bypass.
684 OnResolveProxyHandler(url, load_flags, &test_params, &info1); 685 OnResolveProxyHandler(url, load_flags, &test_params, &info1);
685 EXPECT_FALSE(info1.is_direct()); 686 EXPECT_FALSE(info1.is_direct());
686 687
687 OnResolveProxyHandler(url, load_flags, &test_params,&info2); 688 OnResolveProxyHandler(url, load_flags, &test_params, &info2);
688 EXPECT_FALSE(info2.is_direct()); 689 EXPECT_FALSE(info2.is_direct());
689 690
690 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; 691 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY;
691 692
692 OnResolveProxyHandler(url, load_flags, &test_params, &info1); 693 OnResolveProxyHandler(url, load_flags, &test_params, &info1);
693 EXPECT_FALSE(info1.is_direct()); 694 EXPECT_FALSE(info1.is_direct());
694 695
695 OnResolveProxyHandler(url, load_flags, &test_params, &info2); 696 OnResolveProxyHandler(url, load_flags, &test_params, &info2);
696 EXPECT_FALSE(info2.is_direct()); 697 EXPECT_FALSE(info2.is_direct());
697 698
(...skipping 18 matching lines...) Expand all
716 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; 717 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY;
717 718
718 OnResolveProxyHandler(url, load_flags, &test_params, &info2); 719 OnResolveProxyHandler(url, load_flags, &test_params, &info2);
719 EXPECT_FALSE(info2.is_direct()); 720 EXPECT_FALSE(info2.is_direct());
720 721
721 OnResolveProxyHandler(url, load_flags, &test_params, &info1); 722 OnResolveProxyHandler(url, load_flags, &test_params, &info1);
722 EXPECT_TRUE(info1.is_direct()); 723 EXPECT_TRUE(info1.is_direct());
723 } 724 }
724 725
725 } // namespace data_reduction_proxy 726 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698