| 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/compositor/test/no_transport_image_transport_factory.h
" | 10 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
| (...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 TEST_F(RenderFrameHostManagerTest, WebUI) { | 1090 TEST_F(RenderFrameHostManagerTest, WebUI) { |
| 1091 set_should_create_webui(true); | 1091 set_should_create_webui(true); |
| 1092 SiteInstance* instance = SiteInstance::Create(browser_context()); | 1092 SiteInstance* instance = SiteInstance::Create(browser_context()); |
| 1093 | 1093 |
| 1094 scoped_ptr<TestWebContents> web_contents( | 1094 scoped_ptr<TestWebContents> web_contents( |
| 1095 TestWebContents::Create(browser_context(), instance)); | 1095 TestWebContents::Create(browser_context(), instance)); |
| 1096 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 1096 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
| 1097 RenderFrameHostImpl* initial_rfh = manager->current_frame_host(); | 1097 RenderFrameHostImpl* initial_rfh = manager->current_frame_host(); |
| 1098 | 1098 |
| 1099 EXPECT_FALSE(manager->current_host()->IsRenderViewLive()); | 1099 EXPECT_FALSE(manager->current_host()->IsRenderViewLive()); |
| 1100 EXPECT_FALSE(manager->web_ui()); | 1100 EXPECT_FALSE(manager->current_frame_host()->web_ui()); |
| 1101 EXPECT_TRUE(initial_rfh); | 1101 EXPECT_TRUE(initial_rfh); |
| 1102 | 1102 |
| 1103 const GURL kUrl("chrome://foo"); | 1103 const GURL kUrl("chrome://foo"); |
| 1104 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | 1104 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, |
| 1105 Referrer(), base::string16() /* title */, | 1105 Referrer(), base::string16() /* title */, |
| 1106 ui::PAGE_TRANSITION_TYPED, | 1106 ui::PAGE_TRANSITION_TYPED, |
| 1107 false /* is_renderer_init */); | 1107 false /* is_renderer_init */); |
| 1108 RenderFrameHostImpl* host = NavigateToEntry(manager, entry); | 1108 RenderFrameHostImpl* host = NavigateToEntry(manager, entry); |
| 1109 | 1109 |
| 1110 // We commit the pending RenderFrameHost immediately because the previous | 1110 // We commit the pending RenderFrameHost immediately because the previous |
| 1111 // RenderFrameHost was not live. We test a case where it is live in | 1111 // RenderFrameHost was not live. We test a case where it is live in |
| 1112 // WebUIInNewTab. | 1112 // WebUIInNewTab. |
| 1113 EXPECT_TRUE(host); | 1113 EXPECT_TRUE(host); |
| 1114 EXPECT_NE(initial_rfh, host); | 1114 EXPECT_NE(initial_rfh, host); |
| 1115 EXPECT_EQ(host, manager->current_frame_host()); | 1115 EXPECT_EQ(host, manager->current_frame_host()); |
| 1116 EXPECT_FALSE(GetPendingFrameHost(manager)); | 1116 EXPECT_FALSE(GetPendingFrameHost(manager)); |
| 1117 | 1117 |
| 1118 // It's important that the SiteInstance get set on the Web UI page as soon | 1118 // It's important that the SiteInstance get set on the Web UI page as soon |
| 1119 // as the navigation starts, rather than lazily after it commits, so we don't | 1119 // as the navigation starts, rather than lazily after it commits, so we don't |
| 1120 // try to re-use the SiteInstance/process for non Web UI things that may | 1120 // try to re-use the SiteInstance/process for non Web UI things that may |
| 1121 // get loaded in between. | 1121 // get loaded in between. |
| 1122 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); | 1122 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
| 1123 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL()); | 1123 EXPECT_EQ(kUrl, host->GetSiteInstance()->GetSiteURL()); |
| 1124 | 1124 |
| 1125 // The Web UI is committed immediately because the RenderViewHost has not been | 1125 // The Web UI is committed immediately because the RenderViewHost has not been |
| 1126 // used yet. UpdateStateForNavigate() took the short cut path. | 1126 // used yet. UpdateStateForNavigate() took the short cut path. |
| 1127 EXPECT_FALSE(manager->GetNavigatingWebUI()); | 1127 EXPECT_TRUE(manager->current_frame_host()->web_ui()); |
| 1128 EXPECT_TRUE(manager->web_ui()); | |
| 1129 | 1128 |
| 1130 // Commit. | 1129 // Commit. |
| 1131 manager->DidNavigateFrame(host, true); | 1130 manager->DidNavigateFrame(host, true); |
| 1132 EXPECT_TRUE( | 1131 EXPECT_TRUE( |
| 1133 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1132 host->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
| 1134 } | 1133 } |
| 1135 | 1134 |
| 1136 // Tests that we can open a WebUI link in a new tab from a WebUI page and still | 1135 // Tests that we can open a WebUI link in a new tab from a WebUI page and still |
| 1137 // grant the correct bindings. http://crbug.com/189101. | 1136 // grant the correct bindings. http://crbug.com/189101. |
| 1138 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) { | 1137 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 const GURL kUrl2("chrome://foo/bar"); | 1186 const GURL kUrl2("chrome://foo/bar"); |
| 1188 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, | 1187 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, |
| 1189 Referrer(), base::string16() /* title */, | 1188 Referrer(), base::string16() /* title */, |
| 1190 ui::PAGE_TRANSITION_LINK, | 1189 ui::PAGE_TRANSITION_LINK, |
| 1191 true /* is_renderer_init */); | 1190 true /* is_renderer_init */); |
| 1192 RenderFrameHostImpl* host2 = NavigateToEntry(manager2, entry2); | 1191 RenderFrameHostImpl* host2 = NavigateToEntry(manager2, entry2); |
| 1193 | 1192 |
| 1194 // No cross-process transition happens because we are already in the right | 1193 // No cross-process transition happens because we are already in the right |
| 1195 // SiteInstance. We should grant bindings immediately. | 1194 // SiteInstance. We should grant bindings immediately. |
| 1196 EXPECT_EQ(host2, manager2->current_frame_host()); | 1195 EXPECT_EQ(host2, manager2->current_frame_host()); |
| 1197 EXPECT_TRUE(manager2->GetNavigatingWebUI()); | 1196 EXPECT_TRUE(host2->web_ui()); |
| 1198 EXPECT_TRUE( | 1197 EXPECT_TRUE( |
| 1199 host2->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1198 host2->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
| 1200 | 1199 |
| 1201 manager2->DidNavigateFrame(host2, true); | 1200 manager2->DidNavigateFrame(host2, true); |
| 1202 } | 1201 } |
| 1203 | 1202 |
| 1204 // Tests that a WebUI is correctly reused between chrome:// pages. | 1203 // Tests that a WebUI is correctly reused between chrome:// pages. |
| 1205 TEST_F(RenderFrameHostManagerTest, WebUIWasReused) { | 1204 TEST_F(RenderFrameHostManagerTest, WebUIWasReused) { |
| 1206 set_should_create_webui(true); | 1205 set_should_create_webui(true); |
| 1207 | 1206 |
| 1208 // Navigate to a WebUI page. | 1207 // Navigate to a WebUI page. |
| 1209 const GURL kUrl1("chrome://foo"); | 1208 const GURL kUrl1("chrome://foo"); |
| 1210 contents()->NavigateAndCommit(kUrl1); | 1209 contents()->NavigateAndCommit(kUrl1); |
| 1211 RenderFrameHostManager* manager = | 1210 WebUIImpl* web_ui = main_test_rfh()->web_ui(); |
| 1212 main_test_rfh()->frame_tree_node()->render_manager(); | |
| 1213 WebUIImpl* web_ui = manager->web_ui(); | |
| 1214 EXPECT_TRUE(web_ui); | 1211 EXPECT_TRUE(web_ui); |
| 1215 | 1212 |
| 1216 // Navigate to another WebUI page which should be same-site and keep the | 1213 // Navigate to another WebUI page which should be same-site and keep the |
| 1217 // current WebUI. | 1214 // current WebUI. |
| 1218 const GURL kUrl2("chrome://foo/bar"); | 1215 const GURL kUrl2("chrome://foo/bar"); |
| 1219 contents()->NavigateAndCommit(kUrl2); | 1216 contents()->NavigateAndCommit(kUrl2); |
| 1220 EXPECT_EQ(web_ui, manager->web_ui()); | 1217 EXPECT_EQ(web_ui, main_test_rfh()->web_ui()); |
| 1221 } | 1218 } |
| 1222 | 1219 |
| 1223 // Tests that a WebUI is correctly cleaned up when navigating from a chrome:// | 1220 // Tests that a WebUI is correctly cleaned up when navigating from a chrome:// |
| 1224 // page to a non-chrome:// page. | 1221 // page to a non-chrome:// page. |
| 1225 TEST_F(RenderFrameHostManagerTest, WebUIWasCleared) { | 1222 TEST_F(RenderFrameHostManagerTest, WebUIWasCleared) { |
| 1226 set_should_create_webui(true); | 1223 set_should_create_webui(true); |
| 1227 | 1224 |
| 1228 // Navigate to a WebUI page. | 1225 // Navigate to a WebUI page. |
| 1229 const GURL kUrl1("chrome://foo"); | 1226 const GURL kUrl1("chrome://foo"); |
| 1230 contents()->NavigateAndCommit(kUrl1); | 1227 contents()->NavigateAndCommit(kUrl1); |
| 1231 EXPECT_TRUE(main_test_rfh()->frame_tree_node()->render_manager()->web_ui()); | 1228 EXPECT_TRUE(main_test_rfh()->web_ui()); |
| 1232 | 1229 |
| 1233 // Navigate to a non-WebUI page. | 1230 // Navigate to a non-WebUI page. |
| 1234 const GURL kUrl2("http://www.google.com"); | 1231 const GURL kUrl2("http://www.google.com"); |
| 1235 contents()->NavigateAndCommit(kUrl2); | 1232 contents()->NavigateAndCommit(kUrl2); |
| 1236 EXPECT_FALSE(main_test_rfh()->frame_tree_node()->render_manager()->web_ui()); | 1233 EXPECT_FALSE(main_test_rfh()->web_ui()); |
| 1237 } | 1234 } |
| 1238 | 1235 |
| 1239 // Tests that we don't end up in an inconsistent state if a page does a back and | 1236 // Tests that we don't end up in an inconsistent state if a page does a back and |
| 1240 // then reload. http://crbug.com/51680 | 1237 // then reload. http://crbug.com/51680 |
| 1241 // Also tests that only user-gesture navigations can interrupt cross-process | 1238 // Also tests that only user-gesture navigations can interrupt cross-process |
| 1242 // navigations. http://crbug.com/75195 | 1239 // navigations. http://crbug.com/75195 |
| 1243 TEST_F(RenderFrameHostManagerTest, PageDoesBackAndReload) { | 1240 TEST_F(RenderFrameHostManagerTest, PageDoesBackAndReload) { |
| 1244 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1241 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1245 switches::kEnableBrowserSideNavigation)) { | 1242 switches::kEnableBrowserSideNavigation)) { |
| 1246 // PlzNavigate uses a significantly different logic for renderer initiated | 1243 // PlzNavigate uses a significantly different logic for renderer initiated |
| (...skipping 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2654 root->render_manager()->GetRenderFrameProxyHost(hostC->GetSiteInstance()); | 2651 root->render_manager()->GetRenderFrameProxyHost(hostC->GetSiteInstance()); |
| 2655 EXPECT_TRUE(proxy); | 2652 EXPECT_TRUE(proxy); |
| 2656 | 2653 |
| 2657 // Since the B->C navigation happened while the current page was focused, | 2654 // Since the B->C navigation happened while the current page was focused, |
| 2658 // page focus should propagate to the new subframe process. Check that | 2655 // page focus should propagate to the new subframe process. Check that |
| 2659 // process C received the proper focus message. | 2656 // process C received the proper focus message. |
| 2660 VerifyPageFocusMessage(hostC->GetProcess(), true, proxy->GetRoutingID()); | 2657 VerifyPageFocusMessage(hostC->GetProcess(), true, proxy->GetRoutingID()); |
| 2661 } | 2658 } |
| 2662 | 2659 |
| 2663 } // namespace content | 2660 } // namespace content |
| OLD | NEW |