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

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: And fix more stuff... Created 6 years, 5 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // Starts a request with the given |method| and checks that the response 182 // Starts a request with the given |method| and checks that the response
183 // contains |content| and the the header |header|: |value|, if |header| is 183 // contains |content| and the the header |header|: |value|, if |header| is
184 // non-empty. Verifies that the request's URL chain is the right length 184 // non-empty. Verifies that the request's URL chain is the right length
185 // depending on whether or not a retry was expected (|expected_retry|). 185 // depending on whether or not a retry was expected (|expected_retry|).
186 void ExecuteRequestExpectingContentAndHeader(const std::string& method, 186 void ExecuteRequestExpectingContentAndHeader(const std::string& method,
187 const std::string& content, 187 const std::string& content,
188 const std::string& header, 188 const std::string& header,
189 const std::string& value, 189 const std::string& value,
190 bool expected_retry) { 190 bool expected_retry) {
191 TestDelegate d; 191 TestDelegate d;
192 URLRequest r(GURL("http://www.google.com/"), 192 scoped_ptr<URLRequest> r(context_->CreateRequest(
193 net::DEFAULT_PRIORITY, 193 GURL("http://www.google.com/"),
194 &d, 194 net::DEFAULT_PRIORITY,
195 context_.get()); 195 &d,
196 r.set_method(method); 196 NULL));
197 r.SetLoadFlags(net::LOAD_NORMAL); 197 r->set_method(method);
198 r->SetLoadFlags(net::LOAD_NORMAL);
198 199
199 r.Start(); 200 r->Start();
200 base::RunLoop().Run(); 201 base::RunLoop().Run();
201 202
202 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r.status().status()); 203 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r->status().status());
203 EXPECT_EQ(net::OK, r.status().error()); 204 EXPECT_EQ(net::OK, r->status().error());
204 if (expected_retry) 205 if (expected_retry)
205 EXPECT_EQ(2U, r.url_chain().size()); 206 EXPECT_EQ(2U, r->url_chain().size());
206 else 207 else
207 EXPECT_EQ(1U, r.url_chain().size()); 208 EXPECT_EQ(1U, r->url_chain().size());
208 209
209 if (!header.empty()) { 210 if (!header.empty()) {
210 // We also have a server header here that isn't set by the proxy. 211 // We also have a server header here that isn't set by the proxy.
211 EXPECT_TRUE(r.response_headers()->HasHeaderValue(header, value)); 212 EXPECT_TRUE(r->response_headers()->HasHeaderValue(header, value));
212 } 213 }
213 214
214 EXPECT_EQ(content, d.data_received()); 215 EXPECT_EQ(content, d.data_received());
215 } 216 }
216 217
217 // Returns the key to the |ProxyRetryInfoMap|. 218 // Returns the key to the |ProxyRetryInfoMap|.
218 std::string GetProxyKey(std::string proxy) { 219 std::string GetProxyKey(std::string proxy) {
219 GURL gurl(proxy); 220 GURL gurl(proxy);
220 std::string host_port = HostPortPair::FromURL(GURL(proxy)).ToString(); 221 std::string host_port = HostPortPair::FromURL(GURL(proxy)).ToString();
221 if (gurl.SchemeIs("https")) 222 if (gurl.SchemeIs("https"))
(...skipping 10 matching lines...) Expand all
232 const std::string& bad_proxy, 233 const std::string& bad_proxy,
233 const std::string& bad_proxy2) { 234 const std::string& bad_proxy2) {
234 const ProxyRetryInfoMap& retry_info = proxy_service_->proxy_retry_info(); 235 const ProxyRetryInfoMap& retry_info = proxy_service_->proxy_retry_info();
235 ASSERT_EQ(expected_num_bad_proxies, retry_info.size()); 236 ASSERT_EQ(expected_num_bad_proxies, retry_info.size());
236 237
237 base::TimeDelta expected_min_duration; 238 base::TimeDelta expected_min_duration;
238 base::TimeDelta expected_max_duration; 239 base::TimeDelta expected_max_duration;
239 if (duration_seconds == 0) { 240 if (duration_seconds == 0) {
240 expected_min_duration = base::TimeDelta::FromMinutes(1); 241 expected_min_duration = base::TimeDelta::FromMinutes(1);
241 expected_max_duration = base::TimeDelta::FromMinutes(5); 242 expected_max_duration = base::TimeDelta::FromMinutes(5);
242 } 243 } else {
243 else {
244 expected_min_duration = base::TimeDelta::FromSeconds(duration_seconds); 244 expected_min_duration = base::TimeDelta::FromSeconds(duration_seconds);
245 expected_max_duration = base::TimeDelta::FromSeconds(duration_seconds); 245 expected_max_duration = base::TimeDelta::FromSeconds(duration_seconds);
246 } 246 }
247 247
248 if (expected_num_bad_proxies >= 1u) { 248 if (expected_num_bad_proxies >= 1u) {
249 ProxyRetryInfoMap::const_iterator i = 249 ProxyRetryInfoMap::const_iterator i =
250 retry_info.find(GetProxyKey(bad_proxy)); 250 retry_info.find(GetProxyKey(bad_proxy));
251 ASSERT_TRUE(i != retry_info.end()); 251 ASSERT_TRUE(i != retry_info.end());
252 EXPECT_TRUE(expected_min_duration <= (*i).second.current_delay); 252 EXPECT_TRUE(expected_min_duration <= (*i).second.current_delay);
253 EXPECT_TRUE((*i).second.current_delay <= expected_max_duration); 253 EXPECT_TRUE((*i).second.current_delay <= expected_max_duration);
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 "Host: www.google.com\r\n" 588 "Host: www.google.com\r\n"
589 "Connection: keep-alive\r\n" 589 "Connection: keep-alive\r\n"
590 "User-Agent:\r\n" 590 "User-Agent:\r\n"
591 "Accept-Encoding: gzip,deflate\r\n\r\n"), 591 "Accept-Encoding: gzip,deflate\r\n\r\n"),
592 }; 592 };
593 StaticSocketDataProvider data1(data_reads, arraysize(data_reads), 593 StaticSocketDataProvider data1(data_reads, arraysize(data_reads),
594 data_writes, arraysize(data_writes)); 594 data_writes, arraysize(data_writes));
595 mock_socket_factory_.AddSocketDataProvider(&data1); 595 mock_socket_factory_.AddSocketDataProvider(&data1);
596 596
597 TestDelegate d; 597 TestDelegate d;
598 URLRequest r(GURL("http://www.google.com/"), 598 scoped_ptr<URLRequest> r(context_->CreateRequest(
599 net::DEFAULT_PRIORITY, 599 GURL("http://www.google.com/"),
600 &d, 600 net::DEFAULT_PRIORITY,
601 context_.get()); 601 &d,
602 r.set_method("GET"); 602 NULL));
603 r.SetLoadFlags(net::LOAD_NORMAL); 603 r->set_method("GET");
604 r->SetLoadFlags(net::LOAD_NORMAL);
604 605
605 r.Start(); 606 r->Start();
606 base::RunLoop().Run(); 607 base::RunLoop().Run();
607 608
608 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r.status().status()); 609 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r->status().status());
609 EXPECT_EQ(net::OK, r.status().error()); 610 EXPECT_EQ(net::OK, r->status().error());
610 611
611 EXPECT_EQ("Bypass message", d.data_received()); 612 EXPECT_EQ("Bypass message", d.data_received());
612 613
613 // We should have no entries in our bad proxy list. 614 // We should have no entries in our bad proxy list.
614 TestBadProxies(0, -1, "", ""); 615 TestBadProxies(0, -1, "", "");
615 } 616 }
616 617
617 class BadEntropyProvider : public base::FieldTrial::EntropyProvider { 618 class BadEntropyProvider : public base::FieldTrial::EntropyProvider {
618 public: 619 public:
619 virtual ~BadEntropyProvider() {} 620 virtual ~BadEntropyProvider() {}
(...skipping 25 matching lines...) Expand all
645 // Other proxy 646 // Other proxy
646 net::ProxyInfo info2; 647 net::ProxyInfo info2;
647 info2.UseNamedProxy("proxy.com"); 648 info2.UseNamedProxy("proxy.com");
648 EXPECT_FALSE(info2.is_empty()); 649 EXPECT_FALSE(info2.is_empty());
649 650
650 // Without DataCompressionProxyCriticalBypass Finch trial set, should never 651 // Without DataCompressionProxyCriticalBypass Finch trial set, should never
651 // bypass. 652 // bypass.
652 OnResolveProxyHandler(url, load_flags, &test_params, &info1); 653 OnResolveProxyHandler(url, load_flags, &test_params, &info1);
653 EXPECT_FALSE(info1.is_direct()); 654 EXPECT_FALSE(info1.is_direct());
654 655
655 OnResolveProxyHandler(url, load_flags, &test_params,&info2); 656 OnResolveProxyHandler(url, load_flags, &test_params, &info2);
656 EXPECT_FALSE(info2.is_direct()); 657 EXPECT_FALSE(info2.is_direct());
657 658
658 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; 659 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY;
659 660
660 OnResolveProxyHandler(url, load_flags, &test_params, &info1); 661 OnResolveProxyHandler(url, load_flags, &test_params, &info1);
661 EXPECT_FALSE(info1.is_direct()); 662 EXPECT_FALSE(info1.is_direct());
662 663
663 OnResolveProxyHandler(url, load_flags, &test_params, &info2); 664 OnResolveProxyHandler(url, load_flags, &test_params, &info2);
664 EXPECT_FALSE(info2.is_direct()); 665 EXPECT_FALSE(info2.is_direct());
665 666
(...skipping 18 matching lines...) Expand all
684 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; 685 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY;
685 686
686 OnResolveProxyHandler(url, load_flags, &test_params, &info2); 687 OnResolveProxyHandler(url, load_flags, &test_params, &info2);
687 EXPECT_FALSE(info2.is_direct()); 688 EXPECT_FALSE(info2.is_direct());
688 689
689 OnResolveProxyHandler(url, load_flags, &test_params, &info1); 690 OnResolveProxyHandler(url, load_flags, &test_params, &info1);
690 EXPECT_TRUE(info1.is_direct()); 691 EXPECT_TRUE(info1.is_direct());
691 } 692 }
692 693
693 } // namespace data_reduction_proxy 694 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698