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

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: Add tests to check RFHM::ConvertToSiteInstance works as expected. 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
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 TEST_F(NavigatorTestWithBrowserSideNavigation,
Charlie Reis 2015/04/02 21:23:25 Let's give a roadmap for the test in a comment bef
carlosk 2015/04/03 16:11:19 Done.
1011 SiteInstanceDescriptionConversion) {
1012 // Navigate to set a current SiteInstance on the RenderFrameHost.
1013 GURL kUrl1("http://a.com");
1014 contents()->NavigateAndCommit(kUrl1);
1015 SiteInstance* current_instance = main_test_rfh()->GetSiteInstance();
1016 ASSERT_TRUE(current_instance);
1017
1018 // Convert a descriptor pointing to the current instance.
1019 RenderFrameHostManager* rfhm =
1020 main_test_rfh()->frame_tree_node()->render_manager();
1021 {
1022 SiteInstanceDescriptor descriptor(current_instance);
1023 SiteInstance* converted_instance =
1024 ConvertToSiteInstance(rfhm, descriptor, nullptr);
1025 EXPECT_EQ(current_instance, converted_instance);
1026 }
carlosk 2015/04/02 17:15:05 I used a lot of scoping here to avoid mixing up th
Charlie Reis 2015/04/02 21:23:24 Acknowledged.
1027
1028 // Convert a descriptor pointing an instance unrelated to the current one,
1029 // with a different site.
1030 GURL kUrl2("http://b.com");
1031 scoped_refptr<SiteInstanceImpl> unrelated_instance(
1032 static_cast<SiteInstanceImpl*>(
1033 SiteInstanceImpl::Create(browser_context())));
1034 unrelated_instance->SetSite(kUrl2);
1035 EXPECT_FALSE(
1036 current_instance->IsRelatedSiteInstance(unrelated_instance.get()));
1037 {
1038 SiteInstanceDescriptor descriptor(unrelated_instance.get());
1039 SiteInstance* converted_instance =
1040 ConvertToSiteInstance(rfhm, descriptor, nullptr);
1041 EXPECT_EQ(unrelated_instance.get(), converted_instance);
1042 }
1043
1044 // Convert a descriptor of a related instance with the same site as the
1045 // current one.
1046 GURL kUrlSameSiteAs1("http://www.a.com/foo");
1047 {
1048 SiteInstanceDescriptor descriptor(kUrlSameSiteAs1, true, browser_context());
1049 SiteInstance* converted_instance =
1050 ConvertToSiteInstance(rfhm, descriptor, nullptr);
1051 EXPECT_EQ(current_instance, converted_instance);
1052 }
1053
1054 // Convert a descriptor of a related instance with a site different from the
1055 // current one.
1056 GURL kUrlSameSiteAs2("http://www.b.com/foo");
1057 scoped_refptr<SiteInstance> related_instance;
1058 {
1059 SiteInstanceDescriptor descriptor(kUrlSameSiteAs2, true, browser_context());
1060 related_instance = ConvertToSiteInstance(rfhm, descriptor, nullptr);
1061 // Should return a new instance, related to the current, set to the new site
1062 // URL.
1063 EXPECT_TRUE(
1064 current_instance->IsRelatedSiteInstance(related_instance.get()));
1065 EXPECT_NE(current_instance, related_instance.get());
1066 EXPECT_NE(unrelated_instance.get(), related_instance.get());
1067 EXPECT_EQ(
1068 SiteInstanceImpl::GetSiteForURL(browser_context(), kUrlSameSiteAs2),
Charlie Reis 2015/04/02 21:23:25 nit: s/SiteInstanceImpl/SiteInstance/ Also, I'm n
carlosk 2015/04/03 16:11:19 Done. Also replaced SiteInstanceImpl::Create + Se
1069 related_instance->GetSiteURL());
1070 }
1071
1072 // Convert a descriptor of an unrelated instance with the same site as the
1073 // current one.
1074 {
1075 SiteInstanceDescriptor descriptor(kUrlSameSiteAs1, false,
1076 browser_context());
1077 scoped_refptr<SiteInstance> converted_instance_1 =
1078 ConvertToSiteInstance(rfhm, descriptor, nullptr);
1079 // Should return a new instance, unrelated to the current one, set to the
1080 // provided site URL.
1081 EXPECT_FALSE(
1082 current_instance->IsRelatedSiteInstance(converted_instance_1.get()));
1083 EXPECT_NE(current_instance, converted_instance_1.get());
1084 EXPECT_NE(unrelated_instance.get(), converted_instance_1.get());
1085 EXPECT_EQ(
1086 SiteInstanceImpl::GetSiteForURL(browser_context(), kUrlSameSiteAs1),
1087 converted_instance_1->GetSiteURL());
1088
1089 // Does the same but this time using unrelated_instance as a candidate,
1090 // which has a different site.
1091 scoped_refptr<SiteInstance> converted_instance_2 =
1092 ConvertToSiteInstance(rfhm, descriptor, unrelated_instance.get());
1093 // Should return yet another new instance, unrelated to the current one, set
1094 // to the same site URL.
1095 EXPECT_FALSE(
1096 current_instance->IsRelatedSiteInstance(converted_instance_2.get()));
1097 EXPECT_NE(current_instance, converted_instance_2.get());
1098 EXPECT_NE(unrelated_instance.get(), converted_instance_2.get());
1099 EXPECT_NE(converted_instance_1.get(), converted_instance_2.get());
1100 EXPECT_EQ(
1101 SiteInstanceImpl::GetSiteForURL(browser_context(), kUrlSameSiteAs1),
1102 converted_instance_2->GetSiteURL());
1103
1104 // Converts once more but with converted_instance_1 as a candidate.
1105 SiteInstance* converted_instance_3 =
1106 ConvertToSiteInstance(rfhm, descriptor, converted_instance_1.get());
1107 // Should return converted_instance_1
Charlie Reis 2015/04/02 21:23:25 nit: End with period. Also mention "because the si
carlosk 2015/04/03 16:11:19 Done.
1108 EXPECT_EQ(converted_instance_1.get(), converted_instance_3);
1109 }
1110
1111 // Convert a descriptor of an unrelated instance with the same site of
1112 // related_instance and using it as a candidate.
1113 {
1114 SiteInstanceDescriptor descriptor(kUrlSameSiteAs2, false,
1115 browser_context());
1116 scoped_refptr<SiteInstance> converted_instance =
1117 ConvertToSiteInstance(rfhm, descriptor, related_instance.get());
1118 // Should return a new instance, unrelated to the current, set to the
1119 // provided site URL.
1120 EXPECT_FALSE(
1121 current_instance->IsRelatedSiteInstance(converted_instance.get()));
1122 EXPECT_NE(related_instance.get(), converted_instance.get());
1123 EXPECT_NE(unrelated_instance.get(), converted_instance.get());
Charlie Reis 2015/04/02 21:23:25 As in case #5, can we add a line to ensure that Co
carlosk 2015/04/03 16:11:19 Done.
1124 EXPECT_EQ(
1125 SiteInstanceImpl::GetSiteForURL(browser_context(), kUrlSameSiteAs2),
1126 converted_instance->GetSiteURL());
1127 }
1128 }
1129
1000 } // namespace content 1130 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698