OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015, Google Inc. All rights reserved. | 2 * Copyright (c) 2015, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 // Low priority iframes enabled, everything should be low priority | 689 // Low priority iframes enabled, everything should be low priority |
690 settings->setLowPriorityIframes(true); | 690 settings->setLowPriorityIframes(true); |
691 EXPECT_EQ(ResourceLoadPriorityVeryLow, | 691 EXPECT_EQ(ResourceLoadPriorityVeryLow, |
692 childFetchContext->modifyPriorityForExperiments( | 692 childFetchContext->modifyPriorityForExperiments( |
693 ResourceLoadPriorityVeryHigh)); | 693 ResourceLoadPriorityVeryHigh)); |
694 EXPECT_EQ(ResourceLoadPriorityVeryLow, | 694 EXPECT_EQ(ResourceLoadPriorityVeryLow, |
695 childFetchContext->modifyPriorityForExperiments( | 695 childFetchContext->modifyPriorityForExperiments( |
696 ResourceLoadPriorityMedium)); | 696 ResourceLoadPriorityMedium)); |
697 } | 697 } |
698 | 698 |
| 699 // Tests if "Save-Data" header is correctly added on the first load and reload. |
699 TEST_F(FrameFetchContextTest, EnableDataSaver) { | 700 TEST_F(FrameFetchContextTest, EnableDataSaver) { |
700 Settings* settings = document->frame()->settings(); | 701 Settings* settings = document->frame()->settings(); |
701 settings->setDataSaverEnabled(true); | 702 settings->setDataSaverEnabled(true); |
702 ResourceRequest resourceRequest("http://www.example.com"); | 703 ResourceRequest resourceRequest("http://www.example.com"); |
703 fetchContext->addAdditionalRequestHeaders(resourceRequest, FetchMainResource); | 704 fetchContext->addAdditionalRequestHeaders(resourceRequest, FetchMainResource); |
704 EXPECT_EQ("on", resourceRequest.httpHeaderField("Save-Data")); | 705 EXPECT_EQ("on", resourceRequest.httpHeaderField("Save-Data")); |
705 | 706 |
706 // Subsequent call to addAdditionalRequestHeaders should not append to the | 707 // Subsequent call to addAdditionalRequestHeaders should not append to the |
707 // save-data header. | 708 // save-data header. |
708 fetchContext->addAdditionalRequestHeaders(resourceRequest, FetchMainResource); | 709 fetchContext->addAdditionalRequestHeaders(resourceRequest, FetchMainResource); |
709 EXPECT_EQ("on", resourceRequest.httpHeaderField("Save-Data")); | 710 EXPECT_EQ("on", resourceRequest.httpHeaderField("Save-Data")); |
710 } | 711 } |
711 | 712 |
| 713 // Tests if "Save-Data" header is not added when the data saver is disabled. |
712 TEST_F(FrameFetchContextTest, DisabledDataSaver) { | 714 TEST_F(FrameFetchContextTest, DisabledDataSaver) { |
713 ResourceRequest resourceRequest("http://www.example.com"); | 715 ResourceRequest resourceRequest("http://www.example.com"); |
714 fetchContext->addAdditionalRequestHeaders(resourceRequest, FetchMainResource); | 716 fetchContext->addAdditionalRequestHeaders(resourceRequest, FetchMainResource); |
715 EXPECT_EQ(String(), resourceRequest.httpHeaderField("Save-Data")); | 717 EXPECT_EQ(String(), resourceRequest.httpHeaderField("Save-Data")); |
716 } | 718 } |
717 | 719 |
| 720 // Tests if reload variants can reflect the current data saver setting. |
| 721 TEST_F(FrameFetchContextTest, ChangeDataSaverConfig) { |
| 722 Settings* settings = document->frame()->settings(); |
| 723 settings->setDataSaverEnabled(true); |
| 724 ResourceRequest resourceRequest("http://www.example.com"); |
| 725 fetchContext->addAdditionalRequestHeaders(resourceRequest, FetchMainResource); |
| 726 EXPECT_EQ("on", resourceRequest.httpHeaderField("Save-Data")); |
| 727 |
| 728 settings->setDataSaverEnabled(false); |
| 729 document->loader()->setLoadType(FrameLoadTypeReloadMainResource); |
| 730 fetchContext->addAdditionalRequestHeaders(resourceRequest, FetchMainResource); |
| 731 EXPECT_EQ(String(), resourceRequest.httpHeaderField("Save-Data")); |
| 732 |
| 733 settings->setDataSaverEnabled(true); |
| 734 fetchContext->addAdditionalRequestHeaders(resourceRequest, FetchMainResource); |
| 735 EXPECT_EQ("on", resourceRequest.httpHeaderField("Save-Data")); |
| 736 |
| 737 settings->setDataSaverEnabled(false); |
| 738 document->loader()->setLoadType(FrameLoadTypeReloadMainResource); |
| 739 fetchContext->addAdditionalRequestHeaders(resourceRequest, FetchMainResource); |
| 740 EXPECT_EQ(String(), resourceRequest.httpHeaderField("Save-Data")); |
| 741 } |
| 742 |
718 // Tests that the embedder gets correct notification when a resource is loaded | 743 // Tests that the embedder gets correct notification when a resource is loaded |
719 // from the memory cache. | 744 // from the memory cache. |
720 TEST_F(FrameFetchContextMockedLocalFrameClientTest, | 745 TEST_F(FrameFetchContextMockedLocalFrameClientTest, |
721 DispatchDidLoadResourceFromMemoryCache) { | 746 DispatchDidLoadResourceFromMemoryCache) { |
722 ResourceRequest resourceRequest(url); | 747 ResourceRequest resourceRequest(url); |
723 Resource* resource = MockResource::create(resourceRequest); | 748 Resource* resource = MockResource::create(resourceRequest); |
724 EXPECT_CALL( | 749 EXPECT_CALL( |
725 *client, | 750 *client, |
726 dispatchDidLoadResourceFromMemoryCache( | 751 dispatchDidLoadResourceFromMemoryCache( |
727 testing::AllOf(testing::Property(&ResourceRequest::url, url), | 752 testing::AllOf(testing::Property(&ResourceRequest::url, url), |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 setFilterPolicy(WebDocumentSubresourceFilter::WouldDisallow); | 931 setFilterPolicy(WebDocumentSubresourceFilter::WouldDisallow); |
907 | 932 |
908 EXPECT_EQ(ResourceRequestBlockedReason::None, canRequest()); | 933 EXPECT_EQ(ResourceRequestBlockedReason::None, canRequest()); |
909 EXPECT_EQ(0, getFilteredLoadCallCount()); | 934 EXPECT_EQ(0, getFilteredLoadCallCount()); |
910 | 935 |
911 EXPECT_EQ(ResourceRequestBlockedReason::None, canRequestPreload()); | 936 EXPECT_EQ(ResourceRequestBlockedReason::None, canRequestPreload()); |
912 EXPECT_EQ(0, getFilteredLoadCallCount()); | 937 EXPECT_EQ(0, getFilteredLoadCallCount()); |
913 } | 938 } |
914 | 939 |
915 } // namespace blink | 940 } // namespace blink |
OLD | NEW |