Index: components/data_reduction_proxy/common/data_reduction_proxy_headers_unittest.cc |
diff --git a/components/data_reduction_proxy/common/data_reduction_proxy_headers_unittest.cc b/components/data_reduction_proxy/common/data_reduction_proxy_headers_unittest.cc |
index da438d8a21ecb13cd49c4df7dcb18f4012f3c48d..58d6537cd2d90eea7efc58727cd9005c3aef5eb4 100644 |
--- a/components/data_reduction_proxy/common/data_reduction_proxy_headers_unittest.cc |
+++ b/components/data_reduction_proxy/common/data_reduction_proxy_headers_unittest.cc |
@@ -24,6 +24,102 @@ namespace data_reduction_proxy { |
class DataReductionProxyHeadersTest : public testing::Test {}; |
+TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyActionValue) { |
+ const struct { |
+ const char* headers; |
+ std::string action_key; |
+ bool expected_result; |
+ std::string expected_action_value; |
+ } tests[] = { |
+ { "HTTP/1.1 200 OK\n" |
+ "Content-Length: 999\n", |
+ "a", |
+ false, |
+ "", |
+ }, |
+ { "HTTP/1.1 200 OK\n" |
+ "connection: keep-alive\n" |
+ "Content-Length: 999\n", |
+ "a", |
+ false, |
+ "", |
+ }, |
+ { "HTTP/1.1 200 OK\n" |
+ "connection: keep-alive\n" |
+ "Chrome-Proxy: bypass=86400\n" |
+ "Content-Length: 999\n", |
+ "bypass", |
+ true, |
+ "86400", |
+ }, |
+ { "HTTP/1.1 200 OK\n" |
+ "connection: keep-alive\n" |
+ "Chrome-Proxy: bypass86400\n" |
+ "Content-Length: 999\n", |
+ "bypass", |
+ false, |
+ "", |
+ }, |
+ { "HTTP/1.1 200 OK\n" |
+ "connection: keep-alive\n" |
+ "Chrome-Proxy: bypass=0\n" |
+ "Content-Length: 999\n", |
+ "bypass", |
+ true, |
+ "0", |
+ }, |
+ { "HTTP/1.1 200 OK\n" |
+ "connection: keep-alive\n" |
+ "Chrome-Proxy: bypass=1500\n" |
+ "Chrome-Proxy: bypass=86400\n" |
+ "Content-Length: 999\n", |
+ "bypass", |
+ true, |
+ "1500", |
+ }, |
+ { "HTTP/1.1 200 OK\n" |
+ "connection: keep-alive\n" |
+ "Chrome-Proxy: block=1500, block=3600\n" |
+ "Content-Length: 999\n", |
+ "block", |
+ true, |
+ "1500", |
+ }, |
+ { "HTTP/1.1 200 OK\n" |
+ "connection: proxy-bypass\n" |
+ "Chrome-Proxy: key=123 \n" |
+ "Content-Length: 999\n", |
+ "key", |
+ true, |
+ "123", |
+ }, |
+ { "HTTP/1.1 200 OK\n" |
+ "connection: proxy-bypass\n" |
+ "Chrome-Proxy: key= \n" |
+ "Content-Length: 999\n", |
+ "key", |
+ true, |
+ "", |
+ }, |
+ }; |
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
+ std::string headers(tests[i].headers); |
+ HeadersToRaw(&headers); |
+ scoped_refptr<net::HttpResponseHeaders> parsed( |
+ new net::HttpResponseHeaders(headers)); |
+ |
+ std::string action_value; |
+ bool has_action_key = GetDataReductionProxyActionValue( |
+ parsed, |
+ tests[i].action_key, |
+ &action_value); |
+ EXPECT_EQ(tests[i].expected_result, has_action_key); |
+ if (has_action_key) { |
+ EXPECT_EQ(tests[i].expected_action_value, action_value); |
+ } |
+ } |
+} |
+ |
TEST_F(DataReductionProxyHeadersTest, GetProxyBypassInfo) { |
const struct { |
const char* headers; |
@@ -195,75 +291,110 @@ TEST_F(DataReductionProxyHeadersTest, HasDataReductionProxyViaHeader) { |
const struct { |
const char* headers; |
bool expected_result; |
+ bool expected_is_the_last; |
} tests[] = { |
{ "HTTP/1.1 200 OK\n" |
"Via: 1.1 Chrome-Proxy\n", |
false, |
+ false, |
}, |
{ "HTTP/1.1 200 OK\n" |
"Via: 1\n", |
false, |
+ false, |
}, |
{ "HTTP/1.1 200 OK\n" |
"Via: 1.1 Chrome-Compression-Proxy\n", |
true, |
+ true, |
}, |
{ "HTTP/1.1 200 OK\n" |
"Via: 1.0 Chrome-Compression-Proxy\n", |
true, |
+ true, |
}, |
{ "HTTP/1.1 200 OK\n" |
"Via: 1.1 Foo-Bar, 1.1 Chrome-Compression-Proxy\n", |
true, |
+ true, |
}, |
{ "HTTP/1.1 200 OK\n" |
"Via: 1.1 Chrome-Compression-Proxy, 1.1 Bar-Foo\n", |
true, |
+ false, |
}, |
{ "HTTP/1.1 200 OK\n" |
"Via: 1.1 chrome-compression-proxy\n", |
false, |
+ false, |
}, |
{ "HTTP/1.1 200 OK\n" |
"Via: 1.1 Foo-Bar\n" |
"Via: 1.1 Chrome-Compression-Proxy\n", |
true, |
+ true, |
+ }, |
+ { "HTTP/1.1 200 OK\n" |
+ "Via: 1.1 Chrome-Compression-Proxy\n" |
+ "Via: 1.1 Foo-Bar\n", |
+ true, |
+ false, |
}, |
{ "HTTP/1.1 200 OK\n" |
"Via: 1.1 Chrome-Proxy\n", |
false, |
+ false, |
}, |
{ "HTTP/1.1 200 OK\n" |
"Via: 1.1 Chrome Compression Proxy\n", |
true, |
+ true, |
}, |
{ "HTTP/1.1 200 OK\n" |
"Via: 1.1 Foo-Bar, 1.1 Chrome Compression Proxy\n", |
true, |
+ true, |
}, |
{ "HTTP/1.1 200 OK\n" |
"Via: 1.1 Chrome Compression Proxy, 1.1 Bar-Foo\n", |
true, |
+ false, |
}, |
{ "HTTP/1.1 200 OK\n" |
"Via: 1.1 chrome compression proxy\n", |
false, |
+ false, |
}, |
{ "HTTP/1.1 200 OK\n" |
"Via: 1.1 Foo-Bar\n" |
"Via: 1.1 Chrome Compression Proxy\n", |
true, |
+ true, |
+ }, |
+ { "HTTP/1.1 200 OK\n" |
+ "Via: 1.1 Chrome Compression Proxy\n" |
+ "Via: 1.1 Foo-Bar\n", |
+ true, |
+ false, |
}, |
}; |
+ bool has, is_the_last; |
+ std::string headers; |
+ scoped_refptr<net::HttpResponseHeaders> parsed; |
bengr
2014/07/29 17:50:28
Why did you move this outside the loop?
xingx1
2014/07/30 03:32:56
Add extra field of "NULL or not". Done.
|
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
- std::string headers(tests[i].headers); |
+ headers = tests[i].headers; |
HeadersToRaw(&headers); |
- scoped_refptr<net::HttpResponseHeaders> parsed( |
- new net::HttpResponseHeaders(headers)); |
+ parsed = new net::HttpResponseHeaders(headers); |
- EXPECT_EQ(tests[i].expected_result, |
- HasDataReductionProxyViaHeader(parsed)); |
+ has = HasDataReductionProxyViaHeader(parsed, &is_the_last); |
+ EXPECT_EQ(tests[i].expected_result, has); |
+ if (has) { |
+ EXPECT_EQ(tests[i].expected_is_the_last, is_the_last); |
+ } |
} |
+ |
+ has = HasDataReductionProxyViaHeader(parsed, NULL); |
bengr
2014/07/29 17:50:28
Why are you adding a case outside the loop of case
xingx1
2014/07/30 03:32:56
Done.
|
+ EXPECT_EQ(tests[ARRAYSIZE_UNSAFE(tests) - 1].expected_result, has); |
} |
TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyBypassEventType) { |