Index: components/data_reduction_proxy/browser/data_reduction_proxy_protocol_unittest.cc |
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_protocol_unittest.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_protocol_unittest.cc |
index 65535764d755a29ebeb81c0ecee72aa95f1c79cd..4737c89600430816796f38f0986da97c0cb9985c 100644 |
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_protocol_unittest.cc |
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_protocol_unittest.cc |
@@ -57,8 +57,11 @@ namespace data_reduction_proxy { |
class TestDataReductionProxyNetworkDelegate : public net::NetworkDelegate { |
public: |
TestDataReductionProxyNetworkDelegate( |
- TestDataReductionProxyParams* test_params) |
- : net::NetworkDelegate(), test_data_reduction_proxy_params_(test_params) { |
+ TestDataReductionProxyParams* test_params, |
+ ProxyService::DataReductionProxyBypassType* bypass_type) |
+ : net::NetworkDelegate(), |
+ test_data_reduction_proxy_params_(test_params), |
+ bypass_type_(bypass_type) { |
} |
virtual int OnHeadersReceived( |
@@ -71,11 +74,13 @@ class TestDataReductionProxyNetworkDelegate : public net::NetworkDelegate { |
test_data_reduction_proxy_params_, |
request, |
original_response_headers, |
- override_response_headers); |
+ override_response_headers, |
+ bypass_type_); |
return net::OK; |
} |
TestDataReductionProxyParams* test_data_reduction_proxy_params_; |
+ ProxyService::DataReductionProxyBypassType* bypass_type_; |
}; |
// Constructs a |TestURLRequestContext| that uses a |MockSocketFactory| to |
@@ -93,13 +98,15 @@ class DataReductionProxyProtocolTest : public testing::Test { |
} |
// Sets up the |TestURLRequestContext| with the provided |ProxyService|. |
bengr
2014/07/21 22:23:57
Mention the bypass_type
megjablon
2014/07/22 02:11:30
Done.
|
- void ConfigureTestDependencies(ProxyService* proxy_service) { |
+ void ConfigureTestDependencies( |
+ ProxyService* proxy_service, |
+ ProxyService::DataReductionProxyBypassType* bypass_type) { |
// Create a context with delayed initialization. |
context_.reset(new TestURLRequestContext(true)); |
proxy_service_.reset(proxy_service); |
network_delegate_.reset(new TestDataReductionProxyNetworkDelegate( |
- proxy_params_.get())); |
+ proxy_params_.get(), bypass_type)); |
context_->set_client_socket_factory(&mock_socket_factory_); |
context_->set_proxy_service(proxy_service_.get()); |
@@ -359,6 +366,7 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
size_t expected_bad_proxy_count; |
bool expect_response_body; |
int expected_duration; |
+ ProxyService::DataReductionProxyBypassType expected_bypass_type; |
} tests[] = { |
// Valid data reduction proxy response with no bypass message. |
{ "GET", |
@@ -368,7 +376,8 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
false, |
0u, |
true, |
- -1 |
+ -1, |
+ ProxyService::BYPASS_EVENT_TYPE_MAX, |
}, |
// Valid data reduction proxy response with older, but still valid via |
// header. |
@@ -379,7 +388,8 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
false, |
0u, |
true, |
- -1 |
+ -1, |
+ ProxyService::BYPASS_EVENT_TYPE_MAX |
}, |
// Valid data reduction proxy response with chained via header, |
// no bypass message. |
@@ -390,7 +400,8 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
false, |
0u, |
true, |
- -1 |
+ -1, |
+ ProxyService::BYPASS_EVENT_TYPE_MAX |
}, |
// Valid data reduction proxy response with a bypass message. |
{ "GET", |
@@ -401,7 +412,8 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
true, |
1u, |
true, |
- 0 |
+ 0, |
+ ProxyService::MEDIUM_BYPASS |
}, |
// Valid data reduction proxy response with a bypass message. |
{ "GET", |
@@ -412,7 +424,8 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
true, |
1u, |
true, |
- 1 |
+ 1, |
+ ProxyService::SHORT_BYPASS |
}, |
// Same as above with the OPTIONS method, which is idempotent. |
{ "OPTIONS", |
@@ -423,7 +436,8 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
true, |
1u, |
true, |
- 0 |
+ 0, |
+ ProxyService::MEDIUM_BYPASS |
}, |
// Same as above with the HEAD method, which is idempotent. |
{ "HEAD", |
@@ -434,7 +448,8 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
true, |
1u, |
false, |
- 0 |
+ 0, |
+ ProxyService::MEDIUM_BYPASS |
}, |
// Same as above with the PUT method, which is idempotent. |
{ "PUT", |
@@ -445,7 +460,8 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
true, |
1u, |
true, |
- 0 |
+ 0, |
+ ProxyService::MEDIUM_BYPASS |
}, |
// Same as above with the DELETE method, which is idempotent. |
{ "DELETE", |
@@ -456,7 +472,8 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
true, |
1u, |
true, |
- 0 |
+ 0, |
+ ProxyService::MEDIUM_BYPASS |
}, |
// Same as above with the TRACE method, which is idempotent. |
{ "TRACE", |
@@ -467,7 +484,8 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
true, |
1u, |
true, |
- 0 |
+ 0, |
+ ProxyService::MEDIUM_BYPASS |
}, |
// 500 responses should be bypassed. |
{ "GET", |
@@ -477,7 +495,8 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
true, |
1u, |
true, |
- 0 |
+ 0, |
+ ProxyService::STATUS_500_HTTP_INTERNAL_SERVER_ERROR |
}, |
// 502 responses should be bypassed. |
{ "GET", |
@@ -487,7 +506,8 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
true, |
1u, |
true, |
- 0 |
+ 0, |
+ ProxyService::STATUS_502_HTTP_BAD_GATEWAY |
}, |
// 503 responses should be bypassed. |
{ "GET", |
@@ -497,7 +517,8 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
true, |
1u, |
true, |
- 0 |
+ 0, |
+ ProxyService::STATUS_503_HTTP_SERVICE_UNAVAILABLE |
}, |
// Invalid data reduction proxy response. Missing Via header. |
{ "GET", |
@@ -506,7 +527,8 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
true, |
1u, |
true, |
- 0 |
+ 0, |
+ ProxyService::MISSING_VIA_HEADER_OTHER |
}, |
// Invalid data reduction proxy response. Wrong Via header. |
{ "GET", |
@@ -516,7 +538,8 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
true, |
1u, |
true, |
- 0 |
+ 0, |
+ ProxyService::MISSING_VIA_HEADER_OTHER |
}, |
// Valid data reduction proxy response. 304 missing Via header. |
{ "GET", |
@@ -525,7 +548,8 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
false, |
0u, |
false, |
- 0 |
+ 0, |
+ ProxyService::BYPASS_EVENT_TYPE_MAX |
}, |
// Valid data reduction proxy response with a bypass message. It will |
// not be retried because the request is non-idempotent. |
@@ -537,7 +561,8 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
false, |
1u, |
true, |
- 0 |
+ 0, |
+ ProxyService::MEDIUM_BYPASS |
}, |
// Valid data reduction proxy response with block message. Both proxies |
// should be on the retry list when it completes. |
@@ -549,21 +574,26 @@ TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
true, |
2u, |
true, |
- 1 |
+ 1, |
+ ProxyService::SHORT_BYPASS |
} |
}; |
std::string primary = proxy_params_->DefaultOrigin(); |
std::string fallback = proxy_params_->DefaultFallbackOrigin(); |
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
+ ProxyService::DataReductionProxyBypassType bypass_type; |
ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( |
"PROXY " + |
HostPortPair::FromURL(GURL(primary)).ToString() + "; PROXY " + |
- HostPortPair::FromURL(GURL(fallback)).ToString() + "; DIRECT")); |
+ HostPortPair::FromURL(GURL(fallback)).ToString() + "; DIRECT"), |
+ &bypass_type); |
TestProxyFallback(tests[i].method, |
tests[i].first_response, |
tests[i].expected_retry, |
tests[i].expect_response_body); |
+ EXPECT_EQ(tests[i].expected_bypass_type, bypass_type); |
+ |
// We should also observe the bad proxy in the retry list. |
TestBadProxies(tests[i].expected_bad_proxy_count, |
tests[i].expected_duration, |
@@ -575,7 +605,8 @@ TEST_F(DataReductionProxyProtocolTest, |
ProxyBypassIgnoredOnDirectConnection) { |
// Verify that a Chrome-Proxy header is ignored when returned from a directly |
// connected origin server. |
- ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult("DIRECT")); |
+ ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult("DIRECT"), |
+ NULL); |
MockRead data_reads[] = { |
MockRead("HTTP/1.1 200 OK\r\n" |