| OLD | NEW |
| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "content/browser/frame_host/navigation_controller_impl.h" | 10 #include "content/browser/frame_host/navigation_controller_impl.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // Note: caller must invoke ClearMessages on the sink at some point before | 102 // Note: caller must invoke ClearMessages on the sink at some point before |
| 103 // the tracked commit happens to clear up commit messages from previous | 103 // the tracked commit happens to clear up commit messages from previous |
| 104 // navigations. | 104 // navigations. |
| 105 bool DidRenderFrameHostRequestCommit(TestRenderFrameHost* rfh) { | 105 bool DidRenderFrameHostRequestCommit(TestRenderFrameHost* rfh) { |
| 106 const IPC::Message* message = | 106 const IPC::Message* message = |
| 107 rfh->GetProcess()->sink().GetUniqueMessageMatching( | 107 rfh->GetProcess()->sink().GetUniqueMessageMatching( |
| 108 FrameMsg_CommitNavigation::ID); | 108 FrameMsg_CommitNavigation::ID); |
| 109 return message && rfh->GetRoutingID() == message->routing_id(); | 109 return message && rfh->GetRoutingID() == message->routing_id(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 scoped_refptr<SiteInstance> ConvertToSiteInstance( | 112 scoped_refptr<SiteInstanceImpl> ConvertToSiteInstance( |
| 113 RenderFrameHostManager* rfhm, | 113 RenderFrameHostManager* rfhm, |
| 114 const SiteInstanceDescriptor& descriptor, | 114 const SiteInstanceDescriptor& descriptor, |
| 115 SiteInstance* candidate_instance) { | 115 SiteInstanceImpl* candidate_instance) { |
| 116 return rfhm->ConvertToSiteInstance(descriptor, candidate_instance); | 116 return rfhm->ConvertToSiteInstance(descriptor, candidate_instance); |
| 117 } | 117 } |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 // PlzNavigate: Test a complete browser-initiated navigation starting with a | 120 // PlzNavigate: Test a complete browser-initiated navigation starting with a |
| 121 // non-live renderer. | 121 // non-live renderer. |
| 122 TEST_F(NavigatorTestWithBrowserSideNavigation, | 122 TEST_F(NavigatorTestWithBrowserSideNavigation, |
| 123 SimpleBrowserInitiatedNavigationFromNonLiveRenderer) { | 123 SimpleBrowserInitiatedNavigationFromNonLiveRenderer) { |
| 124 const GURL kUrl("http://chromium.org/"); | 124 const GURL kUrl("http://chromium.org/"); |
| 125 | 125 |
| (...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 // 2) Pointer to an unrelated SiteInstance. | 1010 // 2) Pointer to an unrelated SiteInstance. |
| 1011 // 3) Same-site URL, related. | 1011 // 3) Same-site URL, related. |
| 1012 // 4) Cross-site URL, related. | 1012 // 4) Cross-site URL, related. |
| 1013 // 5) Same-site URL, unrelated (with and without candidate SiteInstances). | 1013 // 5) Same-site URL, unrelated (with and without candidate SiteInstances). |
| 1014 // 6) Cross-site URL, unrelated (with candidate SiteInstance). | 1014 // 6) Cross-site URL, unrelated (with candidate SiteInstance). |
| 1015 TEST_F(NavigatorTestWithBrowserSideNavigation, | 1015 TEST_F(NavigatorTestWithBrowserSideNavigation, |
| 1016 SiteInstanceDescriptionConversion) { | 1016 SiteInstanceDescriptionConversion) { |
| 1017 // Navigate to set a current SiteInstance on the RenderFrameHost. | 1017 // Navigate to set a current SiteInstance on the RenderFrameHost. |
| 1018 GURL kUrl1("http://a.com"); | 1018 GURL kUrl1("http://a.com"); |
| 1019 contents()->NavigateAndCommit(kUrl1); | 1019 contents()->NavigateAndCommit(kUrl1); |
| 1020 SiteInstance* current_instance = main_test_rfh()->GetSiteInstance(); | 1020 SiteInstanceImpl* current_instance = main_test_rfh()->GetSiteInstance(); |
| 1021 ASSERT_TRUE(current_instance); | 1021 ASSERT_TRUE(current_instance); |
| 1022 | 1022 |
| 1023 // 1) Convert a descriptor pointing to the current instance. | 1023 // 1) Convert a descriptor pointing to the current instance. |
| 1024 RenderFrameHostManager* rfhm = | 1024 RenderFrameHostManager* rfhm = |
| 1025 main_test_rfh()->frame_tree_node()->render_manager(); | 1025 main_test_rfh()->frame_tree_node()->render_manager(); |
| 1026 { | 1026 { |
| 1027 SiteInstanceDescriptor descriptor(current_instance); | 1027 SiteInstanceDescriptor descriptor(current_instance); |
| 1028 scoped_refptr<SiteInstance> converted_instance = | 1028 scoped_refptr<SiteInstanceImpl> converted_instance = |
| 1029 ConvertToSiteInstance(rfhm, descriptor, nullptr); | 1029 ConvertToSiteInstance(rfhm, descriptor, nullptr); |
| 1030 EXPECT_EQ(current_instance, converted_instance); | 1030 EXPECT_EQ(current_instance, converted_instance); |
| 1031 } | 1031 } |
| 1032 | 1032 |
| 1033 // 2) Convert a descriptor pointing an instance unrelated to the current one, | 1033 // 2) Convert a descriptor pointing an instance unrelated to the current one, |
| 1034 // with a different site. | 1034 // with a different site. |
| 1035 GURL kUrl2("http://b.com"); | 1035 GURL kUrl2("http://b.com"); |
| 1036 scoped_refptr<SiteInstance> unrelated_instance( | 1036 scoped_refptr<SiteInstanceImpl> unrelated_instance( |
| 1037 SiteInstance::CreateForURL(browser_context(), kUrl2)); | 1037 SiteInstanceImpl::CreateForURL(browser_context(), kUrl2)); |
| 1038 EXPECT_FALSE( | 1038 EXPECT_FALSE( |
| 1039 current_instance->IsRelatedSiteInstance(unrelated_instance.get())); | 1039 current_instance->IsRelatedSiteInstance(unrelated_instance.get())); |
| 1040 { | 1040 { |
| 1041 SiteInstanceDescriptor descriptor(unrelated_instance.get()); | 1041 SiteInstanceDescriptor descriptor(unrelated_instance.get()); |
| 1042 scoped_refptr<SiteInstance> converted_instance = | 1042 scoped_refptr<SiteInstanceImpl> converted_instance = |
| 1043 ConvertToSiteInstance(rfhm, descriptor, nullptr); | 1043 ConvertToSiteInstance(rfhm, descriptor, nullptr); |
| 1044 EXPECT_EQ(unrelated_instance.get(), converted_instance); | 1044 EXPECT_EQ(unrelated_instance.get(), converted_instance); |
| 1045 } | 1045 } |
| 1046 | 1046 |
| 1047 // 3) Convert a descriptor of a related instance with the same site as the | 1047 // 3) Convert a descriptor of a related instance with the same site as the |
| 1048 // current one. | 1048 // current one. |
| 1049 GURL kUrlSameSiteAs1("http://www.a.com/foo"); | 1049 GURL kUrlSameSiteAs1("http://www.a.com/foo"); |
| 1050 { | 1050 { |
| 1051 SiteInstanceDescriptor descriptor(browser_context(), kUrlSameSiteAs1, | 1051 SiteInstanceDescriptor descriptor(browser_context(), kUrlSameSiteAs1, |
| 1052 SiteInstanceRelation::RELATED); | 1052 SiteInstanceRelation::RELATED); |
| 1053 scoped_refptr<SiteInstance> converted_instance = | 1053 scoped_refptr<SiteInstanceImpl> converted_instance = |
| 1054 ConvertToSiteInstance(rfhm, descriptor, nullptr); | 1054 ConvertToSiteInstance(rfhm, descriptor, nullptr); |
| 1055 EXPECT_EQ(current_instance, converted_instance); | 1055 EXPECT_EQ(current_instance, converted_instance); |
| 1056 } | 1056 } |
| 1057 | 1057 |
| 1058 // 4) Convert a descriptor of a related instance with a site different from | 1058 // 4) Convert a descriptor of a related instance with a site different from |
| 1059 // the current one. | 1059 // the current one. |
| 1060 GURL kUrlSameSiteAs2("http://www.b.com/foo"); | 1060 GURL kUrlSameSiteAs2("http://www.b.com/foo"); |
| 1061 scoped_refptr<SiteInstance> related_instance; | 1061 scoped_refptr<SiteInstanceImpl> related_instance; |
| 1062 { | 1062 { |
| 1063 SiteInstanceDescriptor descriptor(browser_context(), kUrlSameSiteAs2, | 1063 SiteInstanceDescriptor descriptor(browser_context(), kUrlSameSiteAs2, |
| 1064 SiteInstanceRelation::RELATED); | 1064 SiteInstanceRelation::RELATED); |
| 1065 related_instance = ConvertToSiteInstance(rfhm, descriptor, nullptr); | 1065 related_instance = ConvertToSiteInstance(rfhm, descriptor, nullptr); |
| 1066 // Should return a new instance, related to the current, set to the new site | 1066 // Should return a new instance, related to the current, set to the new site |
| 1067 // URL. | 1067 // URL. |
| 1068 EXPECT_TRUE( | 1068 EXPECT_TRUE( |
| 1069 current_instance->IsRelatedSiteInstance(related_instance.get())); | 1069 current_instance->IsRelatedSiteInstance(related_instance.get())); |
| 1070 EXPECT_NE(current_instance, related_instance.get()); | 1070 EXPECT_NE(current_instance, related_instance.get()); |
| 1071 EXPECT_NE(unrelated_instance.get(), related_instance.get()); | 1071 EXPECT_NE(unrelated_instance.get(), related_instance.get()); |
| 1072 EXPECT_EQ(SiteInstance::GetSiteForURL(browser_context(), kUrlSameSiteAs2), | 1072 EXPECT_EQ(SiteInstance::GetSiteForURL(browser_context(), kUrlSameSiteAs2), |
| 1073 related_instance->GetSiteURL()); | 1073 related_instance->GetSiteURL()); |
| 1074 } | 1074 } |
| 1075 | 1075 |
| 1076 // 5) Convert a descriptor of an unrelated instance with the same site as the | 1076 // 5) Convert a descriptor of an unrelated instance with the same site as the |
| 1077 // current one, several times, with and without candidate sites. | 1077 // current one, several times, with and without candidate sites. |
| 1078 { | 1078 { |
| 1079 SiteInstanceDescriptor descriptor(browser_context(), kUrlSameSiteAs1, | 1079 SiteInstanceDescriptor descriptor(browser_context(), kUrlSameSiteAs1, |
| 1080 SiteInstanceRelation::UNRELATED); | 1080 SiteInstanceRelation::UNRELATED); |
| 1081 scoped_refptr<SiteInstance> converted_instance_1 = | 1081 scoped_refptr<SiteInstanceImpl> converted_instance_1 = |
| 1082 ConvertToSiteInstance(rfhm, descriptor, nullptr); | 1082 ConvertToSiteInstance(rfhm, descriptor, nullptr); |
| 1083 // Should return a new instance, unrelated to the current one, set to the | 1083 // Should return a new instance, unrelated to the current one, set to the |
| 1084 // provided site URL. | 1084 // provided site URL. |
| 1085 EXPECT_FALSE( | 1085 EXPECT_FALSE( |
| 1086 current_instance->IsRelatedSiteInstance(converted_instance_1.get())); | 1086 current_instance->IsRelatedSiteInstance(converted_instance_1.get())); |
| 1087 EXPECT_NE(current_instance, converted_instance_1.get()); | 1087 EXPECT_NE(current_instance, converted_instance_1.get()); |
| 1088 EXPECT_NE(unrelated_instance.get(), converted_instance_1.get()); | 1088 EXPECT_NE(unrelated_instance.get(), converted_instance_1.get()); |
| 1089 EXPECT_EQ(SiteInstance::GetSiteForURL(browser_context(), kUrlSameSiteAs1), | 1089 EXPECT_EQ(SiteInstance::GetSiteForURL(browser_context(), kUrlSameSiteAs1), |
| 1090 converted_instance_1->GetSiteURL()); | 1090 converted_instance_1->GetSiteURL()); |
| 1091 | 1091 |
| 1092 // Does the same but this time using unrelated_instance as a candidate, | 1092 // Does the same but this time using unrelated_instance as a candidate, |
| 1093 // which has a different site. | 1093 // which has a different site. |
| 1094 scoped_refptr<SiteInstance> converted_instance_2 = | 1094 scoped_refptr<SiteInstanceImpl> converted_instance_2 = |
| 1095 ConvertToSiteInstance(rfhm, descriptor, unrelated_instance.get()); | 1095 ConvertToSiteInstance(rfhm, descriptor, unrelated_instance.get()); |
| 1096 // Should return yet another new instance, unrelated to the current one, set | 1096 // Should return yet another new instance, unrelated to the current one, set |
| 1097 // to the same site URL. | 1097 // to the same site URL. |
| 1098 EXPECT_FALSE( | 1098 EXPECT_FALSE( |
| 1099 current_instance->IsRelatedSiteInstance(converted_instance_2.get())); | 1099 current_instance->IsRelatedSiteInstance(converted_instance_2.get())); |
| 1100 EXPECT_NE(current_instance, converted_instance_2.get()); | 1100 EXPECT_NE(current_instance, converted_instance_2.get()); |
| 1101 EXPECT_NE(unrelated_instance.get(), converted_instance_2.get()); | 1101 EXPECT_NE(unrelated_instance.get(), converted_instance_2.get()); |
| 1102 EXPECT_NE(converted_instance_1.get(), converted_instance_2.get()); | 1102 EXPECT_NE(converted_instance_1.get(), converted_instance_2.get()); |
| 1103 EXPECT_EQ(SiteInstance::GetSiteForURL(browser_context(), kUrlSameSiteAs1), | 1103 EXPECT_EQ(SiteInstance::GetSiteForURL(browser_context(), kUrlSameSiteAs1), |
| 1104 converted_instance_2->GetSiteURL()); | 1104 converted_instance_2->GetSiteURL()); |
| 1105 | 1105 |
| 1106 // Converts once more but with |converted_instance_1| as a candidate. | 1106 // Converts once more but with |converted_instance_1| as a candidate. |
| 1107 scoped_refptr<SiteInstance> converted_instance_3 = | 1107 scoped_refptr<SiteInstanceImpl> converted_instance_3 = |
| 1108 ConvertToSiteInstance(rfhm, descriptor, converted_instance_1.get()); | 1108 ConvertToSiteInstance(rfhm, descriptor, converted_instance_1.get()); |
| 1109 // Should return |converted_instance_1| because its site matches and it is | 1109 // Should return |converted_instance_1| because its site matches and it is |
| 1110 // unrelated to the current SiteInstance. | 1110 // unrelated to the current SiteInstance. |
| 1111 EXPECT_EQ(converted_instance_1.get(), converted_instance_3); | 1111 EXPECT_EQ(converted_instance_1.get(), converted_instance_3); |
| 1112 } | 1112 } |
| 1113 | 1113 |
| 1114 // 6) Convert a descriptor of an unrelated instance with the same site of | 1114 // 6) Convert a descriptor of an unrelated instance with the same site of |
| 1115 // related_instance and using it as a candidate. | 1115 // related_instance and using it as a candidate. |
| 1116 { | 1116 { |
| 1117 SiteInstanceDescriptor descriptor(browser_context(), kUrlSameSiteAs2, | 1117 SiteInstanceDescriptor descriptor(browser_context(), kUrlSameSiteAs2, |
| 1118 SiteInstanceRelation::UNRELATED); | 1118 SiteInstanceRelation::UNRELATED); |
| 1119 scoped_refptr<SiteInstance> converted_instance_1 = | 1119 scoped_refptr<SiteInstanceImpl> converted_instance_1 = |
| 1120 ConvertToSiteInstance(rfhm, descriptor, related_instance.get()); | 1120 ConvertToSiteInstance(rfhm, descriptor, related_instance.get()); |
| 1121 // Should return a new instance, unrelated to the current, set to the | 1121 // Should return a new instance, unrelated to the current, set to the |
| 1122 // provided site URL. | 1122 // provided site URL. |
| 1123 EXPECT_FALSE( | 1123 EXPECT_FALSE( |
| 1124 current_instance->IsRelatedSiteInstance(converted_instance_1.get())); | 1124 current_instance->IsRelatedSiteInstance(converted_instance_1.get())); |
| 1125 EXPECT_NE(related_instance.get(), converted_instance_1.get()); | 1125 EXPECT_NE(related_instance.get(), converted_instance_1.get()); |
| 1126 EXPECT_NE(unrelated_instance.get(), converted_instance_1.get()); | 1126 EXPECT_NE(unrelated_instance.get(), converted_instance_1.get()); |
| 1127 EXPECT_EQ(SiteInstance::GetSiteForURL(browser_context(), kUrlSameSiteAs2), | 1127 EXPECT_EQ(SiteInstance::GetSiteForURL(browser_context(), kUrlSameSiteAs2), |
| 1128 converted_instance_1->GetSiteURL()); | 1128 converted_instance_1->GetSiteURL()); |
| 1129 | 1129 |
| 1130 scoped_refptr<SiteInstance> converted_instance_2 = | 1130 scoped_refptr<SiteInstanceImpl> converted_instance_2 = |
| 1131 ConvertToSiteInstance(rfhm, descriptor, unrelated_instance.get()); | 1131 ConvertToSiteInstance(rfhm, descriptor, unrelated_instance.get()); |
| 1132 // Should return |unrelated_instance| because its site matches and it is | 1132 // Should return |unrelated_instance| because its site matches and it is |
| 1133 // unrelated to the current SiteInstance. | 1133 // unrelated to the current SiteInstance. |
| 1134 EXPECT_EQ(unrelated_instance.get(), converted_instance_2); | 1134 EXPECT_EQ(unrelated_instance.get(), converted_instance_2); |
| 1135 } | 1135 } |
| 1136 } | 1136 } |
| 1137 | 1137 |
| 1138 namespace { | 1138 namespace { |
| 1139 void SetWithinPage(const GURL& url, | 1139 void SetWithinPage(const GURL& url, |
| 1140 FrameHostMsg_DidCommitProvisionalLoad_Params* params) { | 1140 FrameHostMsg_DidCommitProvisionalLoad_Params* params) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1160 main_test_rfh()->PrepareForCommit(); | 1160 main_test_rfh()->PrepareForCommit(); |
| 1161 | 1161 |
| 1162 // Claim that the navigation was within same page. | 1162 // Claim that the navigation was within same page. |
| 1163 int bad_msg_count = process()->bad_msg_count(); | 1163 int bad_msg_count = process()->bad_msg_count(); |
| 1164 GetSpeculativeRenderFrameHost(node)->SendNavigateWithModificationCallback( | 1164 GetSpeculativeRenderFrameHost(node)->SendNavigateWithModificationCallback( |
| 1165 0, entry_id, true, kUrl2, base::Bind(SetWithinPage, kUrl1)); | 1165 0, entry_id, true, kUrl2, base::Bind(SetWithinPage, kUrl1)); |
| 1166 EXPECT_EQ(process()->bad_msg_count(), bad_msg_count + 1); | 1166 EXPECT_EQ(process()->bad_msg_count(), bad_msg_count + 1); |
| 1167 } | 1167 } |
| 1168 | 1168 |
| 1169 } // namespace content | 1169 } // namespace content |
| OLD | NEW |