Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/test/scoped_feature_list.h" | |
| 18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig_test_utils.h" | 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig_test_utils.h" |
| 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h" | 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h" |
| 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw ork_delegate.h" | 22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw ork_delegate.h" |
| 22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ est_options.h" | 23 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ est_options.h" |
| 23 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h" | 24 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h" |
| 25 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_featu res.h" | |
| 24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" | 26 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" |
| 25 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" | 27 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" |
| 26 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s_test_utils.h" | 28 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s_test_utils.h" |
| 27 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" | 29 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" |
| 28 #include "content/public/browser/resource_request_info.h" | 30 #include "content/public/browser/resource_request_info.h" |
| 29 #include "content/public/common/previews_state.h" | 31 #include "content/public/common/previews_state.h" |
| 30 #include "net/base/load_flags.h" | 32 #include "net/base/load_flags.h" |
| 31 #include "net/base/network_delegate_impl.h" | 33 #include "net/base/network_delegate_impl.h" |
| 32 #include "net/http/http_request_headers.h" | 34 #include "net/http/http_request_headers.h" |
| 33 #include "net/proxy/proxy_info.h" | 35 #include "net/proxy/proxy_info.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value); | 186 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value); |
| 185 if (expected_if_heavy) { | 187 if (expected_if_heavy) { |
| 186 std::string lite_page_if_heavy = base::StringPrintf( | 188 std::string lite_page_if_heavy = base::StringPrintf( |
| 187 "%s;%s", lite_page_directive(), if_heavy_qualifier()); | 189 "%s;%s", lite_page_directive(), if_heavy_qualifier()); |
| 188 EXPECT_EQ(expected_lofi_preview_used, lite_page_if_heavy == header_value); | 190 EXPECT_EQ(expected_lofi_preview_used, lite_page_if_heavy == header_value); |
| 189 } else { | 191 } else { |
| 190 EXPECT_EQ(expected_lofi_preview_used, | 192 EXPECT_EQ(expected_lofi_preview_used, |
| 191 header_value == lite_page_directive()); | 193 header_value == lite_page_directive()); |
| 192 } | 194 } |
| 193 } | 195 } |
| 194 | 196 |
|
megjablon
2017/06/01 00:06:21
Can we move even more of the repetitive code:
sta
dougarnett
2017/06/01 18:16:48
Pulling in the target api call helps quite a bit.
| |
| 197 static void VerifyAcceptTransformHeader( | |
| 198 bool expected_accept_lite_page, | |
| 199 bool expected_accept_empty_image, | |
| 200 const net::HttpRequestHeaders& headers) { | |
| 201 if (expected_accept_lite_page || expected_accept_empty_image) { | |
| 202 EXPECT_TRUE(headers.HasHeader(chrome_proxy_accept_transform_header())); | |
| 203 std::string header_value; | |
| 204 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value); | |
| 205 if (expected_accept_lite_page) { | |
| 206 EXPECT_TRUE(header_value == lite_page_directive()); | |
| 207 } else if (expected_accept_empty_image) { | |
| 208 EXPECT_TRUE(header_value == empty_image_directive()); | |
| 209 } | |
| 210 } else { | |
| 211 EXPECT_FALSE(headers.HasHeader(chrome_proxy_accept_transform_header())); | |
| 212 } | |
| 213 } | |
| 214 | |
| 195 static void VerifyVideoHeader(bool expected_compressed_video_used, | 215 static void VerifyVideoHeader(bool expected_compressed_video_used, |
| 196 const net::HttpRequestHeaders& headers) { | 216 const net::HttpRequestHeaders& headers) { |
| 197 EXPECT_EQ(expected_compressed_video_used, | 217 EXPECT_EQ(expected_compressed_video_used, |
| 198 headers.HasHeader(chrome_proxy_accept_transform_header())); | 218 headers.HasHeader(chrome_proxy_accept_transform_header())); |
| 199 std::string header_value; | 219 std::string header_value; |
| 200 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value); | 220 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value); |
| 201 EXPECT_EQ( | 221 EXPECT_EQ( |
| 202 expected_compressed_video_used, | 222 expected_compressed_video_used, |
| 203 header_value.find(compressed_video_directive()) != std::string::npos); | 223 header_value.find(compressed_video_directive()) != std::string::npos); |
| 204 } | 224 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 VerifyLoFiHeader(!tests[i].is_using_lite_page, !tests[i].is_using_lofi, | 319 VerifyLoFiHeader(!tests[i].is_using_lite_page, !tests[i].is_using_lofi, |
| 300 headers); | 320 headers); |
| 301 VerifyLitePageHeader(false, false, headers); | 321 VerifyLitePageHeader(false, false, headers); |
| 302 data = DataReductionProxyData::GetData(*request); | 322 data = DataReductionProxyData::GetData(*request); |
| 303 // |lofi_requested| should be set to false when Lo-Fi is enabled using | 323 // |lofi_requested| should be set to false when Lo-Fi is enabled using |
| 304 // flags. | 324 // flags. |
| 305 EXPECT_FALSE(data->lofi_requested()); | 325 EXPECT_FALSE(data->lofi_requested()); |
| 306 } | 326 } |
| 307 } | 327 } |
| 308 | 328 |
| 329 TEST_F(ContentLoFiDeciderTest, MaybeSetAcceptTransformNoAcceptForPreviewsOff) { | |
| 330 // Turn on proxy-decides-transform feature for these unit tests. | |
| 331 base::test::ScopedFeatureList scoped_feature_list; | |
| 332 scoped_feature_list.InitAndEnableFeature( | |
| 333 features::kDataReductionProxyDecidesTransform); | |
| 334 | |
| 335 std::unique_ptr<data_reduction_proxy::ContentLoFiDecider> lofi_decider( | |
| 336 new data_reduction_proxy::ContentLoFiDecider()); | |
| 337 | |
| 338 content::PreviewsState both_previews_enabled = | |
| 339 content::SERVER_LITE_PAGE_ON | content::SERVER_LOFI_ON; | |
| 340 | |
| 341 // Verify no accept header if previews state indicates to not accept. | |
| 342 content::PreviewsState previews_off = | |
| 343 content::PREVIEWS_OFF & both_previews_enabled; | |
| 344 std::unique_ptr<net::URLRequest> request = | |
| 345 CreateRequest(true /* is main */, previews_off); | |
| 346 net::HttpRequestHeaders headers; | |
| 347 lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false, &headers); | |
| 348 VerifyAcceptTransformHeader(false /* lite-page */, false /* empty-image */, | |
| 349 headers); | |
| 350 | |
| 351 content::PreviewsState previews_no_transform = | |
| 352 content::PREVIEWS_NO_TRANSFORM & both_previews_enabled; | |
| 353 request = CreateRequest(true /* is main */, previews_no_transform); | |
| 354 lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false, &headers); | |
| 355 VerifyAcceptTransformHeader(false /* lite-page */, false /* empty-image */, | |
| 356 headers); | |
| 357 } | |
| 358 | |
| 359 TEST_F(ContentLoFiDeciderTest, MaybeSetAcceptTransformNoAcceptForHttps) { | |
| 360 // Turn on proxy-decides-transform feature for these unit tests. | |
| 361 base::test::ScopedFeatureList scoped_feature_list; | |
| 362 scoped_feature_list.InitAndEnableFeature( | |
| 363 features::kDataReductionProxyDecidesTransform); | |
| 364 | |
| 365 std::unique_ptr<data_reduction_proxy::ContentLoFiDecider> lofi_decider( | |
| 366 new data_reduction_proxy::ContentLoFiDecider()); | |
| 367 | |
| 368 content::PreviewsState both_previews_enabled = | |
| 369 content::SERVER_LITE_PAGE_ON | content::SERVER_LOFI_ON; | |
| 370 | |
| 371 // Verify no accept header for HTTPS. | |
| 372 std::unique_ptr<net::URLRequest> request = | |
| 373 CreateRequestByType(content::RESOURCE_TYPE_MAIN_FRAME, true /* https */, | |
| 374 both_previews_enabled); | |
| 375 net::HttpRequestHeaders headers; | |
| 376 lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false, &headers); | |
| 377 VerifyAcceptTransformHeader(false /* lite-page */, false /* empty-image */, | |
| 378 headers); | |
| 379 | |
| 380 request = CreateRequestByType(content::RESOURCE_TYPE_IMAGE, true /* https */, | |
| 381 both_previews_enabled); | |
| 382 lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false, &headers); | |
| 383 VerifyAcceptTransformHeader(false /* lite-page */, false /* empty-image */, | |
| 384 headers); | |
| 385 } | |
| 386 | |
| 387 TEST_F(ContentLoFiDeciderTest, MaybeSetAcceptTransformHeaderAcceptLitePage) { | |
| 388 // Turn on proxy-decides-transform feature for these unit tests. | |
| 389 base::test::ScopedFeatureList scoped_feature_list; | |
| 390 scoped_feature_list.InitAndEnableFeature( | |
| 391 features::kDataReductionProxyDecidesTransform); | |
| 392 | |
| 393 std::unique_ptr<data_reduction_proxy::ContentLoFiDecider> lofi_decider( | |
| 394 new data_reduction_proxy::ContentLoFiDecider()); | |
| 395 | |
| 396 content::PreviewsState lite_page_enabled = content::SERVER_LITE_PAGE_ON; | |
| 397 | |
| 398 // Verify accepting lite-page per resource type. | |
| 399 std::unique_ptr<net::URLRequest> request = | |
| 400 CreateRequest(true /* is main */, lite_page_enabled); | |
| 401 net::HttpRequestHeaders headers1; | |
| 402 lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false, &headers1); | |
| 403 VerifyAcceptTransformHeader(true /* lite-page */, false /* empty-image */, | |
| 404 headers1); | |
| 405 | |
| 406 net::HttpRequestHeaders headers2; | |
| 407 request = CreateRequest(false /* is main */, lite_page_enabled); | |
| 408 lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false, &headers2); | |
| 409 VerifyAcceptTransformHeader(false /* lite-page */, false /* empty-image */, | |
| 410 headers2); | |
| 411 } | |
| 412 | |
| 413 TEST_F(ContentLoFiDeciderTest, MaybeSetAcceptTransformHeaderAcceptEmptyImage) { | |
| 414 // Turn on proxy-decides-transform feature for these unit tests. | |
| 415 base::test::ScopedFeatureList scoped_feature_list; | |
| 416 scoped_feature_list.InitAndEnableFeature( | |
| 417 features::kDataReductionProxyDecidesTransform); | |
| 418 | |
| 419 std::unique_ptr<data_reduction_proxy::ContentLoFiDecider> lofi_decider( | |
| 420 new data_reduction_proxy::ContentLoFiDecider()); | |
| 421 | |
| 422 content::PreviewsState lofi_enabled = content::SERVER_LOFI_ON; | |
| 423 | |
| 424 // Verify accepting empty-image per resource type. | |
| 425 std::unique_ptr<net::URLRequest> request = CreateRequestByType( | |
| 426 content::RESOURCE_TYPE_MAIN_FRAME, false /* https */, lofi_enabled); | |
| 427 net::HttpRequestHeaders headers1; | |
| 428 lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false, &headers1); | |
| 429 VerifyAcceptTransformHeader(false /* lite-page */, false /* empty-image */, | |
| 430 headers1); | |
| 431 | |
| 432 net::HttpRequestHeaders headers2; | |
| 433 request = CreateRequestByType(content::RESOURCE_TYPE_IMAGE, false /* https */, | |
| 434 lofi_enabled); | |
| 435 lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false, &headers2); | |
| 436 VerifyAcceptTransformHeader(false /* lite-page */, true /* empty-image */, | |
| 437 headers2); | |
| 438 | |
| 439 net::HttpRequestHeaders headers3; | |
| 440 request = CreateRequestByType(content::RESOURCE_TYPE_FAVICON, | |
| 441 false /* https */, lofi_enabled); | |
| 442 lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false, &headers3); | |
| 443 VerifyAcceptTransformHeader(false /* lite-page */, true /* empty-image */, | |
| 444 headers3); | |
| 445 | |
| 446 net::HttpRequestHeaders headers4; | |
| 447 request = CreateRequestByType(content::RESOURCE_TYPE_SCRIPT, | |
| 448 false /* https */, lofi_enabled); | |
| 449 lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false, &headers4); | |
| 450 VerifyAcceptTransformHeader(false /* lite-page */, false /* empty-image */, | |
| 451 headers4); | |
| 452 | |
| 453 net::HttpRequestHeaders headers5; | |
| 454 request = CreateRequestByType(content::RESOURCE_TYPE_STYLESHEET, | |
| 455 false /* https */, lofi_enabled); | |
| 456 lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false, &headers5); | |
| 457 VerifyAcceptTransformHeader(false /* lite-page */, false /* empty-image */, | |
| 458 headers5); | |
| 459 } | |
| 460 | |
| 309 TEST_F(ContentLoFiDeciderTest, LoFiEnabledFieldTrial) { | 461 TEST_F(ContentLoFiDeciderTest, LoFiEnabledFieldTrial) { |
| 310 base::FieldTrialList field_trial_list(nullptr); | 462 base::FieldTrialList field_trial_list(nullptr); |
| 311 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), | 463 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 312 "Enabled"); | 464 "Enabled"); |
| 313 | 465 |
| 314 // Enable Lo-Fi. | 466 // Enable Lo-Fi. |
| 315 const struct { | 467 const struct { |
| 316 bool is_using_lofi; | 468 bool is_using_lofi; |
| 317 content::ResourceType resource_type; | 469 content::ResourceType resource_type; |
| 318 } tests[] = {{false, content::RESOURCE_TYPE_MAIN_FRAME}, | 470 } tests[] = {{false, content::RESOURCE_TYPE_MAIN_FRAME}, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 net::HttpRequestHeaders headers; | 544 net::HttpRequestHeaders headers; |
| 393 NotifyBeforeSendHeaders(&headers, request.get(), true); | 545 NotifyBeforeSendHeaders(&headers, request.get(), true); |
| 394 VerifyLoFiHeader(false, false, headers); | 546 VerifyLoFiHeader(false, false, headers); |
| 395 VerifyLitePageHeader(false, false, headers); | 547 VerifyLitePageHeader(false, false, headers); |
| 396 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); | 548 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); |
| 397 EXPECT_EQ(tests[i].is_using_lofi, data->lofi_requested()) << i; | 549 EXPECT_EQ(tests[i].is_using_lofi, data->lofi_requested()) << i; |
| 398 } | 550 } |
| 399 } | 551 } |
| 400 | 552 |
| 401 TEST_F(ContentLoFiDeciderTest, LitePageFieldTrial) { | 553 TEST_F(ContentLoFiDeciderTest, LitePageFieldTrial) { |
| 554 // Turn off proxy-decides-transform feature for these unit tests. | |
| 555 base::test::ScopedFeatureList scoped_feature_list; | |
| 556 scoped_feature_list.InitAndDisableFeature( | |
| 557 features::kDataReductionProxyDecidesTransform); | |
| 558 | |
| 402 base::FieldTrialList field_trial_list(nullptr); | 559 base::FieldTrialList field_trial_list(nullptr); |
| 403 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), | 560 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 404 "Enabled_Preview"); | 561 "Enabled_Preview"); |
| 405 // Enable Lo-Fi. | 562 // Enable Lo-Fi. |
| 406 const struct { | 563 const struct { |
| 407 bool is_using_lite_page; | 564 bool is_using_lite_page; |
| 408 bool is_main_frame; | 565 bool is_main_frame; |
| 409 } tests[] = { | 566 } tests[] = { |
| 410 {false, false}, {true, false}, {false, true}, {true, true}, | 567 {false, false}, {true, false}, {false, true}, {true, true}, |
| 411 }; | 568 }; |
| 412 | 569 |
| 413 for (size_t i = 0; i < arraysize(tests); ++i) { | 570 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 414 std::unique_ptr<net::URLRequest> request = | 571 std::unique_ptr<net::URLRequest> request = |
| 415 CreateRequest(tests[i].is_main_frame, tests[i].is_using_lite_page | 572 CreateRequest(tests[i].is_main_frame, tests[i].is_using_lite_page |
| 416 ? content::SERVER_LITE_PAGE_ON | 573 ? content::SERVER_LITE_PAGE_ON |
| 417 : content::PREVIEWS_OFF); | 574 : content::PREVIEWS_OFF); |
| 418 net::HttpRequestHeaders headers; | 575 net::HttpRequestHeaders headers; |
| 419 NotifyBeforeSendHeaders(&headers, request.get(), true); | 576 NotifyBeforeSendHeaders(&headers, request.get(), true); |
| 420 VerifyLoFiHeader(false, false, headers); | 577 VerifyLoFiHeader(false, false, headers); |
| 421 VerifyLitePageHeader(tests[i].is_main_frame, !tests[i].is_using_lite_page, | 578 VerifyLitePageHeader(tests[i].is_main_frame, !tests[i].is_using_lite_page, |
| 422 headers); | 579 headers); |
| 423 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); | 580 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); |
| 424 EXPECT_EQ(tests[i].is_using_lite_page, data->lofi_requested()) << i; | 581 EXPECT_EQ(tests[i].is_using_lite_page, data->lofi_requested()) << i; |
| 425 } | 582 } |
| 426 } | 583 } |
| 427 | 584 |
| 428 TEST_F(ContentLoFiDeciderTest, LitePageFieldTrialFallbackDisabled) { | 585 TEST_F(ContentLoFiDeciderTest, LitePageFieldTrialFallbackDisabled) { |
| 586 // Turn off proxy-decides-transform feature for these unit tests. | |
| 587 base::test::ScopedFeatureList scoped_feature_list; | |
| 588 scoped_feature_list.InitAndDisableFeature( | |
| 589 features::kDataReductionProxyDecidesTransform); | |
| 590 | |
| 429 base::FieldTrialList field_trial_list(nullptr); | 591 base::FieldTrialList field_trial_list(nullptr); |
| 430 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), | 592 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 431 "Enabled_Preview"); | 593 "Enabled_Preview"); |
| 432 // Enable Lo-Fi. | 594 // Enable Lo-Fi. |
| 433 const struct { | 595 const struct { |
| 434 bool is_using_lofi; | 596 bool is_using_lofi; |
| 435 bool is_using_lite_page; | 597 bool is_using_lite_page; |
| 436 bool is_main_frame; | 598 bool is_main_frame; |
| 437 } tests[] = { | 599 } tests[] = { |
| 438 {false, false, false}, {false, false, true}, {true, false, true}, | 600 {false, false, false}, {false, false, true}, {true, false, true}, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 458 tests[i].is_main_frame && !tests[i].is_using_lite_page, | 620 tests[i].is_main_frame && !tests[i].is_using_lite_page, |
| 459 headers); | 621 headers); |
| 460 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); | 622 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); |
| 461 EXPECT_EQ(tests[i].is_using_lofi || tests[i].is_using_lite_page, | 623 EXPECT_EQ(tests[i].is_using_lofi || tests[i].is_using_lite_page, |
| 462 data->lofi_requested()) | 624 data->lofi_requested()) |
| 463 << i; | 625 << i; |
| 464 } | 626 } |
| 465 } | 627 } |
| 466 | 628 |
| 467 TEST_F(ContentLoFiDeciderTest, AutoLoFi) { | 629 TEST_F(ContentLoFiDeciderTest, AutoLoFi) { |
| 630 // Turn off proxy-decides-transform feature for these unit tests. | |
| 631 base::test::ScopedFeatureList scoped_feature_list; | |
| 632 scoped_feature_list.InitAndDisableFeature( | |
| 633 features::kDataReductionProxyDecidesTransform); | |
| 634 | |
| 468 const struct { | 635 const struct { |
| 469 bool auto_lofi_enabled_group; | 636 bool auto_lofi_enabled_group; |
| 470 bool auto_lofi_control_group; | 637 bool auto_lofi_control_group; |
| 471 bool network_prohibitively_slow; | 638 bool network_prohibitively_slow; |
| 472 bool is_main_frame; | 639 bool is_main_frame; |
| 473 } tests[] = { | 640 } tests[] = { |
| 474 {false, false, false, false}, | 641 {false, false, false, false}, |
| 475 {false, false, true, false}, | 642 {false, false, true, false}, |
| 476 {true, false, false, false}, | 643 {true, false, false, false}, |
| 477 {true, false, true, false}, | 644 {true, false, true, false}, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 506 tests[i].is_main_frame, tests[i].network_prohibitively_slow); | 673 tests[i].is_main_frame, tests[i].network_prohibitively_slow); |
| 507 net::HttpRequestHeaders headers; | 674 net::HttpRequestHeaders headers; |
| 508 NotifyBeforeSendHeaders(&headers, request.get(), true); | 675 NotifyBeforeSendHeaders(&headers, request.get(), true); |
| 509 | 676 |
| 510 VerifyLoFiHeader(expect_lofi_header, !tests[i].network_prohibitively_slow, | 677 VerifyLoFiHeader(expect_lofi_header, !tests[i].network_prohibitively_slow, |
| 511 headers); | 678 headers); |
| 512 } | 679 } |
| 513 } | 680 } |
| 514 | 681 |
| 515 TEST_F(ContentLoFiDeciderTest, SlowConnectionsFlag) { | 682 TEST_F(ContentLoFiDeciderTest, SlowConnectionsFlag) { |
| 683 // Turn off proxy-decides-transform feature for these unit tests. | |
| 684 base::test::ScopedFeatureList scoped_feature_list; | |
| 685 scoped_feature_list.InitAndDisableFeature( | |
| 686 features::kDataReductionProxyDecidesTransform); | |
| 687 | |
| 516 const struct { | 688 const struct { |
| 517 bool slow_connections_flag_enabled; | 689 bool slow_connections_flag_enabled; |
| 518 bool network_prohibitively_slow; | 690 bool network_prohibitively_slow; |
| 519 bool auto_lofi_enabled_group; | 691 bool auto_lofi_enabled_group; |
| 520 bool is_main_frame; | 692 bool is_main_frame; |
| 521 } tests[] = { | 693 } tests[] = { |
| 522 {false, false, false, false}, {false, true, false, false}, | 694 {false, false, false, false}, {false, true, false, false}, |
| 523 {true, false, false, false}, {true, true, false, false}, | 695 {true, false, false, false}, {true, true, false, false}, |
| 524 {true, true, false, true}, {false, false, true, false}, | 696 {true, true, false, true}, {false, false, true, false}, |
| 525 {false, false, true, true}, {false, true, true, false}, | 697 {false, false, true, true}, {false, true, true, false}, |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 733 content::CLIENT_LOFI_AUTO_RELOAD))); | 905 content::CLIENT_LOFI_AUTO_RELOAD))); |
| 734 | 906 |
| 735 // IsClientLoFiAutoReloadRequest() should return false for any request without | 907 // IsClientLoFiAutoReloadRequest() should return false for any request without |
| 736 // the CLIENT_LOFI_AUTO_RELOAD bit set. | 908 // the CLIENT_LOFI_AUTO_RELOAD bit set. |
| 737 EXPECT_FALSE(ContentLoFiDecider().IsClientLoFiAutoReloadRequest( | 909 EXPECT_FALSE(ContentLoFiDecider().IsClientLoFiAutoReloadRequest( |
| 738 *CreateRequestByType(content::RESOURCE_TYPE_IMAGE, false, | 910 *CreateRequestByType(content::RESOURCE_TYPE_IMAGE, false, |
| 739 content::PREVIEWS_NO_TRANSFORM))); | 911 content::PREVIEWS_NO_TRANSFORM))); |
| 740 } | 912 } |
| 741 | 913 |
| 742 } // namespace data_reduction_proxy | 914 } // namespace data_reduction_proxy |
| OLD | NEW |