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 "content/browser/frame_host/render_frame_host_manager.h" | 5 #include "content/browser/frame_host/render_frame_host_manager.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <tuple> | 9 #include <tuple> |
10 #include <utility> | 10 #include <utility> |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is | 497 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is |
498 // a regression test for bug 9364. | 498 // a regression test for bug 9364. |
499 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { | 499 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { |
500 set_should_create_webui(true); | 500 set_should_create_webui(true); |
501 const GURL kChromeUrl("chrome://foo"); | 501 const GURL kChromeUrl("chrome://foo"); |
502 const GURL kDestUrl("http://www.google.com/"); | 502 const GURL kDestUrl("http://www.google.com/"); |
503 | 503 |
504 // Navigate our first tab to the chrome url and then to the destination, | 504 // Navigate our first tab to the chrome url and then to the destination, |
505 // ensuring we grant bindings to the chrome URL. | 505 // ensuring we grant bindings to the chrome URL. |
506 NavigateActiveAndCommit(kChromeUrl); | 506 NavigateActiveAndCommit(kChromeUrl); |
507 EXPECT_TRUE(active_rvh()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 507 EXPECT_TRUE(main_rfh()->GetEnabledBindings() & |
| 508 BINDINGS_POLICY_WEB_UI); |
508 NavigateActiveAndCommit(kDestUrl); | 509 NavigateActiveAndCommit(kDestUrl); |
509 | 510 |
510 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 511 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
511 | 512 |
512 // Make a second tab. | 513 // Make a second tab. |
513 std::unique_ptr<TestWebContents> contents2( | 514 std::unique_ptr<TestWebContents> contents2( |
514 TestWebContents::Create(browser_context(), NULL)); | 515 TestWebContents::Create(browser_context(), NULL)); |
515 | 516 |
516 // Load the two URLs in the second tab. Note that the first navigation creates | 517 // Load the two URLs in the second tab. Note that the first navigation creates |
517 // a RFH that's not pending (since there is no cross-site transition), so | 518 // a RFH that's not pending (since there is no cross-site transition), so |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 EXPECT_EQ(host->web_ui(), manager->GetNavigatingWebUI()); | 1027 EXPECT_EQ(host->web_ui(), manager->GetNavigatingWebUI()); |
1027 EXPECT_EQ(host->web_ui(), host->pending_web_ui()); | 1028 EXPECT_EQ(host->web_ui(), host->pending_web_ui()); |
1028 } else { | 1029 } else { |
1029 // The WebUI was immediately committed and there should be none navigating. | 1030 // The WebUI was immediately committed and there should be none navigating. |
1030 EXPECT_FALSE(manager->GetNavigatingWebUI()); | 1031 EXPECT_FALSE(manager->GetNavigatingWebUI()); |
1031 } | 1032 } |
1032 EXPECT_TRUE(manager->current_frame_host()->web_ui()); | 1033 EXPECT_TRUE(manager->current_frame_host()->web_ui()); |
1033 | 1034 |
1034 // Commit. | 1035 // Commit. |
1035 manager->DidNavigateFrame(host, true); | 1036 manager->DidNavigateFrame(host, true); |
1036 EXPECT_TRUE( | 1037 EXPECT_TRUE(host->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
1037 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | |
1038 } | 1038 } |
1039 | 1039 |
1040 // Tests that we can open a WebUI link in a new tab from a WebUI page and still | 1040 // Tests that we can open a WebUI link in a new tab from a WebUI page and still |
1041 // grant the correct bindings. http://crbug.com/189101. | 1041 // grant the correct bindings. http://crbug.com/189101. |
1042 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) { | 1042 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) { |
1043 set_should_create_webui(true); | 1043 set_should_create_webui(true); |
1044 scoped_refptr<SiteInstance> blank_instance = | 1044 scoped_refptr<SiteInstance> blank_instance = |
1045 SiteInstance::Create(browser_context()); | 1045 SiteInstance::Create(browser_context()); |
1046 blank_instance->GetProcess()->Init(); | 1046 blank_instance->GetProcess()->Init(); |
1047 | 1047 |
(...skipping 13 matching lines...) Expand all Loading... |
1061 NavigationEntryImpl entry1(NULL /* instance */, kUrl1, | 1061 NavigationEntryImpl entry1(NULL /* instance */, kUrl1, |
1062 Referrer(), base::string16() /* title */, | 1062 Referrer(), base::string16() /* title */, |
1063 ui::PAGE_TRANSITION_TYPED, | 1063 ui::PAGE_TRANSITION_TYPED, |
1064 false /* is_renderer_init */); | 1064 false /* is_renderer_init */); |
1065 RenderFrameHostImpl* host1 = NavigateToEntry(manager1, entry1); | 1065 RenderFrameHostImpl* host1 = NavigateToEntry(manager1, entry1); |
1066 | 1066 |
1067 // We should have a pending navigation to the WebUI RenderViewHost. | 1067 // We should have a pending navigation to the WebUI RenderViewHost. |
1068 // It should already have bindings. | 1068 // It should already have bindings. |
1069 EXPECT_EQ(host1, GetPendingFrameHost(manager1)); | 1069 EXPECT_EQ(host1, GetPendingFrameHost(manager1)); |
1070 EXPECT_NE(host1, manager1->current_frame_host()); | 1070 EXPECT_NE(host1, manager1->current_frame_host()); |
1071 EXPECT_TRUE( | 1071 EXPECT_TRUE(host1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
1072 host1->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | |
1073 | 1072 |
1074 // Commit and ensure we still have bindings. | 1073 // Commit and ensure we still have bindings. |
1075 manager1->DidNavigateFrame(host1, true); | 1074 manager1->DidNavigateFrame(host1, true); |
1076 SiteInstance* webui_instance = host1->GetSiteInstance(); | 1075 SiteInstance* webui_instance = host1->GetSiteInstance(); |
1077 EXPECT_EQ(host1, manager1->current_frame_host()); | 1076 EXPECT_EQ(host1, manager1->current_frame_host()); |
1078 EXPECT_TRUE( | 1077 EXPECT_TRUE(host1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
1079 host1->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | |
1080 | 1078 |
1081 // Now simulate clicking a link that opens in a new tab. | 1079 // Now simulate clicking a link that opens in a new tab. |
1082 std::unique_ptr<TestWebContents> web_contents2( | 1080 std::unique_ptr<TestWebContents> web_contents2( |
1083 TestWebContents::Create(browser_context(), webui_instance)); | 1081 TestWebContents::Create(browser_context(), webui_instance)); |
1084 RenderFrameHostManager* manager2 = | 1082 RenderFrameHostManager* manager2 = |
1085 web_contents2->GetRenderManagerForTesting(); | 1083 web_contents2->GetRenderManagerForTesting(); |
1086 // Make sure the new RVH is considered live. This is usually done in | 1084 // Make sure the new RVH is considered live. This is usually done in |
1087 // RenderWidgetHost::Init when opening a new tab from a link. | 1085 // RenderWidgetHost::Init when opening a new tab from a link. |
1088 manager2->current_host()->CreateRenderView(-1, MSG_ROUTING_NONE, | 1086 manager2->current_host()->CreateRenderView(-1, MSG_ROUTING_NONE, |
1089 FrameReplicationState(), false); | 1087 FrameReplicationState(), false); |
1090 EXPECT_TRUE(manager2->current_host()->IsRenderViewLive()); | 1088 EXPECT_TRUE(manager2->current_host()->IsRenderViewLive()); |
1091 | 1089 |
1092 const GURL kUrl2("chrome://foo/bar"); | 1090 const GURL kUrl2("chrome://foo/bar"); |
1093 NavigationEntryImpl entry2(NULL /* instance */, kUrl2, | 1091 NavigationEntryImpl entry2(NULL /* instance */, kUrl2, |
1094 Referrer(), base::string16() /* title */, | 1092 Referrer(), base::string16() /* title */, |
1095 ui::PAGE_TRANSITION_LINK, | 1093 ui::PAGE_TRANSITION_LINK, |
1096 true /* is_renderer_init */); | 1094 true /* is_renderer_init */); |
1097 RenderFrameHostImpl* host2 = NavigateToEntry(manager2, entry2); | 1095 RenderFrameHostImpl* host2 = NavigateToEntry(manager2, entry2); |
1098 | 1096 |
1099 // No cross-process transition happens because we are already in the right | 1097 // No cross-process transition happens because we are already in the right |
1100 // SiteInstance. We should grant bindings immediately. | 1098 // SiteInstance. We should grant bindings immediately. |
1101 EXPECT_EQ(host2, manager2->current_frame_host()); | 1099 EXPECT_EQ(host2, manager2->current_frame_host()); |
1102 EXPECT_TRUE(manager2->GetNavigatingWebUI()); | 1100 EXPECT_TRUE(manager2->GetNavigatingWebUI()); |
1103 EXPECT_FALSE(host2->web_ui()); | 1101 EXPECT_FALSE(host2->web_ui()); |
1104 EXPECT_TRUE( | 1102 EXPECT_TRUE(host2->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
1105 host2->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | |
1106 | 1103 |
1107 manager2->DidNavigateFrame(host2, true); | 1104 manager2->DidNavigateFrame(host2, true); |
1108 } | 1105 } |
1109 | 1106 |
1110 // Tests that a WebUI is correctly reused between chrome:// pages. | 1107 // Tests that a WebUI is correctly reused between chrome:// pages. |
1111 TEST_F(RenderFrameHostManagerTest, WebUIWasReused) { | 1108 TEST_F(RenderFrameHostManagerTest, WebUIWasReused) { |
1112 set_should_create_webui(true); | 1109 set_should_create_webui(true); |
1113 | 1110 |
1114 // Navigate to a WebUI page. | 1111 // Navigate to a WebUI page. |
1115 const GURL kUrl1("chrome://foo"); | 1112 const GURL kUrl1("chrome://foo"); |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1550 TEST_F(RenderFrameHostManagerTest, EnableWebUIWithSwappedOutOpener) { | 1547 TEST_F(RenderFrameHostManagerTest, EnableWebUIWithSwappedOutOpener) { |
1551 set_should_create_webui(true); | 1548 set_should_create_webui(true); |
1552 const GURL kSettingsUrl("chrome://chrome/settings"); | 1549 const GURL kSettingsUrl("chrome://chrome/settings"); |
1553 const GURL kPluginUrl("chrome://plugins"); | 1550 const GURL kPluginUrl("chrome://plugins"); |
1554 | 1551 |
1555 // Navigate to an initial WebUI URL. | 1552 // Navigate to an initial WebUI URL. |
1556 contents()->NavigateAndCommit(kSettingsUrl); | 1553 contents()->NavigateAndCommit(kSettingsUrl); |
1557 | 1554 |
1558 // Ensure the RVH has WebUI bindings. | 1555 // Ensure the RVH has WebUI bindings. |
1559 TestRenderViewHost* rvh1 = test_rvh(); | 1556 TestRenderViewHost* rvh1 = test_rvh(); |
1560 EXPECT_TRUE(rvh1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1557 EXPECT_TRUE(rvh1->GetMainFrame()->GetEnabledBindings() & |
| 1558 BINDINGS_POLICY_WEB_UI); |
1561 | 1559 |
1562 // Create a new tab and simulate it being the opener for the main | 1560 // Create a new tab and simulate it being the opener for the main |
1563 // tab. It should be in the same SiteInstance. | 1561 // tab. It should be in the same SiteInstance. |
1564 std::unique_ptr<TestWebContents> opener1( | 1562 std::unique_ptr<TestWebContents> opener1( |
1565 TestWebContents::Create(browser_context(), rvh1->GetSiteInstance())); | 1563 TestWebContents::Create(browser_context(), rvh1->GetSiteInstance())); |
1566 RenderFrameHostManager* opener1_manager = | 1564 RenderFrameHostManager* opener1_manager = |
1567 opener1->GetRenderManagerForTesting(); | 1565 opener1->GetRenderManagerForTesting(); |
1568 contents()->SetOpener(opener1.get()); | 1566 contents()->SetOpener(opener1.get()); |
1569 | 1567 |
1570 // Navigate to a different WebUI URL (different SiteInstance, same | 1568 // Navigate to a different WebUI URL (different SiteInstance, same |
1571 // BrowsingInstance). | 1569 // BrowsingInstance). |
1572 contents()->NavigateAndCommit(kPluginUrl); | 1570 contents()->NavigateAndCommit(kPluginUrl); |
1573 TestRenderViewHost* rvh2 = test_rvh(); | 1571 TestRenderViewHost* rvh2 = test_rvh(); |
1574 EXPECT_NE(rvh1->GetSiteInstance(), rvh2->GetSiteInstance()); | 1572 EXPECT_NE(rvh1->GetSiteInstance(), rvh2->GetSiteInstance()); |
1575 EXPECT_TRUE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( | 1573 EXPECT_TRUE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( |
1576 rvh2->GetSiteInstance())); | 1574 rvh2->GetSiteInstance())); |
1577 | 1575 |
1578 // Ensure a proxy and swapped out RVH are created in the first opener tab. | 1576 // Ensure a proxy and swapped out RVH are created in the first opener tab. |
1579 EXPECT_TRUE( | 1577 EXPECT_TRUE( |
1580 opener1_manager->GetRenderFrameProxyHost(rvh2->GetSiteInstance())); | 1578 opener1_manager->GetRenderFrameProxyHost(rvh2->GetSiteInstance())); |
1581 TestRenderViewHost* opener1_rvh = static_cast<TestRenderViewHost*>( | 1579 TestRenderViewHost* opener1_rvh = static_cast<TestRenderViewHost*>( |
1582 opener1_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); | 1580 opener1_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); |
1583 EXPECT_FALSE(opener1_rvh->is_active()); | 1581 EXPECT_FALSE(opener1_rvh->is_active()); |
1584 | 1582 |
1585 // Ensure the new RVH has WebUI bindings. | 1583 // Ensure the new RVH has WebUI bindings. |
1586 EXPECT_TRUE(rvh2->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1584 EXPECT_TRUE(rvh2->GetMainFrame()->GetEnabledBindings() & |
| 1585 BINDINGS_POLICY_WEB_UI); |
1587 } | 1586 } |
1588 | 1587 |
1589 // Test that we reuse the same guest SiteInstance if we navigate across sites. | 1588 // Test that we reuse the same guest SiteInstance if we navigate across sites. |
1590 TEST_F(RenderFrameHostManagerTest, NoSwapOnGuestNavigations) { | 1589 TEST_F(RenderFrameHostManagerTest, NoSwapOnGuestNavigations) { |
1591 GURL guest_url(std::string(kGuestScheme).append("://abc123")); | 1590 GURL guest_url(std::string(kGuestScheme).append("://abc123")); |
1592 scoped_refptr<SiteInstance> instance = | 1591 scoped_refptr<SiteInstance> instance = |
1593 SiteInstance::CreateForURL(browser_context(), guest_url); | 1592 SiteInstance::CreateForURL(browser_context(), guest_url); |
1594 std::unique_ptr<TestWebContents> web_contents( | 1593 std::unique_ptr<TestWebContents> web_contents( |
1595 TestWebContents::Create(browser_context(), instance)); | 1594 TestWebContents::Create(browser_context(), instance)); |
1596 | 1595 |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2136 // Start a pending WebUI navigation in the main frame and verify that the | 2135 // Start a pending WebUI navigation in the main frame and verify that the |
2137 // pending RVH has bindings. | 2136 // pending RVH has bindings. |
2138 const GURL kWebUIUrl("chrome://foo"); | 2137 const GURL kWebUIUrl("chrome://foo"); |
2139 NavigationEntryImpl webui_entry( | 2138 NavigationEntryImpl webui_entry( |
2140 nullptr /* instance */, kWebUIUrl, Referrer(), | 2139 nullptr /* instance */, kWebUIUrl, Referrer(), |
2141 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, | 2140 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
2142 false /* is_renderer_init */); | 2141 false /* is_renderer_init */); |
2143 RenderFrameHostManager* main_rfhm = contents()->GetRenderManagerForTesting(); | 2142 RenderFrameHostManager* main_rfhm = contents()->GetRenderManagerForTesting(); |
2144 RenderFrameHostImpl* webui_rfh = NavigateToEntry(main_rfhm, webui_entry); | 2143 RenderFrameHostImpl* webui_rfh = NavigateToEntry(main_rfhm, webui_entry); |
2145 EXPECT_EQ(webui_rfh, GetPendingFrameHost(main_rfhm)); | 2144 EXPECT_EQ(webui_rfh, GetPendingFrameHost(main_rfhm)); |
2146 EXPECT_TRUE(webui_rfh->render_view_host()->GetEnabledBindings() & | 2145 EXPECT_TRUE(webui_rfh->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
2147 BINDINGS_POLICY_WEB_UI); | |
2148 | 2146 |
2149 // Before it commits, do a cross-process navigation in a subframe. This | 2147 // Before it commits, do a cross-process navigation in a subframe. This |
2150 // should not grant WebUI bindings to the subframe's RVH. | 2148 // should not grant WebUI bindings to the subframe's RVH. |
2151 const GURL kSubframeUrl("http://bar.com"); | 2149 const GURL kSubframeUrl("http://bar.com"); |
2152 NavigationEntryImpl subframe_entry( | 2150 NavigationEntryImpl subframe_entry( |
2153 nullptr /* instance */, kSubframeUrl, Referrer(), | 2151 nullptr /* instance */, kSubframeUrl, Referrer(), |
2154 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, | 2152 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
2155 false /* is_renderer_init */); | 2153 false /* is_renderer_init */); |
2156 RenderFrameHostImpl* bar_rfh = NavigateToEntry(subframe_rfhm, subframe_entry); | 2154 RenderFrameHostImpl* bar_rfh = NavigateToEntry(subframe_rfhm, subframe_entry); |
2157 EXPECT_FALSE(bar_rfh->render_view_host()->GetEnabledBindings() & | 2155 EXPECT_FALSE(bar_rfh->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
2158 BINDINGS_POLICY_WEB_UI); | |
2159 } | 2156 } |
2160 | 2157 |
2161 // Test that opener proxies are created properly with a cycle on the opener | 2158 // Test that opener proxies are created properly with a cycle on the opener |
2162 // chain. | 2159 // chain. |
2163 TEST_F(RenderFrameHostManagerTest, CreateOpenerProxiesWithCycleOnOpenerChain) { | 2160 TEST_F(RenderFrameHostManagerTest, CreateOpenerProxiesWithCycleOnOpenerChain) { |
2164 const GURL kUrl1("http://www.google.com/"); | 2161 const GURL kUrl1("http://www.google.com/"); |
2165 const GURL kUrl2("http://www.chromium.org/"); | 2162 const GURL kUrl2("http://www.chromium.org/"); |
2166 | 2163 |
2167 // Navigate to an initial URL. | 2164 // Navigate to an initial URL. |
2168 contents()->NavigateAndCommit(kUrl1); | 2165 contents()->NavigateAndCommit(kUrl1); |
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3149 ASSERT_FALSE(delete_observer.deleted()); | 3146 ASSERT_FALSE(delete_observer.deleted()); |
3150 EXPECT_FALSE(initial_rfh->is_active()); | 3147 EXPECT_FALSE(initial_rfh->is_active()); |
3151 | 3148 |
3152 // The initial RFH receives a DidStartProvisionalLoad IPC. It should not | 3149 // The initial RFH receives a DidStartProvisionalLoad IPC. It should not |
3153 // create a NavigationHandle. | 3150 // create a NavigationHandle. |
3154 initial_rfh->SimulateNavigationStart(kUrl3); | 3151 initial_rfh->SimulateNavigationStart(kUrl3); |
3155 EXPECT_FALSE(initial_rfh->navigation_handle()); | 3152 EXPECT_FALSE(initial_rfh->navigation_handle()); |
3156 } | 3153 } |
3157 | 3154 |
3158 } // namespace content | 3155 } // namespace content |
OLD | NEW |