| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/test/base/chrome_render_view_host_test_harness.h" | 5 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 6 #include "chrome/test/base/testing_profile.h" | 6 #include "chrome/test/base/testing_profile.h" |
| 7 #include "content/browser/browser_thread_impl.h" |
| 7 #include "content/browser/browser_url_handler.h" | 8 #include "content/browser/browser_url_handler.h" |
| 8 #include "content/browser/site_instance.h" | 9 #include "content/browser/site_instance.h" |
| 9 #include "content/browser/tab_contents/navigation_controller.h" | 10 #include "content/browser/tab_contents/navigation_controller.h" |
| 10 #include "content/browser/tab_contents/navigation_entry.h" | 11 #include "content/browser/tab_contents/navigation_entry.h" |
| 11 #include "content/browser/tab_contents/render_view_host_manager.h" | 12 #include "content/browser/tab_contents/render_view_host_manager.h" |
| 12 #include "content/browser/tab_contents/test_tab_contents.h" | 13 #include "content/browser/tab_contents/test_tab_contents.h" |
| 13 #include "content/common/test_url_constants.h" | 14 #include "content/common/test_url_constants.h" |
| 14 #include "content/common/view_messages.h" | 15 #include "content/common/view_messages.h" |
| 15 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
| 16 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
| 17 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
| 18 #include "content/public/common/page_transition_types.h" | 19 #include "content/public/common/page_transition_types.h" |
| 19 #include "content/test/test_browser_thread.h" | |
| 20 #include "content/test/test_browser_thread.h" | |
| 21 #include "content/test/test_notification_tracker.h" | 20 #include "content/test/test_notification_tracker.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "webkit/glue/webkit_glue.h" | 22 #include "webkit/glue/webkit_glue.h" |
| 24 | 23 |
| 24 using content::BrowserThreadImpl; |
| 25 |
| 25 class RenderViewHostManagerTest : public ChromeRenderViewHostTestHarness { | 26 class RenderViewHostManagerTest : public ChromeRenderViewHostTestHarness { |
| 26 public: | 27 public: |
| 27 void NavigateActiveAndCommit(const GURL& url) { | 28 void NavigateActiveAndCommit(const GURL& url) { |
| 28 // Note: we navigate the active RenderViewHost because previous navigations | 29 // Note: we navigate the active RenderViewHost because previous navigations |
| 29 // won't have committed yet, so NavigateAndCommit does the wrong thing | 30 // won't have committed yet, so NavigateAndCommit does the wrong thing |
| 30 // for us. | 31 // for us. |
| 31 controller().LoadURL( | 32 controller().LoadURL( |
| 32 url, GURL(), content::PAGE_TRANSITION_LINK, std::string()); | 33 url, GURL(), content::PAGE_TRANSITION_LINK, std::string()); |
| 33 TestRenderViewHost* old_rvh = rvh(); | 34 TestRenderViewHost* old_rvh = rvh(); |
| 34 | 35 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 54 const NavigationEntry* new_entry) const { | 55 const NavigationEntry* new_entry) const { |
| 55 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry); | 56 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry); |
| 56 } | 57 } |
| 57 }; | 58 }; |
| 58 | 59 |
| 59 // Tests that when you navigate from the New TabPage to another page, and | 60 // Tests that when you navigate from the New TabPage to another page, and |
| 60 // then do that same thing in another tab, that the two resulting pages have | 61 // then do that same thing in another tab, that the two resulting pages have |
| 61 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is | 62 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is |
| 62 // a regression test for bug 9364. | 63 // a regression test for bug 9364. |
| 63 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { | 64 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { |
| 64 content::TestBrowserThread ui_thread(BrowserThread::UI, | 65 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); |
| 65 MessageLoop::current()); | |
| 66 const GURL kNtpUrl(chrome::kTestNewTabURL); | 66 const GURL kNtpUrl(chrome::kTestNewTabURL); |
| 67 const GURL kDestUrl("http://www.google.com/"); | 67 const GURL kDestUrl("http://www.google.com/"); |
| 68 | 68 |
| 69 // Navigate our first tab to the new tab page and then to the destination. | 69 // Navigate our first tab to the new tab page and then to the destination. |
| 70 NavigateActiveAndCommit(kNtpUrl); | 70 NavigateActiveAndCommit(kNtpUrl); |
| 71 NavigateActiveAndCommit(kDestUrl); | 71 NavigateActiveAndCommit(kDestUrl); |
| 72 | 72 |
| 73 // Make a second tab. | 73 // Make a second tab. |
| 74 TestTabContents contents2(profile(), NULL); | 74 TestTabContents contents2(profile(), NULL); |
| 75 | 75 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 114 |
| 115 EXPECT_EQ(active_rvh()->site_instance(), | 115 EXPECT_EQ(active_rvh()->site_instance(), |
| 116 contents2.render_view_host()->site_instance()); | 116 contents2.render_view_host()->site_instance()); |
| 117 } | 117 } |
| 118 | 118 |
| 119 // When there is an error with the specified page, renderer exits view-source | 119 // When there is an error with the specified page, renderer exits view-source |
| 120 // mode. See WebFrameImpl::DidFail(). We check by this test that | 120 // mode. See WebFrameImpl::DidFail(). We check by this test that |
| 121 // EnableViewSourceMode message is sent on every navigation regardless | 121 // EnableViewSourceMode message is sent on every navigation regardless |
| 122 // RenderView is being newly created or reused. | 122 // RenderView is being newly created or reused. |
| 123 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { | 123 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { |
| 124 content::TestBrowserThread ui_thread(BrowserThread::UI, | 124 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); |
| 125 MessageLoop::current()); | |
| 126 const GURL kNtpUrl(chrome::kTestNewTabURL); | 125 const GURL kNtpUrl(chrome::kTestNewTabURL); |
| 127 const GURL kUrl("view-source:http://foo"); | 126 const GURL kUrl("view-source:http://foo"); |
| 128 | 127 |
| 129 // We have to navigate to some page at first since without this, the first | 128 // We have to navigate to some page at first since without this, the first |
| 130 // navigation will reuse the SiteInstance created by Init(), and the second | 129 // navigation will reuse the SiteInstance created by Init(), and the second |
| 131 // one will create a new SiteInstance. Because current_instance and | 130 // one will create a new SiteInstance. Because current_instance and |
| 132 // new_instance will be different, a new RenderViewHost will be created for | 131 // new_instance will be different, a new RenderViewHost will be created for |
| 133 // the second navigation. We have to avoid this in order to exercise the | 132 // the second navigation. We have to avoid this in order to exercise the |
| 134 // target code patch. | 133 // target code patch. |
| 135 NavigateActiveAndCommit(kNtpUrl); | 134 NavigateActiveAndCommit(kNtpUrl); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // Check the pending RenderViewHost has been committed. | 266 // Check the pending RenderViewHost has been committed. |
| 268 EXPECT_FALSE(manager.pending_render_view_host()); | 267 EXPECT_FALSE(manager.pending_render_view_host()); |
| 269 | 268 |
| 270 // We should observe a notification. | 269 // We should observe a notification. |
| 271 EXPECT_TRUE(notifications.Check1AndReset( | 270 EXPECT_TRUE(notifications.Check1AndReset( |
| 272 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | 271 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); |
| 273 } | 272 } |
| 274 | 273 |
| 275 // Tests WebUI creation. | 274 // Tests WebUI creation. |
| 276 TEST_F(RenderViewHostManagerTest, WebUI) { | 275 TEST_F(RenderViewHostManagerTest, WebUI) { |
| 277 content::TestBrowserThread ui_thread(BrowserThread::UI, | 276 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); |
| 278 MessageLoop::current()); | |
| 279 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile()); | 277 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile()); |
| 280 | 278 |
| 281 TestTabContents tab_contents(profile(), instance); | 279 TestTabContents tab_contents(profile(), instance); |
| 282 RenderViewHostManager manager(&tab_contents, &tab_contents); | 280 RenderViewHostManager manager(&tab_contents, &tab_contents); |
| 283 | 281 |
| 284 manager.Init(profile(), instance, MSG_ROUTING_NONE); | 282 manager.Init(profile(), instance, MSG_ROUTING_NONE); |
| 285 | 283 |
| 286 const GURL kUrl(chrome::kTestNewTabURL); | 284 const GURL kUrl(chrome::kTestNewTabURL); |
| 287 NavigationEntry entry(NULL /* instance */, -1 /* page_id */, kUrl, | 285 NavigationEntry entry(NULL /* instance */, -1 /* page_id */, kUrl, |
| 288 GURL() /* referrer */, string16() /* title */, | 286 GURL() /* referrer */, string16() /* title */, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 308 | 306 |
| 309 // Commit. | 307 // Commit. |
| 310 manager.DidNavigateMainFrame(host); | 308 manager.DidNavigateMainFrame(host); |
| 311 } | 309 } |
| 312 | 310 |
| 313 // Tests that chrome: URLs that are not Web UI pages do not get grouped into | 311 // Tests that chrome: URLs that are not Web UI pages do not get grouped into |
| 314 // Web UI renderers, even if --process-per-tab is enabled. In that mode, we | 312 // Web UI renderers, even if --process-per-tab is enabled. In that mode, we |
| 315 // still swap processes if ShouldSwapProcessesForNavigation is true. | 313 // still swap processes if ShouldSwapProcessesForNavigation is true. |
| 316 // Regression test for bug 46290. | 314 // Regression test for bug 46290. |
| 317 TEST_F(RenderViewHostManagerTest, NonWebUIChromeURLs) { | 315 TEST_F(RenderViewHostManagerTest, NonWebUIChromeURLs) { |
| 318 content::TestBrowserThread thread(BrowserThread::UI, &message_loop_); | 316 BrowserThreadImpl thread(BrowserThread::UI, &message_loop_); |
| 319 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile()); | 317 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile()); |
| 320 TestTabContents tab_contents(profile(), instance); | 318 TestTabContents tab_contents(profile(), instance); |
| 321 RenderViewHostManager manager(&tab_contents, &tab_contents); | 319 RenderViewHostManager manager(&tab_contents, &tab_contents); |
| 322 manager.Init(profile(), instance, MSG_ROUTING_NONE); | 320 manager.Init(profile(), instance, MSG_ROUTING_NONE); |
| 323 | 321 |
| 324 // NTP is a Web UI page. | 322 // NTP is a Web UI page. |
| 325 const GURL kNtpUrl(chrome::kTestNewTabURL); | 323 const GURL kNtpUrl(chrome::kTestNewTabURL); |
| 326 NavigationEntry ntp_entry(NULL /* instance */, -1 /* page_id */, kNtpUrl, | 324 NavigationEntry ntp_entry(NULL /* instance */, -1 /* page_id */, kNtpUrl, |
| 327 GURL() /* referrer */, string16() /* title */, | 325 GURL() /* referrer */, string16() /* title */, |
| 328 content::PAGE_TRANSITION_TYPED, | 326 content::PAGE_TRANSITION_TYPED, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 // current one. | 378 // current one. |
| 381 EXPECT_TRUE(contents()->render_manager_for_testing()-> | 379 EXPECT_TRUE(contents()->render_manager_for_testing()-> |
| 382 pending_render_view_host() == NULL); | 380 pending_render_view_host() == NULL); |
| 383 EXPECT_EQ(evil_rvh, contents()->render_manager_for_testing()->current_host()); | 381 EXPECT_EQ(evil_rvh, contents()->render_manager_for_testing()->current_host()); |
| 384 | 382 |
| 385 // Also we should not have a pending navigation entry. | 383 // Also we should not have a pending navigation entry. |
| 386 NavigationEntry* entry = contents()->controller().GetActiveEntry(); | 384 NavigationEntry* entry = contents()->controller().GetActiveEntry(); |
| 387 ASSERT_TRUE(entry != NULL); | 385 ASSERT_TRUE(entry != NULL); |
| 388 EXPECT_EQ(kUrl2, entry->url()); | 386 EXPECT_EQ(kUrl2, entry->url()); |
| 389 } | 387 } |
| OLD | NEW |