| 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/browser/browser_url_handler.h" | 5 #include "chrome/browser/browser_url_handler.h" |
| 6 #include "chrome/common/render_messages.h" | 6 #include "chrome/common/render_messages.h" |
| 7 #include "chrome/common/url_constants.h" | 7 #include "chrome/common/url_constants.h" |
| 8 #include "chrome/test/test_notification_tracker.h" | 8 #include "chrome/test/test_notification_tracker.h" |
| 9 #include "chrome/test/testing_profile.h" | 9 #include "chrome/test/testing_profile.h" |
| 10 #include "content/browser/browser_thread.h" | 10 #include "content/browser/browser_thread.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "webkit/glue/webkit_glue.h" | 22 #include "webkit/glue/webkit_glue.h" |
| 23 | 23 |
| 24 class RenderViewHostManagerTest : public RenderViewHostTestHarness { | 24 class RenderViewHostManagerTest : public RenderViewHostTestHarness { |
| 25 public: | 25 public: |
| 26 void NavigateActiveAndCommit(const GURL& url) { | 26 void NavigateActiveAndCommit(const GURL& url) { |
| 27 // Note: we navigate the active RenderViewHost because previous navigations | 27 // Note: we navigate the active RenderViewHost because previous navigations |
| 28 // won't have committed yet, so NavigateAndCommit does the wrong thing | 28 // won't have committed yet, so NavigateAndCommit does the wrong thing |
| 29 // for us. | 29 // for us. |
| 30 controller().LoadURL(url, GURL(), PageTransition::LINK); | 30 controller().LoadURL(url, GURL(), PageTransition::LINK); |
| 31 TestRenderViewHost* old_rvh = rvh(); |
| 32 |
| 33 // Simulate the ShouldClose_ACK that is received from the current renderer |
| 34 // for a cross-site navigation. |
| 35 if (old_rvh != active_rvh()) |
| 36 old_rvh->SendShouldCloseACK(true); |
| 37 |
| 38 // Commit the navigation. |
| 31 active_rvh()->SendNavigate( | 39 active_rvh()->SendNavigate( |
| 32 static_cast<MockRenderProcessHost*>(active_rvh()->process())-> | 40 static_cast<MockRenderProcessHost*>(active_rvh()->process())-> |
| 33 max_page_id() + 1, | 41 max_page_id() + 1, |
| 34 url); | 42 url); |
| 43 |
| 44 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation |
| 45 // without making any network requests. |
| 46 if (old_rvh != active_rvh()) |
| 47 old_rvh->OnSwapOutACK(); |
| 35 } | 48 } |
| 36 | 49 |
| 37 bool ShouldSwapProcesses(RenderViewHostManager* manager, | 50 bool ShouldSwapProcesses(RenderViewHostManager* manager, |
| 38 const NavigationEntry* cur_entry, | 51 const NavigationEntry* cur_entry, |
| 39 const NavigationEntry* new_entry) const { | 52 const NavigationEntry* new_entry) const { |
| 40 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry); | 53 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry); |
| 41 } | 54 } |
| 42 }; | 55 }; |
| 43 | 56 |
| 44 // Tests that when you navigate from the New TabPage to another page, and | 57 // Tests that when you navigate from the New TabPage to another page, and |
| 45 // then do that same thing in another tab, that the two resulting pages have | 58 // then do that same thing in another tab, that the two resulting pages have |
| 46 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is | 59 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is |
| 47 // a regression test for bug 9364. | 60 // a regression test for bug 9364. |
| 48 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { | 61 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { |
| 49 BrowserThread ui_thread(BrowserThread::UI, MessageLoop::current()); | 62 BrowserThread ui_thread(BrowserThread::UI, MessageLoop::current()); |
| 50 GURL ntp(chrome::kChromeUINewTabURL); | 63 GURL ntp(chrome::kChromeUINewTabURL); |
| 51 GURL dest("http://www.google.com/"); | 64 GURL dest("http://www.google.com/"); |
| 52 | 65 |
| 53 // Navigate our first tab to the new tab page and then to the destination. | 66 // Navigate our first tab to the new tab page and then to the destination. |
| 54 NavigateActiveAndCommit(ntp); | 67 NavigateActiveAndCommit(ntp); |
| 55 NavigateActiveAndCommit(dest); | 68 NavigateActiveAndCommit(dest); |
| 56 | 69 |
| 57 // Make a second tab. | 70 // Make a second tab. |
| 58 TestTabContents contents2(profile_.get(), NULL); | 71 TestTabContents contents2(profile_.get(), NULL); |
| 59 | 72 |
| 60 // Load the two URLs in the second tab. Note that the first navigation creates | 73 // Load the two URLs in the second tab. Note that the first navigation creates |
| 61 // a RVH that's not pending (since there is no cross-site transition), so | 74 // a RVH that's not pending (since there is no cross-site transition), so |
| 62 // we use the committed one, but the second one is the opposite. | 75 // we use the committed one, but the second one is the opposite. |
| 63 contents2.controller().LoadURL(ntp, GURL(), PageTransition::LINK); | 76 contents2.controller().LoadURL(ntp, GURL(), PageTransition::LINK); |
| 64 static_cast<TestRenderViewHost*>(contents2.render_manager()-> | 77 TestRenderViewHost* ntp_rvh2 = static_cast<TestRenderViewHost*>( |
| 65 current_host())->SendNavigate(100, ntp); | 78 contents2.render_manager()->current_host()); |
| 79 ntp_rvh2->SendNavigate(100, ntp); |
| 66 contents2.controller().LoadURL(dest, GURL(), PageTransition::LINK); | 80 contents2.controller().LoadURL(dest, GURL(), PageTransition::LINK); |
| 67 static_cast<TestRenderViewHost*>(contents2.render_manager()-> | 81 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( |
| 68 pending_render_view_host())->SendNavigate(101, dest); | 82 contents2.render_manager()->pending_render_view_host()); |
| 83 dest_rvh2->SendNavigate(101, dest); |
| 84 ntp_rvh2->OnSwapOutACK(); |
| 69 | 85 |
| 70 // The two RVH's should be different in every way. | 86 // The two RVH's should be different in every way. |
| 71 EXPECT_NE(active_rvh()->process(), contents2.render_view_host()->process()); | 87 EXPECT_NE(active_rvh()->process(), dest_rvh2->process()); |
| 72 EXPECT_NE(active_rvh()->site_instance(), | 88 EXPECT_NE(active_rvh()->site_instance(), dest_rvh2->site_instance()); |
| 73 contents2.render_view_host()->site_instance()); | |
| 74 EXPECT_NE(active_rvh()->site_instance()->browsing_instance(), | 89 EXPECT_NE(active_rvh()->site_instance()->browsing_instance(), |
| 75 contents2.render_view_host()->site_instance()->browsing_instance()); | 90 dest_rvh2->site_instance()->browsing_instance()); |
| 76 | 91 |
| 77 // Navigate both to the new tab page, and verify that they share a | 92 // Navigate both to the new tab page, and verify that they share a |
| 78 // SiteInstance. | 93 // SiteInstance. |
| 79 NavigateActiveAndCommit(ntp); | 94 NavigateActiveAndCommit(ntp); |
| 80 | 95 |
| 81 contents2.controller().LoadURL(ntp, GURL(), PageTransition::LINK); | 96 contents2.controller().LoadURL(ntp, GURL(), PageTransition::LINK); |
| 97 dest_rvh2->SendShouldCloseACK(true); |
| 82 static_cast<TestRenderViewHost*>(contents2.render_manager()-> | 98 static_cast<TestRenderViewHost*>(contents2.render_manager()-> |
| 83 pending_render_view_host())->SendNavigate(102, ntp); | 99 pending_render_view_host())->SendNavigate(102, ntp); |
| 100 dest_rvh2->OnSwapOutACK(); |
| 84 | 101 |
| 85 EXPECT_EQ(active_rvh()->site_instance(), | 102 EXPECT_EQ(active_rvh()->site_instance(), |
| 86 contents2.render_view_host()->site_instance()); | 103 contents2.render_view_host()->site_instance()); |
| 87 } | 104 } |
| 88 | 105 |
| 89 // When there is an error with the specified page, renderer exits view-source | 106 // When there is an error with the specified page, renderer exits view-source |
| 90 // mode. See WebFrameImpl::DidFail(). We check by this test that | 107 // mode. See WebFrameImpl::DidFail(). We check by this test that |
| 91 // EnableViewSourceMode message is sent on every navigation regardless | 108 // EnableViewSourceMode message is sent on every navigation regardless |
| 92 // RenderView is being newly created or reused. | 109 // RenderView is being newly created or reused. |
| 93 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { | 110 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 // That should have cancelled the pending RVH, and the evil RVH should be the | 354 // That should have cancelled the pending RVH, and the evil RVH should be the |
| 338 // current one. | 355 // current one. |
| 339 EXPECT_TRUE(contents()->render_manager()->pending_render_view_host() == NULL); | 356 EXPECT_TRUE(contents()->render_manager()->pending_render_view_host() == NULL); |
| 340 EXPECT_EQ(evil_rvh, contents()->render_manager()->current_host()); | 357 EXPECT_EQ(evil_rvh, contents()->render_manager()->current_host()); |
| 341 | 358 |
| 342 // Also we should not have a pending navigation entry. | 359 // Also we should not have a pending navigation entry. |
| 343 NavigationEntry* entry = contents()->controller().GetActiveEntry(); | 360 NavigationEntry* entry = contents()->controller().GetActiveEntry(); |
| 344 ASSERT_TRUE(entry != NULL); | 361 ASSERT_TRUE(entry != NULL); |
| 345 EXPECT_EQ(url2, entry->url()); | 362 EXPECT_EQ(url2, entry->url()); |
| 346 } | 363 } |
| OLD | NEW |