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 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
756 document->Loader()->SetLoadType(kFrameLoadTypeBackForward); | 756 document->Loader()->SetLoadType(kFrameLoadTypeBackForward); |
757 EXPECT_EQ(WebCachePolicy::kReturnCacheDataElseLoad, | 757 EXPECT_EQ(WebCachePolicy::kReturnCacheDataElseLoad, |
758 fetch_context->ResourceRequestCachePolicy( | 758 fetch_context->ResourceRequestCachePolicy( |
759 conditional, Resource::kMock, FetchParameters::kNoDefer)); | 759 conditional, Resource::kMock, FetchParameters::kNoDefer)); |
760 } | 760 } |
761 | 761 |
762 TEST_F(FrameFetchContextTest, SetFirstPartyCookieAndRequestorOrigin) { | 762 TEST_F(FrameFetchContextTest, SetFirstPartyCookieAndRequestorOrigin) { |
763 struct TestCase { | 763 struct TestCase { |
764 const char* document_url; | 764 const char* document_url; |
765 bool document_sandboxed; | 765 bool document_sandboxed; |
766 const char* requestor_origin; // "" => unique origin | 766 const char* requestor_origin; // "" => null |
767 WebURLRequest::FrameType frame_type; | 767 WebURLRequest::FrameType frame_type; |
768 const char* serialized_origin; // "" => unique origin | 768 const char* serialized_origin; // "" => null |
769 } cases[] = { | 769 } cases[] = { |
770 // No document origin => unique request origin | 770 // No document origin => unique request origin |
771 {"", false, "", WebURLRequest::kFrameTypeNone, "null"}, | 771 {"", false, "", WebURLRequest::kFrameTypeNone, "null"}, |
772 {"", true, "", WebURLRequest::kFrameTypeNone, "null"}, | 772 {"", true, "", WebURLRequest::kFrameTypeNone, "null"}, |
773 | 773 |
774 // Document origin => request origin | 774 // Document origin => request origin |
775 {"http://example.test", false, "", WebURLRequest::kFrameTypeNone, | 775 {"http://example.test", false, "", WebURLRequest::kFrameTypeNone, |
776 "http://example.test"}, | 776 "http://example.test"}, |
777 {"http://example.test", true, "", WebURLRequest::kFrameTypeNone, | 777 {"http://example.test", true, "", WebURLRequest::kFrameTypeNone, |
778 "http://example.test"}, | 778 "http://example.test"}, |
779 | 779 |
780 // If the request already has a requestor origin, then | 780 // If the request already has a requestor origin, then |
781 // 'setFirstPartyCookieAndRequestorOrigin' leaves it alone: | 781 // 'SetFirstPartyCookieAndRequestorOrigin' leaves it alone: |
782 {"http://example.test", false, "http://not-example.test", | 782 {"http://example.test", false, "http://not-example.test", |
783 WebURLRequest::kFrameTypeNone, "http://not-example.test"}, | 783 WebURLRequest::kFrameTypeNone, "http://not-example.test"}, |
784 {"http://example.test", true, "http://not-example.test", | 784 {"http://example.test", true, "http://not-example.test", |
785 WebURLRequest::kFrameTypeNone, "http://not-example.test"}, | 785 WebURLRequest::kFrameTypeNone, "http://not-example.test"}, |
786 | |
787 // If the request's frame type is not 'none', then | |
788 // 'setFirstPartyCookieAndRequestorOrigin' | |
789 // leaves it alone: | |
790 {"http://example.test", false, "", WebURLRequest::kFrameTypeTopLevel, ""}, | |
791 {"http://example.test", false, "", WebURLRequest::kFrameTypeAuxiliary, | |
792 ""}, | |
793 {"http://example.test", false, "", WebURLRequest::kFrameTypeNested, ""}, | |
kinuko
2017/06/07 02:00:49
Now SetFirstPartyCookieAndRequestorOrigin also han
| |
794 }; | 786 }; |
795 | 787 |
788 int index = 0; | |
796 for (const auto& test : cases) { | 789 for (const auto& test : cases) { |
797 SCOPED_TRACE(::testing::Message() | 790 SCOPED_TRACE(::testing::Message() << index++ << " " << test.document_url |
798 << test.document_url << " => " << test.serialized_origin); | 791 << " => " << test.serialized_origin); |
799 // Set up a new document to ensure sandbox flags are cleared: | 792 // Set up a new document to ensure sandbox flags are cleared: |
800 dummy_page_holder = DummyPageHolder::Create(IntSize(500, 500)); | 793 dummy_page_holder = DummyPageHolder::Create(IntSize(500, 500)); |
801 dummy_page_holder->GetPage().SetDeviceScaleFactorDeprecated(1.0); | 794 dummy_page_holder->GetPage().SetDeviceScaleFactorDeprecated(1.0); |
802 document = &dummy_page_holder->GetDocument(); | 795 document = &dummy_page_holder->GetDocument(); |
803 FrameFetchContext::ProvideDocumentToContext(*fetch_context, document.Get()); | 796 FrameFetchContext::ProvideDocumentToContext(*fetch_context, document.Get()); |
804 | 797 |
805 // Setup the test: | 798 // Setup the test: |
806 document->SetURL(KURL(kParsedURLString, test.document_url)); | 799 document->SetURL(KURL(kParsedURLString, test.document_url)); |
807 document->SetSecurityOrigin(SecurityOrigin::Create(document->Url())); | 800 document->SetSecurityOrigin(SecurityOrigin::Create(document->Url())); |
808 | 801 |
809 if (test.document_sandboxed) | 802 if (test.document_sandboxed) |
810 document->EnforceSandboxFlags(kSandboxOrigin); | 803 document->EnforceSandboxFlags(kSandboxOrigin); |
811 | 804 |
812 ResourceRequest request("http://example.test/"); | 805 ResourceRequest request("http://example.test/"); |
813 request.SetFrameType(test.frame_type); | 806 request.SetFrameType(test.frame_type); |
814 if (strlen(test.requestor_origin) > 0) { | 807 if (strlen(test.requestor_origin) > 0) { |
815 request.SetRequestorOrigin(SecurityOrigin::Create( | 808 request.SetRequestorOrigin(SecurityOrigin::Create( |
816 KURL(kParsedURLString, test.requestor_origin))); | 809 KURL(kParsedURLString, test.requestor_origin))); |
817 } | 810 } |
818 | 811 |
819 // Compare the populated |requestorOrigin| against |test.serializedOrigin| | 812 // Compare the populated |requestorOrigin| against |test.serializedOrigin| |
820 fetch_context->SetFirstPartyCookieAndRequestorOrigin(request); | 813 fetch_context->SetFirstPartyCookieAndRequestorOrigin(request); |
821 if (strlen(test.serialized_origin) == 0) { | 814 if (strlen(test.serialized_origin) == 0) { |
822 EXPECT_TRUE(request.RequestorOrigin()->IsUnique()); | 815 EXPECT_TRUE(!request.RequestorOrigin()); |
823 } else { | 816 } else { |
824 EXPECT_EQ(String(test.serialized_origin), | 817 EXPECT_EQ(String(test.serialized_origin), |
825 request.RequestorOrigin()->ToString()); | 818 request.RequestorOrigin()->ToString()); |
826 } | 819 } |
827 | 820 |
828 EXPECT_EQ(document->FirstPartyForCookies(), request.FirstPartyForCookies()); | 821 EXPECT_EQ(document->FirstPartyForCookies(), request.FirstPartyForCookies()); |
829 } | 822 } |
830 } | 823 } |
831 | 824 |
832 // Tests if "Save-Data" header is correctly added on the first load and reload. | 825 // Tests if "Save-Data" header is correctly added on the first load and reload. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
947 SetFilterPolicy(WebDocumentSubresourceFilter::kWouldDisallow); | 940 SetFilterPolicy(WebDocumentSubresourceFilter::kWouldDisallow); |
948 | 941 |
949 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequest()); | 942 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequest()); |
950 EXPECT_EQ(0, GetFilteredLoadCallCount()); | 943 EXPECT_EQ(0, GetFilteredLoadCallCount()); |
951 | 944 |
952 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequestPreload()); | 945 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequestPreload()); |
953 EXPECT_EQ(0, GetFilteredLoadCallCount()); | 946 EXPECT_EQ(0, GetFilteredLoadCallCount()); |
954 } | 947 } |
955 | 948 |
956 } // namespace blink | 949 } // namespace blink |
OLD | NEW |