| 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 957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 | 968 |
| 969 // Invoke OnDidCommitProvisionalLoad. | 969 // Invoke OnDidCommitProvisionalLoad. |
| 970 speculative_rfh->SendNavigate(0, entry_id, true, kUrlRedirect); | 970 speculative_rfh->SendNavigate(0, entry_id, true, kUrlRedirect); |
| 971 | 971 |
| 972 // Check that the speculative RenderFrameHost was swapped in. | 972 // Check that the speculative RenderFrameHost was swapped in. |
| 973 EXPECT_EQ(redirect_site_instance_id, | 973 EXPECT_EQ(redirect_site_instance_id, |
| 974 main_test_rfh()->GetSiteInstance()->GetId()); | 974 main_test_rfh()->GetSiteInstance()->GetId()); |
| 975 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); | 975 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| 976 } | 976 } |
| 977 | 977 |
| 978 // PlzNavigate: Verify that a previously swapped out RenderFrameHost is | |
| 979 // correctly reused when spawning a speculative RenderFrameHost in a navigation | |
| 980 // using the same SiteInstance. | |
| 981 TEST_F(NavigatorTestWithBrowserSideNavigation, | |
| 982 SpeculativeRendererReuseSwappedOutRFH) { | |
| 983 // This test doesn't make sense in --site-per-process where swapped out | |
| 984 // RenderFrameHost is no longer used. | |
| 985 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) | |
| 986 return; | |
| 987 | |
| 988 // Navigate to an initial site. | |
| 989 const GURL kUrl1("http://wikipedia.org/"); | |
| 990 contents()->NavigateAndCommit(kUrl1); | |
| 991 TestRenderFrameHost* rfh1 = main_test_rfh(); | |
| 992 FrameTreeNode* node = rfh1->frame_tree_node(); | |
| 993 RenderFrameHostManager* rfhm = node->render_manager(); | |
| 994 | |
| 995 // Increment active frame count to cause the RenderFrameHost to be swapped out | |
| 996 // (instead of immediately destroyed). | |
| 997 rfh1->GetSiteInstance()->IncrementActiveFrameCount(); | |
| 998 | |
| 999 // Navigate to another site to swap out the initial RenderFrameHost. | |
| 1000 const GURL kUrl2("http://chromium.org/"); | |
| 1001 contents()->NavigateAndCommit(kUrl2); | |
| 1002 ASSERT_NE(rfh1, main_test_rfh()); | |
| 1003 EXPECT_NE(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | |
| 1004 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state()); | |
| 1005 EXPECT_TRUE(rfhm->IsOnSwappedOutList(rfh1)); | |
| 1006 | |
| 1007 // Now go back to the initial site so that the swapped out RenderFrameHost | |
| 1008 // should be reused. | |
| 1009 process()->sink().ClearMessages(); | |
| 1010 rfh1->GetProcess()->sink().ClearMessages(); | |
| 1011 int entry_id = RequestNavigation(node, kUrl1); | |
| 1012 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node)); | |
| 1013 | |
| 1014 main_test_rfh()->SendBeforeUnloadACK(true); | |
| 1015 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node)); | |
| 1016 EXPECT_NE(RenderFrameHostImpl::STATE_DEFAULT, | |
| 1017 GetSpeculativeRenderFrameHost(node)->rfh_state()); | |
| 1018 | |
| 1019 scoped_refptr<ResourceResponse> response(new ResourceResponse); | |
| 1020 GetLoaderForNavigationRequest(node->navigation_request()) | |
| 1021 ->CallOnResponseStarted(response, MakeEmptyStream()); | |
| 1022 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node)); | |
| 1023 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, | |
| 1024 GetSpeculativeRenderFrameHost(node)->rfh_state()); | |
| 1025 EXPECT_TRUE(DidRenderFrameHostRequestCommit(rfh1)); | |
| 1026 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh())); | |
| 1027 | |
| 1028 rfh1->SendNavigate(1, entry_id, true, kUrl1); | |
| 1029 EXPECT_EQ(rfh1, main_test_rfh()); | |
| 1030 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | |
| 1031 EXPECT_FALSE(rfhm->IsOnSwappedOutList(rfh1)); | |
| 1032 } | |
| 1033 | |
| 1034 // PlzNavigate: Verify that data urls are properly handled. | 978 // PlzNavigate: Verify that data urls are properly handled. |
| 1035 TEST_F(NavigatorTestWithBrowserSideNavigation, DataUrls) { | 979 TEST_F(NavigatorTestWithBrowserSideNavigation, DataUrls) { |
| 1036 const GURL kUrl1("http://wikipedia.org/"); | 980 const GURL kUrl1("http://wikipedia.org/"); |
| 1037 const GURL kUrl2("data:text/html,test"); | 981 const GURL kUrl2("data:text/html,test"); |
| 1038 | 982 |
| 1039 // Navigate to an initial site. | 983 // Navigate to an initial site. |
| 1040 contents()->NavigateAndCommit(kUrl1); | 984 contents()->NavigateAndCommit(kUrl1); |
| 1041 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); | 985 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
| 1042 | 986 |
| 1043 // Navigate to a data url. The request should not have been sent to the IO | 987 // Navigate to a data url. The request should not have been sent to the IO |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1216 main_test_rfh()->PrepareForCommit(); | 1160 main_test_rfh()->PrepareForCommit(); |
| 1217 | 1161 |
| 1218 // Claim that the navigation was within same page. | 1162 // Claim that the navigation was within same page. |
| 1219 int bad_msg_count = process()->bad_msg_count(); | 1163 int bad_msg_count = process()->bad_msg_count(); |
| 1220 GetSpeculativeRenderFrameHost(node)->SendNavigateWithModificationCallback( | 1164 GetSpeculativeRenderFrameHost(node)->SendNavigateWithModificationCallback( |
| 1221 0, entry_id, true, kUrl2, base::Bind(SetWithinPage, kUrl1)); | 1165 0, entry_id, true, kUrl2, base::Bind(SetWithinPage, kUrl1)); |
| 1222 EXPECT_EQ(process()->bad_msg_count(), bad_msg_count + 1); | 1166 EXPECT_EQ(process()->bad_msg_count(), bad_msg_count + 1); |
| 1223 } | 1167 } |
| 1224 | 1168 |
| 1225 } // namespace content | 1169 } // namespace content |
| OLD | NEW |