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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 { "GET", true }, | 291 { "GET", true }, |
292 { "OPTIONS", true }, | 292 { "OPTIONS", true }, |
293 { "HEAD", true }, | 293 { "HEAD", true }, |
294 { "PUT", true }, | 294 { "PUT", true }, |
295 { "DELETE", true }, | 295 { "DELETE", true }, |
296 { "TRACE", true }, | 296 { "TRACE", true }, |
297 { "POST", false }, | 297 { "POST", false }, |
298 { "CONNECT", false }, | 298 { "CONNECT", false }, |
299 }; | 299 }; |
300 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 300 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
301 net::TestURLRequest request(GURL("http://www.google.com/"), | 301 scoped_ptr<net::URLRequest> request( |
302 net::DEFAULT_PRIORITY, | 302 context.CreateRequest(GURL("http://www.google.com/"), |
303 NULL, | 303 net::DEFAULT_PRIORITY, |
304 &context); | 304 NULL, |
305 request.set_method(tests[i].method); | 305 NULL)); |
306 EXPECT_EQ(tests[i].expected_result, IsRequestIdempotent(&request)); | 306 request->set_method(tests[i].method); |
| 307 EXPECT_EQ(tests[i].expected_result, IsRequestIdempotent(request.get())); |
307 } | 308 } |
308 } | 309 } |
309 | 310 |
310 // Tests that the response is correctly overwritten as a redirect. | 311 // Tests that the response is correctly overwritten as a redirect. |
311 TEST_F(DataReductionProxyProtocolTest, OverrideResponseAsRedirect) { | 312 TEST_F(DataReductionProxyProtocolTest, OverrideResponseAsRedirect) { |
312 net::TestURLRequestContext context; | 313 net::TestURLRequestContext context; |
313 const struct { | 314 const struct { |
314 const char* headers; | 315 const char* headers; |
315 const char* expected_headers; | 316 const char* expected_headers; |
316 } tests[] = { | 317 } tests[] = { |
(...skipping 23 matching lines...) Expand all Loading... |
340 }, | 341 }, |
341 }; | 342 }; |
342 | 343 |
343 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 344 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
344 std::string headers(tests[i].headers); | 345 std::string headers(tests[i].headers); |
345 HeadersToRaw(&headers); | 346 HeadersToRaw(&headers); |
346 scoped_refptr<HttpResponseHeaders> original_response_headers( | 347 scoped_refptr<HttpResponseHeaders> original_response_headers( |
347 new HttpResponseHeaders(headers)); | 348 new HttpResponseHeaders(headers)); |
348 scoped_refptr<HttpResponseHeaders> override_response_headers; | 349 scoped_refptr<HttpResponseHeaders> override_response_headers; |
349 TestDelegate test_delegate; | 350 TestDelegate test_delegate; |
350 net::TestURLRequest request(GURL("http://www.google.com/"), | 351 scoped_ptr<net::URLRequest> request( |
351 net::DEFAULT_PRIORITY, | 352 context.CreateRequest(GURL("http://www.google.com/"), |
352 NULL, | 353 net::DEFAULT_PRIORITY, |
353 &context); | 354 NULL, |
354 OverrideResponseAsRedirect( | 355 NULL)); |
355 &request, original_response_headers.get(), &override_response_headers); | 356 OverrideResponseAsRedirect(request.get(), original_response_headers.get(), |
| 357 &override_response_headers); |
356 int expected_flags = net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY; | 358 int expected_flags = net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY; |
357 EXPECT_EQ(expected_flags, request.load_flags()); | 359 EXPECT_EQ(expected_flags, request->load_flags()); |
358 std::string override_headers; | 360 std::string override_headers; |
359 override_response_headers->GetNormalizedHeaders(&override_headers); | 361 override_response_headers->GetNormalizedHeaders(&override_headers); |
360 EXPECT_EQ(std::string(tests[i].expected_headers), override_headers); | 362 EXPECT_EQ(std::string(tests[i].expected_headers), override_headers); |
361 } | 363 } |
362 } | 364 } |
363 | 365 |
364 | 366 |
365 // After each test, the proxy retry info will contain zero, one, or two of the | 367 // After each test, the proxy retry info will contain zero, one, or two of the |
366 // data reduction proxies depending on whether no bypass was indicated by the | 368 // data reduction proxies depending on whether no bypass was indicated by the |
367 // initial response, a single proxy bypass was indicated, or a double bypass | 369 // initial response, a single proxy bypass was indicated, or a double bypass |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 &other_proxy_info); | 914 &other_proxy_info); |
913 EXPECT_FALSE(other_proxy_info.is_direct()); | 915 EXPECT_FALSE(other_proxy_info.is_direct()); |
914 | 916 |
915 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, | 917 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, |
916 empty_proxy_retry_info, &test_params, | 918 empty_proxy_retry_info, &test_params, |
917 &data_reduction_proxy_info); | 919 &data_reduction_proxy_info); |
918 EXPECT_TRUE(data_reduction_proxy_info.is_direct()); | 920 EXPECT_TRUE(data_reduction_proxy_info.is_direct()); |
919 } | 921 } |
920 | 922 |
921 } // namespace data_reduction_proxy | 923 } // namespace data_reduction_proxy |
OLD | NEW |