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/core/browser/data_reduction_proxy_netw
ork_delegate.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw
ork_delegate.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 DataReductionProxyData* data = | 863 DataReductionProxyData* data = |
864 DataReductionProxyData::GetData(*request.get()); | 864 DataReductionProxyData::GetData(*request.get()); |
865 if (!test.used_data_reduction_proxy) { | 865 if (!test.used_data_reduction_proxy) { |
866 EXPECT_FALSE(data); | 866 EXPECT_FALSE(data); |
867 } else { | 867 } else { |
868 EXPECT_TRUE(data); | 868 EXPECT_TRUE(data); |
869 EXPECT_EQ(test.main_frame ? net::EFFECTIVE_CONNECTION_TYPE_OFFLINE | 869 EXPECT_EQ(test.main_frame ? net::EFFECTIVE_CONNECTION_TYPE_OFFLINE |
870 : net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, | 870 : net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
871 data->effective_connection_type()); | 871 data->effective_connection_type()); |
872 EXPECT_TRUE(data->used_data_reduction_proxy()); | 872 EXPECT_TRUE(data->used_data_reduction_proxy()); |
873 EXPECT_EQ(GURL(kTestURL), data->request_url()); | 873 EXPECT_EQ(test.main_frame ? GURL(kTestURL) : GURL(), data->request_url()); |
874 EXPECT_EQ("fake-session", data->session_key()); | 874 EXPECT_EQ(test.main_frame ? "fake-session" : "", data->session_key()); |
875 EXPECT_EQ(test.lofi_on, data->lofi_requested()); | 875 EXPECT_EQ(test.lofi_on, data->lofi_requested()); |
876 } | 876 } |
877 } | 877 } |
878 } | 878 } |
879 | 879 |
880 TEST_F(DataReductionProxyNetworkDelegateTest, | 880 TEST_F(DataReductionProxyNetworkDelegateTest, |
881 RequestDataHoldbackConfigurations) { | 881 RequestDataHoldbackConfigurations) { |
882 Init(USE_INSECURE_PROXY, false); | 882 Init(USE_INSECURE_PROXY, false); |
883 const struct { | 883 const struct { |
884 bool data_reduction_proxy_enabled; | 884 bool data_reduction_proxy_enabled; |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 "HTTP/1.1 200 OK\r\n" | 1182 "HTTP/1.1 200 OK\r\n" |
1183 "Date: Wed, 28 Nov 2007 09:40:09 GMT\r\n" | 1183 "Date: Wed, 28 Nov 2007 09:40:09 GMT\r\n" |
1184 "Expires: Mon, 24 Nov 2014 12:45:26 GMT\r\n" | 1184 "Expires: Mon, 24 Nov 2014 12:45:26 GMT\r\n" |
1185 "Via: 1.1 Chrome-Compression-Proxy\r\n" | 1185 "Via: 1.1 Chrome-Compression-Proxy\r\n" |
1186 "x-original-content-length: 200\r\n"; | 1186 "x-original-content-length: 200\r\n"; |
1187 | 1187 |
1188 if (tests[i].lofi_response) | 1188 if (tests[i].lofi_response) |
1189 response_headers += "Chrome-Proxy-Content-Transform: empty-image\r\n"; | 1189 response_headers += "Chrome-Proxy-Content-Transform: empty-image\r\n"; |
1190 | 1190 |
1191 response_headers += "\r\n"; | 1191 response_headers += "\r\n"; |
1192 FetchURLRequest(GURL(kTestURL), nullptr, response_headers, 140, 0); | 1192 auto request = |
1193 | 1193 FetchURLRequest(GURL(kTestURL), nullptr, response_headers, 140, 0); |
| 1194 EXPECT_EQ(tests[i].lofi_response, |
| 1195 DataReductionProxyData::GetData(*request)->lofi_received()); |
1194 VerifyDidNotifyLoFiResponse(tests[i].lofi_response); | 1196 VerifyDidNotifyLoFiResponse(tests[i].lofi_response); |
1195 } | 1197 } |
1196 } | 1198 } |
1197 | 1199 |
1198 TEST_F(DataReductionProxyNetworkDelegateTest, | 1200 TEST_F(DataReductionProxyNetworkDelegateTest, |
1199 TestLoFiTransformationTypeHistogram) { | 1201 TestLoFiTransformationTypeHistogram) { |
1200 Init(USE_INSECURE_PROXY, false); | 1202 Init(USE_INSECURE_PROXY, false); |
1201 const char kLoFiTransformationTypeHistogram[] = | 1203 const char kLoFiTransformationTypeHistogram[] = |
1202 "DataReductionProxy.LoFi.TransformationType"; | 1204 "DataReductionProxy.LoFi.TransformationType"; |
1203 base::HistogramTester histogram_tester; | 1205 base::HistogramTester histogram_tester; |
1204 | 1206 |
1205 net::HttpRequestHeaders request_headers; | 1207 net::HttpRequestHeaders request_headers; |
1206 request_headers.SetHeader("chrome-proxy-accept-transform", "lite-page"); | 1208 request_headers.SetHeader("chrome-proxy-accept-transform", "lite-page"); |
1207 lofi_decider()->ignore_is_using_data_reduction_proxy_check(); | 1209 lofi_decider()->ignore_is_using_data_reduction_proxy_check(); |
1208 FetchURLRequest(GURL(kTestURL), &request_headers, std::string(), 140, 0); | 1210 FetchURLRequest(GURL(kTestURL), &request_headers, std::string(), 140, 0); |
1209 histogram_tester.ExpectBucketCount(kLoFiTransformationTypeHistogram, | 1211 histogram_tester.ExpectBucketCount(kLoFiTransformationTypeHistogram, |
1210 NO_TRANSFORMATION_LITE_PAGE_REQUESTED, 1); | 1212 NO_TRANSFORMATION_LITE_PAGE_REQUESTED, 1); |
1211 | 1213 |
1212 std::string response_headers = | 1214 std::string response_headers = |
1213 "HTTP/1.1 200 OK\r\n" | 1215 "HTTP/1.1 200 OK\r\n" |
1214 "Chrome-Proxy-Content-Transform: lite-page\r\n" | 1216 "Chrome-Proxy-Content-Transform: lite-page\r\n" |
1215 "Date: Wed, 28 Nov 2007 09:40:09 GMT\r\n" | 1217 "Date: Wed, 28 Nov 2007 09:40:09 GMT\r\n" |
1216 "Expires: Mon, 24 Nov 2014 12:45:26 GMT\r\n" | 1218 "Expires: Mon, 24 Nov 2014 12:45:26 GMT\r\n" |
1217 "Via: 1.1 Chrome-Compression-Proxy\r\n" | 1219 "Via: 1.1 Chrome-Compression-Proxy\r\n" |
1218 "x-original-content-length: 200\r\n"; | 1220 "x-original-content-length: 200\r\n"; |
1219 | 1221 |
1220 response_headers += "\r\n"; | 1222 response_headers += "\r\n"; |
1221 FetchURLRequest(GURL(kTestURL), nullptr, response_headers, 140, 0); | 1223 auto request = |
| 1224 FetchURLRequest(GURL(kTestURL), nullptr, response_headers, 140, 0); |
| 1225 EXPECT_TRUE(DataReductionProxyData::GetData(*request)->lite_page_received()); |
1222 | 1226 |
1223 histogram_tester.ExpectBucketCount(kLoFiTransformationTypeHistogram, | 1227 histogram_tester.ExpectBucketCount(kLoFiTransformationTypeHistogram, |
1224 LITE_PAGE, 1); | 1228 LITE_PAGE, 1); |
1225 } | 1229 } |
1226 | 1230 |
1227 // Test that Brotli is not added to the accept-encoding header when it is | 1231 // Test that Brotli is not added to the accept-encoding header when it is |
1228 // disabled globally. | 1232 // disabled globally. |
1229 TEST_F(DataReductionProxyNetworkDelegateTest, | 1233 TEST_F(DataReductionProxyNetworkDelegateTest, |
1230 BrotliAdvertisement_BrotliDisabled) { | 1234 BrotliAdvertisement_BrotliDisabled) { |
1231 Init(USE_SECURE_PROXY, false /* enable_brotli_globally */); | 1235 Init(USE_SECURE_PROXY, false /* enable_brotli_globally */); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1405 io_data()->request_options()->SetSecureSession("new-session"); | 1409 io_data()->request_options()->SetSecureSession("new-session"); |
1406 network_delegate()->NotifyBeforeSendHeaders( | 1410 network_delegate()->NotifyBeforeSendHeaders( |
1407 request.get(), data_reduction_proxy_info, proxy_retry_info, &headers); | 1411 request.get(), data_reduction_proxy_info, proxy_retry_info, &headers); |
1408 data = DataReductionProxyData::GetData(*request.get()); | 1412 data = DataReductionProxyData::GetData(*request.get()); |
1409 EXPECT_EQ(1u, data->page_id().value()); | 1413 EXPECT_EQ(1u, data->page_id().value()); |
1410 } | 1414 } |
1411 | 1415 |
1412 } // namespace | 1416 } // namespace |
1413 | 1417 |
1414 } // namespace data_reduction_proxy | 1418 } // namespace data_reduction_proxy |
OLD | NEW |