OLD | NEW |
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 Loading... |
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 Loading... |
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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 "Host: www.google.com\r\n" | 746 "Host: www.google.com\r\n" |
747 "Connection: keep-alive\r\n" | 747 "Connection: keep-alive\r\n" |
748 "User-Agent:\r\n" | 748 "User-Agent:\r\n" |
749 "Accept-Encoding: gzip,deflate\r\n\r\n"), | 749 "Accept-Encoding: gzip,deflate\r\n\r\n"), |
750 }; | 750 }; |
751 StaticSocketDataProvider data1(data_reads, arraysize(data_reads), | 751 StaticSocketDataProvider data1(data_reads, arraysize(data_reads), |
752 data_writes, arraysize(data_writes)); | 752 data_writes, arraysize(data_writes)); |
753 mock_socket_factory_.AddSocketDataProvider(&data1); | 753 mock_socket_factory_.AddSocketDataProvider(&data1); |
754 | 754 |
755 TestDelegate d; | 755 TestDelegate d; |
756 URLRequest r(GURL("http://www.google.com/"), | 756 scoped_ptr<URLRequest> r(context_->CreateRequest( |
757 net::DEFAULT_PRIORITY, | 757 GURL("http://www.google.com/"), |
758 &d, | 758 net::DEFAULT_PRIORITY, |
759 context_.get()); | 759 &d, |
760 r.set_method("GET"); | 760 NULL)); |
761 r.SetLoadFlags(net::LOAD_NORMAL); | 761 r->set_method("GET"); |
| 762 r->SetLoadFlags(net::LOAD_NORMAL); |
762 | 763 |
763 r.Start(); | 764 r->Start(); |
764 base::RunLoop().Run(); | 765 base::RunLoop().Run(); |
765 | 766 |
766 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r.status().status()); | 767 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r->status().status()); |
767 EXPECT_EQ(net::OK, r.status().error()); | 768 EXPECT_EQ(net::OK, r->status().error()); |
768 | 769 |
769 EXPECT_EQ("Bypass message", d.data_received()); | 770 EXPECT_EQ("Bypass message", d.data_received()); |
770 | 771 |
771 // We should have no entries in our bad proxy list. | 772 // We should have no entries in our bad proxy list. |
772 TestBadProxies(0, -1, "", ""); | 773 TestBadProxies(0, -1, "", ""); |
773 } | 774 } |
774 | 775 |
775 class BadEntropyProvider : public base::FieldTrial::EntropyProvider { | 776 class BadEntropyProvider : public base::FieldTrial::EntropyProvider { |
776 public: | 777 public: |
777 virtual ~BadEntropyProvider() {} | 778 virtual ~BadEntropyProvider() {} |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 &other_proxy_info); | 913 &other_proxy_info); |
913 EXPECT_FALSE(other_proxy_info.is_direct()); | 914 EXPECT_FALSE(other_proxy_info.is_direct()); |
914 | 915 |
915 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, | 916 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, |
916 empty_proxy_retry_info, &test_params, | 917 empty_proxy_retry_info, &test_params, |
917 &data_reduction_proxy_info); | 918 &data_reduction_proxy_info); |
918 EXPECT_TRUE(data_reduction_proxy_info.is_direct()); | 919 EXPECT_TRUE(data_reduction_proxy_info.is_direct()); |
919 } | 920 } |
920 | 921 |
921 } // namespace data_reduction_proxy | 922 } // namespace data_reduction_proxy |
OLD | NEW |