Index: components/data_reduction_proxy/core/common/data_reduction_proxy_headers_unittest.cc |
diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_headers_unittest.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_headers_unittest.cc |
index e2f884493325f168f9be12986e7c3b37cbb85f1e..cba90e139d2ca891f9a957e7d3f090c26be56990 100644 |
--- a/components/data_reduction_proxy/core/common/data_reduction_proxy_headers_unittest.cc |
+++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_headers_unittest.cc |
@@ -18,6 +18,7 @@ |
#include "net/http/http_response_headers.h" |
#include "net/proxy/proxy_service.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#include "url/gurl.h" |
namespace data_reduction_proxy { |
@@ -497,9 +498,8 @@ TEST_F(DataReductionProxyHeadersTest, GetProxyBypassInfo) { |
new net::HttpResponseHeaders(headers)); |
DataReductionProxyInfo data_reduction_proxy_info; |
- EXPECT_EQ( |
- tests[i].expected_result, |
- ParseHeadersForBypassInfo(parsed.get(), &data_reduction_proxy_info)); |
+ EXPECT_EQ(tests[i].expected_result, |
+ ParseHeadersForBypassInfo(*parsed, &data_reduction_proxy_info)); |
EXPECT_EQ(tests[i].expected_retry_delay, |
data_reduction_proxy_info.bypass_duration.InSeconds()); |
EXPECT_EQ(tests[i].expected_bypass_all, |
@@ -520,8 +520,7 @@ TEST_F(DataReductionProxyHeadersTest, ParseHeadersAndSetProxyInfo) { |
new net::HttpResponseHeaders(headers)); |
DataReductionProxyInfo data_reduction_proxy_info; |
- EXPECT_TRUE( |
- ParseHeadersForBypassInfo(parsed.get(), &data_reduction_proxy_info)); |
+ EXPECT_TRUE(ParseHeadersForBypassInfo(*parsed, &data_reduction_proxy_info)); |
EXPECT_LE(60, data_reduction_proxy_info.bypass_duration.InSeconds()); |
EXPECT_GE(5 * 60, data_reduction_proxy_info.bypass_duration.InSeconds()); |
EXPECT_FALSE(data_reduction_proxy_info.bypass_all); |
@@ -612,11 +611,11 @@ TEST_F(DataReductionProxyHeadersTest, HasDataReductionProxyViaHeader) { |
bool has_chrome_proxy_via_header, has_intermediary; |
if (tests[i].ignore_intermediary) { |
has_chrome_proxy_via_header = |
- HasDataReductionProxyViaHeader(parsed.get(), NULL); |
+ HasDataReductionProxyViaHeader(*parsed, NULL); |
} |
else { |
has_chrome_proxy_via_header = |
- HasDataReductionProxyViaHeader(parsed.get(), &has_intermediary); |
+ HasDataReductionProxyViaHeader(*parsed, &has_intermediary); |
} |
EXPECT_EQ(tests[i].expected_result, has_chrome_proxy_via_header); |
if (has_chrome_proxy_via_header && !tests[i].ignore_intermediary) { |
@@ -768,8 +767,87 @@ TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyBypassEventType) { |
tests[i].in_tamper_detection_experiment ? "TamperDetection_Enabled" |
: "TamperDetection_Disabled"); |
- EXPECT_EQ(tests[i].expected_result, GetDataReductionProxyBypassType( |
- parsed.get(), &chrome_proxy_info)); |
+ EXPECT_EQ(tests[i].expected_result, |
+ GetDataReductionProxyBypassType(std::vector<GURL>(), *parsed, |
+ &chrome_proxy_info)); |
+ } |
+} |
+ |
+TEST_F(DataReductionProxyHeadersTest, |
+ GetDataReductionProxyBypassEventTypeURLRedirectCycle) { |
+ const struct { |
+ const char* headers; |
+ std::vector<GURL> url_chain; |
+ DataReductionProxyBypassType expected_result; |
+ } tests[] = { |
+ { |
+ "HTTP/1.1 200 OK\n" |
+ "Via: 1.1 Chrome-Compression-Proxy\n", |
+ std::vector<GURL>{GURL("http://google.com/1"), |
+ GURL("http://google.com/2"), |
+ GURL("http://google.com/1")}, |
+ BYPASS_EVENT_TYPE_URL_REDIRECT_CYCLE, |
+ }, |
+ { |
+ "HTTP/1.1 200 OK\n" |
+ "Via: 1.1 Chrome-Compression-Proxy\n", |
+ std::vector<GURL>{ |
+ GURL("http://google.com/1"), GURL("http://google.com/2"), |
+ GURL("http://google.com/1"), GURL("http://google.com/2")}, |
+ BYPASS_EVENT_TYPE_URL_REDIRECT_CYCLE, |
+ }, |
+ { |
+ "HTTP/1.1 200 OK\n" |
+ "Via: 1.1 Chrome-Compression-Proxy\n", |
+ std::vector<GURL>{GURL("http://google.com/1")}, BYPASS_EVENT_TYPE_MAX, |
+ }, |
+ { |
+ "HTTP/1.1 200 OK\n" |
+ "Via: 1.1 Chrome-Compression-Proxy\n", |
+ std::vector<GURL>{GURL("http://google.com/1"), |
+ GURL("http://google.com/2")}, |
+ BYPASS_EVENT_TYPE_MAX, |
+ }, |
+ { |
+ "HTTP/1.1 200 OK\n" |
+ "Via: 1.1 Chrome-Compression-Proxy\n", |
+ std::vector<GURL>{GURL("http://google.com/1"), |
+ GURL("http://google.com/2"), |
+ GURL("http://google.com/3")}, |
+ BYPASS_EVENT_TYPE_MAX, |
+ }, |
+ { |
+ "HTTP/1.1 200 OK\n" |
+ "Via: 1.1 Chrome-Compression-Proxy\n", |
+ std::vector<GURL>{ |
+ GURL("http://google.com/1"), GURL("http://google.com/2"), |
+ GURL("http://google.com/3"), GURL("http://google.com/1")}, |
+ BYPASS_EVENT_TYPE_URL_REDIRECT_CYCLE, |
+ }, |
+ { |
+ "HTTP/1.1 200 OK\n" |
+ "Via: 1.1 Chrome-Compression-Proxy\n", |
+ std::vector<GURL>{ |
+ GURL("http://google.com/1"), GURL("http://google.com/2"), |
+ GURL("http://google.com/1"), GURL("http://google.com/3")}, |
+ BYPASS_EVENT_TYPE_MAX, |
+ }, |
+ { |
+ "HTTP/1.1 200 OK\n" |
+ "Via: 1.1 Chrome-Compression-Proxy\n", |
+ std::vector<GURL>(), BYPASS_EVENT_TYPE_MAX, |
+ }}; |
+ |
+ for (const auto& test : tests) { |
+ std::string headers(test.headers); |
+ HeadersToRaw(&headers); |
+ scoped_refptr<net::HttpResponseHeaders> parsed( |
+ new net::HttpResponseHeaders(headers)); |
+ DataReductionProxyInfo chrome_proxy_info; |
+ |
+ EXPECT_EQ(test.expected_result, |
+ GetDataReductionProxyBypassType(test.url_chain, *parsed, |
+ &chrome_proxy_info)); |
} |
} |