| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/browser_url_handler.h" |
| 5 #include "chrome/browser/renderer_host/test/test_render_view_host.h" | 6 #include "chrome/browser/renderer_host/test/test_render_view_host.h" |
| 6 #include "chrome/browser/tab_contents/navigation_controller.h" | 7 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 7 #include "chrome/browser/tab_contents/navigation_entry.h" | 8 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 8 #include "chrome/browser/tab_contents/render_view_host_manager.h" | 9 #include "chrome/browser/tab_contents/render_view_host_manager.h" |
| 9 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
| 10 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
| 11 #include "chrome/test/test_notification_tracker.h" | 12 #include "chrome/test/test_notification_tracker.h" |
| 12 #include "ipc/ipc_message.h" | 13 #include "ipc/ipc_message.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 class RenderViewHostManagerTest : public RenderViewHostTestHarness { | 16 class RenderViewHostManagerTest : public RenderViewHostTestHarness { |
| 16 public: | 17 public: |
| 17 void NavigateActiveAndCommit(const GURL& url) { | 18 void NavigateActiveAndCommit(const GURL& url) { |
| 18 // Note: we navigate the active RenderViewHost because previous navigations | 19 // Note: we navigate the active RenderViewHost because previous navigations |
| 19 // won't have committed yet, so NavigateAndCommit does the wrong thing | 20 // won't have committed yet, so NavigateAndCommit does the wrong thing |
| 20 // for us. | 21 // for us. |
| 21 controller().LoadURL(url, GURL(), 0); | 22 controller().LoadURL(url, GURL(), 0); |
| 22 active_rvh()->SendNavigate( | 23 active_rvh()->SendNavigate( |
| 23 static_cast<MockRenderProcessHost*>(active_rvh()->process())-> | 24 static_cast<MockRenderProcessHost*>(active_rvh()->process())-> |
| 24 max_page_id() + 1, | 25 max_page_id() + 1, |
| 25 url); | 26 url); |
| 26 } | 27 } |
| 28 |
| 29 bool ShouldSwapProcesses(RenderViewHostManager* manager, |
| 30 const NavigationEntry* cur_entry, |
| 31 const NavigationEntry* new_entry) const { |
| 32 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry); |
| 33 } |
| 27 }; | 34 }; |
| 28 | 35 |
| 29 // Tests that when you navigate from the New TabPage to another page, and | 36 // Tests that when you navigate from the New TabPage to another page, and |
| 30 // then do that same thing in another tab, that the two resulting pages have | 37 // then do that same thing in another tab, that the two resulting pages have |
| 31 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is | 38 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is |
| 32 // a regression test for bug 9364. | 39 // a regression test for bug 9364. |
| 33 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { | 40 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { |
| 34 ChromeThread ui_thread(ChromeThread::UI, MessageLoop::current()); | 41 ChromeThread ui_thread(ChromeThread::UI, MessageLoop::current()); |
| 35 GURL ntp(chrome::kChromeUINewTabURL); | 42 GURL ntp(chrome::kChromeUINewTabURL); |
| 36 GURL dest("http://www.google.com/"); | 43 GURL dest("http://www.google.com/"); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 manager.Init(profile_.get(), instance, MSG_ROUTING_NONE); | 140 manager.Init(profile_.get(), instance, MSG_ROUTING_NONE); |
| 134 | 141 |
| 135 RenderViewHost* host = manager.current_host(); | 142 RenderViewHost* host = manager.current_host(); |
| 136 ASSERT_TRUE(host); | 143 ASSERT_TRUE(host); |
| 137 EXPECT_TRUE(instance == host->site_instance()); | 144 EXPECT_TRUE(instance == host->site_instance()); |
| 138 EXPECT_TRUE(&tab_contents == host->delegate()); | 145 EXPECT_TRUE(&tab_contents == host->delegate()); |
| 139 EXPECT_TRUE(manager.GetRenderWidgetHostView()); | 146 EXPECT_TRUE(manager.GetRenderWidgetHostView()); |
| 140 EXPECT_FALSE(manager.pending_render_view_host()); | 147 EXPECT_FALSE(manager.pending_render_view_host()); |
| 141 } | 148 } |
| 142 | 149 |
| 143 // Tests the Navigate function. We navigate three sites consequently and check | 150 // Tests the Navigate function. We navigate three sites consecutively and check |
| 144 // how the pending/committed RenderViewHost are modified. | 151 // how the pending/committed RenderViewHost are modified. |
| 145 TEST_F(RenderViewHostManagerTest, Navigate) { | 152 TEST_F(RenderViewHostManagerTest, Navigate) { |
| 146 TestNotificationTracker notifications; | 153 TestNotificationTracker notifications; |
| 147 | 154 |
| 148 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get()); | 155 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get()); |
| 149 | 156 |
| 150 TestTabContents tab_contents(profile_.get(), instance); | 157 TestTabContents tab_contents(profile_.get(), instance); |
| 151 notifications.ListenFor(NotificationType::RENDER_VIEW_HOST_CHANGED, | 158 notifications.ListenFor(NotificationType::RENDER_VIEW_HOST_CHANGED, |
| 152 Source<NavigationController>(&tab_contents.controller())); | 159 Source<NavigationController>(&tab_contents.controller())); |
| 153 | 160 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 // get loaded in between. | 255 // get loaded in between. |
| 249 EXPECT_TRUE(host->site_instance()->has_site()); | 256 EXPECT_TRUE(host->site_instance()->has_site()); |
| 250 EXPECT_EQ(url, host->site_instance()->site()); | 257 EXPECT_EQ(url, host->site_instance()->site()); |
| 251 | 258 |
| 252 // Commit. | 259 // Commit. |
| 253 manager.DidNavigateMainFrame(host); | 260 manager.DidNavigateMainFrame(host); |
| 254 | 261 |
| 255 EXPECT_FALSE(manager.pending_dom_ui()); | 262 EXPECT_FALSE(manager.pending_dom_ui()); |
| 256 EXPECT_TRUE(manager.dom_ui()); | 263 EXPECT_TRUE(manager.dom_ui()); |
| 257 } | 264 } |
| 265 |
| 266 // Tests that chrome: URLs that are not DOM UI pages do not get grouped into |
| 267 // DOM UI renderers, even if --process-per-tab is enabled. In that mode, we |
| 268 // still swap processes if ShouldSwapProcessesForNavigation is true. |
| 269 // Regression test for bug 46290. |
| 270 TEST_F(RenderViewHostManagerTest, NonDOMUIChromeURLs) { |
| 271 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get()); |
| 272 TestTabContents tab_contents(profile_.get(), instance); |
| 273 RenderViewHostManager manager(&tab_contents, &tab_contents); |
| 274 manager.Init(profile_.get(), instance, MSG_ROUTING_NONE); |
| 275 |
| 276 // NTP is a DOM UI page. |
| 277 GURL ntp_url(chrome::kChromeUINewTabURL); |
| 278 NavigationEntry ntp_entry(NULL /* instance */, -1 /* page_id */, ntp_url, |
| 279 GURL() /* referrer */, string16() /* title */, |
| 280 PageTransition::TYPED); |
| 281 |
| 282 // about: URLs are not DOM UI pages. |
| 283 GURL about_url(chrome::kAboutMemoryURL); |
| 284 // Rewrite so it looks like chrome://about/memory |
| 285 bool reverse_on_redirect = false; |
| 286 BrowserURLHandler::RewriteURLIfNecessary( |
| 287 &about_url, profile_.get(), &reverse_on_redirect); |
| 288 NavigationEntry about_entry(NULL /* instance */, -1 /* page_id */, about_url, |
| 289 GURL() /* referrer */, string16() /* title */, |
| 290 PageTransition::TYPED); |
| 291 |
| 292 EXPECT_TRUE(ShouldSwapProcesses(&manager, &ntp_entry, &about_entry)); |
| 293 } |
| OLD | NEW |