| 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 protected: | 227 protected: |
| 228 base::MessageLoopForIO message_loop_; | 228 base::MessageLoopForIO message_loop_; |
| 229 net::TestURLRequestContext context_; | 229 net::TestURLRequestContext context_; |
| 230 net::TestDelegate delegate_; | 230 net::TestDelegate delegate_; |
| 231 std::unique_ptr<DataReductionProxyTestContext> test_context_; | 231 std::unique_ptr<DataReductionProxyTestContext> test_context_; |
| 232 std::unique_ptr<DataReductionProxyNetworkDelegate> | 232 std::unique_ptr<DataReductionProxyNetworkDelegate> |
| 233 data_reduction_proxy_network_delegate_; | 233 data_reduction_proxy_network_delegate_; |
| 234 }; | 234 }; |
| 235 | 235 |
| 236 TEST_F(ContentLoFiDeciderTest, LoFiFlags) { | 236 TEST_F(ContentLoFiDeciderTest, LoFiFlags) { |
| 237 // Turn off proxy-decides-transform feature for these unit tests. |
| 238 base::test::ScopedFeatureList scoped_feature_list; |
| 239 scoped_feature_list.InitAndDisableFeature( |
| 240 features::kDataReductionProxyDecidesTransform); |
| 241 |
| 237 // Enable Lo-Fi. | 242 // Enable Lo-Fi. |
| 238 const struct { | 243 const struct { |
| 239 bool is_using_lofi; | 244 bool is_using_lofi; |
| 240 bool is_using_lite_page; | 245 bool is_using_lite_page; |
| 241 bool is_main_frame; | 246 bool is_main_frame; |
| 242 } tests[] = { | 247 } tests[] = { |
| 243 {false, false, false}, {false, false, true}, {true, false, true}, | 248 {false, false, false}, {false, false, true}, {true, false, true}, |
| 244 {true, false, false}, {false, true, false}, {false, true, true}, | 249 {true, false, false}, {false, true, false}, {false, true, true}, |
| 245 {true, true, true}, {true, true, false}, | 250 {true, true, true}, {true, true, false}, |
| 246 }; | 251 }; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 VerifyAcceptTransformHeader(*request.get(), false /* lite-page */, | 420 VerifyAcceptTransformHeader(*request.get(), false /* lite-page */, |
| 416 false /* empty-image */); | 421 false /* empty-image */); |
| 417 | 422 |
| 418 request = CreateRequestByType(content::RESOURCE_TYPE_STYLESHEET, | 423 request = CreateRequestByType(content::RESOURCE_TYPE_STYLESHEET, |
| 419 false /* https */, lofi_enabled); | 424 false /* https */, lofi_enabled); |
| 420 VerifyAcceptTransformHeader(*request.get(), false /* lite-page */, | 425 VerifyAcceptTransformHeader(*request.get(), false /* lite-page */, |
| 421 false /* empty-image */); | 426 false /* empty-image */); |
| 422 } | 427 } |
| 423 | 428 |
| 424 TEST_F(ContentLoFiDeciderTest, LoFiEnabledFieldTrial) { | 429 TEST_F(ContentLoFiDeciderTest, LoFiEnabledFieldTrial) { |
| 430 // Turn off proxy-decides-transform feature for these unit tests. |
| 431 base::test::ScopedFeatureList scoped_feature_list; |
| 432 scoped_feature_list.InitAndDisableFeature( |
| 433 features::kDataReductionProxyDecidesTransform); |
| 434 |
| 425 base::FieldTrialList field_trial_list(nullptr); | 435 base::FieldTrialList field_trial_list(nullptr); |
| 426 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), | 436 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 427 "Enabled"); | 437 "Enabled"); |
| 428 | 438 |
| 429 // Enable Lo-Fi. | 439 // Enable Lo-Fi. |
| 430 const struct { | 440 const struct { |
| 431 bool is_using_lofi; | 441 bool is_using_lofi; |
| 432 content::ResourceType resource_type; | 442 content::ResourceType resource_type; |
| 433 } tests[] = {{false, content::RESOURCE_TYPE_MAIN_FRAME}, | 443 } tests[] = {{false, content::RESOURCE_TYPE_MAIN_FRAME}, |
| 434 {false, content::RESOURCE_TYPE_SUB_FRAME}, | 444 {false, content::RESOURCE_TYPE_SUB_FRAME}, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 tests[i].resource_type == content::RESOURCE_TYPE_CSP_REPORT); | 494 tests[i].resource_type == content::RESOURCE_TYPE_CSP_REPORT); |
| 485 | 495 |
| 486 VerifyLoFiHeader(is_lofi_resource_type, !tests[i].is_using_lofi, headers); | 496 VerifyLoFiHeader(is_lofi_resource_type, !tests[i].is_using_lofi, headers); |
| 487 VerifyLitePageHeader(false, false, headers); | 497 VerifyLitePageHeader(false, false, headers); |
| 488 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); | 498 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); |
| 489 EXPECT_EQ(tests[i].is_using_lofi, data->lofi_requested()) << i; | 499 EXPECT_EQ(tests[i].is_using_lofi, data->lofi_requested()) << i; |
| 490 } | 500 } |
| 491 } | 501 } |
| 492 | 502 |
| 493 TEST_F(ContentLoFiDeciderTest, LoFiControlFieldTrial) { | 503 TEST_F(ContentLoFiDeciderTest, LoFiControlFieldTrial) { |
| 504 // Turn off proxy-decides-transform feature for these unit tests. |
| 505 base::test::ScopedFeatureList scoped_feature_list; |
| 506 scoped_feature_list.InitAndDisableFeature( |
| 507 features::kDataReductionProxyDecidesTransform); |
| 508 |
| 494 base::FieldTrialList field_trial_list(nullptr); | 509 base::FieldTrialList field_trial_list(nullptr); |
| 495 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), | 510 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 496 "Control"); | 511 "Control"); |
| 497 // Enable Lo-Fi. | 512 // Enable Lo-Fi. |
| 498 const struct { | 513 const struct { |
| 499 bool is_using_lofi; | 514 bool is_using_lofi; |
| 500 bool is_main_frame; | 515 bool is_main_frame; |
| 501 } tests[] = {{false, false}, {false, true}, {true, false}, {true, true}}; | 516 } tests[] = {{false, false}, {false, true}, {true, false}, {true, true}}; |
| 502 | 517 |
| 503 for (size_t i = 0; i < arraysize(tests); ++i) { | 518 for (size_t i = 0; i < arraysize(tests); ++i) { |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 content::CLIENT_LOFI_AUTO_RELOAD))); | 882 content::CLIENT_LOFI_AUTO_RELOAD))); |
| 868 | 883 |
| 869 // IsClientLoFiAutoReloadRequest() should return false for any request without | 884 // IsClientLoFiAutoReloadRequest() should return false for any request without |
| 870 // the CLIENT_LOFI_AUTO_RELOAD bit set. | 885 // the CLIENT_LOFI_AUTO_RELOAD bit set. |
| 871 EXPECT_FALSE(ContentLoFiDecider().IsClientLoFiAutoReloadRequest( | 886 EXPECT_FALSE(ContentLoFiDecider().IsClientLoFiAutoReloadRequest( |
| 872 *CreateRequestByType(content::RESOURCE_TYPE_IMAGE, false, | 887 *CreateRequestByType(content::RESOURCE_TYPE_IMAGE, false, |
| 873 content::PREVIEWS_NO_TRANSFORM))); | 888 content::PREVIEWS_NO_TRANSFORM))); |
| 874 } | 889 } |
| 875 | 890 |
| 876 } // namespace data_reduction_proxy | 891 } // namespace data_reduction_proxy |
| OLD | NEW |