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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 bool IsUsingLoFi(const net::URLRequest& request) const override { | 140 bool IsUsingLoFi(const net::URLRequest& request) const override { |
141 return should_request_lofi_resource_; | 141 return should_request_lofi_resource_; |
142 } | 142 } |
143 | 143 |
144 void SetIsUsingLoFi(bool should_request_lofi_resource) { | 144 void SetIsUsingLoFi(bool should_request_lofi_resource) { |
145 should_request_lofi_resource_ = should_request_lofi_resource; | 145 should_request_lofi_resource_ = should_request_lofi_resource; |
146 } | 146 } |
147 | 147 |
148 void MaybeSetAcceptTransformHeader( | 148 void MaybeSetAcceptTransformHeader( |
149 const net::URLRequest& request, | 149 const net::URLRequest& request, |
150 bool is_previews_disabled, | |
151 net::HttpRequestHeaders* headers) const override { | 150 net::HttpRequestHeaders* headers) const override { |
152 if (should_request_lofi_resource_) { | 151 if (should_request_lofi_resource_) { |
153 headers->SetHeader(chrome_proxy_accept_transform_header(), | 152 headers->SetHeader(chrome_proxy_accept_transform_header(), |
154 empty_image_directive()); | 153 empty_image_directive()); |
155 } | 154 } |
156 } | 155 } |
157 | 156 |
158 bool IsSlowPagePreviewRequested( | 157 bool IsSlowPagePreviewRequested( |
159 const net::HttpRequestHeaders& headers) const override { | 158 const net::HttpRequestHeaders& headers) const override { |
160 std::string header_value; | 159 std::string header_value; |
(...skipping 14 matching lines...) Expand all Loading... |
175 return false; | 174 return false; |
176 } | 175 } |
177 | 176 |
178 void RemoveAcceptTransformHeader( | 177 void RemoveAcceptTransformHeader( |
179 net::HttpRequestHeaders* headers) const override { | 178 net::HttpRequestHeaders* headers) const override { |
180 if (ignore_is_using_data_reduction_proxy_check_) | 179 if (ignore_is_using_data_reduction_proxy_check_) |
181 return; | 180 return; |
182 headers->RemoveHeader(chrome_proxy_accept_transform_header()); | 181 headers->RemoveHeader(chrome_proxy_accept_transform_header()); |
183 } | 182 } |
184 | 183 |
185 void MaybeSetIgnorePreviewsBlacklistDirective( | 184 void MaybeSetForceLitePageDirective( |
186 net::HttpRequestHeaders* headers) const override {} | 185 net::HttpRequestHeaders* headers) const override {} |
187 | 186 |
188 bool ShouldRecordLoFiUMA(const net::URLRequest& request) const override { | 187 bool ShouldRecordLoFiUMA(const net::URLRequest& request) const override { |
189 return should_request_lofi_resource_; | 188 return should_request_lofi_resource_; |
190 } | 189 } |
191 | 190 |
192 void ignore_is_using_data_reduction_proxy_check() { | 191 void ignore_is_using_data_reduction_proxy_check() { |
193 ignore_is_using_data_reduction_proxy_check_ = true; | 192 ignore_is_using_data_reduction_proxy_check_ = true; |
194 } | 193 } |
195 | 194 |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 headers.GetHeader(chrome_proxy_header(), &header_value); | 773 headers.GetHeader(chrome_proxy_header(), &header_value); |
775 EXPECT_TRUE(header_value.find("ps=") != std::string::npos); | 774 EXPECT_TRUE(header_value.find("ps=") != std::string::npos); |
776 EXPECT_TRUE(header_value.find("sid=") != std::string::npos); | 775 EXPECT_TRUE(header_value.find("sid=") != std::string::npos); |
777 } | 776 } |
778 | 777 |
779 TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { | 778 TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { |
780 Init(USE_INSECURE_PROXY, false); | 779 Init(USE_INSECURE_PROXY, false); |
781 // Enable Lo-Fi. | 780 // Enable Lo-Fi. |
782 const struct { | 781 const struct { |
783 bool lofi_switch_enabled; | 782 bool lofi_switch_enabled; |
784 bool auto_lofi_enabled; | 783 bool lofi_field_trial; |
785 bool is_data_reduction_proxy; | 784 bool is_data_reduction_proxy; |
786 } tests[] = { | 785 } tests[] = { |
787 { | 786 { |
788 // Lo-Fi enabled through switch and not using a Data Reduction Proxy. | 787 // Lo-Fi enabled through switch and not using a Data Reduction Proxy. |
789 true, false, false, | 788 true, false, false, |
790 }, | 789 }, |
791 { | 790 { |
792 // Lo-Fi enabled through switch and using a Data Reduction Proxy. | 791 // Lo-Fi enabled through switch and using a Data Reduction Proxy. |
793 true, false, true, | 792 true, false, true, |
794 }, | 793 }, |
795 { | 794 { |
796 // Lo-Fi enabled through field trial and not using a Data Reduction | 795 // Lo-Fi enabled through field trial and not using a Data Reduction |
797 // Proxy. | 796 // Proxy. |
798 false, true, false, | 797 false, true, false, |
799 }, | 798 }, |
800 { | 799 { |
801 // Lo-Fi enabled through field trial and using a Data Reduction Proxy. | 800 // Lo-Fi enabled through field trial and using a Data Reduction Proxy. |
802 false, true, true, | 801 false, true, true, |
803 }, | 802 }, |
804 }; | 803 }; |
805 | 804 |
806 for (size_t i = 0; i < arraysize(tests); ++i) { | 805 for (size_t i = 0; i < arraysize(tests); ++i) { |
807 if (tests[i].lofi_switch_enabled) { | 806 if (tests[i].lofi_switch_enabled) { |
808 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 807 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
809 switches::kDataReductionProxyLoFi, | 808 switches::kDataReductionProxyLoFi, |
810 switches::kDataReductionProxyLoFiValueAlwaysOn); | 809 switches::kDataReductionProxyLoFiValueAlwaysOn); |
811 } | 810 } |
812 base::FieldTrialList field_trial_list(nullptr); | 811 base::FieldTrialList field_trial_list(nullptr); |
813 if (tests[i].auto_lofi_enabled) { | 812 if (tests[i].lofi_field_trial) { |
814 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), | 813 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
815 "Enabled"); | 814 "Enabled"); |
816 } | 815 } |
817 config()->SetNetworkProhibitivelySlow(tests[i].auto_lofi_enabled); | 816 config()->SetNetworkProhibitivelySlow(tests[i].lofi_field_trial); |
818 io_data()->SetLoFiModeActiveOnMainFrame(false); | 817 io_data()->SetLoFiModeActiveOnMainFrame(false); |
819 | 818 |
820 net::ProxyInfo data_reduction_proxy_info; | 819 net::ProxyInfo data_reduction_proxy_info; |
821 std::string proxy; | 820 std::string proxy; |
822 if (tests[i].is_data_reduction_proxy) | 821 if (tests[i].is_data_reduction_proxy) |
823 base::TrimString(params()->DefaultOrigin(), "/", &proxy); | 822 base::TrimString(params()->DefaultOrigin(), "/", &proxy); |
824 else | 823 else |
825 base::TrimString(kOtherProxy, "/", &proxy); | 824 base::TrimString(kOtherProxy, "/", &proxy); |
826 data_reduction_proxy_info.UseNamedProxy(proxy); | 825 data_reduction_proxy_info.UseNamedProxy(proxy); |
827 | 826 |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 histogram_tester.ExpectUniqueSample(kCacheableHistogramName, | 1166 histogram_tester.ExpectUniqueSample(kCacheableHistogramName, |
1168 kResponseContentLength, 1); | 1167 kResponseContentLength, 1); |
1169 histogram_tester.ExpectUniqueSample(kCacheable4HoursHistogramName, | 1168 histogram_tester.ExpectUniqueSample(kCacheable4HoursHistogramName, |
1170 kResponseContentLength, 1); | 1169 kResponseContentLength, 1); |
1171 histogram_tester.ExpectUniqueSample(kCacheable24HoursHistogramName, | 1170 histogram_tester.ExpectUniqueSample(kCacheable24HoursHistogramName, |
1172 kResponseContentLength, 1); | 1171 kResponseContentLength, 1); |
1173 | 1172 |
1174 // Check Lo-Fi histograms. | 1173 // Check Lo-Fi histograms. |
1175 const struct { | 1174 const struct { |
1176 bool lofi_enabled_through_switch; | 1175 bool lofi_enabled_through_switch; |
1177 bool auto_lofi_enabled; | 1176 bool lofi_field_trial; |
1178 int expected_count; | 1177 int expected_count; |
1179 } tests[] = { | 1178 } tests[] = { |
1180 { | 1179 { |
1181 // Lo-Fi disabled. | 1180 // Lo-Fi disabled. |
1182 false, false, 0, | 1181 false, false, 0, |
1183 }, | 1182 }, |
1184 { | 1183 { |
1185 // Auto Lo-Fi enabled. | 1184 // Lo-Fi enabled by field trial. |
1186 // This should populate Lo-Fi content length histogram. | 1185 // This should populate Lo-Fi content length histogram. |
1187 false, true, 1, | 1186 false, true, 1, |
1188 }, | 1187 }, |
1189 { | 1188 { |
1190 // Lo-Fi enabled through switch. | 1189 // Lo-Fi enabled through switch. |
1191 // This should populate Lo-Fi content length histogram. | 1190 // This should populate Lo-Fi content length histogram. |
1192 true, false, 1, | 1191 true, false, 1, |
1193 }, | 1192 }, |
1194 { | 1193 { |
1195 // Lo-Fi enabled through switch and Auto Lo-Fi also enabled. | 1194 // Lo-Fi enabled through switch and also field trial. |
1196 // This should populate Lo-Fi content length histogram. | 1195 // This should populate Lo-Fi content length histogram. |
1197 true, true, 1, | 1196 true, true, 1, |
1198 }, | 1197 }, |
1199 }; | 1198 }; |
1200 | 1199 |
1201 for (size_t i = 0; i < arraysize(tests); ++i) { | 1200 for (size_t i = 0; i < arraysize(tests); ++i) { |
1202 config()->ResetLoFiStatusForTest(); | 1201 config()->ResetLoFiStatusForTest(); |
1203 config()->SetNetworkProhibitivelySlow(tests[i].auto_lofi_enabled); | 1202 config()->SetNetworkProhibitivelySlow(tests[i].lofi_field_trial); |
1204 base::FieldTrialList field_trial_list(nullptr); | 1203 base::FieldTrialList field_trial_list(nullptr); |
1205 if (tests[i].auto_lofi_enabled) { | 1204 if (tests[i].lofi_field_trial) { |
1206 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), | 1205 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
1207 "Enabled"); | 1206 "Enabled"); |
1208 } | 1207 } |
1209 | 1208 |
1210 if (tests[i].lofi_enabled_through_switch) { | 1209 if (tests[i].lofi_enabled_through_switch) { |
1211 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 1210 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
1212 switches::kDataReductionProxyLoFi, | 1211 switches::kDataReductionProxyLoFi, |
1213 switches::kDataReductionProxyLoFiValueAlwaysOn); | 1212 switches::kDataReductionProxyLoFiValueAlwaysOn); |
1214 } | 1213 } |
1215 | 1214 |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1630 FetchURLRequestAndVerifyECTHeader(effective_connection_types[0], true, true); | 1629 FetchURLRequestAndVerifyECTHeader(effective_connection_types[0], true, true); |
1631 | 1630 |
1632 // When the ECT is set to a different value, the response should still be | 1631 // When the ECT is set to a different value, the response should still be |
1633 // served from the cache. | 1632 // served from the cache. |
1634 FetchURLRequestAndVerifyECTHeader(effective_connection_types[1], true, true); | 1633 FetchURLRequestAndVerifyECTHeader(effective_connection_types[1], true, true); |
1635 } | 1634 } |
1636 | 1635 |
1637 } // namespace | 1636 } // namespace |
1638 | 1637 |
1639 } // namespace data_reduction_proxy | 1638 } // namespace data_reduction_proxy |
OLD | NEW |