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

Side by Side Diff: content/browser/frame_host/navigator_impl_unittest.cc

Issue 967383002: PlzNavigate: Avoid duplicate SiteInstance creation during navigation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + content-exporting SiteInstanceDescriptor. Created 5 years, 8 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/browser/frame_host/render_frame_host_manager.h » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "content/browser/frame_host/navigation_controller_impl.h" 8 #include "content/browser/frame_host/navigation_controller_impl.h"
9 #include "content/browser/frame_host/navigation_entry_impl.h" 9 #include "content/browser/frame_host/navigation_entry_impl.h"
10 #include "content/browser/frame_host/navigation_request.h" 10 #include "content/browser/frame_host/navigation_request.h"
(...skipping 18 matching lines...) Expand all
29 #include "net/http/http_response_headers.h" 29 #include "net/http/http_response_headers.h"
30 #include "net/url_request/redirect_info.h" 30 #include "net/url_request/redirect_info.h"
31 #include "ui/base/page_transition_types.h" 31 #include "ui/base/page_transition_types.h"
32 #include "url/url_constants.h" 32 #include "url/url_constants.h"
33 33
34 namespace content { 34 namespace content {
35 35
36 class NavigatorTestWithBrowserSideNavigation 36 class NavigatorTestWithBrowserSideNavigation
37 : public RenderViewHostImplTestHarness { 37 : public RenderViewHostImplTestHarness {
38 public: 38 public:
39 // Re-defines the private RenderFrameHostManager::SiteInstanceDescriptor here
40 // to allow access to it from tests.
41 typedef RenderFrameHostManager::SiteInstanceDescriptor SiteInstanceDescriptor;
42
39 void SetUp() override { 43 void SetUp() override {
40 EnableBrowserSideNavigation(); 44 EnableBrowserSideNavigation();
41 RenderViewHostImplTestHarness::SetUp(); 45 RenderViewHostImplTestHarness::SetUp();
42 } 46 }
43 47
44 TestNavigationURLLoader* GetLoaderForNavigationRequest( 48 TestNavigationURLLoader* GetLoaderForNavigationRequest(
45 NavigationRequest* request) const { 49 NavigationRequest* request) const {
46 return static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); 50 return static_cast<TestNavigationURLLoader*>(request->loader_for_testing());
47 } 51 }
48 52
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 bool DidRenderFrameHostRequestCommit(RenderFrameHostImpl* rfh) { 87 bool DidRenderFrameHostRequestCommit(RenderFrameHostImpl* rfh) {
84 MockRenderProcessHost* rph = 88 MockRenderProcessHost* rph =
85 static_cast<MockRenderProcessHost*>(rfh->GetProcess()); 89 static_cast<MockRenderProcessHost*>(rfh->GetProcess());
86 const FrameMsg_CommitNavigation* commit_message = 90 const FrameMsg_CommitNavigation* commit_message =
87 static_cast<const FrameMsg_CommitNavigation*>( 91 static_cast<const FrameMsg_CommitNavigation*>(
88 rph->sink().GetUniqueMessageMatching( 92 rph->sink().GetUniqueMessageMatching(
89 FrameMsg_CommitNavigation::ID)); 93 FrameMsg_CommitNavigation::ID));
90 return commit_message && 94 return commit_message &&
91 rfh->GetRoutingID() == commit_message->routing_id(); 95 rfh->GetRoutingID() == commit_message->routing_id();
92 } 96 }
97
98 SiteInstance* ConvertToSiteInstance(RenderFrameHostManager* rfhm,
99 const SiteInstanceDescriptor& descriptor,
100 SiteInstance* candidate_instance) {
101 return rfhm->ConvertToSiteInstance(descriptor, candidate_instance);
102 }
93 }; 103 };
94 104
95 // PlzNavigate: Test a complete browser-initiated navigation starting with a 105 // PlzNavigate: Test a complete browser-initiated navigation starting with a
96 // non-live renderer. 106 // non-live renderer.
97 TEST_F(NavigatorTestWithBrowserSideNavigation, 107 TEST_F(NavigatorTestWithBrowserSideNavigation,
98 SimpleBrowserInitiatedNavigationFromNonLiveRenderer) { 108 SimpleBrowserInitiatedNavigationFromNonLiveRenderer) {
99 const GURL kUrl("http://chromium.org/"); 109 const GURL kUrl("http://chromium.org/");
100 110
101 EXPECT_FALSE(main_test_rfh()->IsRenderFrameLive()); 111 EXPECT_FALSE(main_test_rfh()->IsRenderFrameLive());
102 112
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 TestRenderFrameHost* main_rfh = main_test_rfh(); 1000 TestRenderFrameHost* main_rfh = main_test_rfh();
991 main_rfh->SendRendererInitiatedNavigationRequest(kUrl2, true); 1001 main_rfh->SendRendererInitiatedNavigationRequest(kUrl2, true);
992 navigation_request = GetNavigationRequestForFrameTreeNode(node); 1002 navigation_request = GetNavigationRequestForFrameTreeNode(node);
993 ASSERT_TRUE(navigation_request); 1003 ASSERT_TRUE(navigation_request);
994 EXPECT_EQ(NavigationRequest::RESPONSE_STARTED, 1004 EXPECT_EQ(NavigationRequest::RESPONSE_STARTED,
995 navigation_request->state()); 1005 navigation_request->state());
996 EXPECT_FALSE(navigation_request->loader_for_testing()); 1006 EXPECT_FALSE(navigation_request->loader_for_testing());
997 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); 1007 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
998 } 1008 }
999 1009
1010 // Tests several cases for converting SiteInstanceDescriptors into
1011 // SiteInstances:
1012 // 1) Pointer to the current SiteInstance.
1013 // 2) Pointer to an unrelated SiteInstance.
1014 // 3) Same-site URL, related.
1015 // 4) Cross-site URL, related.
1016 // 5) Same-site URL, unrelated (with and without candidate SiteInstances).
1017 // 6) Cross-site URL, unrelated (with candidate SiteInstance).
1018 TEST_F(NavigatorTestWithBrowserSideNavigation,
1019 SiteInstanceDescriptionConversion) {
1020 // Navigate to set a current SiteInstance on the RenderFrameHost.
1021 GURL kUrl1("http://a.com");
1022 contents()->NavigateAndCommit(kUrl1);
1023 SiteInstance* current_instance = main_test_rfh()->GetSiteInstance();
1024 ASSERT_TRUE(current_instance);
1025
1026 // 1) Convert a descriptor pointing to the current instance.
1027 RenderFrameHostManager* rfhm =
1028 main_test_rfh()->frame_tree_node()->render_manager();
1029 {
1030 SiteInstanceDescriptor descriptor(current_instance);
1031 SiteInstance* converted_instance =
1032 ConvertToSiteInstance(rfhm, descriptor, nullptr);
1033 EXPECT_EQ(current_instance, converted_instance);
1034 }
1035
1036 // 2) Convert a descriptor pointing an instance unrelated to the current one,
1037 // with a different site.
1038 GURL kUrl2("http://b.com");
1039 scoped_refptr<SiteInstance> unrelated_instance(
1040 SiteInstance::CreateForURL(browser_context(), kUrl2));
1041 EXPECT_FALSE(
1042 current_instance->IsRelatedSiteInstance(unrelated_instance.get()));
1043 {
1044 SiteInstanceDescriptor descriptor(unrelated_instance.get());
1045 SiteInstance* converted_instance =
1046 ConvertToSiteInstance(rfhm, descriptor, nullptr);
1047 EXPECT_EQ(unrelated_instance.get(), converted_instance);
1048 }
1049
1050 // 3) Convert a descriptor of a related instance with the same site as the
1051 // current one.
1052 GURL kUrlSameSiteAs1("http://www.a.com/foo");
1053 {
1054 SiteInstanceDescriptor descriptor(browser_context(), kUrlSameSiteAs1, true);
1055 SiteInstance* converted_instance =
1056 ConvertToSiteInstance(rfhm, descriptor, nullptr);
1057 EXPECT_EQ(current_instance, converted_instance);
1058 }
1059
1060 // 4) Convert a descriptor of a related instance with a site different from
1061 // the current one.
1062 GURL kUrlSameSiteAs2("http://www.b.com/foo");
1063 scoped_refptr<SiteInstance> related_instance;
1064 {
1065 SiteInstanceDescriptor descriptor(browser_context(), kUrlSameSiteAs2, true);
1066 related_instance = ConvertToSiteInstance(rfhm, descriptor, nullptr);
1067 // Should return a new instance, related to the current, set to the new site
1068 // URL.
1069 EXPECT_TRUE(
1070 current_instance->IsRelatedSiteInstance(related_instance.get()));
1071 EXPECT_NE(current_instance, related_instance.get());
1072 EXPECT_NE(unrelated_instance.get(), related_instance.get());
1073 EXPECT_EQ(SiteInstance::GetSiteForURL(browser_context(), kUrlSameSiteAs2),
1074 related_instance->GetSiteURL());
1075 }
1076
1077 // 5) Convert a descriptor of an unrelated instance with the same site as the
1078 // current one, several times, with and without candidate sites.
1079 {
1080 SiteInstanceDescriptor descriptor(browser_context(), kUrlSameSiteAs1,
1081 false);
1082 scoped_refptr<SiteInstance> converted_instance_1 =
1083 ConvertToSiteInstance(rfhm, descriptor, nullptr);
1084 // Should return a new instance, unrelated to the current one, set to the
1085 // provided site URL.
1086 EXPECT_FALSE(
1087 current_instance->IsRelatedSiteInstance(converted_instance_1.get()));
1088 EXPECT_NE(current_instance, converted_instance_1.get());
1089 EXPECT_NE(unrelated_instance.get(), converted_instance_1.get());
1090 EXPECT_EQ(SiteInstance::GetSiteForURL(browser_context(), kUrlSameSiteAs1),
1091 converted_instance_1->GetSiteURL());
1092
1093 // Does the same but this time using unrelated_instance as a candidate,
1094 // which has a different site.
1095 scoped_refptr<SiteInstance> converted_instance_2 =
1096 ConvertToSiteInstance(rfhm, descriptor, unrelated_instance.get());
1097 // Should return yet another new instance, unrelated to the current one, set
1098 // to the same site URL.
1099 EXPECT_FALSE(
1100 current_instance->IsRelatedSiteInstance(converted_instance_2.get()));
1101 EXPECT_NE(current_instance, converted_instance_2.get());
1102 EXPECT_NE(unrelated_instance.get(), converted_instance_2.get());
1103 EXPECT_NE(converted_instance_1.get(), converted_instance_2.get());
1104 EXPECT_EQ(SiteInstance::GetSiteForURL(browser_context(), kUrlSameSiteAs1),
1105 converted_instance_2->GetSiteURL());
1106
1107 // Converts once more but with |converted_instance_1| as a candidate.
1108 SiteInstance* converted_instance_3 =
1109 ConvertToSiteInstance(rfhm, descriptor, converted_instance_1.get());
1110 // Should return |converted_instance_1| because its site matches and it is
1111 // unrelated to the current SiteInstance.
1112 EXPECT_EQ(converted_instance_1.get(), converted_instance_3);
1113 }
1114
1115 // 6) Convert a descriptor of an unrelated instance with the same site of
1116 // related_instance and using it as a candidate.
1117 {
1118 SiteInstanceDescriptor descriptor(browser_context(), kUrlSameSiteAs2,
1119 false);
1120 scoped_refptr<SiteInstance> converted_instance_1 =
1121 ConvertToSiteInstance(rfhm, descriptor, related_instance.get());
1122 // Should return a new instance, unrelated to the current, set to the
1123 // provided site URL.
1124 EXPECT_FALSE(
1125 current_instance->IsRelatedSiteInstance(converted_instance_1.get()));
1126 EXPECT_NE(related_instance.get(), converted_instance_1.get());
1127 EXPECT_NE(unrelated_instance.get(), converted_instance_1.get());
1128 EXPECT_EQ(SiteInstance::GetSiteForURL(browser_context(), kUrlSameSiteAs2),
1129 converted_instance_1->GetSiteURL());
1130
1131 SiteInstance* converted_instance_2 =
1132 ConvertToSiteInstance(rfhm, descriptor, unrelated_instance.get());
1133 // Should return |unrelated_instance| because its site matches and it is
1134 // unrelated to the current SiteInstance.
1135 EXPECT_EQ(unrelated_instance.get(), converted_instance_2);
1136 }
1137 }
1138
1000 } // namespace content 1139 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/frame_host/render_frame_host_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698