Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: third_party/WebKit/Source/core/loader/FrameFetchContextTest.cpp

Issue 2918653004: Remove dup'ed code for RequestorOrigin and FirstPartyCookie (Closed)
Patch Set: . Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 document->Loader()->SetLoadType(kFrameLoadTypeBackForward); 761 document->Loader()->SetLoadType(kFrameLoadTypeBackForward);
762 EXPECT_EQ(WebCachePolicy::kReturnCacheDataElseLoad, 762 EXPECT_EQ(WebCachePolicy::kReturnCacheDataElseLoad,
763 fetch_context->ResourceRequestCachePolicy( 763 fetch_context->ResourceRequestCachePolicy(
764 conditional, Resource::kMock, FetchParameters::kNoDefer)); 764 conditional, Resource::kMock, FetchParameters::kNoDefer));
765 } 765 }
766 766
767 TEST_F(FrameFetchContextTest, SetFirstPartyCookieAndRequestorOrigin) { 767 TEST_F(FrameFetchContextTest, SetFirstPartyCookieAndRequestorOrigin) {
768 struct TestCase { 768 struct TestCase {
769 const char* document_url; 769 const char* document_url;
770 bool document_sandboxed; 770 bool document_sandboxed;
771 const char* requestor_origin; // "" => unique origin 771 const char* requestor_origin; // "" => null
772 WebURLRequest::FrameType frame_type; 772 WebURLRequest::FrameType frame_type;
773 const char* serialized_origin; // "" => unique origin 773 const char* serialized_origin; // "" => null
774 } cases[] = { 774 } cases[] = {
775 // No document origin => unique request origin 775 // No document origin => unique request origin
776 {"", false, "", WebURLRequest::kFrameTypeNone, "null"}, 776 {"", false, "", WebURLRequest::kFrameTypeNone, "null"},
777 {"", true, "", WebURLRequest::kFrameTypeNone, "null"}, 777 {"", true, "", WebURLRequest::kFrameTypeNone, "null"},
778 778
779 // Document origin => request origin 779 // Document origin => request origin
780 {"http://example.test", false, "", WebURLRequest::kFrameTypeNone, 780 {"http://example.test", false, "", WebURLRequest::kFrameTypeNone,
781 "http://example.test"}, 781 "http://example.test"},
782 {"http://example.test", true, "", WebURLRequest::kFrameTypeNone, 782 {"http://example.test", true, "", WebURLRequest::kFrameTypeNone,
783 "http://example.test"}, 783 "http://example.test"},
784 784
785 // If the request already has a requestor origin, then 785 // If the request already has a requestor origin, then
786 // 'setFirstPartyCookieAndRequestorOrigin' leaves it alone: 786 // 'SetFirstPartyCookieAndRequestorOrigin' leaves it alone:
787 {"http://example.test", false, "http://not-example.test", 787 {"http://example.test", false, "http://not-example.test",
788 WebURLRequest::kFrameTypeNone, "http://not-example.test"}, 788 WebURLRequest::kFrameTypeNone, "http://not-example.test"},
789 {"http://example.test", true, "http://not-example.test", 789 {"http://example.test", true, "http://not-example.test",
790 WebURLRequest::kFrameTypeNone, "http://not-example.test"}, 790 WebURLRequest::kFrameTypeNone, "http://not-example.test"},
791
792 // If the request's frame type is not 'none', then
793 // 'setFirstPartyCookieAndRequestorOrigin'
794 // leaves it alone:
795 {"http://example.test", false, "", WebURLRequest::kFrameTypeTopLevel, ""},
796 {"http://example.test", false, "", WebURLRequest::kFrameTypeAuxiliary,
797 ""},
798 {"http://example.test", false, "", WebURLRequest::kFrameTypeNested, ""},
799 }; 791 };
800 792
793 int index = 0;
801 for (const auto& test : cases) { 794 for (const auto& test : cases) {
802 SCOPED_TRACE(::testing::Message() 795 SCOPED_TRACE(::testing::Message() << index++ << " " << test.document_url
803 << test.document_url << " => " << test.serialized_origin); 796 << " => " << test.serialized_origin);
804 // Set up a new document to ensure sandbox flags are cleared: 797 // Set up a new document to ensure sandbox flags are cleared:
805 dummy_page_holder = DummyPageHolder::Create(IntSize(500, 500)); 798 dummy_page_holder = DummyPageHolder::Create(IntSize(500, 500));
806 dummy_page_holder->GetPage().SetDeviceScaleFactorDeprecated(1.0); 799 dummy_page_holder->GetPage().SetDeviceScaleFactorDeprecated(1.0);
807 document = &dummy_page_holder->GetDocument(); 800 document = &dummy_page_holder->GetDocument();
808 FrameFetchContext::ProvideDocumentToContext(*fetch_context, document.Get()); 801 FrameFetchContext::ProvideDocumentToContext(*fetch_context, document.Get());
809 802
810 // Setup the test: 803 // Setup the test:
811 document->SetURL(KURL(kParsedURLString, test.document_url)); 804 document->SetURL(KURL(kParsedURLString, test.document_url));
812 document->SetSecurityOrigin(SecurityOrigin::Create(document->Url())); 805 document->SetSecurityOrigin(SecurityOrigin::Create(document->Url()));
813 806
814 if (test.document_sandboxed) 807 if (test.document_sandboxed)
815 document->EnforceSandboxFlags(kSandboxOrigin); 808 document->EnforceSandboxFlags(kSandboxOrigin);
816 809
817 ResourceRequest request("http://example.test/"); 810 ResourceRequest request("http://example.test/");
818 request.SetFrameType(test.frame_type); 811 request.SetFrameType(test.frame_type);
819 if (strlen(test.requestor_origin) > 0) { 812 if (strlen(test.requestor_origin) > 0) {
820 request.SetRequestorOrigin(SecurityOrigin::Create( 813 request.SetRequestorOrigin(SecurityOrigin::Create(
821 KURL(kParsedURLString, test.requestor_origin))); 814 KURL(kParsedURLString, test.requestor_origin)));
822 } 815 }
823 816
824 // Compare the populated |requestorOrigin| against |test.serializedOrigin| 817 // Compare the populated |requestorOrigin| against |test.serializedOrigin|
825 fetch_context->SetFirstPartyCookieAndRequestorOrigin(request); 818 fetch_context->SetFirstPartyCookieAndRequestorOrigin(request);
826 if (strlen(test.serialized_origin) == 0) { 819 if (strlen(test.serialized_origin) == 0) {
827 EXPECT_TRUE(request.RequestorOrigin()->IsUnique()); 820 EXPECT_TRUE(!request.RequestorOrigin());
828 } else { 821 } else {
829 EXPECT_EQ(String(test.serialized_origin), 822 EXPECT_EQ(String(test.serialized_origin),
830 request.RequestorOrigin()->ToString()); 823 request.RequestorOrigin()->ToString());
831 } 824 }
832 825
833 EXPECT_EQ(document->FirstPartyForCookies(), request.FirstPartyForCookies()); 826 EXPECT_EQ(document->FirstPartyForCookies(), request.FirstPartyForCookies());
834 } 827 }
835 } 828 }
836 829
837 // Tests if "Save-Data" header is correctly added on the first load and reload. 830 // 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
952 SetFilterPolicy(WebDocumentSubresourceFilter::kWouldDisallow); 945 SetFilterPolicy(WebDocumentSubresourceFilter::kWouldDisallow);
953 946
954 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequest()); 947 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequest());
955 EXPECT_EQ(0, GetFilteredLoadCallCount()); 948 EXPECT_EQ(0, GetFilteredLoadCallCount());
956 949
957 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequestPreload()); 950 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequestPreload());
958 EXPECT_EQ(0, GetFilteredLoadCallCount()); 951 EXPECT_EQ(0, GetFilteredLoadCallCount());
959 } 952 }
960 953
961 } // namespace blink 954 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698