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" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params_te
st_utils.h" | 14 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params_te
st_utils.h" |
15 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" | 15 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" |
| 16 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers_te
st_utils.h" |
16 #include "net/base/completion_callback.h" | 17 #include "net/base/completion_callback.h" |
17 #include "net/base/host_port_pair.h" | 18 #include "net/base/host_port_pair.h" |
18 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
19 #include "net/base/network_delegate.h" | 20 #include "net/base/network_delegate.h" |
20 #include "net/http/http_response_headers.h" | 21 #include "net/http/http_response_headers.h" |
21 #include "net/http/http_transaction_test_util.h" | 22 #include "net/http/http_transaction_test_util.h" |
22 #include "net/proxy/proxy_service.h" | 23 #include "net/proxy/proxy_service.h" |
23 #include "net/socket/socket_test_util.h" | 24 #include "net/socket/socket_test_util.h" |
24 #include "net/url_request/static_http_user_agent_settings.h" | 25 #include "net/url_request/static_http_user_agent_settings.h" |
25 #include "net/url_request/url_request.h" | 26 #include "net/url_request/url_request.h" |
26 #include "net/url_request/url_request_context.h" | 27 #include "net/url_request/url_request_context.h" |
27 #include "net/url_request/url_request_test_util.h" | 28 #include "net/url_request/url_request_test_util.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
29 | 30 |
30 using net::HttpResponseHeaders; | 31 using net::HttpResponseHeaders; |
31 using net::HostPortPair; | 32 using net::HostPortPair; |
32 using net::MockRead; | 33 using net::MockRead; |
33 using net::MockWrite; | 34 using net::MockWrite; |
34 using net::ProxyRetryInfoMap; | 35 using net::ProxyRetryInfoMap; |
35 using net::ProxyService; | 36 using net::ProxyService; |
36 using net::StaticSocketDataProvider; | 37 using net::StaticSocketDataProvider; |
37 using net::TestDelegate; | 38 using net::TestDelegate; |
38 using net::URLRequest; | 39 using net::URLRequest; |
39 using net::TestURLRequestContext; | 40 using net::TestURLRequestContext; |
40 | 41 |
41 | 42 |
42 namespace { | |
43 // Transform "normal"-looking headers (\n-separated) to the appropriate | |
44 // input format for ParseRawHeaders (\0-separated). | |
45 void HeadersToRaw(std::string* headers) { | |
46 std::replace(headers->begin(), headers->end(), '\n', '\0'); | |
47 if (!headers->empty()) | |
48 *headers += '\0'; | |
49 } | |
50 | |
51 } // namespace | |
52 | |
53 | |
54 namespace data_reduction_proxy { | 43 namespace data_reduction_proxy { |
55 | 44 |
56 // A test network delegate that exercises the bypass logic of the data | 45 // A test network delegate that exercises the bypass logic of the data |
57 // reduction proxy. | 46 // reduction proxy. |
58 class TestDataReductionProxyNetworkDelegate : public net::NetworkDelegate { | 47 class TestDataReductionProxyNetworkDelegate : public net::NetworkDelegate { |
59 public: | 48 public: |
60 TestDataReductionProxyNetworkDelegate( | 49 TestDataReductionProxyNetworkDelegate( |
61 TestDataReductionProxyParams* test_params, | 50 TestDataReductionProxyParams* test_params, |
62 DataReductionProxyBypassType* bypass_type) | 51 DataReductionProxyBypassType* bypass_type) |
63 : net::NetworkDelegate(), | 52 : net::NetworkDelegate(), |
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 &other_proxy_info); | 903 &other_proxy_info); |
915 EXPECT_FALSE(other_proxy_info.is_direct()); | 904 EXPECT_FALSE(other_proxy_info.is_direct()); |
916 | 905 |
917 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, | 906 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, |
918 empty_proxy_retry_info, &test_params, | 907 empty_proxy_retry_info, &test_params, |
919 &data_reduction_proxy_info); | 908 &data_reduction_proxy_info); |
920 EXPECT_TRUE(data_reduction_proxy_info.is_direct()); | 909 EXPECT_TRUE(data_reduction_proxy_info.is_direct()); |
921 } | 910 } |
922 | 911 |
923 } // namespace data_reduction_proxy | 912 } // namespace data_reduction_proxy |
OLD | NEW |