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/common/data_reduction_proxy_headers.h" | 5 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" |
6 | 6 |
7 #include "net/http/http_response_headers.h" | 7 #include "net/http/http_response_headers.h" |
8 #include "net/proxy/proxy_service.h" | 8 #include "net/proxy/proxy_service.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 { "HTTP/1.1 200 OK\n" | 47 { "HTTP/1.1 200 OK\n" |
48 "connection: keep-alive\n" | 48 "connection: keep-alive\n" |
49 "Chrome-Proxy: bypass=86400\n" | 49 "Chrome-Proxy: bypass=86400\n" |
50 "Content-Length: 999\n", | 50 "Content-Length: 999\n", |
51 true, | 51 true, |
52 86400, | 52 86400, |
53 false, | 53 false, |
54 }, | 54 }, |
55 { "HTTP/1.1 200 OK\n" | 55 { "HTTP/1.1 200 OK\n" |
56 "connection: keep-alive\n" | 56 "connection: keep-alive\n" |
57 "Chrome-Proxy: bypass=0\n" | |
58 "Content-Length: 999\n", | |
59 true, | |
60 0, | |
61 false, | |
62 }, | |
63 { "HTTP/1.1 200 OK\n" | |
64 "connection: keep-alive\n" | |
65 "Chrome-Proxy: bypass=-1\n" | 57 "Chrome-Proxy: bypass=-1\n" |
66 "Content-Length: 999\n", | 58 "Content-Length: 999\n", |
67 false, | 59 false, |
68 0, | 60 0, |
69 false, | 61 false, |
70 }, | 62 }, |
71 { "HTTP/1.1 200 OK\n" | 63 { "HTTP/1.1 200 OK\n" |
72 "connection: keep-alive\n" | 64 "connection: keep-alive\n" |
73 "Chrome-Proxy: bypass=xyz\n" | 65 "Chrome-Proxy: bypass=xyz\n" |
74 "Content-Length: 999\n", | 66 "Content-Length: 999\n", |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 }, | 168 }, |
177 }; | 169 }; |
178 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 170 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
179 std::string headers(tests[i].headers); | 171 std::string headers(tests[i].headers); |
180 HeadersToRaw(&headers); | 172 HeadersToRaw(&headers); |
181 scoped_refptr<net::HttpResponseHeaders> parsed( | 173 scoped_refptr<net::HttpResponseHeaders> parsed( |
182 new net::HttpResponseHeaders(headers)); | 174 new net::HttpResponseHeaders(headers)); |
183 | 175 |
184 DataReductionProxyInfo data_reduction_proxy_info; | 176 DataReductionProxyInfo data_reduction_proxy_info; |
185 EXPECT_EQ(tests[i].expected_result, | 177 EXPECT_EQ(tests[i].expected_result, |
186 GetDataReductionProxyInfo(parsed, &data_reduction_proxy_info)); | 178 ParseHeadersAndSetProxyInfo(parsed, &data_reduction_proxy_info)); |
187 EXPECT_EQ(tests[i].expected_retry_delay, | 179 EXPECT_EQ(tests[i].expected_retry_delay, |
188 data_reduction_proxy_info.bypass_duration.InSeconds()); | 180 data_reduction_proxy_info.bypass_duration.InSeconds()); |
189 EXPECT_EQ(tests[i].expected_bypass_all, | 181 EXPECT_EQ(tests[i].expected_bypass_all, |
190 data_reduction_proxy_info.bypass_all); | 182 data_reduction_proxy_info.bypass_all); |
191 } | 183 } |
192 } | 184 } |
193 | 185 |
186 TEST_F(DataReductionProxyHeadersTest, ParseHeadersAndSetProxyInfo) { | |
187 std::string headers = "HTTP/1.1 200 OK\n" | |
188 "connection: keep-alive\n" | |
189 "Chrome-Proxy: bypass=0\n" | |
190 "Content-Length: 999\n"; | |
191 HeadersToRaw(&headers); | |
192 scoped_refptr<net::HttpResponseHeaders> parsed( | |
193 new net::HttpResponseHeaders(headers)); | |
194 | |
195 DataReductionProxyInfo data_reduction_proxy_info; | |
196 EXPECT_TRUE( | |
Alexei Svitkine (slow)
2014/07/21 20:25:35
Nit: Indentation is off.
Not at Google. Contact bengr
2014/07/21 21:45:09
Done.
| |
197 ParseHeadersAndSetProxyInfo(parsed, &data_reduction_proxy_info)); | |
198 EXPECT_LE(60, data_reduction_proxy_info.bypass_duration.InSeconds()); | |
199 EXPECT_GE(5 * 60, data_reduction_proxy_info.bypass_duration.InSeconds()); | |
200 EXPECT_FALSE(data_reduction_proxy_info.bypass_all); | |
201 } | |
202 | |
194 TEST_F(DataReductionProxyHeadersTest, HasDataReductionProxyViaHeader) { | 203 TEST_F(DataReductionProxyHeadersTest, HasDataReductionProxyViaHeader) { |
195 const struct { | 204 const struct { |
196 const char* headers; | 205 const char* headers; |
197 bool expected_result; | 206 bool expected_result; |
198 } tests[] = { | 207 } tests[] = { |
199 { "HTTP/1.1 200 OK\n" | 208 { "HTTP/1.1 200 OK\n" |
200 "Via: 1.1 Chrome-Proxy\n", | 209 "Via: 1.1 Chrome-Proxy\n", |
201 false, | 210 false, |
202 }, | 211 }, |
203 { "HTTP/1.1 200 OK\n" | 212 { "HTTP/1.1 200 OK\n" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 } | 276 } |
268 | 277 |
269 TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyBypassEventType) { | 278 TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyBypassEventType) { |
270 const struct { | 279 const struct { |
271 const char* headers; | 280 const char* headers; |
272 net::ProxyService::DataReductionProxyBypassType expected_result; | 281 net::ProxyService::DataReductionProxyBypassType expected_result; |
273 } tests[] = { | 282 } tests[] = { |
274 { "HTTP/1.1 200 OK\n" | 283 { "HTTP/1.1 200 OK\n" |
275 "Chrome-Proxy: bypass=0\n" | 284 "Chrome-Proxy: bypass=0\n" |
276 "Via: 1.1 Chrome-Compression-Proxy\n", | 285 "Via: 1.1 Chrome-Compression-Proxy\n", |
277 net::ProxyService::SHORT_BYPASS, | 286 net::ProxyService::MEDIUM_BYPASS, |
278 }, | 287 }, |
279 { "HTTP/1.1 200 OK\n" | 288 { "HTTP/1.1 200 OK\n" |
280 "Chrome-Proxy: bypass=59\n" | 289 "Chrome-Proxy: bypass=59\n" |
281 "Via: 1.1 Chrome-Compression-Proxy\n", | 290 "Via: 1.1 Chrome-Compression-Proxy\n", |
282 net::ProxyService::SHORT_BYPASS, | 291 net::ProxyService::SHORT_BYPASS, |
283 }, | 292 }, |
284 { "HTTP/1.1 200 OK\n" | 293 { "HTTP/1.1 200 OK\n" |
285 "Chrome-Proxy: bypass=60\n" | 294 "Chrome-Proxy: bypass=60\n" |
286 "Via: 1.1 Chrome-Compression-Proxy\n", | 295 "Via: 1.1 Chrome-Compression-Proxy\n", |
287 net::ProxyService::MEDIUM_BYPASS, | 296 net::ProxyService::MEDIUM_BYPASS, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 std::string headers(tests[i].headers); | 370 std::string headers(tests[i].headers); |
362 HeadersToRaw(&headers); | 371 HeadersToRaw(&headers); |
363 scoped_refptr<net::HttpResponseHeaders> parsed( | 372 scoped_refptr<net::HttpResponseHeaders> parsed( |
364 new net::HttpResponseHeaders(headers)); | 373 new net::HttpResponseHeaders(headers)); |
365 DataReductionProxyInfo chrome_proxy_info; | 374 DataReductionProxyInfo chrome_proxy_info; |
366 EXPECT_EQ(tests[i].expected_result, | 375 EXPECT_EQ(tests[i].expected_result, |
367 GetDataReductionProxyBypassType(parsed, &chrome_proxy_info)); | 376 GetDataReductionProxyBypassType(parsed, &chrome_proxy_info)); |
368 } | 377 } |
369 } | 378 } |
370 } // namespace data_reduction_proxy | 379 } // namespace data_reduction_proxy |
OLD | NEW |