| 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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 | 886 |
| 883 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 887 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
| 884 RenderFrameHostImpl* host = NULL; | 888 RenderFrameHostImpl* host = NULL; |
| 885 | 889 |
| 886 // 1) The first navigation. -------------------------- | 890 // 1) The first navigation. -------------------------- |
| 887 const GURL kUrl1("http://www.google.com/"); | 891 const GURL kUrl1("http://www.google.com/"); |
| 888 NavigationEntryImpl entry1( | 892 NavigationEntryImpl entry1( |
| 889 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), | 893 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), |
| 890 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, | 894 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
| 891 false /* is_renderer_init */); | 895 false /* is_renderer_init */); |
| 892 host = GetFrameHostForNavigation(manager, entry1); | 896 host = NavigateToEntry(manager, entry1); |
| 893 | 897 |
| 894 // The RenderFrameHost created in Init will be reused. | 898 // The RenderFrameHost created in Init will be reused. |
| 895 EXPECT_TRUE(host == manager->current_frame_host()); | 899 EXPECT_TRUE(host == manager->current_frame_host()); |
| 896 EXPECT_FALSE(GetPendingFrameHost(manager)); | 900 EXPECT_FALSE(GetPendingFrameHost(manager)); |
| 897 | 901 |
| 898 // Commit. | 902 // Commit. |
| 899 manager->DidNavigateFrame(host, true); | 903 manager->DidNavigateFrame(host, true); |
| 900 // Commit to SiteInstance should be delayed until RenderFrame commit. | 904 // Commit to SiteInstance should be delayed until RenderFrame commit. |
| 901 EXPECT_TRUE(host == manager->current_frame_host()); | 905 EXPECT_TRUE(host == manager->current_frame_host()); |
| 902 ASSERT_TRUE(host); | 906 ASSERT_TRUE(host); |
| 903 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); | 907 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); |
| 904 host->GetSiteInstance()->SetSite(kUrl1); | 908 host->GetSiteInstance()->SetSite(kUrl1); |
| 905 | 909 |
| 906 // 2) Navigate to next site. ------------------------- | 910 // 2) Navigate to next site. ------------------------- |
| 907 const GURL kUrl2("http://www.google.com/foo"); | 911 const GURL kUrl2("http://www.google.com/foo"); |
| 908 NavigationEntryImpl entry2( | 912 NavigationEntryImpl entry2( |
| 909 NULL /* instance */, -1 /* page_id */, kUrl2, | 913 NULL /* instance */, -1 /* page_id */, kUrl2, |
| 910 Referrer(kUrl1, blink::WebReferrerPolicyDefault), | 914 Referrer(kUrl1, blink::WebReferrerPolicyDefault), |
| 911 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, | 915 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
| 912 true /* is_renderer_init */); | 916 true /* is_renderer_init */); |
| 913 host = GetFrameHostForNavigation(manager, entry2); | 917 host = NavigateToEntry(manager, entry2); |
| 914 | 918 |
| 915 // The RenderFrameHost created in Init will be reused. | 919 // The RenderFrameHost created in Init will be reused. |
| 916 EXPECT_TRUE(host == manager->current_frame_host()); | 920 EXPECT_TRUE(host == manager->current_frame_host()); |
| 917 EXPECT_FALSE(GetPendingFrameHost(manager)); | 921 EXPECT_FALSE(GetPendingFrameHost(manager)); |
| 918 | 922 |
| 919 // Commit. | 923 // Commit. |
| 920 manager->DidNavigateFrame(host, true); | 924 manager->DidNavigateFrame(host, true); |
| 921 EXPECT_TRUE(host == manager->current_frame_host()); | 925 EXPECT_TRUE(host == manager->current_frame_host()); |
| 922 ASSERT_TRUE(host); | 926 ASSERT_TRUE(host); |
| 923 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); | 927 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
| 924 | 928 |
| 925 // 3) Cross-site navigate to next site. -------------- | 929 // 3) Cross-site navigate to next site. -------------- |
| 926 const GURL kUrl3("http://webkit.org/"); | 930 const GURL kUrl3("http://webkit.org/"); |
| 927 NavigationEntryImpl entry3( | 931 NavigationEntryImpl entry3( |
| 928 NULL /* instance */, -1 /* page_id */, kUrl3, | 932 NULL /* instance */, -1 /* page_id */, kUrl3, |
| 929 Referrer(kUrl2, blink::WebReferrerPolicyDefault), | 933 Referrer(kUrl2, blink::WebReferrerPolicyDefault), |
| 930 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, | 934 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
| 931 false /* is_renderer_init */); | 935 false /* is_renderer_init */); |
| 932 host = GetFrameHostForNavigation(manager, entry3); | 936 host = NavigateToEntry(manager, entry3); |
| 933 | 937 |
| 934 // A new RenderFrameHost should be created. | 938 // A new RenderFrameHost should be created. |
| 935 EXPECT_TRUE(GetPendingFrameHost(manager)); | 939 EXPECT_TRUE(GetPendingFrameHost(manager)); |
| 936 ASSERT_EQ(host, GetPendingFrameHost(manager)); | 940 ASSERT_EQ(host, GetPendingFrameHost(manager)); |
| 937 | 941 |
| 938 notifications.Reset(); | 942 notifications.Reset(); |
| 939 | 943 |
| 940 // Commit. | 944 // Commit. |
| 941 manager->DidNavigateFrame(GetPendingFrameHost(manager), true); | 945 manager->DidNavigateFrame(GetPendingFrameHost(manager), true); |
| 942 EXPECT_TRUE(host == manager->current_frame_host()); | 946 EXPECT_TRUE(host == manager->current_frame_host()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 962 | 966 |
| 963 EXPECT_FALSE(manager->current_host()->IsRenderViewLive()); | 967 EXPECT_FALSE(manager->current_host()->IsRenderViewLive()); |
| 964 EXPECT_FALSE(manager->web_ui()); | 968 EXPECT_FALSE(manager->web_ui()); |
| 965 EXPECT_TRUE(initial_rfh); | 969 EXPECT_TRUE(initial_rfh); |
| 966 | 970 |
| 967 const GURL kUrl("chrome://foo"); | 971 const GURL kUrl("chrome://foo"); |
| 968 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | 972 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, |
| 969 Referrer(), base::string16() /* title */, | 973 Referrer(), base::string16() /* title */, |
| 970 ui::PAGE_TRANSITION_TYPED, | 974 ui::PAGE_TRANSITION_TYPED, |
| 971 false /* is_renderer_init */); | 975 false /* is_renderer_init */); |
| 972 RenderFrameHostImpl* host = GetFrameHostForNavigation(manager, entry); | 976 RenderFrameHostImpl* host = NavigateToEntry(manager, entry); |
| 973 | 977 |
| 974 // We commit the pending RenderFrameHost immediately because the previous | 978 // We commit the pending RenderFrameHost immediately because the previous |
| 975 // RenderFrameHost was not live. We test a case where it is live in | 979 // RenderFrameHost was not live. We test a case where it is live in |
| 976 // WebUIInNewTab. | 980 // WebUIInNewTab. |
| 977 EXPECT_TRUE(host); | 981 EXPECT_TRUE(host); |
| 978 EXPECT_NE(initial_rfh, host); | 982 EXPECT_NE(initial_rfh, host); |
| 979 EXPECT_EQ(host, manager->current_frame_host()); | 983 EXPECT_EQ(host, manager->current_frame_host()); |
| 980 EXPECT_FALSE(GetPendingFrameHost(manager)); | 984 EXPECT_FALSE(GetPendingFrameHost(manager)); |
| 981 | 985 |
| 982 // It's important that the SiteInstance get set on the Web UI page as soon | 986 // 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... |
| 1018 base::string16(), -1, MSG_ROUTING_NONE, -1, false); | 1022 base::string16(), -1, MSG_ROUTING_NONE, -1, false); |
| 1019 EXPECT_TRUE(manager1->current_host()->IsRenderViewLive()); | 1023 EXPECT_TRUE(manager1->current_host()->IsRenderViewLive()); |
| 1020 EXPECT_TRUE(manager1->current_frame_host()->IsRenderFrameLive()); | 1024 EXPECT_TRUE(manager1->current_frame_host()->IsRenderFrameLive()); |
| 1021 | 1025 |
| 1022 // Navigate to a WebUI page. | 1026 // Navigate to a WebUI page. |
| 1023 const GURL kUrl1("chrome://foo"); | 1027 const GURL kUrl1("chrome://foo"); |
| 1024 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, | 1028 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, |
| 1025 Referrer(), base::string16() /* title */, | 1029 Referrer(), base::string16() /* title */, |
| 1026 ui::PAGE_TRANSITION_TYPED, | 1030 ui::PAGE_TRANSITION_TYPED, |
| 1027 false /* is_renderer_init */); | 1031 false /* is_renderer_init */); |
| 1028 RenderFrameHostImpl* host1 = GetFrameHostForNavigation(manager1, entry1); | 1032 RenderFrameHostImpl* host1 = NavigateToEntry(manager1, entry1); |
| 1029 | 1033 |
| 1030 // We should have a pending navigation to the WebUI RenderViewHost. | 1034 // We should have a pending navigation to the WebUI RenderViewHost. |
| 1031 // It should already have bindings. | 1035 // It should already have bindings. |
| 1032 EXPECT_EQ(host1, GetPendingFrameHost(manager1)); | 1036 EXPECT_EQ(host1, GetPendingFrameHost(manager1)); |
| 1033 EXPECT_NE(host1, manager1->current_frame_host()); | 1037 EXPECT_NE(host1, manager1->current_frame_host()); |
| 1034 EXPECT_TRUE( | 1038 EXPECT_TRUE( |
| 1035 host1->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1039 host1->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
| 1036 | 1040 |
| 1037 // Commit and ensure we still have bindings. | 1041 // Commit and ensure we still have bindings. |
| 1038 manager1->DidNavigateFrame(host1, true); | 1042 manager1->DidNavigateFrame(host1, true); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1050 // RenderWidgetHost::Init when opening a new tab from a link. | 1054 // RenderWidgetHost::Init when opening a new tab from a link. |
| 1051 manager2->current_host()->CreateRenderView( | 1055 manager2->current_host()->CreateRenderView( |
| 1052 base::string16(), -1, MSG_ROUTING_NONE, -1, false); | 1056 base::string16(), -1, MSG_ROUTING_NONE, -1, false); |
| 1053 EXPECT_TRUE(manager2->current_host()->IsRenderViewLive()); | 1057 EXPECT_TRUE(manager2->current_host()->IsRenderViewLive()); |
| 1054 | 1058 |
| 1055 const GURL kUrl2("chrome://foo/bar"); | 1059 const GURL kUrl2("chrome://foo/bar"); |
| 1056 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, | 1060 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, |
| 1057 Referrer(), base::string16() /* title */, | 1061 Referrer(), base::string16() /* title */, |
| 1058 ui::PAGE_TRANSITION_LINK, | 1062 ui::PAGE_TRANSITION_LINK, |
| 1059 true /* is_renderer_init */); | 1063 true /* is_renderer_init */); |
| 1060 RenderFrameHostImpl* host2 = GetFrameHostForNavigation(manager2, entry2); | 1064 RenderFrameHostImpl* host2 = NavigateToEntry(manager2, entry2); |
| 1061 | 1065 |
| 1062 // No cross-process transition happens because we are already in the right | 1066 // No cross-process transition happens because we are already in the right |
| 1063 // SiteInstance. We should grant bindings immediately. | 1067 // SiteInstance. We should grant bindings immediately. |
| 1064 EXPECT_EQ(host2, manager2->current_frame_host()); | 1068 EXPECT_EQ(host2, manager2->current_frame_host()); |
| 1065 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1069 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1066 switches::kEnableBrowserSideNavigation)) { | 1070 switches::kEnableBrowserSideNavigation)) { |
| 1067 EXPECT_TRUE(manager2->speculative_web_ui()); | 1071 EXPECT_TRUE(manager2->speculative_web_ui()); |
| 1068 } else { | 1072 } else { |
| 1069 EXPECT_TRUE(manager2->pending_web_ui()); | 1073 EXPECT_TRUE(manager2->pending_web_ui()); |
| 1070 } | 1074 } |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1556 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 1560 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
| 1557 | 1561 |
| 1558 RenderFrameHostImpl* host = NULL; | 1562 RenderFrameHostImpl* host = NULL; |
| 1559 | 1563 |
| 1560 // 1) The first navigation. -------------------------- | 1564 // 1) The first navigation. -------------------------- |
| 1561 const GURL kUrl1("http://www.google.com/"); | 1565 const GURL kUrl1("http://www.google.com/"); |
| 1562 NavigationEntryImpl entry1( | 1566 NavigationEntryImpl entry1( |
| 1563 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), | 1567 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), |
| 1564 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, | 1568 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
| 1565 false /* is_renderer_init */); | 1569 false /* is_renderer_init */); |
| 1566 host = manager->Navigate(entry1); | 1570 host = NavigateToEntry(manager, entry1); |
| 1567 | 1571 |
| 1568 // The RenderFrameHost created in Init will be reused. | 1572 // The RenderFrameHost created in Init will be reused. |
| 1569 EXPECT_TRUE(host == manager->current_frame_host()); | 1573 EXPECT_TRUE(host == manager->current_frame_host()); |
| 1570 EXPECT_FALSE(manager->pending_frame_host()); | 1574 EXPECT_FALSE(manager->pending_frame_host()); |
| 1571 EXPECT_EQ(manager->current_frame_host()->GetSiteInstance(), instance); | 1575 EXPECT_EQ(manager->current_frame_host()->GetSiteInstance(), instance); |
| 1572 | 1576 |
| 1573 // Commit. | 1577 // Commit. |
| 1574 manager->DidNavigateFrame(host, true); | 1578 manager->DidNavigateFrame(host, true); |
| 1575 // Commit to SiteInstance should be delayed until RenderFrame commit. | 1579 // Commit to SiteInstance should be delayed until RenderFrame commit. |
| 1576 EXPECT_EQ(host, manager->current_frame_host()); | 1580 EXPECT_EQ(host, manager->current_frame_host()); |
| 1577 ASSERT_TRUE(host); | 1581 ASSERT_TRUE(host); |
| 1578 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); | 1582 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
| 1579 | 1583 |
| 1580 // 2) Navigate to a different domain. ------------------------- | 1584 // 2) Navigate to a different domain. ------------------------- |
| 1581 // Guests stay in the same process on navigation. | 1585 // Guests stay in the same process on navigation. |
| 1582 const GURL kUrl2("http://www.chromium.org"); | 1586 const GURL kUrl2("http://www.chromium.org"); |
| 1583 NavigationEntryImpl entry2( | 1587 NavigationEntryImpl entry2( |
| 1584 NULL /* instance */, -1 /* page_id */, kUrl2, | 1588 NULL /* instance */, -1 /* page_id */, kUrl2, |
| 1585 Referrer(kUrl1, blink::WebReferrerPolicyDefault), | 1589 Referrer(kUrl1, blink::WebReferrerPolicyDefault), |
| 1586 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, | 1590 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
| 1587 true /* is_renderer_init */); | 1591 true /* is_renderer_init */); |
| 1588 host = manager->Navigate(entry2); | 1592 host = NavigateToEntry(manager, entry2); |
| 1589 | 1593 |
| 1590 // The RenderFrameHost created in Init will be reused. | 1594 // The RenderFrameHost created in Init will be reused. |
| 1591 EXPECT_EQ(host, manager->current_frame_host()); | 1595 EXPECT_EQ(host, manager->current_frame_host()); |
| 1592 EXPECT_FALSE(manager->pending_frame_host()); | 1596 EXPECT_FALSE(manager->pending_frame_host()); |
| 1593 | 1597 |
| 1594 // Commit. | 1598 // Commit. |
| 1595 manager->DidNavigateFrame(host, true); | 1599 manager->DidNavigateFrame(host, true); |
| 1596 EXPECT_EQ(host, manager->current_frame_host()); | 1600 EXPECT_EQ(host, manager->current_frame_host()); |
| 1597 ASSERT_TRUE(host); | 1601 ASSERT_TRUE(host); |
| 1598 EXPECT_EQ(host->GetSiteInstance(), instance); | 1602 EXPECT_EQ(host->GetSiteInstance(), instance); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1613 Source<WebContents>(web_contents.get())); | 1617 Source<WebContents>(web_contents.get())); |
| 1614 | 1618 |
| 1615 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 1619 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
| 1616 | 1620 |
| 1617 // 1) The first navigation. -------------------------- | 1621 // 1) The first navigation. -------------------------- |
| 1618 const GURL kUrl1("http://www.google.com/"); | 1622 const GURL kUrl1("http://www.google.com/"); |
| 1619 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, | 1623 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, |
| 1620 Referrer(), base::string16() /* title */, | 1624 Referrer(), base::string16() /* title */, |
| 1621 ui::PAGE_TRANSITION_TYPED, | 1625 ui::PAGE_TRANSITION_TYPED, |
| 1622 false /* is_renderer_init */); | 1626 false /* is_renderer_init */); |
| 1623 RenderFrameHostImpl* host = manager->Navigate(entry1); | 1627 RenderFrameHostImpl* host = NavigateToEntry(manager, entry1); |
| 1624 | 1628 |
| 1625 // The RenderFrameHost created in Init will be reused. | 1629 // The RenderFrameHost created in Init will be reused. |
| 1626 EXPECT_EQ(host, manager->current_frame_host()); | 1630 EXPECT_EQ(host, manager->current_frame_host()); |
| 1627 EXPECT_FALSE(manager->pending_frame_host()); | 1631 EXPECT_FALSE(GetPendingFrameHost(manager)); |
| 1628 | 1632 |
| 1629 // We should observe a notification. | 1633 // We should observe a notification. |
| 1630 EXPECT_TRUE( | 1634 EXPECT_TRUE( |
| 1631 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | 1635 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); |
| 1632 notifications.Reset(); | 1636 notifications.Reset(); |
| 1633 | 1637 |
| 1634 // Commit. | 1638 // Commit. |
| 1635 manager->DidNavigateFrame(host, true); | 1639 manager->DidNavigateFrame(host, true); |
| 1636 | 1640 |
| 1637 // Commit to SiteInstance should be delayed until RenderFrame commits. | 1641 // Commit to SiteInstance should be delayed until RenderFrame commits. |
| 1638 EXPECT_EQ(host, manager->current_frame_host()); | 1642 EXPECT_EQ(host, manager->current_frame_host()); |
| 1639 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); | 1643 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); |
| 1640 host->GetSiteInstance()->SetSite(kUrl1); | 1644 host->GetSiteInstance()->SetSite(kUrl1); |
| 1641 | 1645 |
| 1642 // 2) Cross-site navigate to next site. ------------------------- | 1646 // 2) Cross-site navigate to next site. ------------------------- |
| 1643 const GURL kUrl2("http://www.example.com"); | 1647 const GURL kUrl2("http://www.example.com"); |
| 1644 NavigationEntryImpl entry2( | 1648 NavigationEntryImpl entry2( |
| 1645 NULL /* instance */, -1 /* page_id */, kUrl2, Referrer(), | 1649 NULL /* instance */, -1 /* page_id */, kUrl2, Referrer(), |
| 1646 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, | 1650 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
| 1647 false /* is_renderer_init */); | 1651 false /* is_renderer_init */); |
| 1648 RenderFrameHostImpl* host2 = manager->Navigate(entry2); | 1652 RenderFrameHostImpl* host2 = NavigateToEntry(manager, entry2); |
| 1649 | 1653 |
| 1650 // A new RenderFrameHost should be created. | 1654 // A new RenderFrameHost should be created. |
| 1651 ASSERT_EQ(host2, manager->pending_frame_host()); | 1655 ASSERT_EQ(host2, GetPendingFrameHost(manager)); |
| 1652 EXPECT_NE(host2, host); | 1656 EXPECT_NE(host2, host); |
| 1653 | 1657 |
| 1654 EXPECT_EQ(host, manager->current_frame_host()); | 1658 EXPECT_EQ(host, manager->current_frame_host()); |
| 1655 EXPECT_FALSE(manager->current_frame_host()->is_swapped_out()); | 1659 EXPECT_FALSE(manager->current_frame_host()->is_swapped_out()); |
| 1656 EXPECT_EQ(host2, manager->pending_frame_host()); | 1660 EXPECT_EQ(host2, GetPendingFrameHost(manager)); |
| 1657 | 1661 |
| 1658 // 3) Close the tab. ------------------------- | 1662 // 3) Close the tab. ------------------------- |
| 1659 notifications.ListenFor(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 1663 notifications.ListenFor(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 1660 Source<RenderWidgetHost>(host2->render_view_host())); | 1664 Source<RenderWidgetHost>(host2->render_view_host())); |
| 1661 manager->OnBeforeUnloadACK(false, true, base::TimeTicks()); | 1665 manager->OnBeforeUnloadACK(false, true, base::TimeTicks()); |
| 1662 | 1666 |
| 1663 EXPECT_TRUE( | 1667 EXPECT_TRUE( |
| 1664 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED)); | 1668 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED)); |
| 1665 EXPECT_FALSE(manager->pending_frame_host()); | 1669 EXPECT_FALSE(GetPendingFrameHost(manager)); |
| 1666 EXPECT_EQ(host, manager->current_frame_host()); | 1670 EXPECT_EQ(host, manager->current_frame_host()); |
| 1667 } | 1671 } |
| 1668 | 1672 |
| 1669 TEST_F(RenderFrameHostManagerTest, CloseWithPendingWhileUnresponsive) { | 1673 TEST_F(RenderFrameHostManagerTest, CloseWithPendingWhileUnresponsive) { |
| 1670 const GURL kUrl1("http://www.google.com/"); | 1674 const GURL kUrl1("http://www.google.com/"); |
| 1671 const GURL kUrl2("http://www.chromium.org/"); | 1675 const GURL kUrl2("http://www.chromium.org/"); |
| 1672 | 1676 |
| 1673 CloseWebContentsDelegate close_delegate; | 1677 CloseWebContentsDelegate close_delegate; |
| 1674 contents()->SetDelegate(&close_delegate); | 1678 contents()->SetDelegate(&close_delegate); |
| 1675 | 1679 |
| 1676 // Navigate to the first page. | 1680 // Navigate to the first page. |
| 1677 contents()->NavigateAndCommit(kUrl1); | 1681 contents()->NavigateAndCommit(kUrl1); |
| 1678 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1682 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
| 1679 | 1683 |
| 1680 // Start to close the tab, but assume it's unresponsive. | 1684 // Start to close the tab, but assume it's unresponsive. |
| 1681 rfh1->render_view_host()->ClosePage(); | 1685 rfh1->render_view_host()->ClosePage(); |
| 1682 EXPECT_TRUE(rfh1->render_view_host()->is_waiting_for_close_ack()); | 1686 EXPECT_TRUE(rfh1->render_view_host()->is_waiting_for_close_ack()); |
| 1683 | 1687 |
| 1684 // Start a navigation to a new site. | 1688 // Start a navigation to a new site. |
| 1685 controller().LoadURL( | 1689 controller().LoadURL( |
| 1686 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1690 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1687 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1691 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1688 switches::kEnableBrowserSideNavigation)) { | 1692 switches::kEnableBrowserSideNavigation)) { |
| 1689 rfh1->PrepareForCommit(); | 1693 rfh1->PrepareForCommit(); |
| 1690 } | 1694 } |
| 1691 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1695 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 1692 | 1696 |
| 1693 // Simulate the unresponsiveness timer. The tab should close. | 1697 // Simulate the unresponsiveness timer. The tab should close. |
| 1694 contents()->RendererUnresponsive(rfh1->render_view_host()); | 1698 contents()->RendererUnresponsive(rfh1->render_view_host()); |
| 1695 EXPECT_TRUE(close_delegate.is_closed()); | 1699 EXPECT_TRUE(close_delegate.is_closed()); |
| 1696 } | 1700 } |
| 1697 | 1701 |
| 1698 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is | 1702 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is |
| 1699 // received. (SwapOut and the corresponding ACK always occur after commit.) | 1703 // received. (SwapOut and the corresponding ACK always occur after commit.) |
| 1700 // Also tests that an early SwapOutACK is properly ignored. | 1704 // Also tests that an early SwapOutACK is properly ignored. |
| 1701 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { | 1705 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { |
| 1702 const GURL kUrl1("http://www.google.com/"); | 1706 const GURL kUrl1("http://www.google.com/"); |
| 1703 const GURL kUrl2("http://www.chromium.org/"); | 1707 const GURL kUrl2("http://www.chromium.org/"); |
| 1704 | 1708 |
| 1705 // Navigate to the first page. | 1709 // Navigate to the first page. |
| 1706 contents()->NavigateAndCommit(kUrl1); | 1710 contents()->NavigateAndCommit(kUrl1); |
| 1707 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1711 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
| 1708 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); | 1712 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
| 1709 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1713 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1710 | 1714 |
| 1711 // Navigate to new site, simulating onbeforeunload approval. | 1715 // Navigate to new site, simulating onbeforeunload approval. |
| 1712 controller().LoadURL( | 1716 controller().LoadURL( |
| 1713 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1717 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1714 contents()->GetMainFrame()->PrepareForCommit(); | 1718 contents()->GetMainFrame()->PrepareForCommit(); |
| 1715 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1719 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 1716 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1720 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1717 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1721 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 1718 | 1722 |
| 1719 // Simulate the swap out ack, unexpectedly early (before commit). It should | 1723 // Simulate the swap out ack, unexpectedly early (before commit). It should |
| 1720 // have no effect. | 1724 // have no effect. |
| 1721 rfh1->OnSwappedOut(); | 1725 rfh1->OnSwappedOut(); |
| 1722 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1726 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 1723 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1727 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1724 | 1728 |
| 1725 // The new page commits. | 1729 // The new page commits. |
| 1726 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1730 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
| 1727 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1731 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 1728 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1732 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
| 1729 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1733 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
| 1730 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1734 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
| 1731 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1735 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
| 1732 EXPECT_TRUE( | 1736 EXPECT_TRUE( |
| 1733 rfh1->frame_tree_node()->render_manager()->IsPendingDeletion(rfh1)); | 1737 rfh1->frame_tree_node()->render_manager()->IsPendingDeletion(rfh1)); |
| 1734 | 1738 |
| 1735 // Simulate the swap out ack. | 1739 // Simulate the swap out ack. |
| 1736 rfh1->OnSwappedOut(); | 1740 rfh1->OnSwappedOut(); |
| 1737 | 1741 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1753 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1757 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1754 | 1758 |
| 1755 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1759 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
| 1756 // not deleted on swap out. | 1760 // not deleted on swap out. |
| 1757 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1761 rfh1->GetSiteInstance()->increment_active_frame_count(); |
| 1758 | 1762 |
| 1759 // Navigate to new site, simulating onbeforeunload approval. | 1763 // Navigate to new site, simulating onbeforeunload approval. |
| 1760 controller().LoadURL( | 1764 controller().LoadURL( |
| 1761 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1765 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1762 contents()->GetMainFrame()->PrepareForCommit(); | 1766 contents()->GetMainFrame()->PrepareForCommit(); |
| 1763 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1767 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 1764 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1768 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1765 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1769 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 1766 | 1770 |
| 1767 // The new page commits. | 1771 // The new page commits. |
| 1768 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1772 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
| 1769 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1773 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 1770 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1774 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
| 1771 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1775 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
| 1772 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1776 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
| 1773 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1777 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
| 1774 | 1778 |
| 1775 // Simulate the swap out ack. | 1779 // Simulate the swap out ack. |
| 1776 rfh1->OnSwappedOut(); | 1780 rfh1->OnSwappedOut(); |
| 1777 | 1781 |
| 1778 // rfh1 should be swapped out. | 1782 // rfh1 should be swapped out. |
| 1779 EXPECT_FALSE(rfh_deleted_observer.deleted()); | 1783 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1796 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1800 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
| 1797 | 1801 |
| 1798 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1802 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
| 1799 // not deleted on swap out. | 1803 // not deleted on swap out. |
| 1800 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1804 rfh1->GetSiteInstance()->increment_active_frame_count(); |
| 1801 | 1805 |
| 1802 // Navigate to new site, simulating onbeforeunload approval. | 1806 // Navigate to new site, simulating onbeforeunload approval. |
| 1803 controller().LoadURL( | 1807 controller().LoadURL( |
| 1804 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1808 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1805 rfh1->PrepareForCommit(); | 1809 rfh1->PrepareForCommit(); |
| 1806 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1810 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 1807 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1811 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
| 1808 | 1812 |
| 1809 // The new page commits. | 1813 // The new page commits. |
| 1810 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1814 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); |
| 1811 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1815 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 1812 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1816 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
| 1813 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1817 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
| 1814 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1818 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
| 1815 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1819 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
| 1816 | 1820 |
| 1817 // Simulate the swap out ack. | 1821 // Simulate the swap out ack. |
| 1818 rfh1->OnSwappedOut(); | 1822 rfh1->OnSwappedOut(); |
| 1819 | 1823 |
| 1820 // rfh1 should be swapped out. | 1824 // rfh1 should be swapped out. |
| 1821 EXPECT_FALSE(rfh_deleted_observer.deleted()); | 1825 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1840 controller().LoadURL( | 1844 controller().LoadURL( |
| 1841 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1845 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1842 { | 1846 { |
| 1843 pending_rfh = contents()->GetFrameTree()->root()->render_manager() | 1847 pending_rfh = contents()->GetFrameTree()->root()->render_manager() |
| 1844 ->pending_frame_host(); | 1848 ->pending_frame_host(); |
| 1845 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); | 1849 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); |
| 1846 | 1850 |
| 1847 // Cancel the navigation by simulating a declined beforeunload dialog. | 1851 // Cancel the navigation by simulating a declined beforeunload dialog. |
| 1848 contents()->GetMainFrame()->OnMessageReceived( | 1852 contents()->GetMainFrame()->OnMessageReceived( |
| 1849 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | 1853 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); |
| 1850 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1854 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 1851 | 1855 |
| 1852 // Since the pending RFH is the only one for the new SiteInstance, it should | 1856 // Since the pending RFH is the only one for the new SiteInstance, it should |
| 1853 // be deleted. | 1857 // be deleted. |
| 1854 EXPECT_TRUE(rfh_deleted_observer.deleted()); | 1858 EXPECT_TRUE(rfh_deleted_observer.deleted()); |
| 1855 } | 1859 } |
| 1856 | 1860 |
| 1857 // Start another cross-site navigation. | 1861 // Start another cross-site navigation. |
| 1858 controller().LoadURL( | 1862 controller().LoadURL( |
| 1859 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1863 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1860 { | 1864 { |
| 1861 pending_rfh = contents()->GetFrameTree()->root()->render_manager() | 1865 pending_rfh = contents()->GetFrameTree()->root()->render_manager() |
| 1862 ->pending_frame_host(); | 1866 ->pending_frame_host(); |
| 1863 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); | 1867 RenderFrameHostDeletedObserver rfh_deleted_observer(pending_rfh); |
| 1864 | 1868 |
| 1865 // Increment the number of active frames in the new SiteInstance, which will | 1869 // Increment the number of active frames in the new SiteInstance, which will |
| 1866 // cause the pending RFH to be swapped out instead of deleted. | 1870 // cause the pending RFH to be swapped out instead of deleted. |
| 1867 pending_rfh->GetSiteInstance()->increment_active_frame_count(); | 1871 pending_rfh->GetSiteInstance()->increment_active_frame_count(); |
| 1868 | 1872 |
| 1869 contents()->GetMainFrame()->OnMessageReceived( | 1873 contents()->GetMainFrame()->OnMessageReceived( |
| 1870 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | 1874 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); |
| 1871 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1875 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 1872 EXPECT_FALSE(rfh_deleted_observer.deleted()); | 1876 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
| 1873 } | 1877 } |
| 1874 } | 1878 } |
| 1875 | 1879 |
| 1876 // Test that a pending RenderFrameHost in a non-root frame tree node is properly | 1880 // Test that a pending RenderFrameHost in a non-root frame tree node is properly |
| 1877 // deleted when the node is detached. Motivated by http://crbug.com/441357 and | 1881 // deleted when the node is detached. Motivated by http://crbug.com/441357 and |
| 1878 // http://crbug.com/444955. | 1882 // http://crbug.com/444955. |
| 1879 TEST_F(RenderFrameHostManagerTest, DetachPendingChild) { | 1883 TEST_F(RenderFrameHostManagerTest, DetachPendingChild) { |
| 1880 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1884 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1881 switches::kSitePerProcess); | 1885 switches::kSitePerProcess); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1896 RenderFrameHostManager* iframe1 = | 1900 RenderFrameHostManager* iframe1 = |
| 1897 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); | 1901 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); |
| 1898 RenderFrameHostManager* iframe2 = | 1902 RenderFrameHostManager* iframe2 = |
| 1899 contents()->GetFrameTree()->root()->child_at(1)->render_manager(); | 1903 contents()->GetFrameTree()->root()->child_at(1)->render_manager(); |
| 1900 | 1904 |
| 1901 // 1) The first navigation. | 1905 // 1) The first navigation. |
| 1902 NavigationEntryImpl entryA(NULL /* instance */, -1 /* page_id */, kUrlA, | 1906 NavigationEntryImpl entryA(NULL /* instance */, -1 /* page_id */, kUrlA, |
| 1903 Referrer(), base::string16() /* title */, | 1907 Referrer(), base::string16() /* title */, |
| 1904 ui::PAGE_TRANSITION_TYPED, | 1908 ui::PAGE_TRANSITION_TYPED, |
| 1905 false /* is_renderer_init */); | 1909 false /* is_renderer_init */); |
| 1906 RenderFrameHostImpl* host1 = GetFrameHostForNavigation(iframe1, entryA); | 1910 RenderFrameHostImpl* host1 = NavigateToEntry(iframe1, entryA); |
| 1907 | 1911 |
| 1908 // The RenderFrameHost created in Init will be reused. | 1912 // The RenderFrameHost created in Init will be reused. |
| 1909 EXPECT_TRUE(host1 == iframe1->current_frame_host()); | 1913 EXPECT_TRUE(host1 == iframe1->current_frame_host()); |
| 1910 EXPECT_FALSE(GetPendingFrameHost(iframe1)); | 1914 EXPECT_FALSE(GetPendingFrameHost(iframe1)); |
| 1911 | 1915 |
| 1912 // Commit. | 1916 // Commit. |
| 1913 iframe1->DidNavigateFrame(host1, true); | 1917 iframe1->DidNavigateFrame(host1, true); |
| 1914 // Commit to SiteInstance should be delayed until RenderFrame commit. | 1918 // Commit to SiteInstance should be delayed until RenderFrame commit. |
| 1915 EXPECT_TRUE(host1 == iframe1->current_frame_host()); | 1919 EXPECT_TRUE(host1 == iframe1->current_frame_host()); |
| 1916 ASSERT_TRUE(host1); | 1920 ASSERT_TRUE(host1); |
| 1917 EXPECT_TRUE(host1->GetSiteInstance()->HasSite()); | 1921 EXPECT_TRUE(host1->GetSiteInstance()->HasSite()); |
| 1918 | 1922 |
| 1919 // 2) Cross-site navigate both frames to next site. | 1923 // 2) Cross-site navigate both frames to next site. |
| 1920 NavigationEntryImpl entryB(NULL /* instance */, -1 /* page_id */, kUrlB, | 1924 NavigationEntryImpl entryB(NULL /* instance */, -1 /* page_id */, kUrlB, |
| 1921 Referrer(kUrlA, blink::WebReferrerPolicyDefault), | 1925 Referrer(kUrlA, blink::WebReferrerPolicyDefault), |
| 1922 base::string16() /* title */, | 1926 base::string16() /* title */, |
| 1923 ui::PAGE_TRANSITION_LINK, | 1927 ui::PAGE_TRANSITION_LINK, |
| 1924 false /* is_renderer_init */); | 1928 false /* is_renderer_init */); |
| 1925 host1 = GetFrameHostForNavigation(iframe1, entryB); | 1929 host1 = NavigateToEntry(iframe1, entryB); |
| 1926 RenderFrameHostImpl* host2 = GetFrameHostForNavigation(iframe2, entryB); | 1930 RenderFrameHostImpl* host2 = NavigateToEntry(iframe2, entryB); |
| 1927 | 1931 |
| 1928 // A new, pending RenderFrameHost should be created in each FrameTreeNode. | 1932 // A new, pending RenderFrameHost should be created in each FrameTreeNode. |
| 1929 EXPECT_TRUE(GetPendingFrameHost(iframe1)); | 1933 EXPECT_TRUE(GetPendingFrameHost(iframe1)); |
| 1930 EXPECT_TRUE(GetPendingFrameHost(iframe2)); | 1934 EXPECT_TRUE(GetPendingFrameHost(iframe2)); |
| 1931 EXPECT_EQ(host1, GetPendingFrameHost(iframe1)); | 1935 EXPECT_EQ(host1, GetPendingFrameHost(iframe1)); |
| 1932 EXPECT_EQ(host2, GetPendingFrameHost(iframe2)); | 1936 EXPECT_EQ(host2, GetPendingFrameHost(iframe2)); |
| 1933 EXPECT_TRUE(RenderFrameHostImpl::IsRFHStateActive( | 1937 EXPECT_TRUE(RenderFrameHostImpl::IsRFHStateActive( |
| 1934 GetPendingFrameHost(iframe1)->rfh_state())); | 1938 GetPendingFrameHost(iframe1)->rfh_state())); |
| 1935 EXPECT_TRUE(RenderFrameHostImpl::IsRFHStateActive( | 1939 EXPECT_TRUE(RenderFrameHostImpl::IsRFHStateActive( |
| 1936 GetPendingFrameHost(iframe2)->rfh_state())); | 1940 GetPendingFrameHost(iframe2)->rfh_state())); |
| 1937 EXPECT_NE(GetPendingFrameHost(iframe1), GetPendingFrameHost(iframe2)); | 1941 EXPECT_NE(GetPendingFrameHost(iframe1), GetPendingFrameHost(iframe2)); |
| 1938 EXPECT_EQ(GetPendingFrameHost(iframe1)->GetSiteInstance(), | 1942 EXPECT_EQ(GetPendingFrameHost(iframe1)->GetSiteInstance(), |
| 1939 GetPendingFrameHost(iframe2)->GetSiteInstance()); | 1943 GetPendingFrameHost(iframe2)->GetSiteInstance()); |
| 1940 EXPECT_NE(iframe1->current_frame_host(), GetPendingFrameHost(iframe1)); | 1944 EXPECT_NE(iframe1->current_frame_host(), GetPendingFrameHost(iframe1)); |
| 1941 EXPECT_NE(iframe2->current_frame_host(), GetPendingFrameHost(iframe2)); | 1945 EXPECT_NE(iframe2->current_frame_host(), GetPendingFrameHost(iframe2)); |
| 1942 EXPECT_FALSE(contents()->cross_navigation_pending()) | 1946 EXPECT_FALSE(contents()->CrossProcessNavigationPending()) |
| 1943 << "There should be no top-level pending navigation."; | 1947 << "There should be no top-level pending navigation."; |
| 1944 | 1948 |
| 1945 RenderFrameHostDeletedObserver delete_watcher1(GetPendingFrameHost(iframe1)); | 1949 RenderFrameHostDeletedObserver delete_watcher1(GetPendingFrameHost(iframe1)); |
| 1946 RenderFrameHostDeletedObserver delete_watcher2(GetPendingFrameHost(iframe2)); | 1950 RenderFrameHostDeletedObserver delete_watcher2(GetPendingFrameHost(iframe2)); |
| 1947 EXPECT_FALSE(delete_watcher1.deleted()); | 1951 EXPECT_FALSE(delete_watcher1.deleted()); |
| 1948 EXPECT_FALSE(delete_watcher2.deleted()); | 1952 EXPECT_FALSE(delete_watcher2.deleted()); |
| 1949 | 1953 |
| 1950 // Keep the SiteInstance alive for testing. | 1954 // Keep the SiteInstance alive for testing. |
| 1951 scoped_refptr<SiteInstanceImpl> site_instance = | 1955 scoped_refptr<SiteInstanceImpl> site_instance = |
| 1952 GetPendingFrameHost(iframe1)->GetSiteInstance(); | 1956 GetPendingFrameHost(iframe1)->GetSiteInstance(); |
| 1953 EXPECT_TRUE(site_instance->HasSite()); | 1957 EXPECT_TRUE(site_instance->HasSite()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2027 contents1->GetMainFrame()->OnCreateChildFrame( | 2031 contents1->GetMainFrame()->OnCreateChildFrame( |
| 2028 contents1->GetMainFrame()->GetProcess()->GetNextRoutingID(), | 2032 contents1->GetMainFrame()->GetProcess()->GetNextRoutingID(), |
| 2029 std::string("frame_name"), SandboxFlags::NONE); | 2033 std::string("frame_name"), SandboxFlags::NONE); |
| 2030 RenderFrameHostManager* iframe = | 2034 RenderFrameHostManager* iframe = |
| 2031 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); | 2035 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); |
| 2032 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl2, | 2036 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl2, |
| 2033 Referrer(kUrl1, blink::WebReferrerPolicyDefault), | 2037 Referrer(kUrl1, blink::WebReferrerPolicyDefault), |
| 2034 base::string16() /* title */, | 2038 base::string16() /* title */, |
| 2035 ui::PAGE_TRANSITION_LINK, | 2039 ui::PAGE_TRANSITION_LINK, |
| 2036 false /* is_renderer_init */); | 2040 false /* is_renderer_init */); |
| 2037 RenderFrameHostImpl* cross_site = GetFrameHostForNavigation(iframe, entry); | 2041 RenderFrameHostImpl* cross_site = NavigateToEntry(iframe, entry); |
| 2038 iframe->DidNavigateFrame(cross_site, true); | 2042 iframe->DidNavigateFrame(cross_site, true); |
| 2039 | 2043 |
| 2040 // A proxy to the iframe should now exist in the SiteInstance of the main | 2044 // A proxy to the iframe should now exist in the SiteInstance of the main |
| 2041 // frames. | 2045 // frames. |
| 2042 EXPECT_NE(cross_site->GetSiteInstance(), contents1->GetSiteInstance()); | 2046 EXPECT_NE(cross_site->GetSiteInstance(), contents1->GetSiteInstance()); |
| 2043 EXPECT_NE(nullptr, | 2047 EXPECT_NE(nullptr, |
| 2044 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); | 2048 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); |
| 2045 EXPECT_NE(nullptr, | 2049 EXPECT_NE(nullptr, |
| 2046 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); | 2050 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); |
| 2047 | 2051 |
| 2048 // Navigate |contents2| away from the sad tab (and thus away from the | 2052 // Navigate |contents2| away from the sad tab (and thus away from the |
| 2049 // SiteInstance of |contents1|). This should not destroy the proxies needed by | 2053 // SiteInstance of |contents1|). This should not destroy the proxies needed by |
| 2050 // |contents1| -- that was http://crbug.com/473714. | 2054 // |contents1| -- that was http://crbug.com/473714. |
| 2051 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); | 2055 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); |
| 2052 contents2->NavigateAndCommit(kUrl3); | 2056 contents2->NavigateAndCommit(kUrl3); |
| 2053 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); | 2057 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); |
| 2054 EXPECT_NE(nullptr, | 2058 EXPECT_NE(nullptr, |
| 2055 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); | 2059 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); |
| 2056 EXPECT_EQ(nullptr, | 2060 EXPECT_EQ(nullptr, |
| 2057 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); | 2061 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); |
| 2058 } | 2062 } |
| 2059 | 2063 |
| 2060 } // namespace content | 2064 } // namespace content |
| OLD | NEW |