| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/test/histogram_tester.h" | 8 #include "base/test/histogram_tester.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "content/browser/frame_host/cross_site_transferring_request.h" | 10 #include "content/browser/frame_host/cross_site_transferring_request.h" |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 const GURL kDestUrl("http://www.google.com/"); | 345 const GURL kDestUrl("http://www.google.com/"); |
| 346 | 346 |
| 347 // Navigate our first tab to a chrome url and then to the destination. | 347 // Navigate our first tab to a chrome url and then to the destination. |
| 348 NavigateActiveAndCommit(kChromeURL); | 348 NavigateActiveAndCommit(kChromeURL); |
| 349 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); | 349 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); |
| 350 | 350 |
| 351 // Navigate to a cross-site URL. | 351 // Navigate to a cross-site URL. |
| 352 contents()->GetController().LoadURL( | 352 contents()->GetController().LoadURL( |
| 353 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 353 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 354 contents()->GetMainFrame()->PrepareForCommit(); | 354 contents()->GetMainFrame()->PrepareForCommit(); |
| 355 EXPECT_TRUE(contents()->cross_navigation_pending()); | 355 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 356 | 356 |
| 357 // Manually increase the number of active frames in the | 357 // Manually increase the number of active frames in the |
| 358 // SiteInstance that ntp_rfh belongs to, to prevent it from being | 358 // SiteInstance that ntp_rfh belongs to, to prevent it from being |
| 359 // destroyed when it gets swapped out. | 359 // destroyed when it gets swapped out. |
| 360 ntp_rfh->GetSiteInstance()->increment_active_frame_count(); | 360 ntp_rfh->GetSiteInstance()->increment_active_frame_count(); |
| 361 | 361 |
| 362 TestRenderFrameHost* dest_rfh = contents()->GetPendingMainFrame(); | 362 TestRenderFrameHost* dest_rfh = contents()->GetPendingMainFrame(); |
| 363 CHECK(dest_rfh); | 363 CHECK(dest_rfh); |
| 364 EXPECT_NE(ntp_rfh, dest_rfh); | 364 EXPECT_NE(ntp_rfh, dest_rfh); |
| 365 | 365 |
| 366 // BeforeUnload finishes. | 366 // BeforeUnload finishes. |
| 367 ntp_rfh->SendBeforeUnloadACK(true); | 367 ntp_rfh->SendBeforeUnloadACK(true); |
| 368 | 368 |
| 369 dest_rfh->SendNavigate(101, kDestUrl); | 369 dest_rfh->SendNavigate(101, kDestUrl); |
| 370 ntp_rfh->OnSwappedOut(); | 370 ntp_rfh->OnSwappedOut(); |
| 371 | 371 |
| 372 EXPECT_TRUE(ntp_rfh->is_swapped_out()); | 372 EXPECT_TRUE(ntp_rfh->is_swapped_out()); |
| 373 return ntp_rfh; | 373 return ntp_rfh; |
| 374 } | 374 } |
| 375 | 375 |
| 376 // Returns the RenderFrameHost that should be used in the navigation to | 376 // Returns the RenderFrameHost that should be used in the navigation to |
| 377 // |entry|. | 377 // |entry|. |
| 378 RenderFrameHostImpl* GetFrameHostForNavigation( | 378 RenderFrameHostImpl* NavigateToEntry( |
| 379 RenderFrameHostManager* manager, | 379 RenderFrameHostManager* manager, |
| 380 const NavigationEntryImpl& entry) { | 380 const NavigationEntryImpl& entry) { |
| 381 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 381 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 382 switches::kEnableBrowserSideNavigation)) { | 382 switches::kEnableBrowserSideNavigation)) { |
| 383 scoped_ptr<NavigationRequest> navigation_request = | 383 scoped_ptr<NavigationRequest> navigation_request = |
| 384 NavigationRequest::CreateBrowserInitiated( | 384 NavigationRequest::CreateBrowserInitiated( |
| 385 manager->frame_tree_node_, entry, FrameMsg_Navigate_Type::NORMAL, | 385 manager->frame_tree_node_, entry, FrameMsg_Navigate_Type::NORMAL, |
| 386 base::TimeTicks::Now(), | 386 base::TimeTicks::Now(), |
| 387 static_cast<NavigationControllerImpl*>(&controller())); | 387 static_cast<NavigationControllerImpl*>(&controller())); |
| 388 return manager->GetFrameHostForNavigation(*navigation_request); | 388 TestRenderFrameHost* frame_host = static_cast<TestRenderFrameHost*>( |
| 389 manager->GetFrameHostForNavigation(*navigation_request)); |
| 390 CHECK(frame_host); |
| 391 frame_host->set_pending_commit(true); |
| 392 return frame_host; |
| 389 } | 393 } |
| 390 return manager->Navigate(entry); | 394 return manager->Navigate(entry); |
| 391 } | 395 } |
| 392 | 396 |
| 393 // Returns the pending RenderFrameHost. | 397 // Returns the pending RenderFrameHost. |
| 394 // PlzNavigate: returns the speculative RenderFrameHost. | 398 // PlzNavigate: returns the speculative RenderFrameHost. |
| 395 RenderFrameHostImpl* GetPendingFrameHost( | 399 RenderFrameHostImpl* GetPendingFrameHost( |
| 396 RenderFrameHostManager* manager) { | 400 RenderFrameHostManager* manager) { |
| 397 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 401 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 398 switches::kEnableBrowserSideNavigation)) { | 402 switches::kEnableBrowserSideNavigation)) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 scoped_ptr<TestWebContents> contents2( | 448 scoped_ptr<TestWebContents> contents2( |
| 445 TestWebContents::Create(browser_context(), NULL)); | 449 TestWebContents::Create(browser_context(), NULL)); |
| 446 | 450 |
| 447 // Load the two URLs in the second tab. Note that the first navigation creates | 451 // Load the two URLs in the second tab. Note that the first navigation creates |
| 448 // a RFH that's not pending (since there is no cross-site transition), so | 452 // a RFH that's not pending (since there is no cross-site transition), so |
| 449 // we use the committed one. | 453 // we use the committed one. |
| 450 contents2->GetController().LoadURL( | 454 contents2->GetController().LoadURL( |
| 451 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 455 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 452 contents2->GetMainFrame()->PrepareForCommit(); | 456 contents2->GetMainFrame()->PrepareForCommit(); |
| 453 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); | 457 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); |
| 454 EXPECT_FALSE(contents2->cross_navigation_pending()); | 458 EXPECT_FALSE(contents2->CrossProcessNavigationPending()); |
| 455 ntp_rfh2->SendNavigate(100, kChromeUrl); | 459 ntp_rfh2->SendNavigate(100, kChromeUrl); |
| 456 | 460 |
| 457 // The second one is the opposite, creating a cross-site transition and | 461 // The second one is the opposite, creating a cross-site transition and |
| 458 // requiring a beforeunload ack. | 462 // requiring a beforeunload ack. |
| 459 contents2->GetController().LoadURL( | 463 contents2->GetController().LoadURL( |
| 460 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 464 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 461 contents2->GetMainFrame()->PrepareForCommit(); | 465 contents2->GetMainFrame()->PrepareForCommit(); |
| 462 EXPECT_TRUE(contents2->cross_navigation_pending()); | 466 EXPECT_TRUE(contents2->CrossProcessNavigationPending()); |
| 463 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); | 467 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); |
| 464 ASSERT_TRUE(dest_rfh2); | 468 ASSERT_TRUE(dest_rfh2); |
| 465 | 469 |
| 466 dest_rfh2->SendNavigate(101, kDestUrl); | 470 dest_rfh2->SendNavigate(101, kDestUrl); |
| 467 | 471 |
| 468 // The two RFH's should be different in every way. | 472 // The two RFH's should be different in every way. |
| 469 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); | 473 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); |
| 470 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), | 474 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), |
| 471 dest_rfh2->GetSiteInstance()); | 475 dest_rfh2->GetSiteInstance()); |
| 472 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( | 476 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 | 888 |
| 885 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 889 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
| 886 RenderFrameHostImpl* host = NULL; | 890 RenderFrameHostImpl* host = NULL; |
| 887 | 891 |
| 888 // 1) The first navigation. -------------------------- | 892 // 1) The first navigation. -------------------------- |
| 889 const GURL kUrl1("http://www.google.com/"); | 893 const GURL kUrl1("http://www.google.com/"); |
| 890 NavigationEntryImpl entry1( | 894 NavigationEntryImpl entry1( |
| 891 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), | 895 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), |
| 892 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, | 896 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
| 893 false /* is_renderer_init */); | 897 false /* is_renderer_init */); |
| 894 host = GetFrameHostForNavigation(manager, entry1); | 898 host = NavigateToEntry(manager, entry1); |
| 895 | 899 |
| 896 // The RenderFrameHost created in Init will be reused. | 900 // The RenderFrameHost created in Init will be reused. |
| 897 EXPECT_TRUE(host == manager->current_frame_host()); | 901 EXPECT_TRUE(host == manager->current_frame_host()); |
| 898 EXPECT_FALSE(GetPendingFrameHost(manager)); | 902 EXPECT_FALSE(GetPendingFrameHost(manager)); |
| 899 | 903 |
| 900 // Commit. | 904 // Commit. |
| 901 manager->DidNavigateFrame(host, true); | 905 manager->DidNavigateFrame(host, true); |
| 902 // Commit to SiteInstance should be delayed until RenderFrame commit. | 906 // Commit to SiteInstance should be delayed until RenderFrame commit. |
| 903 EXPECT_TRUE(host == manager->current_frame_host()); | 907 EXPECT_TRUE(host == manager->current_frame_host()); |
| 904 ASSERT_TRUE(host); | 908 ASSERT_TRUE(host); |
| 905 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); | 909 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); |
| 906 host->GetSiteInstance()->SetSite(kUrl1); | 910 host->GetSiteInstance()->SetSite(kUrl1); |
| 907 | 911 |
| 908 // 2) Navigate to next site. ------------------------- | 912 // 2) Navigate to next site. ------------------------- |
| 909 const GURL kUrl2("http://www.google.com/foo"); | 913 const GURL kUrl2("http://www.google.com/foo"); |
| 910 NavigationEntryImpl entry2( | 914 NavigationEntryImpl entry2( |
| 911 NULL /* instance */, -1 /* page_id */, kUrl2, | 915 NULL /* instance */, -1 /* page_id */, kUrl2, |
| 912 Referrer(kUrl1, blink::WebReferrerPolicyDefault), | 916 Referrer(kUrl1, blink::WebReferrerPolicyDefault), |
| 913 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, | 917 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
| 914 true /* is_renderer_init */); | 918 true /* is_renderer_init */); |
| 915 host = GetFrameHostForNavigation(manager, entry2); | 919 host = NavigateToEntry(manager, entry2); |
| 916 | 920 |
| 917 // The RenderFrameHost created in Init will be reused. | 921 // The RenderFrameHost created in Init will be reused. |
| 918 EXPECT_TRUE(host == manager->current_frame_host()); | 922 EXPECT_TRUE(host == manager->current_frame_host()); |
| 919 EXPECT_FALSE(GetPendingFrameHost(manager)); | 923 EXPECT_FALSE(GetPendingFrameHost(manager)); |
| 920 | 924 |
| 921 // Commit. | 925 // Commit. |
| 922 manager->DidNavigateFrame(host, true); | 926 manager->DidNavigateFrame(host, true); |
| 923 EXPECT_TRUE(host == manager->current_frame_host()); | 927 EXPECT_TRUE(host == manager->current_frame_host()); |
| 924 ASSERT_TRUE(host); | 928 ASSERT_TRUE(host); |
| 925 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); | 929 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
| 926 | 930 |
| 927 // 3) Cross-site navigate to next site. -------------- | 931 // 3) Cross-site navigate to next site. -------------- |
| 928 const GURL kUrl3("http://webkit.org/"); | 932 const GURL kUrl3("http://webkit.org/"); |
| 929 NavigationEntryImpl entry3( | 933 NavigationEntryImpl entry3( |
| 930 NULL /* instance */, -1 /* page_id */, kUrl3, | 934 NULL /* instance */, -1 /* page_id */, kUrl3, |
| 931 Referrer(kUrl2, blink::WebReferrerPolicyDefault), | 935 Referrer(kUrl2, blink::WebReferrerPolicyDefault), |
| 932 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, | 936 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
| 933 false /* is_renderer_init */); | 937 false /* is_renderer_init */); |
| 934 host = GetFrameHostForNavigation(manager, entry3); | 938 host = NavigateToEntry(manager, entry3); |
| 935 | 939 |
| 936 // A new RenderFrameHost should be created. | 940 // A new RenderFrameHost should be created. |
| 937 EXPECT_TRUE(GetPendingFrameHost(manager)); | 941 EXPECT_TRUE(GetPendingFrameHost(manager)); |
| 938 ASSERT_EQ(host, GetPendingFrameHost(manager)); | 942 ASSERT_EQ(host, GetPendingFrameHost(manager)); |
| 939 | 943 |
| 940 notifications.Reset(); | 944 notifications.Reset(); |
| 941 | 945 |
| 942 // Commit. | 946 // Commit. |
| 943 manager->DidNavigateFrame(GetPendingFrameHost(manager), true); | 947 manager->DidNavigateFrame(GetPendingFrameHost(manager), true); |
| 944 EXPECT_TRUE(host == manager->current_frame_host()); | 948 EXPECT_TRUE(host == manager->current_frame_host()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 964 | 968 |
| 965 EXPECT_FALSE(manager->current_host()->IsRenderViewLive()); | 969 EXPECT_FALSE(manager->current_host()->IsRenderViewLive()); |
| 966 EXPECT_FALSE(manager->web_ui()); | 970 EXPECT_FALSE(manager->web_ui()); |
| 967 EXPECT_TRUE(initial_rfh); | 971 EXPECT_TRUE(initial_rfh); |
| 968 | 972 |
| 969 const GURL kUrl("chrome://foo"); | 973 const GURL kUrl("chrome://foo"); |
| 970 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | 974 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, |
| 971 Referrer(), base::string16() /* title */, | 975 Referrer(), base::string16() /* title */, |
| 972 ui::PAGE_TRANSITION_TYPED, | 976 ui::PAGE_TRANSITION_TYPED, |
| 973 false /* is_renderer_init */); | 977 false /* is_renderer_init */); |
| 974 RenderFrameHostImpl* host = GetFrameHostForNavigation(manager, entry); | 978 RenderFrameHostImpl* host = NavigateToEntry(manager, entry); |
| 975 | 979 |
| 976 // We commit the pending RenderFrameHost immediately because the previous | 980 // We commit the pending RenderFrameHost immediately because the previous |
| 977 // RenderFrameHost was not live. We test a case where it is live in | 981 // RenderFrameHost was not live. We test a case where it is live in |
| 978 // WebUIInNewTab. | 982 // WebUIInNewTab. |
| 979 EXPECT_TRUE(host); | 983 EXPECT_TRUE(host); |
| 980 EXPECT_NE(initial_rfh, host); | 984 EXPECT_NE(initial_rfh, host); |
| 981 EXPECT_EQ(host, manager->current_frame_host()); | 985 EXPECT_EQ(host, manager->current_frame_host()); |
| 982 EXPECT_FALSE(GetPendingFrameHost(manager)); | 986 EXPECT_FALSE(GetPendingFrameHost(manager)); |
| 983 | 987 |
| 984 // It's important that the SiteInstance get set on the Web UI page as soon | 988 // It's important that the SiteInstance get set on the Web UI page as soon |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 base::string16(), -1, MSG_ROUTING_NONE, -1, false); | 1024 base::string16(), -1, MSG_ROUTING_NONE, -1, false); |
| 1021 EXPECT_TRUE(manager1->current_host()->IsRenderViewLive()); | 1025 EXPECT_TRUE(manager1->current_host()->IsRenderViewLive()); |
| 1022 EXPECT_TRUE(manager1->current_frame_host()->IsRenderFrameLive()); | 1026 EXPECT_TRUE(manager1->current_frame_host()->IsRenderFrameLive()); |
| 1023 | 1027 |
| 1024 // Navigate to a WebUI page. | 1028 // Navigate to a WebUI page. |
| 1025 const GURL kUrl1("chrome://foo"); | 1029 const GURL kUrl1("chrome://foo"); |
| 1026 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, | 1030 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, |
| 1027 Referrer(), base::string16() /* title */, | 1031 Referrer(), base::string16() /* title */, |
| 1028 ui::PAGE_TRANSITION_TYPED, | 1032 ui::PAGE_TRANSITION_TYPED, |
| 1029 false /* is_renderer_init */); | 1033 false /* is_renderer_init */); |
| 1030 RenderFrameHostImpl* host1 = GetFrameHostForNavigation(manager1, entry1); | 1034 RenderFrameHostImpl* host1 = NavigateToEntry(manager1, entry1); |
| 1031 | 1035 |
| 1032 // We should have a pending navigation to the WebUI RenderViewHost. | 1036 // We should have a pending navigation to the WebUI RenderViewHost. |
| 1033 // It should already have bindings. | 1037 // It should already have bindings. |
| 1034 EXPECT_EQ(host1, GetPendingFrameHost(manager1)); | 1038 EXPECT_EQ(host1, GetPendingFrameHost(manager1)); |
| 1035 EXPECT_NE(host1, manager1->current_frame_host()); | 1039 EXPECT_NE(host1, manager1->current_frame_host()); |
| 1036 EXPECT_TRUE( | 1040 EXPECT_TRUE( |
| 1037 host1->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1041 host1->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
| 1038 | 1042 |
| 1039 // Commit and ensure we still have bindings. | 1043 // Commit and ensure we still have bindings. |
| 1040 manager1->DidNavigateFrame(host1, true); | 1044 manager1->DidNavigateFrame(host1, true); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1052 // RenderWidgetHost::Init when opening a new tab from a link. | 1056 // RenderWidgetHost::Init when opening a new tab from a link. |
| 1053 manager2->current_host()->CreateRenderView( | 1057 manager2->current_host()->CreateRenderView( |
| 1054 base::string16(), -1, MSG_ROUTING_NONE, -1, false); | 1058 base::string16(), -1, MSG_ROUTING_NONE, -1, false); |
| 1055 EXPECT_TRUE(manager2->current_host()->IsRenderViewLive()); | 1059 EXPECT_TRUE(manager2->current_host()->IsRenderViewLive()); |
| 1056 | 1060 |
| 1057 const GURL kUrl2("chrome://foo/bar"); | 1061 const GURL kUrl2("chrome://foo/bar"); |
| 1058 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, | 1062 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, |
| 1059 Referrer(), base::string16() /* title */, | 1063 Referrer(), base::string16() /* title */, |
| 1060 ui::PAGE_TRANSITION_LINK, | 1064 ui::PAGE_TRANSITION_LINK, |
| 1061 true /* is_renderer_init */); | 1065 true /* is_renderer_init */); |
| 1062 RenderFrameHostImpl* host2 = GetFrameHostForNavigation(manager2, entry2); | 1066 RenderFrameHostImpl* host2 = NavigateToEntry(manager2, entry2); |
| 1063 | 1067 |
| 1064 // No cross-process transition happens because we are already in the right | 1068 // No cross-process transition happens because we are already in the right |
| 1065 // SiteInstance. We should grant bindings immediately. | 1069 // SiteInstance. We should grant bindings immediately. |
| 1066 EXPECT_EQ(host2, manager2->current_frame_host()); | 1070 EXPECT_EQ(host2, manager2->current_frame_host()); |
| 1067 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1071 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1068 switches::kEnableBrowserSideNavigation)) { | 1072 switches::kEnableBrowserSideNavigation)) { |
| 1069 EXPECT_TRUE(manager2->speculative_web_ui()); | 1073 EXPECT_TRUE(manager2->speculative_web_ui()); |
| 1070 } else { | 1074 } else { |
| 1071 EXPECT_TRUE(manager2->pending_web_ui()); | 1075 EXPECT_TRUE(manager2->pending_web_ui()); |
| 1072 } | 1076 } |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1558 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 1562 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
| 1559 | 1563 |
| 1560 RenderFrameHostImpl* host = NULL; | 1564 RenderFrameHostImpl* host = NULL; |
| 1561 | 1565 |
| 1562 // 1) The first navigation. -------------------------- | 1566 // 1) The first navigation. -------------------------- |
| 1563 const GURL kUrl1("http://www.google.com/"); | 1567 const GURL kUrl1("http://www.google.com/"); |
| 1564 NavigationEntryImpl entry1( | 1568 NavigationEntryImpl entry1( |
| 1565 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), | 1569 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), |
| 1566 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, | 1570 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
| 1567 false /* is_renderer_init */); | 1571 false /* is_renderer_init */); |
| 1568 host = manager->Navigate(entry1); | 1572 host = NavigateToEntry(manager, entry1); |
| 1569 | 1573 |
| 1570 // The RenderFrameHost created in Init will be reused. | 1574 // The RenderFrameHost created in Init will be reused. |
| 1571 EXPECT_TRUE(host == manager->current_frame_host()); | 1575 EXPECT_TRUE(host == manager->current_frame_host()); |
| 1572 EXPECT_FALSE(manager->pending_frame_host()); | 1576 EXPECT_FALSE(manager->pending_frame_host()); |
| 1573 EXPECT_EQ(manager->current_frame_host()->GetSiteInstance(), instance); | 1577 EXPECT_EQ(manager->current_frame_host()->GetSiteInstance(), instance); |
| 1574 | 1578 |
| 1575 // Commit. | 1579 // Commit. |
| 1576 manager->DidNavigateFrame(host, true); | 1580 manager->DidNavigateFrame(host, true); |
| 1577 // Commit to SiteInstance should be delayed until RenderFrame commit. | 1581 // Commit to SiteInstance should be delayed until RenderFrame commit. |
| 1578 EXPECT_EQ(host, manager->current_frame_host()); | 1582 EXPECT_EQ(host, manager->current_frame_host()); |
| 1579 ASSERT_TRUE(host); | 1583 ASSERT_TRUE(host); |
| 1580 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); | 1584 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
| 1581 | 1585 |
| 1582 // 2) Navigate to a different domain. ------------------------- | 1586 // 2) Navigate to a different domain. ------------------------- |
| 1583 // Guests stay in the same process on navigation. | 1587 // Guests stay in the same process on navigation. |
| 1584 const GURL kUrl2("http://www.chromium.org"); | 1588 const GURL kUrl2("http://www.chromium.org"); |
| 1585 NavigationEntryImpl entry2( | 1589 NavigationEntryImpl entry2( |
| 1586 NULL /* instance */, -1 /* page_id */, kUrl2, | 1590 NULL /* instance */, -1 /* page_id */, kUrl2, |
| 1587 Referrer(kUrl1, blink::WebReferrerPolicyDefault), | 1591 Referrer(kUrl1, blink::WebReferrerPolicyDefault), |
| 1588 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, | 1592 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
| 1589 true /* is_renderer_init */); | 1593 true /* is_renderer_init */); |
| 1590 host = manager->Navigate(entry2); | 1594 host = NavigateToEntry(manager, entry2); |
| 1591 | 1595 |
| 1592 // The RenderFrameHost created in Init will be reused. | 1596 // The RenderFrameHost created in Init will be reused. |
| 1593 EXPECT_EQ(host, manager->current_frame_host()); | 1597 EXPECT_EQ(host, manager->current_frame_host()); |
| 1594 EXPECT_FALSE(manager->pending_frame_host()); | 1598 EXPECT_FALSE(manager->pending_frame_host()); |
| 1595 | 1599 |
| 1596 // Commit. | 1600 // Commit. |
| 1597 manager->DidNavigateFrame(host, true); | 1601 manager->DidNavigateFrame(host, true); |
| 1598 EXPECT_EQ(host, manager->current_frame_host()); | 1602 EXPECT_EQ(host, manager->current_frame_host()); |
| 1599 ASSERT_TRUE(host); | 1603 ASSERT_TRUE(host); |
| 1600 EXPECT_EQ(host->GetSiteInstance(), instance); | 1604 EXPECT_EQ(host->GetSiteInstance(), instance); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1615 Source<WebContents>(web_contents.get())); | 1619 Source<WebContents>(web_contents.get())); |
| 1616 | 1620 |
| 1617 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 1621 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
| 1618 | 1622 |
| 1619 // 1) The first navigation. -------------------------- | 1623 // 1) The first navigation. -------------------------- |
| 1620 const GURL kUrl1("http://www.google.com/"); | 1624 const GURL kUrl1("http://www.google.com/"); |
| 1621 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, | 1625 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, |
| 1622 Referrer(), base::string16() /* title */, | 1626 Referrer(), base::string16() /* title */, |
| 1623 ui::PAGE_TRANSITION_TYPED, | 1627 ui::PAGE_TRANSITION_TYPED, |
| 1624 false /* is_renderer_init */); | 1628 false /* is_renderer_init */); |
| 1625 RenderFrameHostImpl* host = manager->Navigate(entry1); | 1629 RenderFrameHostImpl* host = NavigateToEntry(manager, entry1); |
| 1626 | 1630 |
| 1627 // The RenderFrameHost created in Init will be reused. | 1631 // The RenderFrameHost created in Init will be reused. |
| 1628 EXPECT_EQ(host, manager->current_frame_host()); | 1632 EXPECT_EQ(host, manager->current_frame_host()); |
| 1629 EXPECT_FALSE(manager->pending_frame_host()); | 1633 EXPECT_FALSE(GetPendingFrameHost(manager)); |
| 1630 | 1634 |
| 1631 // We should observe a notification. | 1635 // We should observe a notification. |
| 1632 EXPECT_TRUE( | 1636 EXPECT_TRUE( |
| 1633 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | 1637 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); |
| 1634 notifications.Reset(); | 1638 notifications.Reset(); |
| 1635 | 1639 |
| 1636 // Commit. | 1640 // Commit. |
| 1637 manager->DidNavigateFrame(host, true); | 1641 manager->DidNavigateFrame(host, true); |
| 1638 | 1642 |
| 1639 // Commit to SiteInstance should be delayed until RenderFrame commits. | 1643 // Commit to SiteInstance should be delayed until RenderFrame commits. |
| 1640 EXPECT_EQ(host, manager->current_frame_host()); | 1644 EXPECT_EQ(host, manager->current_frame_host()); |
| 1641 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); | 1645 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); |
| 1642 host->GetSiteInstance()->SetSite(kUrl1); | 1646 host->GetSiteInstance()->SetSite(kUrl1); |
| 1643 | 1647 |
| 1644 // 2) Cross-site navigate to next site. ------------------------- | 1648 // 2) Cross-site navigate to next site. ------------------------- |
| 1645 const GURL kUrl2("http://www.example.com"); | 1649 const GURL kUrl2("http://www.example.com"); |
| 1646 NavigationEntryImpl entry2( | 1650 NavigationEntryImpl entry2( |
| 1647 NULL /* instance */, -1 /* page_id */, kUrl2, Referrer(), | 1651 NULL /* instance */, -1 /* page_id */, kUrl2, Referrer(), |
| 1648 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, | 1652 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
| 1649 false /* is_renderer_init */); | 1653 false /* is_renderer_init */); |
| 1650 RenderFrameHostImpl* host2 = manager->Navigate(entry2); | 1654 RenderFrameHostImpl* host2 = NavigateToEntry(manager, entry2); |
| 1651 | 1655 |
| 1652 // A new RenderFrameHost should be created. | 1656 // A new RenderFrameHost should be created. |
| 1653 ASSERT_EQ(host2, manager->pending_frame_host()); | 1657 ASSERT_EQ(host2, GetPendingFrameHost(manager)); |
| 1654 EXPECT_NE(host2, host); | 1658 EXPECT_NE(host2, host); |
| 1655 | 1659 |
| 1656 EXPECT_EQ(host, manager->current_frame_host()); | 1660 EXPECT_EQ(host, manager->current_frame_host()); |
| 1657 EXPECT_FALSE(manager->current_frame_host()->is_swapped_out()); | 1661 EXPECT_FALSE(manager->current_frame_host()->is_swapped_out()); |
| 1658 EXPECT_EQ(host2, manager->pending_frame_host()); | 1662 EXPECT_EQ(host2, GetPendingFrameHost(manager)); |
| 1659 | 1663 |
| 1660 // 3) Close the tab. ------------------------- | 1664 // 3) Close the tab. ------------------------- |
| 1661 notifications.ListenFor(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 1665 notifications.ListenFor(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 1662 Source<RenderWidgetHost>(host2->render_view_host())); | 1666 Source<RenderWidgetHost>(host2->render_view_host())); |
| 1663 manager->OnBeforeUnloadACK(false, true, base::TimeTicks()); | 1667 manager->OnBeforeUnloadACK(false, true, base::TimeTicks()); |
| 1664 | 1668 |
| 1665 EXPECT_TRUE( | 1669 EXPECT_TRUE( |
| 1666 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED)); | 1670 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED)); |
| 1667 EXPECT_FALSE(manager->pending_frame_host()); | 1671 EXPECT_FALSE(GetPendingFrameHost(manager)); |
| 1668 EXPECT_EQ(host, manager->current_frame_host()); | 1672 EXPECT_EQ(host, manager->current_frame_host()); |
| 1669 } | 1673 } |
| 1670 | 1674 |
| 1671 TEST_F(RenderFrameHostManagerTest, CloseWithPendingWhileUnresponsive) { | 1675 TEST_F(RenderFrameHostManagerTest, CloseWithPendingWhileUnresponsive) { |
| 1672 const GURL kUrl1("http://www.google.com/"); | 1676 const GURL kUrl1("http://www.google.com/"); |
| 1673 const GURL kUrl2("http://www.chromium.org/"); | 1677 const GURL kUrl2("http://www.chromium.org/"); |
| 1674 | 1678 |
| 1675 CloseWebContentsDelegate close_delegate; | 1679 CloseWebContentsDelegate close_delegate; |
| 1676 contents()->SetDelegate(&close_delegate); | 1680 contents()->SetDelegate(&close_delegate); |
| 1677 | 1681 |
| 1678 // Navigate to the first page. | 1682 // Navigate to the first page. |
| 1679 contents()->NavigateAndCommit(kUrl1); | 1683 contents()->NavigateAndCommit(kUrl1); |
| 1680 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1684 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
| 1681 | 1685 |
| 1682 // Start to close the tab, but assume it's unresponsive. | 1686 // Start to close the tab, but assume it's unresponsive. |
| 1683 rfh1->render_view_host()->ClosePage(); | 1687 rfh1->render_view_host()->ClosePage(); |
| 1684 EXPECT_TRUE(rfh1->render_view_host()->is_waiting_for_close_ack()); | 1688 EXPECT_TRUE(rfh1->render_view_host()->is_waiting_for_close_ack()); |
| 1685 | 1689 |
| 1686 // Start a navigation to a new site. | 1690 // Start a navigation to a new site. |
| 1687 controller().LoadURL( | 1691 controller().LoadURL( |
| 1688 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1692 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1689 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1693 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1690 switches::kEnableBrowserSideNavigation)) { | 1694 switches::kEnableBrowserSideNavigation)) { |
| 1691 rfh1->PrepareForCommit(); | 1695 rfh1->PrepareForCommit(); |
| 1692 } | 1696 } |
| 1693 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1697 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 1694 | 1698 |
| 1695 // Simulate the unresponsiveness timer. The tab should close. | 1699 // Simulate the unresponsiveness timer. The tab should close. |
| 1696 contents()->RendererUnresponsive(rfh1->render_view_host()); | 1700 contents()->RendererUnresponsive(rfh1->render_view_host()); |
| 1697 EXPECT_TRUE(close_delegate.is_closed()); | 1701 EXPECT_TRUE(close_delegate.is_closed()); |
| 1698 } | 1702 } |
| 1699 | 1703 |
| 1700 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is | 1704 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is |
| 1701 // received. (SwapOut and the corresponding ACK always occur after commit.) | 1705 // received. (SwapOut and the corresponding ACK always occur after commit.) |
| 1702 // Also tests that an early SwapOutACK is properly ignored. | 1706 // Also tests that an early SwapOutACK is properly ignored. |
| 1703 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { | 1707 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { |
| 1704 const GURL kUrl1("http://www.google.com/"); | 1708 const GURL kUrl1("http://www.google.com/"); |
| 1705 const GURL kUrl2("http://www.chromium.org/"); | 1709 const GURL kUrl2("http://www.chromium.org/"); |
| 1706 | 1710 |
| 1707 // Navigate to the first page. | 1711 // Navigate to the first page. |
| 1708 contents()->NavigateAndCommit(kUrl1); | 1712 contents()->NavigateAndCommit(kUrl1); |
| 1709 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1713 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
| 1710 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); | 1714 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
| 1711 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1715 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1712 | 1716 |
| 1713 // Navigate to new site, simulating onbeforeunload approval. | 1717 // Navigate to new site, simulating onbeforeunload approval. |
| 1714 controller().LoadURL( | 1718 controller().LoadURL( |
| 1715 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1719 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1716 contents()->GetMainFrame()->PrepareForCommit(); | 1720 contents()->GetMainFrame()->PrepareForCommit(); |
| 1717 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1721 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 1718 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1722 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1719 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1723 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 1720 | 1724 |
| 1721 // Simulate the swap out ack, unexpectedly early (before commit). It should | 1725 // Simulate the swap out ack, unexpectedly early (before commit). It should |
| 1722 // have no effect. | 1726 // have no effect. |
| 1723 rfh1->OnSwappedOut(); | 1727 rfh1->OnSwappedOut(); |
| 1724 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1728 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 1725 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1729 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1726 | 1730 |
| 1727 // The new page commits. | 1731 // The new page commits. |
| 1728 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1732 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
| 1729 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1733 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 1730 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1734 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
| 1731 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1735 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
| 1732 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1736 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
| 1733 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1737 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
| 1734 EXPECT_TRUE( | 1738 EXPECT_TRUE( |
| 1735 rfh1->frame_tree_node()->render_manager()->IsPendingDeletion(rfh1)); | 1739 rfh1->frame_tree_node()->render_manager()->IsPendingDeletion(rfh1)); |
| 1736 | 1740 |
| 1737 // Simulate the swap out ack. | 1741 // Simulate the swap out ack. |
| 1738 rfh1->OnSwappedOut(); | 1742 rfh1->OnSwappedOut(); |
| 1739 | 1743 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1755 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1759 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1756 | 1760 |
| 1757 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1761 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
| 1758 // not deleted on swap out. | 1762 // not deleted on swap out. |
| 1759 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1763 rfh1->GetSiteInstance()->increment_active_frame_count(); |
| 1760 | 1764 |
| 1761 // Navigate to new site, simulating onbeforeunload approval. | 1765 // Navigate to new site, simulating onbeforeunload approval. |
| 1762 controller().LoadURL( | 1766 controller().LoadURL( |
| 1763 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1767 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1764 contents()->GetMainFrame()->PrepareForCommit(); | 1768 contents()->GetMainFrame()->PrepareForCommit(); |
| 1765 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1769 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 1766 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1770 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1767 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1771 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 1768 | 1772 |
| 1769 // The new page commits. | 1773 // The new page commits. |
| 1770 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1774 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
| 1771 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1775 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 1772 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1776 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
| 1773 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1777 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
| 1774 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1778 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
| 1775 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1779 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
| 1776 | 1780 |
| 1777 // Simulate the swap out ack. | 1781 // Simulate the swap out ack. |
| 1778 rfh1->OnSwappedOut(); | 1782 rfh1->OnSwappedOut(); |
| 1779 | 1783 |
| 1780 // rfh1 should be swapped out. | 1784 // rfh1 should be swapped out. |
| 1781 EXPECT_FALSE(rfh_deleted_observer.deleted()); | 1785 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1798 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1802 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1799 | 1803 |
| 1800 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1804 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
| 1801 // not deleted on swap out. | 1805 // not deleted on swap out. |
| 1802 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1806 rfh1->GetSiteInstance()->increment_active_frame_count(); |
| 1803 | 1807 |
| 1804 // Navigate to new site, simulating onbeforeunload approval. | 1808 // Navigate to new site, simulating onbeforeunload approval. |
| 1805 controller().LoadURL( | 1809 controller().LoadURL( |
| 1806 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1810 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1807 rfh1->PrepareForCommit(); | 1811 rfh1->PrepareForCommit(); |
| 1808 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1812 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 1809 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1813 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 1810 | 1814 |
| 1811 // The new page commits. | 1815 // The new page commits. |
| 1812 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1816 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
| 1813 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1817 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 1814 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1818 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
| 1815 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1819 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
| 1816 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1820 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
| 1817 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1821 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
| 1818 | 1822 |
| 1819 // Simulate the swap out ack. | 1823 // Simulate the swap out ack. |
| 1820 rfh1->OnSwappedOut(); | 1824 rfh1->OnSwappedOut(); |
| 1821 | 1825 |
| 1822 // rfh1 should be swapped out. | 1826 // rfh1 should be swapped out. |
| 1823 EXPECT_FALSE(rfh_deleted_observer.deleted()); | 1827 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1842 controller().LoadURL( | 1846 controller().LoadURL( |
| 1843 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1847 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1844 { | 1848 { |
| 1845 pending_rfh = contents()->GetFrameTree()->root()->render_manager() | 1849 pending_rfh = contents()->GetFrameTree()->root()->render_manager() |
| 1846 ->pending_frame_host(); | 1850 ->pending_frame_host(); |
| 1847 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); | 1851 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); |
| 1848 | 1852 |
| 1849 // Cancel the navigation by simulating a declined beforeunload dialog. | 1853 // Cancel the navigation by simulating a declined beforeunload dialog. |
| 1850 contents()->GetMainFrame()->OnMessageReceived( | 1854 contents()->GetMainFrame()->OnMessageReceived( |
| 1851 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | 1855 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); |
| 1852 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1856 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 1853 | 1857 |
| 1854 // Since the pending RFH is the only one for the new SiteInstance, it should | 1858 // Since the pending RFH is the only one for the new SiteInstance, it should |
| 1855 // be deleted. | 1859 // be deleted. |
| 1856 EXPECT_TRUE(rfh_deleted_observer.deleted()); | 1860 EXPECT_TRUE(rfh_deleted_observer.deleted()); |
| 1857 } | 1861 } |
| 1858 | 1862 |
| 1859 // Start another cross-site navigation. | 1863 // Start another cross-site navigation. |
| 1860 controller().LoadURL( | 1864 controller().LoadURL( |
| 1861 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1865 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1862 { | 1866 { |
| 1863 pending_rfh = contents()->GetFrameTree()->root()->render_manager() | 1867 pending_rfh = contents()->GetFrameTree()->root()->render_manager() |
| 1864 ->pending_frame_host(); | 1868 ->pending_frame_host(); |
| 1865 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); | 1869 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); |
| 1866 | 1870 |
| 1867 // Increment the number of active frames in the new SiteInstance, which will | 1871 // Increment the number of active frames in the new SiteInstance, which will |
| 1868 // cause the pending RFH to be swapped out instead of deleted. | 1872 // cause the pending RFH to be swapped out instead of deleted. |
| 1869 pending_rfh->GetSiteInstance()->increment_active_frame_count(); | 1873 pending_rfh->GetSiteInstance()->increment_active_frame_count(); |
| 1870 | 1874 |
| 1871 contents()->GetMainFrame()->OnMessageReceived( | 1875 contents()->GetMainFrame()->OnMessageReceived( |
| 1872 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | 1876 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); |
| 1873 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1877 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 1874 EXPECT_FALSE(rfh_deleted_observer.deleted()); | 1878 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
| 1875 } | 1879 } |
| 1876 } | 1880 } |
| 1877 | 1881 |
| 1878 // Test that a pending RenderFrameHost in a non-root frame tree node is properly | 1882 // Test that a pending RenderFrameHost in a non-root frame tree node is properly |
| 1879 // deleted when the node is detached. Motivated by http://crbug.com/441357 and | 1883 // deleted when the node is detached. Motivated by http://crbug.com/441357 and |
| 1880 // http://crbug.com/444955. | 1884 // http://crbug.com/444955. |
| 1881 TEST_F(RenderFrameHostManagerTest, DetachPendingChild) { | 1885 TEST_F(RenderFrameHostManagerTest, DetachPendingChild) { |
| 1882 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1886 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1883 switches::kSitePerProcess); | 1887 switches::kSitePerProcess); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1898 RenderFrameHostManager* iframe1 = | 1902 RenderFrameHostManager* iframe1 = |
| 1899 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); | 1903 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); |
| 1900 RenderFrameHostManager* iframe2 = | 1904 RenderFrameHostManager* iframe2 = |
| 1901 contents()->GetFrameTree()->root()->child_at(1)->render_manager(); | 1905 contents()->GetFrameTree()->root()->child_at(1)->render_manager(); |
| 1902 | 1906 |
| 1903 // 1) The first navigation. | 1907 // 1) The first navigation. |
| 1904 NavigationEntryImpl entryA(NULL /* instance */, -1 /* page_id */, kUrlA, | 1908 NavigationEntryImpl entryA(NULL /* instance */, -1 /* page_id */, kUrlA, |
| 1905 Referrer(), base::string16() /* title */, | 1909 Referrer(), base::string16() /* title */, |
| 1906 ui::PAGE_TRANSITION_TYPED, | 1910 ui::PAGE_TRANSITION_TYPED, |
| 1907 false /* is_renderer_init */); | 1911 false /* is_renderer_init */); |
| 1908 RenderFrameHostImpl* host1 = GetFrameHostForNavigation(iframe1, entryA); | 1912 RenderFrameHostImpl* host1 = NavigateToEntry(iframe1, entryA); |
| 1909 | 1913 |
| 1910 // The RenderFrameHost created in Init will be reused. | 1914 // The RenderFrameHost created in Init will be reused. |
| 1911 EXPECT_TRUE(host1 == iframe1->current_frame_host()); | 1915 EXPECT_TRUE(host1 == iframe1->current_frame_host()); |
| 1912 EXPECT_FALSE(GetPendingFrameHost(iframe1)); | 1916 EXPECT_FALSE(GetPendingFrameHost(iframe1)); |
| 1913 | 1917 |
| 1914 // Commit. | 1918 // Commit. |
| 1915 iframe1->DidNavigateFrame(host1, true); | 1919 iframe1->DidNavigateFrame(host1, true); |
| 1916 // Commit to SiteInstance should be delayed until RenderFrame commit. | 1920 // Commit to SiteInstance should be delayed until RenderFrame commit. |
| 1917 EXPECT_TRUE(host1 == iframe1->current_frame_host()); | 1921 EXPECT_TRUE(host1 == iframe1->current_frame_host()); |
| 1918 ASSERT_TRUE(host1); | 1922 ASSERT_TRUE(host1); |
| 1919 EXPECT_TRUE(host1->GetSiteInstance()->HasSite()); | 1923 EXPECT_TRUE(host1->GetSiteInstance()->HasSite()); |
| 1920 | 1924 |
| 1921 // 2) Cross-site navigate both frames to next site. | 1925 // 2) Cross-site navigate both frames to next site. |
| 1922 NavigationEntryImpl entryB(NULL /* instance */, -1 /* page_id */, kUrlB, | 1926 NavigationEntryImpl entryB(NULL /* instance */, -1 /* page_id */, kUrlB, |
| 1923 Referrer(kUrlA, blink::WebReferrerPolicyDefault), | 1927 Referrer(kUrlA, blink::WebReferrerPolicyDefault), |
| 1924 base::string16() /* title */, | 1928 base::string16() /* title */, |
| 1925 ui::PAGE_TRANSITION_LINK, | 1929 ui::PAGE_TRANSITION_LINK, |
| 1926 false /* is_renderer_init */); | 1930 false /* is_renderer_init */); |
| 1927 host1 = GetFrameHostForNavigation(iframe1, entryB); | 1931 host1 = NavigateToEntry(iframe1, entryB); |
| 1928 RenderFrameHostImpl* host2 = GetFrameHostForNavigation(iframe2, entryB); | 1932 RenderFrameHostImpl* host2 = NavigateToEntry(iframe2, entryB); |
| 1929 | 1933 |
| 1930 // A new, pending RenderFrameHost should be created in each FrameTreeNode. | 1934 // A new, pending RenderFrameHost should be created in each FrameTreeNode. |
| 1931 EXPECT_TRUE(GetPendingFrameHost(iframe1)); | 1935 EXPECT_TRUE(GetPendingFrameHost(iframe1)); |
| 1932 EXPECT_TRUE(GetPendingFrameHost(iframe2)); | 1936 EXPECT_TRUE(GetPendingFrameHost(iframe2)); |
| 1933 EXPECT_EQ(host1, GetPendingFrameHost(iframe1)); | 1937 EXPECT_EQ(host1, GetPendingFrameHost(iframe1)); |
| 1934 EXPECT_EQ(host2, GetPendingFrameHost(iframe2)); | 1938 EXPECT_EQ(host2, GetPendingFrameHost(iframe2)); |
| 1935 EXPECT_TRUE(RenderFrameHostImpl::IsRFHStateActive( | 1939 EXPECT_TRUE(RenderFrameHostImpl::IsRFHStateActive( |
| 1936 GetPendingFrameHost(iframe1)->rfh_state())); | 1940 GetPendingFrameHost(iframe1)->rfh_state())); |
| 1937 EXPECT_TRUE(RenderFrameHostImpl::IsRFHStateActive( | 1941 EXPECT_TRUE(RenderFrameHostImpl::IsRFHStateActive( |
| 1938 GetPendingFrameHost(iframe2)->rfh_state())); | 1942 GetPendingFrameHost(iframe2)->rfh_state())); |
| 1939 EXPECT_NE(GetPendingFrameHost(iframe1), GetPendingFrameHost(iframe2)); | 1943 EXPECT_NE(GetPendingFrameHost(iframe1), GetPendingFrameHost(iframe2)); |
| 1940 EXPECT_EQ(GetPendingFrameHost(iframe1)->GetSiteInstance(), | 1944 EXPECT_EQ(GetPendingFrameHost(iframe1)->GetSiteInstance(), |
| 1941 GetPendingFrameHost(iframe2)->GetSiteInstance()); | 1945 GetPendingFrameHost(iframe2)->GetSiteInstance()); |
| 1942 EXPECT_NE(iframe1->current_frame_host(), GetPendingFrameHost(iframe1)); | 1946 EXPECT_NE(iframe1->current_frame_host(), GetPendingFrameHost(iframe1)); |
| 1943 EXPECT_NE(iframe2->current_frame_host(), GetPendingFrameHost(iframe2)); | 1947 EXPECT_NE(iframe2->current_frame_host(), GetPendingFrameHost(iframe2)); |
| 1944 EXPECT_FALSE(contents()->cross_navigation_pending()) | 1948 EXPECT_FALSE(contents()->CrossProcessNavigationPending()) |
| 1945 << "There should be no top-level pending navigation."; | 1949 << "There should be no top-level pending navigation."; |
| 1946 | 1950 |
| 1947 RenderFrameHostDeletedObserver delete_watcher1(GetPendingFrameHost(iframe1)); | 1951 RenderFrameHostDeletedObserver delete_watcher1(GetPendingFrameHost(iframe1)); |
| 1948 RenderFrameHostDeletedObserver delete_watcher2(GetPendingFrameHost(iframe2)); | 1952 RenderFrameHostDeletedObserver delete_watcher2(GetPendingFrameHost(iframe2)); |
| 1949 EXPECT_FALSE(delete_watcher1.deleted()); | 1953 EXPECT_FALSE(delete_watcher1.deleted()); |
| 1950 EXPECT_FALSE(delete_watcher2.deleted()); | 1954 EXPECT_FALSE(delete_watcher2.deleted()); |
| 1951 | 1955 |
| 1952 // Keep the SiteInstance alive for testing. | 1956 // Keep the SiteInstance alive for testing. |
| 1953 scoped_refptr<SiteInstanceImpl> site_instance = | 1957 scoped_refptr<SiteInstanceImpl> site_instance = |
| 1954 GetPendingFrameHost(iframe1)->GetSiteInstance(); | 1958 GetPendingFrameHost(iframe1)->GetSiteInstance(); |
| 1955 EXPECT_TRUE(site_instance->HasSite()); | 1959 EXPECT_TRUE(site_instance->HasSite()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2029 contents1->GetMainFrame()->OnCreateChildFrame( | 2033 contents1->GetMainFrame()->OnCreateChildFrame( |
| 2030 contents1->GetMainFrame()->GetProcess()->GetNextRoutingID(), | 2034 contents1->GetMainFrame()->GetProcess()->GetNextRoutingID(), |
| 2031 std::string("frame_name"), SandboxFlags::NONE); | 2035 std::string("frame_name"), SandboxFlags::NONE); |
| 2032 RenderFrameHostManager* iframe = | 2036 RenderFrameHostManager* iframe = |
| 2033 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); | 2037 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); |
| 2034 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl2, | 2038 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl2, |
| 2035 Referrer(kUrl1, blink::WebReferrerPolicyDefault), | 2039 Referrer(kUrl1, blink::WebReferrerPolicyDefault), |
| 2036 base::string16() /* title */, | 2040 base::string16() /* title */, |
| 2037 ui::PAGE_TRANSITION_LINK, | 2041 ui::PAGE_TRANSITION_LINK, |
| 2038 false /* is_renderer_init */); | 2042 false /* is_renderer_init */); |
| 2039 RenderFrameHostImpl* cross_site = GetFrameHostForNavigation(iframe, entry); | 2043 RenderFrameHostImpl* cross_site = NavigateToEntry(iframe, entry); |
| 2040 iframe->DidNavigateFrame(cross_site, true); | 2044 iframe->DidNavigateFrame(cross_site, true); |
| 2041 | 2045 |
| 2042 // A proxy to the iframe should now exist in the SiteInstance of the main | 2046 // A proxy to the iframe should now exist in the SiteInstance of the main |
| 2043 // frames. | 2047 // frames. |
| 2044 EXPECT_NE(cross_site->GetSiteInstance(), contents1->GetSiteInstance()); | 2048 EXPECT_NE(cross_site->GetSiteInstance(), contents1->GetSiteInstance()); |
| 2045 EXPECT_NE(nullptr, | 2049 EXPECT_NE(nullptr, |
| 2046 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); | 2050 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); |
| 2047 EXPECT_NE(nullptr, | 2051 EXPECT_NE(nullptr, |
| 2048 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); | 2052 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); |
| 2049 | 2053 |
| 2050 // Navigate |contents2| away from the sad tab (and thus away from the | 2054 // Navigate |contents2| away from the sad tab (and thus away from the |
| 2051 // SiteInstance of |contents1|). This should not destroy the proxies needed by | 2055 // SiteInstance of |contents1|). This should not destroy the proxies needed by |
| 2052 // |contents1| -- that was http://crbug.com/473714. | 2056 // |contents1| -- that was http://crbug.com/473714. |
| 2053 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); | 2057 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); |
| 2054 contents2->NavigateAndCommit(kUrl3); | 2058 contents2->NavigateAndCommit(kUrl3); |
| 2055 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); | 2059 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); |
| 2056 EXPECT_NE(nullptr, | 2060 EXPECT_NE(nullptr, |
| 2057 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); | 2061 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); |
| 2058 EXPECT_EQ(nullptr, | 2062 EXPECT_EQ(nullptr, |
| 2059 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); | 2063 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); |
| 2060 } | 2064 } |
| 2061 | 2065 |
| 2062 } // namespace content | 2066 } // namespace content |
| OLD | NEW |