| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/content/browser/content_lofi_decider.h
" | 5 #include "components/data_reduction_proxy/content/browser/content_lofi_decider.h
" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 content::PreviewsState previews_state) { | 100 content::PreviewsState previews_state) { |
| 101 content::ResourceRequestInfo::AllocateForTesting( | 101 content::ResourceRequestInfo::AllocateForTesting( |
| 102 request, resource_type, NULL, -1, -1, -1, | 102 request, resource_type, NULL, -1, -1, -1, |
| 103 resource_type == content::RESOURCE_TYPE_MAIN_FRAME, | 103 resource_type == content::RESOURCE_TYPE_MAIN_FRAME, |
| 104 false, // parent_is_main_frame | 104 false, // parent_is_main_frame |
| 105 false, // allow_download | 105 false, // allow_download |
| 106 false, // is_async | 106 false, // is_async |
| 107 previews_state); | 107 previews_state); |
| 108 } | 108 } |
| 109 | 109 |
| 110 std::unique_ptr<net::URLRequest> CreateRequest(bool is_main_frame, | 110 std::unique_ptr<net::URLRequest> CreateRequest( |
| 111 bool is_using_lofi) { | 111 bool is_main_frame, |
| 112 content::PreviewsState previews_state) { |
| 112 std::unique_ptr<net::URLRequest> request = context_.CreateRequest( | 113 std::unique_ptr<net::URLRequest> request = context_.CreateRequest( |
| 113 GURL("http://www.google.com/"), net::IDLE, &delegate_); | 114 GURL("http://www.google.com/"), net::IDLE, &delegate_); |
| 114 AllocateRequestInfoForTesting( | 115 AllocateRequestInfoForTesting( |
| 115 request.get(), (is_main_frame ? content::RESOURCE_TYPE_MAIN_FRAME | 116 request.get(), (is_main_frame ? content::RESOURCE_TYPE_MAIN_FRAME |
| 116 : content::RESOURCE_TYPE_SUB_FRAME), | 117 : content::RESOURCE_TYPE_SUB_FRAME), |
| 117 is_using_lofi ? content::SERVER_LOFI_ON : content::PREVIEWS_OFF); | 118 previews_state); |
| 118 return request; | 119 return request; |
| 119 } | 120 } |
| 120 | 121 |
| 121 std::unique_ptr<net::URLRequest> CreateRequestByType( | 122 std::unique_ptr<net::URLRequest> CreateRequestByType( |
| 122 content::ResourceType resource_type, | 123 content::ResourceType resource_type, |
| 123 bool scheme_is_https, | 124 bool scheme_is_https, |
| 124 bool is_using_lofi) { | 125 content::PreviewsState previews_state) { |
| 125 std::unique_ptr<net::URLRequest> request = | 126 std::unique_ptr<net::URLRequest> request = |
| 126 context_.CreateRequest(GURL(scheme_is_https ? "https://www.google.com/" | 127 context_.CreateRequest(GURL(scheme_is_https ? "https://www.google.com/" |
| 127 : "http://www.google.com/"), | 128 : "http://www.google.com/"), |
| 128 net::IDLE, &delegate_); | 129 net::IDLE, &delegate_); |
| 129 AllocateRequestInfoForTesting( | 130 AllocateRequestInfoForTesting(request.get(), resource_type, previews_state); |
| 130 request.get(), resource_type, | |
| 131 is_using_lofi ? content::SERVER_LOFI_ON : content::PREVIEWS_OFF); | |
| 132 return request; | 131 return request; |
| 133 } | 132 } |
| 134 | 133 |
| 135 std::unique_ptr<net::URLRequest> CreateNoTransformRequest( | |
| 136 bool is_main_frame) { | |
| 137 std::unique_ptr<net::URLRequest> request = context_.CreateRequest( | |
| 138 GURL("http://www.google.com/"), net::IDLE, &delegate_); | |
| 139 AllocateRequestInfoForTesting( | |
| 140 request.get(), (is_main_frame ? content::RESOURCE_TYPE_MAIN_FRAME | |
| 141 : content::RESOURCE_TYPE_SUB_FRAME), | |
| 142 content::PREVIEWS_NO_TRANSFORM); | |
| 143 return request; | |
| 144 } | |
| 145 | |
| 146 void DelegateStageDone(int result) {} | 134 void DelegateStageDone(int result) {} |
| 147 | 135 |
| 148 void NotifyBeforeSendHeaders(net::HttpRequestHeaders* headers, | 136 void NotifyBeforeSendHeaders(net::HttpRequestHeaders* headers, |
| 149 net::URLRequest* request, | 137 net::URLRequest* request, |
| 150 bool use_data_reduction_proxy) { | 138 bool use_data_reduction_proxy) { |
| 151 net::ProxyInfo data_reduction_proxy_info; | 139 net::ProxyInfo data_reduction_proxy_info; |
| 152 net::ProxyRetryInfoMap proxy_retry_info; | 140 net::ProxyRetryInfoMap proxy_retry_info; |
| 153 | 141 |
| 154 if (use_data_reduction_proxy) { | 142 if (use_data_reduction_proxy) { |
| 155 std::string data_reduction_proxy; | 143 std::string data_reduction_proxy; |
| 156 base::TrimString(test_context_->config()->test_params()->DefaultOrigin(), | 144 base::TrimString(test_context_->config()->test_params()->DefaultOrigin(), |
| 157 "/", &data_reduction_proxy); | 145 "/", &data_reduction_proxy); |
| 158 data_reduction_proxy_info.UseNamedProxy(data_reduction_proxy); | 146 data_reduction_proxy_info.UseNamedProxy(data_reduction_proxy); |
| 159 } else { | 147 } else { |
| 160 data_reduction_proxy_info.UseNamedProxy("proxy.com"); | 148 data_reduction_proxy_info.UseNamedProxy("proxy.com"); |
| 161 } | 149 } |
| 162 | 150 |
| 163 data_reduction_proxy_network_delegate_->NotifyBeforeStartTransaction( | 151 data_reduction_proxy_network_delegate_->NotifyBeforeStartTransaction( |
| 164 request, base::Bind(&ContentLoFiDeciderTest::DelegateStageDone, | 152 request, base::Bind(&ContentLoFiDeciderTest::DelegateStageDone, |
| 165 base::Unretained(this)), | 153 base::Unretained(this)), |
| 166 headers); | 154 headers); |
| 167 data_reduction_proxy_network_delegate_->NotifyBeforeSendHeaders( | 155 data_reduction_proxy_network_delegate_->NotifyBeforeSendHeaders( |
| 168 request, data_reduction_proxy_info, proxy_retry_info, headers); | 156 request, data_reduction_proxy_info, proxy_retry_info, headers); |
| 169 } | 157 } |
| 170 | 158 |
| 171 static void VerifyLitePageHeader(bool expected_lite_page_used, | |
| 172 const net::HttpRequestHeaders& headers) { | |
| 173 if (expected_lite_page_used) | |
| 174 EXPECT_TRUE(headers.HasHeader(chrome_proxy_accept_transform_header())); | |
| 175 std::string header_value; | |
| 176 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value); | |
| 177 EXPECT_EQ(expected_lite_page_used, | |
| 178 header_value.find(lite_page_directive()) != std::string::npos); | |
| 179 } | |
| 180 | |
| 181 static void VerifyLoFiHeader(bool expected_lofi_used, | 159 static void VerifyLoFiHeader(bool expected_lofi_used, |
| 182 bool expected_if_heavy, | 160 bool expected_if_heavy, |
| 183 const net::HttpRequestHeaders& headers) { | 161 const net::HttpRequestHeaders& headers) { |
| 184 if (expected_lofi_used) | 162 if (expected_lofi_used) |
| 185 EXPECT_TRUE(headers.HasHeader(chrome_proxy_accept_transform_header())); | 163 EXPECT_TRUE(headers.HasHeader(chrome_proxy_accept_transform_header())); |
| 186 std::string header_value; | 164 std::string header_value; |
| 187 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value); | 165 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value); |
| 188 if (expected_if_heavy) { | 166 if (expected_if_heavy) { |
| 189 std::string empty_image_if_heavy = base::StringPrintf( | 167 std::string empty_image_if_heavy = base::StringPrintf( |
| 190 "%s;%s", empty_image_directive(), if_heavy_qualifier()); | 168 "%s;%s", empty_image_directive(), if_heavy_qualifier()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 bool is_using_lofi; | 227 bool is_using_lofi; |
| 250 bool is_using_lite_page; | 228 bool is_using_lite_page; |
| 251 bool is_main_frame; | 229 bool is_main_frame; |
| 252 } tests[] = { | 230 } tests[] = { |
| 253 {false, false, false}, {false, false, true}, {true, false, true}, | 231 {false, false, false}, {false, false, true}, {true, false, true}, |
| 254 {true, false, false}, {false, true, false}, {false, true, true}, | 232 {true, false, false}, {false, true, false}, {false, true, true}, |
| 255 {true, true, true}, {true, true, false}, | 233 {true, true, true}, {true, true, false}, |
| 256 }; | 234 }; |
| 257 | 235 |
| 258 for (size_t i = 0; i < arraysize(tests); ++i) { | 236 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 237 content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED; |
| 238 if (tests[i].is_using_lofi) |
| 239 previews_state |= content::SERVER_LOFI_ON; |
| 240 if (tests[i].is_using_lite_page) |
| 241 previews_state |= content::SERVER_LITE_PAGE_ON; |
| 242 if (previews_state == content::PREVIEWS_UNSPECIFIED) |
| 243 previews_state = content::PREVIEWS_OFF; |
| 244 |
| 259 std::unique_ptr<net::URLRequest> request = | 245 std::unique_ptr<net::URLRequest> request = |
| 260 CreateRequest(tests[i].is_main_frame, tests[i].is_using_lofi); | 246 CreateRequest(tests[i].is_main_frame, previews_state); |
| 261 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 247 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 262 command_line->InitFromArgv(command_line->argv()); | 248 command_line->InitFromArgv(command_line->argv()); |
| 263 if (tests[i].is_using_lite_page) { | 249 if (tests[i].is_using_lite_page) { |
| 264 command_line->AppendSwitch(switches::kEnableDataReductionProxyLitePage); | 250 command_line->AppendSwitch(switches::kEnableDataReductionProxyLitePage); |
| 265 } | 251 } |
| 266 | 252 |
| 267 // No flags or field trials. The Lo-Fi header should not be added. | 253 // No flags or field trials. The Lo-Fi header should not be added. |
| 268 net::HttpRequestHeaders headers; | 254 net::HttpRequestHeaders headers; |
| 269 NotifyBeforeSendHeaders(&headers, request.get(), true); | 255 NotifyBeforeSendHeaders(&headers, request.get(), true); |
| 270 VerifyLoFiHeader(false, false, headers); | 256 VerifyLoFiHeader(false, false, headers); |
| 271 VerifyLitePageHeader(false, false, headers); | 257 VerifyLitePageHeader(false, false, headers); |
| 272 VerifyLitePageIgnoreBlacklistHeader(false, headers); | 258 VerifyLitePageIgnoreBlacklistHeader(false, headers); |
| 273 | 259 |
| 274 // The Lo-Fi flag is "always-on", Lo-Fi is being used, and it's a main frame | 260 // The Lo-Fi flag is "always-on", Lo-Fi is being used, and it's a main frame |
| 275 // request. Lo-Fi or lite page header should be added. | 261 // request. Lo-Fi or lite page header should be added. |
| 276 command_line->AppendSwitchASCII( | 262 command_line->AppendSwitchASCII( |
| 277 switches::kDataReductionProxyLoFi, | 263 switches::kDataReductionProxyLoFi, |
| 278 switches::kDataReductionProxyLoFiValueAlwaysOn); | 264 switches::kDataReductionProxyLoFiValueAlwaysOn); |
| 279 headers.Clear(); | 265 headers.Clear(); |
| 280 NotifyBeforeSendHeaders(&headers, request.get(), true); | 266 NotifyBeforeSendHeaders(&headers, request.get(), true); |
| 281 VerifyLoFiHeader(!tests[i].is_using_lite_page && !tests[i].is_main_frame, | 267 VerifyLoFiHeader(!tests[i].is_main_frame && !tests[i].is_using_lite_page, |
| 282 !tests[i].is_using_lofi, headers); | 268 !tests[i].is_main_frame && !tests[i].is_using_lofi && |
| 269 !tests[i].is_using_lite_page, |
| 270 headers); |
| 283 VerifyLitePageHeader(tests[i].is_using_lite_page && tests[i].is_main_frame, | 271 VerifyLitePageHeader(tests[i].is_using_lite_page && tests[i].is_main_frame, |
| 284 !tests[i].is_using_lofi, headers); | 272 false, headers); |
| 285 VerifyLitePageIgnoreBlacklistHeader( | 273 VerifyLitePageIgnoreBlacklistHeader( |
| 286 tests[i].is_using_lite_page && tests[i].is_main_frame, headers); | 274 tests[i].is_using_lite_page && tests[i].is_main_frame, headers); |
| 287 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); | 275 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); |
| 288 // |lofi_requested| should be set to false when Lo-Fi is enabled using | 276 // |lofi_requested| should be set to false when Lo-Fi is enabled using |
| 289 // flags. | 277 // flags. |
| 290 EXPECT_FALSE(data->lofi_requested()); | 278 EXPECT_FALSE(data->lofi_requested()); |
| 291 | 279 |
| 292 // The Lo-Fi flag is "always-on" and Lo-Fi is being used. Lo-Fi header | 280 // The Lo-Fi flag is "always-on" and Lo-Fi is being used. Lo-Fi header |
| 293 // should be added. | 281 // should be added. |
| 294 AllocateRequestInfoForTesting( | 282 AllocateRequestInfoForTesting( |
| 295 request.get(), content::RESOURCE_TYPE_SUB_FRAME, | 283 request.get(), content::RESOURCE_TYPE_SUB_FRAME, previews_state); |
| 296 tests[i].is_using_lofi ? content::SERVER_LOFI_ON | |
| 297 : content::PREVIEWS_OFF); | |
| 298 headers.Clear(); | 284 headers.Clear(); |
| 299 NotifyBeforeSendHeaders(&headers, request.get(), true); | 285 NotifyBeforeSendHeaders(&headers, request.get(), true); |
| 300 VerifyLoFiHeader(!tests[i].is_using_lite_page, !tests[i].is_using_lofi, | 286 VerifyLoFiHeader(!tests[i].is_using_lite_page, !tests[i].is_using_lofi, |
| 301 headers); | 287 headers); |
| 302 VerifyLitePageHeader(false, false, headers); | 288 VerifyLitePageHeader(false, false, headers); |
| 303 VerifyLitePageIgnoreBlacklistHeader(false, headers); | 289 VerifyLitePageIgnoreBlacklistHeader(false, headers); |
| 304 | 290 |
| 305 // The Lo-Fi flag is "cellular-only" and Lo-Fi is being used. Lo-Fi header | 291 // The Lo-Fi flag is "cellular-only" and Lo-Fi is being used. Lo-Fi header |
| 306 // should be added. | 292 // should be added. |
| 307 command_line->AppendSwitchASCII( | 293 command_line->AppendSwitchASCII( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 {true, content::RESOURCE_TYPE_SHARED_WORKER}, | 362 {true, content::RESOURCE_TYPE_SHARED_WORKER}, |
| 377 {true, content::RESOURCE_TYPE_PREFETCH}, | 363 {true, content::RESOURCE_TYPE_PREFETCH}, |
| 378 {true, content::RESOURCE_TYPE_FAVICON}, | 364 {true, content::RESOURCE_TYPE_FAVICON}, |
| 379 {true, content::RESOURCE_TYPE_XHR}, | 365 {true, content::RESOURCE_TYPE_XHR}, |
| 380 {true, content::RESOURCE_TYPE_PING}, | 366 {true, content::RESOURCE_TYPE_PING}, |
| 381 {true, content::RESOURCE_TYPE_SERVICE_WORKER}, | 367 {true, content::RESOURCE_TYPE_SERVICE_WORKER}, |
| 382 {true, content::RESOURCE_TYPE_CSP_REPORT}, | 368 {true, content::RESOURCE_TYPE_CSP_REPORT}, |
| 383 {true, content::RESOURCE_TYPE_PLUGIN_RESOURCE}}; | 369 {true, content::RESOURCE_TYPE_PLUGIN_RESOURCE}}; |
| 384 | 370 |
| 385 for (size_t i = 0; i < arraysize(tests); ++i) { | 371 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 386 std::unique_ptr<net::URLRequest> request = CreateRequestByType( | 372 std::unique_ptr<net::URLRequest> request = |
| 387 tests[i].resource_type, false, tests[i].is_using_lofi); | 373 CreateRequestByType(tests[i].resource_type, false, |
| 374 tests[i].is_using_lofi ? content::SERVER_LOFI_ON |
| 375 : content::PREVIEWS_OFF); |
| 388 net::HttpRequestHeaders headers; | 376 net::HttpRequestHeaders headers; |
| 389 NotifyBeforeSendHeaders(&headers, request.get(), true); | 377 NotifyBeforeSendHeaders(&headers, request.get(), true); |
| 390 bool is_lofi_resource_type = | 378 bool is_lofi_resource_type = |
| 391 !(tests[i].resource_type == content::RESOURCE_TYPE_MAIN_FRAME || | 379 !(tests[i].resource_type == content::RESOURCE_TYPE_MAIN_FRAME || |
| 392 tests[i].resource_type == content::RESOURCE_TYPE_STYLESHEET || | 380 tests[i].resource_type == content::RESOURCE_TYPE_STYLESHEET || |
| 393 tests[i].resource_type == content::RESOURCE_TYPE_SCRIPT || | 381 tests[i].resource_type == content::RESOURCE_TYPE_SCRIPT || |
| 394 tests[i].resource_type == content::RESOURCE_TYPE_FONT_RESOURCE || | 382 tests[i].resource_type == content::RESOURCE_TYPE_FONT_RESOURCE || |
| 395 tests[i].resource_type == content::RESOURCE_TYPE_MEDIA || | 383 tests[i].resource_type == content::RESOURCE_TYPE_MEDIA || |
| 396 tests[i].resource_type == content::RESOURCE_TYPE_CSP_REPORT); | 384 tests[i].resource_type == content::RESOURCE_TYPE_CSP_REPORT); |
| 397 | 385 |
| 398 VerifyLoFiHeader(is_lofi_resource_type, !tests[i].is_using_lofi, headers); | 386 VerifyLoFiHeader(is_lofi_resource_type, !tests[i].is_using_lofi, headers); |
| 399 VerifyLitePageHeader(false, false, headers); | 387 VerifyLitePageHeader(false, false, headers); |
| 400 VerifyLitePageIgnoreBlacklistHeader(false, headers); | 388 VerifyLitePageIgnoreBlacklistHeader(false, headers); |
| 401 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); | 389 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); |
| 402 EXPECT_EQ(tests[i].is_using_lofi, data->lofi_requested()) << i; | 390 EXPECT_EQ(tests[i].is_using_lofi, data->lofi_requested()) << i; |
| 403 } | 391 } |
| 404 } | 392 } |
| 405 | 393 |
| 406 TEST_F(ContentLoFiDeciderTest, LoFiControlFieldTrial) { | 394 TEST_F(ContentLoFiDeciderTest, LoFiControlFieldTrial) { |
| 407 base::FieldTrialList field_trial_list(nullptr); | 395 base::FieldTrialList field_trial_list(nullptr); |
| 408 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), | 396 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 409 "Control"); | 397 "Control"); |
| 410 // Enable Lo-Fi. | 398 // Enable Lo-Fi. |
| 411 const struct { | 399 const struct { |
| 412 bool is_using_lofi; | 400 bool is_using_lofi; |
| 413 bool is_main_frame; | 401 bool is_main_frame; |
| 414 } tests[] = {{false, false}, {false, true}, {true, false}, {true, true}}; | 402 } tests[] = {{false, false}, {false, true}, {true, false}, {true, true}}; |
| 415 | 403 |
| 416 for (size_t i = 0; i < arraysize(tests); ++i) { | 404 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 417 std::unique_ptr<net::URLRequest> request = | 405 std::unique_ptr<net::URLRequest> request = CreateRequest( |
| 418 CreateRequest(tests[i].is_main_frame, tests[i].is_using_lofi); | 406 tests[i].is_main_frame, tests[i].is_using_lofi ? content::SERVER_LOFI_ON |
| 407 : content::PREVIEWS_OFF); |
| 419 net::HttpRequestHeaders headers; | 408 net::HttpRequestHeaders headers; |
| 420 NotifyBeforeSendHeaders(&headers, request.get(), true); | 409 NotifyBeforeSendHeaders(&headers, request.get(), true); |
| 421 VerifyLoFiHeader(false, false, headers); | 410 VerifyLoFiHeader(false, false, headers); |
| 422 VerifyLitePageHeader(false, false, headers); | 411 VerifyLitePageHeader(false, false, headers); |
| 423 VerifyLitePageIgnoreBlacklistHeader(false, headers); | 412 VerifyLitePageIgnoreBlacklistHeader(false, headers); |
| 424 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); | 413 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); |
| 425 EXPECT_EQ(tests[i].is_using_lofi, data->lofi_requested()) << i; | 414 EXPECT_EQ(tests[i].is_using_lofi, data->lofi_requested()) << i; |
| 426 } | 415 } |
| 427 } | 416 } |
| 428 | 417 |
| 429 TEST_F(ContentLoFiDeciderTest, LitePageFieldTrial) { | 418 TEST_F(ContentLoFiDeciderTest, LitePageFieldTrial) { |
| 430 base::FieldTrialList field_trial_list(nullptr); | 419 base::FieldTrialList field_trial_list(nullptr); |
| 431 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), | 420 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 432 "Enabled_Preview"); | 421 "Enabled_Preview"); |
| 433 // Enable Lo-Fi. | 422 // Enable Lo-Fi. |
| 434 const struct { | 423 const struct { |
| 435 bool is_using_lofi; | 424 bool is_using_lite_page; |
| 436 bool is_main_frame; | 425 bool is_main_frame; |
| 437 } tests[] = { | 426 } tests[] = { |
| 438 {false, false}, {true, false}, {false, true}, {true, true}, | 427 {false, false}, {true, false}, {false, true}, {true, true}, |
| 439 }; | 428 }; |
| 440 | 429 |
| 441 for (size_t i = 0; i < arraysize(tests); ++i) { | 430 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 442 std::unique_ptr<net::URLRequest> request = | 431 std::unique_ptr<net::URLRequest> request = |
| 443 CreateRequest(tests[i].is_main_frame, tests[i].is_using_lofi); | 432 CreateRequest(tests[i].is_main_frame, tests[i].is_using_lite_page |
| 433 ? content::SERVER_LITE_PAGE_ON |
| 434 : content::PREVIEWS_OFF); |
| 444 net::HttpRequestHeaders headers; | 435 net::HttpRequestHeaders headers; |
| 445 NotifyBeforeSendHeaders(&headers, request.get(), true); | 436 NotifyBeforeSendHeaders(&headers, request.get(), true); |
| 446 VerifyLoFiHeader(false, false, headers); | 437 VerifyLoFiHeader(false, false, headers); |
| 447 VerifyLitePageHeader(tests[i].is_main_frame, !tests[i].is_using_lofi, | 438 VerifyLitePageHeader(tests[i].is_main_frame, !tests[i].is_using_lite_page, |
| 448 headers); | 439 headers); |
| 449 VerifyLitePageIgnoreBlacklistHeader(false, headers); | 440 VerifyLitePageIgnoreBlacklistHeader(false, headers); |
| 450 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); | 441 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); |
| 451 EXPECT_EQ(tests[i].is_using_lofi, data->lofi_requested()) << i; | 442 EXPECT_EQ(tests[i].is_using_lite_page, data->lofi_requested()) << i; |
| 452 } | 443 } |
| 453 } | 444 } |
| 454 | 445 |
| 446 TEST_F(ContentLoFiDeciderTest, LitePageFieldTrialFallbackToLoFi) { |
| 447 base::FieldTrialList field_trial_list(nullptr); |
| 448 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 449 "Enabled_Preview"); |
| 450 // Enable Lo-Fi. |
| 451 const struct { |
| 452 bool is_using_lofi; |
| 453 bool is_using_lite_page; |
| 454 bool is_main_frame; |
| 455 } tests[] = { |
| 456 {false, false, false}, {false, false, true}, {true, false, true}, |
| 457 {true, false, false}, {false, true, false}, {false, true, true}, |
| 458 {true, true, true}, {true, true, false}, |
| 459 }; |
| 460 |
| 461 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 462 content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED; |
| 463 if (tests[i].is_using_lofi) |
| 464 previews_state |= content::SERVER_LOFI_ON; |
| 465 if (tests[i].is_using_lite_page) |
| 466 previews_state |= content::SERVER_LITE_PAGE_ON; |
| 467 if (previews_state == content::PREVIEWS_UNSPECIFIED) |
| 468 previews_state = content::PREVIEWS_OFF; |
| 469 |
| 470 std::unique_ptr<net::URLRequest> request = |
| 471 CreateRequest(tests[i].is_main_frame, previews_state); |
| 472 net::HttpRequestHeaders headers; |
| 473 NotifyBeforeSendHeaders(&headers, request.get(), true); |
| 474 VerifyLoFiHeader(!tests[i].is_main_frame && !tests[i].is_using_lite_page, |
| 475 !tests[i].is_main_frame && !tests[i].is_using_lofi && |
| 476 !tests[i].is_using_lite_page, |
| 477 headers); |
| 478 VerifyLitePageHeader(tests[i].is_main_frame, |
| 479 tests[i].is_main_frame && !tests[i].is_using_lite_page, |
| 480 headers); |
| 481 VerifyLitePageIgnoreBlacklistHeader(false, headers); |
| 482 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); |
| 483 EXPECT_EQ(tests[i].is_using_lofi || tests[i].is_using_lite_page, |
| 484 data->lofi_requested()) |
| 485 << i; |
| 486 } |
| 487 } |
| 488 |
| 455 TEST_F(ContentLoFiDeciderTest, AutoLoFi) { | 489 TEST_F(ContentLoFiDeciderTest, AutoLoFi) { |
| 456 const struct { | 490 const struct { |
| 457 bool auto_lofi_enabled_group; | 491 bool auto_lofi_enabled_group; |
| 458 bool auto_lofi_control_group; | 492 bool auto_lofi_control_group; |
| 459 bool network_prohibitively_slow; | 493 bool network_prohibitively_slow; |
| 460 bool is_main_frame; | 494 bool is_main_frame; |
| 461 } tests[] = { | 495 } tests[] = { |
| 462 {false, false, false, false}, | 496 {false, false, false, false}, |
| 463 {false, false, true, false}, | 497 {false, false, true, false}, |
| 464 {true, false, false, false}, | 498 {true, false, false, false}, |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 VerifyLoFiHeader(expect_lofi_header, false, headers); | 586 VerifyLoFiHeader(expect_lofi_header, false, headers); |
| 553 } | 587 } |
| 554 } | 588 } |
| 555 | 589 |
| 556 TEST_F(ContentLoFiDeciderTest, ProxyIsNotDataReductionProxy) { | 590 TEST_F(ContentLoFiDeciderTest, ProxyIsNotDataReductionProxy) { |
| 557 base::FieldTrialList field_trial_list(nullptr); | 591 base::FieldTrialList field_trial_list(nullptr); |
| 558 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), | 592 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 559 "Enabled"); | 593 "Enabled"); |
| 560 // Enable Lo-Fi. | 594 // Enable Lo-Fi. |
| 561 const struct { | 595 const struct { |
| 562 bool is_using_lofi; | 596 content::PreviewsState previews_state; |
| 563 } tests[] = { | 597 } tests[] = { |
| 564 {false}, {true}, | 598 {content::PREVIEWS_OFF}, {content::SERVER_LOFI_ON}, |
| 565 }; | 599 }; |
| 566 | 600 |
| 567 for (size_t i = 0; i < arraysize(tests); ++i) { | 601 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 568 std::unique_ptr<net::URLRequest> request = | 602 std::unique_ptr<net::URLRequest> request = |
| 569 CreateRequest(false, tests[i].is_using_lofi); | 603 CreateRequest(false, tests[i].previews_state); |
| 570 net::HttpRequestHeaders headers; | 604 net::HttpRequestHeaders headers; |
| 571 NotifyBeforeSendHeaders(&headers, request.get(), false); | 605 NotifyBeforeSendHeaders(&headers, request.get(), false); |
| 572 std::string header_value; | 606 std::string header_value; |
| 573 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value); | 607 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value); |
| 574 EXPECT_EQ(std::string::npos, header_value.find(empty_image_directive())); | 608 EXPECT_EQ(std::string::npos, header_value.find(empty_image_directive())); |
| 575 } | 609 } |
| 576 } | 610 } |
| 577 | 611 |
| 578 TEST_F(ContentLoFiDeciderTest, VideoDirectiveNotOverridden) { | 612 TEST_F(ContentLoFiDeciderTest, VideoDirectiveNotOverridden) { |
| 579 base::FieldTrialList field_trial_list(nullptr); | 613 base::FieldTrialList field_trial_list(nullptr); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 lofi_decider->MaybeSetIgnorePreviewsBlacklistDirective(&headers); | 729 lofi_decider->MaybeSetIgnorePreviewsBlacklistDirective(&headers); |
| 696 EXPECT_TRUE(headers.HasHeader(chrome_proxy_header())); | 730 EXPECT_TRUE(headers.HasHeader(chrome_proxy_header())); |
| 697 headers.GetHeader(chrome_proxy_header(), &header_value); | 731 headers.GetHeader(chrome_proxy_header(), &header_value); |
| 698 EXPECT_EQ("Foo, exp=ignore_preview_blacklist", header_value); | 732 EXPECT_EQ("Foo, exp=ignore_preview_blacklist", header_value); |
| 699 } | 733 } |
| 700 | 734 |
| 701 TEST_F(ContentLoFiDeciderTest, NoTransformDoesNotAddHeader) { | 735 TEST_F(ContentLoFiDeciderTest, NoTransformDoesNotAddHeader) { |
| 702 base::FieldTrialList field_trial_list(nullptr); | 736 base::FieldTrialList field_trial_list(nullptr); |
| 703 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), | 737 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 704 "Enabled"); | 738 "Enabled"); |
| 705 std::unique_ptr<net::URLRequest> request = CreateNoTransformRequest(false); | 739 std::unique_ptr<net::URLRequest> request = |
| 740 CreateRequest(false, content::PREVIEWS_NO_TRANSFORM); |
| 706 net::HttpRequestHeaders headers; | 741 net::HttpRequestHeaders headers; |
| 707 NotifyBeforeSendHeaders(&headers, request.get(), true); | 742 NotifyBeforeSendHeaders(&headers, request.get(), true); |
| 708 EXPECT_FALSE(headers.HasHeader(chrome_proxy_accept_transform_header())); | 743 EXPECT_FALSE(headers.HasHeader(chrome_proxy_accept_transform_header())); |
| 709 } | 744 } |
| 710 | 745 |
| 711 } // namespace data_reduction_proxy | 746 } // namespace data_reduction_proxy |
| OLD | NEW |