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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 // |lofi_requested| should be set to false when Lo-Fi is enabled using | 303 // |lofi_requested| should be set to false when Lo-Fi is enabled using |
304 // flags. | 304 // flags. |
305 EXPECT_FALSE(data->lofi_requested()); | 305 EXPECT_FALSE(data->lofi_requested()); |
306 } | 306 } |
307 } | 307 } |
308 | 308 |
309 TEST_F(ContentLoFiDeciderTest, LoFiEnabledFieldTrial) { | 309 TEST_F(ContentLoFiDeciderTest, LoFiEnabledFieldTrial) { |
310 base::FieldTrialList field_trial_list(nullptr); | 310 base::FieldTrialList field_trial_list(nullptr); |
311 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), | 311 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
312 "Enabled"); | 312 "Enabled"); |
313 // Add the Lite Page fallback field trial. Having this enabled when not in the | |
314 // Enabled_Previews group should not affect how Lo-Fi works. | |
315 base::FieldTrialList::CreateFieldTrial( | |
316 params::GetLitePageFallbackFieldTrialName(), "Enabled"); | |
317 | 313 |
318 // Enable Lo-Fi. | 314 // Enable Lo-Fi. |
319 const struct { | 315 const struct { |
320 bool is_using_lofi; | 316 bool is_using_lofi; |
321 content::ResourceType resource_type; | 317 content::ResourceType resource_type; |
322 } tests[] = {{false, content::RESOURCE_TYPE_MAIN_FRAME}, | 318 } tests[] = {{false, content::RESOURCE_TYPE_MAIN_FRAME}, |
323 {false, content::RESOURCE_TYPE_SUB_FRAME}, | 319 {false, content::RESOURCE_TYPE_SUB_FRAME}, |
324 {false, content::RESOURCE_TYPE_STYLESHEET}, | 320 {false, content::RESOURCE_TYPE_STYLESHEET}, |
325 {false, content::RESOURCE_TYPE_SCRIPT}, | 321 {false, content::RESOURCE_TYPE_SCRIPT}, |
326 {false, content::RESOURCE_TYPE_IMAGE}, | 322 {false, content::RESOURCE_TYPE_IMAGE}, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 net::HttpRequestHeaders headers; | 418 net::HttpRequestHeaders headers; |
423 NotifyBeforeSendHeaders(&headers, request.get(), true); | 419 NotifyBeforeSendHeaders(&headers, request.get(), true); |
424 VerifyLoFiHeader(false, false, headers); | 420 VerifyLoFiHeader(false, false, headers); |
425 VerifyLitePageHeader(tests[i].is_main_frame, !tests[i].is_using_lite_page, | 421 VerifyLitePageHeader(tests[i].is_main_frame, !tests[i].is_using_lite_page, |
426 headers); | 422 headers); |
427 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); | 423 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); |
428 EXPECT_EQ(tests[i].is_using_lite_page, data->lofi_requested()) << i; | 424 EXPECT_EQ(tests[i].is_using_lite_page, data->lofi_requested()) << i; |
429 } | 425 } |
430 } | 426 } |
431 | 427 |
432 TEST_F(ContentLoFiDeciderTest, LitePageFieldTrialFallbackEnabled) { | |
433 base::FieldTrialList field_trial_list(nullptr); | |
434 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), | |
435 "Enabled_Preview"); | |
436 base::FieldTrialList::CreateFieldTrial( | |
437 params::GetLitePageFallbackFieldTrialName(), "Enabled"); | |
438 | |
439 // Enable Lo-Fi. | |
440 const struct { | |
441 bool is_using_lofi; | |
442 bool is_using_lite_page; | |
443 bool is_main_frame; | |
444 } tests[] = { | |
445 {false, false, false}, {false, false, true}, {true, false, true}, | |
446 {true, false, false}, {false, true, false}, {false, true, true}, | |
447 {true, true, true}, {true, true, false}, | |
448 }; | |
449 | |
450 for (size_t i = 0; i < arraysize(tests); ++i) { | |
451 content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED; | |
452 if (tests[i].is_using_lofi) | |
453 previews_state |= content::SERVER_LOFI_ON; | |
454 if (tests[i].is_using_lite_page) | |
455 previews_state |= content::SERVER_LITE_PAGE_ON; | |
456 if (previews_state == content::PREVIEWS_UNSPECIFIED) | |
457 previews_state = content::PREVIEWS_OFF; | |
458 | |
459 std::unique_ptr<net::URLRequest> request = | |
460 CreateRequest(tests[i].is_main_frame, previews_state); | |
461 net::HttpRequestHeaders headers; | |
462 NotifyBeforeSendHeaders(&headers, request.get(), true); | |
463 VerifyLoFiHeader(!tests[i].is_main_frame && !tests[i].is_using_lite_page, | |
464 !tests[i].is_main_frame && !tests[i].is_using_lofi && | |
465 !tests[i].is_using_lite_page, | |
466 headers); | |
467 VerifyLitePageHeader(tests[i].is_main_frame, | |
468 tests[i].is_main_frame && !tests[i].is_using_lite_page, | |
469 headers); | |
470 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); | |
471 EXPECT_EQ(tests[i].is_using_lofi || tests[i].is_using_lite_page, | |
472 data->lofi_requested()) | |
473 << i; | |
474 } | |
475 } | |
476 | |
477 TEST_F(ContentLoFiDeciderTest, LitePageFieldTrialFallbackDisabled) { | 428 TEST_F(ContentLoFiDeciderTest, LitePageFieldTrialFallbackDisabled) { |
478 base::FieldTrialList field_trial_list(nullptr); | 429 base::FieldTrialList field_trial_list(nullptr); |
479 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), | 430 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
480 "Enabled_Preview"); | 431 "Enabled_Preview"); |
481 // Enable Lo-Fi. | 432 // Enable Lo-Fi. |
482 const struct { | 433 const struct { |
483 bool is_using_lofi; | 434 bool is_using_lofi; |
484 bool is_using_lite_page; | 435 bool is_using_lite_page; |
485 bool is_main_frame; | 436 bool is_main_frame; |
486 } tests[] = { | 437 } tests[] = { |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 content::CLIENT_LOFI_AUTO_RELOAD))); | 733 content::CLIENT_LOFI_AUTO_RELOAD))); |
783 | 734 |
784 // IsClientLoFiAutoReloadRequest() should return false for any request without | 735 // IsClientLoFiAutoReloadRequest() should return false for any request without |
785 // the CLIENT_LOFI_AUTO_RELOAD bit set. | 736 // the CLIENT_LOFI_AUTO_RELOAD bit set. |
786 EXPECT_FALSE(ContentLoFiDecider().IsClientLoFiAutoReloadRequest( | 737 EXPECT_FALSE(ContentLoFiDecider().IsClientLoFiAutoReloadRequest( |
787 *CreateRequestByType(content::RESOURCE_TYPE_IMAGE, false, | 738 *CreateRequestByType(content::RESOURCE_TYPE_IMAGE, false, |
788 content::PREVIEWS_NO_TRANSFORM))); | 739 content::PREVIEWS_NO_TRANSFORM))); |
789 } | 740 } |
790 | 741 |
791 } // namespace data_reduction_proxy | 742 } // namespace data_reduction_proxy |
OLD | NEW |