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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "platform/loader/fetch/FetchInitiatorInfo.h" | 45 #include "platform/loader/fetch/FetchInitiatorInfo.h" |
46 #include "platform/loader/fetch/ResourceRequest.h" | 46 #include "platform/loader/fetch/ResourceRequest.h" |
47 #include "platform/loader/fetch/UniqueIdentifier.h" | 47 #include "platform/loader/fetch/UniqueIdentifier.h" |
48 #include "platform/loader/testing/MockResource.h" | 48 #include "platform/loader/testing/MockResource.h" |
49 #include "platform/weborigin/KURL.h" | 49 #include "platform/weborigin/KURL.h" |
50 #include "platform/weborigin/SecurityViolationReportingPolicy.h" | 50 #include "platform/weborigin/SecurityViolationReportingPolicy.h" |
51 #include "public/platform/WebAddressSpace.h" | 51 #include "public/platform/WebAddressSpace.h" |
52 #include "public/platform/WebCachePolicy.h" | 52 #include "public/platform/WebCachePolicy.h" |
53 #include "public/platform/WebDocumentSubresourceFilter.h" | 53 #include "public/platform/WebDocumentSubresourceFilter.h" |
54 #include "public/platform/WebInsecureRequestPolicy.h" | 54 #include "public/platform/WebInsecureRequestPolicy.h" |
| 55 #include "public/web/WebDataSaverFlag.h" |
55 #include "testing/gmock/include/gmock/gmock.h" | 56 #include "testing/gmock/include/gmock/gmock.h" |
56 #include "testing/gtest/include/gtest/gtest.h" | 57 #include "testing/gtest/include/gtest/gtest.h" |
57 | 58 |
58 namespace blink { | 59 namespace blink { |
59 | 60 |
60 class StubLocalFrameClientWithParent final : public EmptyLocalFrameClient { | 61 class StubLocalFrameClientWithParent final : public EmptyLocalFrameClient { |
61 public: | 62 public: |
62 static StubLocalFrameClientWithParent* Create(Frame* parent) { | 63 static StubLocalFrameClientWithParent* Create(Frame* parent) { |
63 return new StubLocalFrameClientWithParent(parent); | 64 return new StubLocalFrameClientWithParent(parent); |
64 } | 65 } |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 request.RequestorOrigin()->ToString()); | 784 request.RequestorOrigin()->ToString()); |
784 } | 785 } |
785 | 786 |
786 EXPECT_EQ(document->FirstPartyForCookies(), request.FirstPartyForCookies()); | 787 EXPECT_EQ(document->FirstPartyForCookies(), request.FirstPartyForCookies()); |
787 } | 788 } |
788 } | 789 } |
789 | 790 |
790 // Tests if "Save-Data" header is correctly added on the first load and reload. | 791 // Tests if "Save-Data" header is correctly added on the first load and reload. |
791 TEST_F(FrameFetchContextTest, EnableDataSaver) { | 792 TEST_F(FrameFetchContextTest, EnableDataSaver) { |
792 Settings* settings = document->GetFrame()->GetSettings(); | 793 Settings* settings = document->GetFrame()->GetSettings(); |
793 settings->SetDataSaverEnabled(true); | 794 settings->SetDataSaverFlag(WebDataSaverFlag::kEnabled); |
794 ResourceRequest resource_request("http://www.example.com"); | 795 ResourceRequest resource_request("http://www.example.com"); |
795 fetch_context->AddAdditionalRequestHeaders(resource_request, | 796 fetch_context->AddAdditionalRequestHeaders(resource_request, |
796 kFetchMainResource); | 797 kFetchMainResource); |
797 EXPECT_EQ("on", resource_request.HttpHeaderField("Save-Data")); | 798 EXPECT_EQ("on", resource_request.HttpHeaderField("Save-Data")); |
798 | 799 |
799 // Subsequent call to addAdditionalRequestHeaders should not append to the | 800 // Subsequent call to addAdditionalRequestHeaders should not append to the |
800 // save-data header. | 801 // save-data header. |
801 fetch_context->AddAdditionalRequestHeaders(resource_request, | 802 fetch_context->AddAdditionalRequestHeaders(resource_request, |
802 kFetchMainResource); | 803 kFetchMainResource); |
803 EXPECT_EQ("on", resource_request.HttpHeaderField("Save-Data")); | 804 EXPECT_EQ("on", resource_request.HttpHeaderField("Save-Data")); |
804 } | 805 } |
805 | 806 |
806 // Tests if "Save-Data" header is not added when the data saver is disabled. | 807 // Tests if "Save-Data" header is not added when the data saver is disabled. |
807 TEST_F(FrameFetchContextTest, DisabledDataSaver) { | 808 TEST_F(FrameFetchContextTest, DisabledDataSaver) { |
808 ResourceRequest resource_request("http://www.example.com"); | 809 ResourceRequest resource_request("http://www.example.com"); |
809 fetch_context->AddAdditionalRequestHeaders(resource_request, | 810 fetch_context->AddAdditionalRequestHeaders(resource_request, |
810 kFetchMainResource); | 811 kFetchMainResource); |
811 EXPECT_EQ(String(), resource_request.HttpHeaderField("Save-Data")); | 812 EXPECT_EQ(String(), resource_request.HttpHeaderField("Save-Data")); |
812 } | 813 } |
813 | 814 |
814 // Tests if reload variants can reflect the current data saver setting. | 815 // Tests if reload variants can reflect the current data saver setting. |
815 TEST_F(FrameFetchContextTest, ChangeDataSaverConfig) { | 816 TEST_F(FrameFetchContextTest, ChangeDataSaverConfig) { |
816 Settings* settings = document->GetFrame()->GetSettings(); | 817 Settings* settings = document->GetFrame()->GetSettings(); |
817 settings->SetDataSaverEnabled(true); | 818 settings->SetDataSaverFlag(WebDataSaverFlag::kEnabled); |
818 ResourceRequest resource_request("http://www.example.com"); | 819 ResourceRequest resource_request("http://www.example.com"); |
819 fetch_context->AddAdditionalRequestHeaders(resource_request, | 820 fetch_context->AddAdditionalRequestHeaders(resource_request, |
820 kFetchMainResource); | 821 kFetchMainResource); |
821 EXPECT_EQ("on", resource_request.HttpHeaderField("Save-Data")); | 822 EXPECT_EQ("on", resource_request.HttpHeaderField("Save-Data")); |
822 | 823 |
823 settings->SetDataSaverEnabled(false); | 824 settings->SetDataSaverFlag(WebDataSaverFlag::kDisabled); |
824 document->Loader()->SetLoadType(kFrameLoadTypeReload); | 825 document->Loader()->SetLoadType(kFrameLoadTypeReload); |
825 fetch_context->AddAdditionalRequestHeaders(resource_request, | 826 fetch_context->AddAdditionalRequestHeaders(resource_request, |
826 kFetchMainResource); | 827 kFetchMainResource); |
827 EXPECT_EQ(String(), resource_request.HttpHeaderField("Save-Data")); | 828 EXPECT_EQ(String(), resource_request.HttpHeaderField("Save-Data")); |
828 | 829 |
829 settings->SetDataSaverEnabled(true); | 830 settings->SetDataSaverFlag(WebDataSaverFlag::kEnabled); |
830 fetch_context->AddAdditionalRequestHeaders(resource_request, | 831 fetch_context->AddAdditionalRequestHeaders(resource_request, |
831 kFetchMainResource); | 832 kFetchMainResource); |
832 EXPECT_EQ("on", resource_request.HttpHeaderField("Save-Data")); | 833 EXPECT_EQ("on", resource_request.HttpHeaderField("Save-Data")); |
833 | 834 |
834 settings->SetDataSaverEnabled(false); | 835 settings->SetDataSaverFlag(WebDataSaverFlag::kDisabled); |
835 document->Loader()->SetLoadType(kFrameLoadTypeReload); | 836 document->Loader()->SetLoadType(kFrameLoadTypeReload); |
836 fetch_context->AddAdditionalRequestHeaders(resource_request, | 837 fetch_context->AddAdditionalRequestHeaders(resource_request, |
837 kFetchMainResource); | 838 kFetchMainResource); |
838 EXPECT_EQ(String(), resource_request.HttpHeaderField("Save-Data")); | 839 EXPECT_EQ(String(), resource_request.HttpHeaderField("Save-Data")); |
839 } | 840 } |
840 | 841 |
841 // Tests that the embedder gets correct notification when a resource is loaded | 842 // Tests that the embedder gets correct notification when a resource is loaded |
842 // from the memory cache. | 843 // from the memory cache. |
843 TEST_F(FrameFetchContextMockedLocalFrameClientTest, | 844 TEST_F(FrameFetchContextMockedLocalFrameClientTest, |
844 DispatchDidLoadResourceFromMemoryCache) { | 845 DispatchDidLoadResourceFromMemoryCache) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 SetFilterPolicy(WebDocumentSubresourceFilter::kWouldDisallow); | 906 SetFilterPolicy(WebDocumentSubresourceFilter::kWouldDisallow); |
906 | 907 |
907 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequest()); | 908 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequest()); |
908 EXPECT_EQ(0, GetFilteredLoadCallCount()); | 909 EXPECT_EQ(0, GetFilteredLoadCallCount()); |
909 | 910 |
910 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequestPreload()); | 911 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequestPreload()); |
911 EXPECT_EQ(0, GetFilteredLoadCallCount()); | 912 EXPECT_EQ(0, GetFilteredLoadCallCount()); |
912 } | 913 } |
913 | 914 |
914 } // namespace blink | 915 } // namespace blink |
OLD | NEW |