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

Side by Side Diff: content/browser/loader/resource_dispatcher_host_browsertest.cc

Issue 2084333002: Correctly set 'firstPartyForCookies' in 'RenderFrameImpl::willSendRequest'. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missed one. Created 4 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
« no previous file with comments | « no previous file | content/renderer/render_frame_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/public/browser/resource_dispatcher_host.h" 5 #include "content/public/browser/resource_dispatcher_host.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 14 matching lines...) Expand all
25 #include "content/public/common/url_constants.h" 25 #include "content/public/common/url_constants.h"
26 #include "content/public/test/browser_test_utils.h" 26 #include "content/public/test/browser_test_utils.h"
27 #include "content/public/test/content_browser_test.h" 27 #include "content/public/test/content_browser_test.h"
28 #include "content/public/test/content_browser_test_utils.h" 28 #include "content/public/test/content_browser_test_utils.h"
29 #include "content/public/test/test_navigation_observer.h" 29 #include "content/public/test/test_navigation_observer.h"
30 #include "content/public/test/test_utils.h" 30 #include "content/public/test/test_utils.h"
31 #include "content/shell/browser/shell.h" 31 #include "content/shell/browser/shell.h"
32 #include "content/shell/browser/shell_content_browser_client.h" 32 #include "content/shell/browser/shell_content_browser_client.h"
33 #include "content/shell/browser/shell_network_delegate.h" 33 #include "content/shell/browser/shell_network_delegate.h"
34 #include "net/base/net_errors.h" 34 #include "net/base/net_errors.h"
35 #include "net/dns/mock_host_resolver.h"
35 #include "net/test/embedded_test_server/embedded_test_server.h" 36 #include "net/test/embedded_test_server/embedded_test_server.h"
36 #include "net/test/embedded_test_server/http_request.h" 37 #include "net/test/embedded_test_server/http_request.h"
37 #include "net/test/embedded_test_server/http_response.h" 38 #include "net/test/embedded_test_server/http_response.h"
38 #include "net/test/url_request/url_request_failed_job.h" 39 #include "net/test/url_request/url_request_failed_job.h"
39 #include "net/test/url_request/url_request_mock_http_job.h" 40 #include "net/test/url_request/url_request_mock_http_job.h"
40 #include "net/url_request/url_request.h" 41 #include "net/url_request/url_request.h"
41 #include "url/gurl.h" 42 #include "url/gurl.h"
42 43
43 using base::ASCIIToUTF16; 44 using base::ASCIIToUTF16;
44 45
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 CheckResourcesRequested(true); 743 CheckResourcesRequested(true);
743 744
744 // Reload with Lo-Fi disabled. 745 // Reload with Lo-Fi disabled.
745 Reset(false); 746 Reset(false);
746 TestNavigationObserver tab_observer(shell()->web_contents(), 1); 747 TestNavigationObserver tab_observer(shell()->web_contents(), 1);
747 shell()->web_contents()->GetController().ReloadDisableLoFi(true); 748 shell()->web_contents()->GetController().ReloadDisableLoFi(true);
748 tab_observer.Wait(); 749 tab_observer.Wait();
749 CheckResourcesRequested(false); 750 CheckResourcesRequested(false);
750 } 751 }
751 752
753 namespace {
754
755 struct RequestDataForDelegate {
756 const GURL url;
757 const GURL first_party;
758
759 RequestDataForDelegate(const GURL& url,
760 const GURL& first_party)
761 : url(url), first_party(first_party) {}
762 };
763
764 // Captures calls to 'RequestBeginning' and records the URL, first-party for
765 // cookies, and initiator.
766 class RequestDataResourceDispatcherHostDelegate
767 : public ResourceDispatcherHostDelegate {
768 public:
769 RequestDataResourceDispatcherHostDelegate() {}
770
771 const ScopedVector<RequestDataForDelegate>& data() { return requests_; }
772
773 // ResourceDispatcherHostDelegate implementation:
774 void RequestBeginning(net::URLRequest* request,
775 ResourceContext* resource_context,
776 AppCacheService* appcache_service,
777 ResourceType resource_type,
778 ScopedVector<ResourceThrottle>* throttles) override {
779 requests_.push_back(new RequestDataForDelegate(
780 request->url(), request->first_party_for_cookies()));
781 }
782
783 void SetDelegate() { ResourceDispatcherHost::Get()->SetDelegate(this); }
784
785 private:
786 ScopedVector<RequestDataForDelegate> requests_;
787
788 DISALLOW_COPY_AND_ASSIGN(RequestDataResourceDispatcherHostDelegate);
789 };
790
791 const GURL kURLWithUniqueOrigin("data:,");
792
793 } // namespace
794
795 class RequestDataResourceDispatcherHostBrowserTest : public ContentBrowserTest {
796 public:
797 ~RequestDataResourceDispatcherHostBrowserTest() override {}
798
799 protected:
800 void SetUpOnMainThread() override {
801 ContentBrowserTest::SetUpOnMainThread();
802
803 ASSERT_TRUE(embedded_test_server()->Start());
804
805 delegate_.reset(new RequestDataResourceDispatcherHostDelegate());
806
807 content::BrowserThread::PostTask(
808 content::BrowserThread::IO, FROM_HERE,
809 base::Bind(&RequestDataResourceDispatcherHostDelegate::SetDelegate,
810 base::Unretained(delegate_.get())));
811 }
812
813 protected:
814 std::unique_ptr<RequestDataResourceDispatcherHostDelegate> delegate_;
815 };
816
817 IN_PROC_BROWSER_TEST_F(RequestDataResourceDispatcherHostBrowserTest, Basic) {
818 GURL top_url(embedded_test_server()->GetURL("/simple_page.html"));
819
820 NavigateToURLBlockUntilNavigationsComplete(shell(), top_url, 1);
821
822 EXPECT_EQ(1u, delegate_->data().size());
823
824 // User-initiated top-level navigations have a first-party and initiator that
825 // matches the URL to which they navigate.
826 EXPECT_EQ(top_url, delegate_->data()[0]->url);
827 EXPECT_EQ(top_url, delegate_->data()[0]->first_party);
828 }
829
830 IN_PROC_BROWSER_TEST_F(RequestDataResourceDispatcherHostBrowserTest,
831 SameOriginNested) {
832 GURL top_url(embedded_test_server()->GetURL("/page_with_iframe.html"));
833 GURL image_url(embedded_test_server()->GetURL("/image.jpg"));
834 GURL nested_url(embedded_test_server()->GetURL("/title1.html"));
835
836 NavigateToURLBlockUntilNavigationsComplete(shell(), top_url, 1);
837
838 EXPECT_EQ(3u, delegate_->data().size());
839
840 // User-initiated top-level navigations have a first-party and initiator that
841 // matches the URL to which they navigate.
842 EXPECT_EQ(top_url, delegate_->data()[0]->url);
843 EXPECT_EQ(top_url, delegate_->data()[0]->first_party);
844
845 // Subresource requests have a first-party and initiator that matches the
846 // document in which they're embedded.
847 EXPECT_EQ(image_url, delegate_->data()[1]->url);
848 EXPECT_EQ(top_url, delegate_->data()[1]->first_party);
849
850 // Same-origin nested frames have a first-party and initiator that matches
851 // the document in which they're embedded.
852 EXPECT_EQ(nested_url, delegate_->data()[2]->url);
853 EXPECT_EQ(top_url, delegate_->data()[2]->first_party);
854 }
855
856 IN_PROC_BROWSER_TEST_F(RequestDataResourceDispatcherHostBrowserTest,
857 SameOriginAuxiliary) {
858 GURL top_url(embedded_test_server()->GetURL("/simple_links.html"));
859 GURL auxiliary_url(embedded_test_server()->GetURL("/title2.html"));
860
861 NavigateToURLBlockUntilNavigationsComplete(shell(), top_url, 1);
862
863 ShellAddedObserver new_shell_observer;
864 bool success = false;
865 EXPECT_TRUE(ExecuteScriptAndExtractBool(
866 shell(),
867 "window.domAutomationController.send(clickSameSiteNewWindowLink());",
868 &success));
869 EXPECT_TRUE(success);
870 Shell* new_shell = new_shell_observer.GetShell();
871 WaitForLoadStop(new_shell->web_contents());
872
873 EXPECT_EQ(2u, delegate_->data().size());
874
875 // User-initiated top-level navigations have a first-party and initiator that
876 // matches the URL to which they navigate, even if they fail to load.
877 EXPECT_EQ(top_url, delegate_->data()[0]->url);
878 EXPECT_EQ(top_url, delegate_->data()[0]->first_party);
879
880 // Auxiliary navigations have a first-party that matches the URL to which they
881 // navigate, and an initiator that matches the document that triggered them.
882 EXPECT_EQ(auxiliary_url, delegate_->data()[1]->url);
883 EXPECT_EQ(auxiliary_url, delegate_->data()[1]->first_party);
884 }
885
886 IN_PROC_BROWSER_TEST_F(RequestDataResourceDispatcherHostBrowserTest,
887 CrossOriginAuxiliary) {
888 GURL top_url(embedded_test_server()->GetURL("/simple_links.html"));
889 GURL auxiliary_url(embedded_test_server()->GetURL("foo.com", "/title2.html"));
890
891 NavigateToURLBlockUntilNavigationsComplete(shell(), top_url, 1);
892
893 const char kReplacePortNumber[] =
894 "window.domAutomationController.send(setPortNumber(%d));";
895 uint16_t port_number = embedded_test_server()->port();
896 bool success = false;
897 EXPECT_TRUE(ExecuteScriptAndExtractBool(
898 shell(), base::StringPrintf(kReplacePortNumber, port_number), &success));
899 success = false;
900
901 ShellAddedObserver new_shell_observer;
902 success = false;
903 EXPECT_TRUE(ExecuteScriptAndExtractBool(
904 shell(),
905 "window.domAutomationController.send(clickCrossSiteNewWindowLink());",
906 &success));
907 EXPECT_TRUE(success);
908 Shell* new_shell = new_shell_observer.GetShell();
909 WaitForLoadStop(new_shell->web_contents());
910
911 EXPECT_EQ(2u, delegate_->data().size());
912
913 // User-initiated top-level navigations have a first-party and initiator that
914 // matches the URL to which they navigate, even if they fail to load.
915 EXPECT_EQ(top_url, delegate_->data()[0]->url);
916 EXPECT_EQ(top_url, delegate_->data()[0]->first_party);
917
918 // Auxiliary navigations have a first-party that matches the URL to which they
919 // navigate, and an initiator that matches the document that triggered them.
920 EXPECT_EQ(auxiliary_url, delegate_->data()[1]->url);
921 EXPECT_EQ(auxiliary_url, delegate_->data()[1]->first_party);
922 }
923
924 IN_PROC_BROWSER_TEST_F(RequestDataResourceDispatcherHostBrowserTest,
925 FailedNavigation) {
926 // Navigating to this URL will fail, as we haven't taught the host resolver
927 // about 'a.com'.
928 GURL top_url(embedded_test_server()->GetURL("a.com", "/simple_page.html"));
929
930 NavigateToURLBlockUntilNavigationsComplete(shell(), top_url, 1);
931
932 EXPECT_EQ(1u, delegate_->data().size());
933
934 // User-initiated top-level navigations have a first-party and initiator that
935 // matches the URL to which they navigate, even if they fail to load.
936 EXPECT_EQ(top_url, delegate_->data()[0]->url);
937 EXPECT_EQ(top_url, delegate_->data()[0]->first_party);
938 }
939
940 IN_PROC_BROWSER_TEST_F(RequestDataResourceDispatcherHostBrowserTest,
941 CrossOriginNested) {
942 host_resolver()->AddRule("*", "127.0.0.1");
943 GURL top_url(embedded_test_server()->GetURL(
944 "a.com", "/cross_site_iframe_factory.html?a(b)"));
945 GURL top_js_url(
946 embedded_test_server()->GetURL("a.com", "/tree_parser_util.js"));
947 GURL nested_url(embedded_test_server()->GetURL(
948 "b.com", "/cross_site_iframe_factory.html?b()"));
949 GURL nested_js_url(
950 embedded_test_server()->GetURL("b.com", "/tree_parser_util.js"));
951
952 NavigateToURLBlockUntilNavigationsComplete(shell(), top_url, 1);
953
954 EXPECT_EQ(4u, delegate_->data().size());
955
956 // User-initiated top-level navigations have a first-party and initiator that
957 // matches the URL to which they navigate.
958 EXPECT_EQ(top_url, delegate_->data()[0]->url);
959 EXPECT_EQ(top_url, delegate_->data()[0]->first_party);
960
961 EXPECT_EQ(top_js_url, delegate_->data()[1]->url);
962 EXPECT_EQ(top_url, delegate_->data()[1]->first_party);
963
964 // Cross-origin frame requests have a first-party and initiator that matches
965 // the URL in which they're embedded.
966 EXPECT_EQ(nested_url, delegate_->data()[2]->url);
967 EXPECT_EQ(top_url, delegate_->data()[2]->first_party);
968
969 // Cross-origin subresource requests have a unique first-party, and an
970 // initiator that matches the document in which they're embedded.
971 EXPECT_EQ(nested_js_url, delegate_->data()[3]->url);
972 EXPECT_EQ(kURLWithUniqueOrigin, delegate_->data()[3]->first_party);
973 }
974
752 } // namespace content 975 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/render_frame_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698