| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
| 6 #include "content/browser/browser_thread_impl.h" | 6 #include "content/browser/browser_thread_impl.h" |
| 7 #include "content/browser/mock_content_browser_client.h" | 7 #include "content/browser/mock_content_browser_client.h" |
| 8 #include "content/browser/renderer_host/test_render_view_host.h" | 8 #include "content/browser/renderer_host/test_render_view_host.h" |
| 9 #include "content/browser/site_instance_impl.h" | 9 #include "content/browser/site_instance_impl.h" |
| 10 #include "content/browser/tab_contents/navigation_controller_impl.h" | 10 #include "content/browser/tab_contents/navigation_controller_impl.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 129 |
| 130 } // namespace | 130 } // namespace |
| 131 | 131 |
| 132 class RenderViewHostManagerTest | 132 class RenderViewHostManagerTest |
| 133 : public RenderViewHostImplTestHarness { | 133 : public RenderViewHostImplTestHarness { |
| 134 public: | 134 public: |
| 135 virtual void SetUp() OVERRIDE { | 135 virtual void SetUp() OVERRIDE { |
| 136 RenderViewHostImplTestHarness::SetUp(); | 136 RenderViewHostImplTestHarness::SetUp(); |
| 137 old_client_ = content::GetContentClient(); | 137 old_client_ = content::GetContentClient(); |
| 138 old_browser_client_ = content::GetContentClient()->browser(); | 138 old_browser_client_ = content::GetContentClient()->browser(); |
| 139 content::SetContentClient(&client_); | 139 old_user_agent_ = content::GetUserAgent(GURL()); |
| 140 content::Initialize(&client_, "RenderViewHostManagerTest"); |
| 140 content::GetContentClient()->set_browser(&browser_client_); | 141 content::GetContentClient()->set_browser(&browser_client_); |
| 141 url_util::AddStandardScheme(chrome::kChromeUIScheme); | 142 url_util::AddStandardScheme(chrome::kChromeUIScheme); |
| 142 } | 143 } |
| 143 | 144 |
| 144 virtual void TearDown() OVERRIDE { | 145 virtual void TearDown() OVERRIDE { |
| 145 RenderViewHostImplTestHarness::TearDown(); | 146 RenderViewHostImplTestHarness::TearDown(); |
| 146 content::GetContentClient()->set_browser(old_browser_client_); | 147 content::GetContentClient()->set_browser(old_browser_client_); |
| 147 content::SetContentClient(old_client_); | 148 content::Initialize(old_client_, old_user_agent_); |
| 148 } | 149 } |
| 149 | 150 |
| 150 void set_should_create_webui(bool should_create_webui) { | 151 void set_should_create_webui(bool should_create_webui) { |
| 151 browser_client_.set_should_create_webui(should_create_webui); | 152 browser_client_.set_should_create_webui(should_create_webui); |
| 152 } | 153 } |
| 153 | 154 |
| 154 void NavigateActiveAndCommit(const GURL& url) { | 155 void NavigateActiveAndCommit(const GURL& url) { |
| 155 // Note: we navigate the active RenderViewHost because previous navigations | 156 // Note: we navigate the active RenderViewHost because previous navigations |
| 156 // won't have committed yet, so NavigateAndCommit does the wrong thing | 157 // won't have committed yet, so NavigateAndCommit does the wrong thing |
| 157 // for us. | 158 // for us. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 179 const NavigationEntryImpl* cur_entry, | 180 const NavigationEntryImpl* cur_entry, |
| 180 const NavigationEntryImpl* new_entry) const { | 181 const NavigationEntryImpl* new_entry) const { |
| 181 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry); | 182 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry); |
| 182 } | 183 } |
| 183 | 184 |
| 184 private: | 185 private: |
| 185 RenderViewHostManagerTestClient client_; | 186 RenderViewHostManagerTestClient client_; |
| 186 RenderViewHostManagerTestBrowserClient browser_client_; | 187 RenderViewHostManagerTestBrowserClient browser_client_; |
| 187 content::ContentClient* old_client_; | 188 content::ContentClient* old_client_; |
| 188 content::ContentBrowserClient* old_browser_client_; | 189 content::ContentBrowserClient* old_browser_client_; |
| 190 std::string old_user_agent_; |
| 189 }; | 191 }; |
| 190 | 192 |
| 191 // Tests that when you navigate from the New TabPage to another page, and | 193 // Tests that when you navigate from the New TabPage to another page, and |
| 192 // then do that same thing in another tab, that the two resulting pages have | 194 // then do that same thing in another tab, that the two resulting pages have |
| 193 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is | 195 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is |
| 194 // a regression test for bug 9364. | 196 // a regression test for bug 9364. |
| 195 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { | 197 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { |
| 196 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); | 198 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); |
| 197 const GURL kNtpUrl(chrome::kTestNewTabURL); | 199 const GURL kNtpUrl(chrome::kTestNewTabURL); |
| 198 const GURL kDestUrl("http://www.google.com/"); | 200 const GURL kDestUrl("http://www.google.com/"); |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 | 765 |
| 764 // We should be able to navigate forward. | 766 // We should be able to navigate forward. |
| 765 contents()->GetController().GoForward(); | 767 contents()->GetController().GoForward(); |
| 766 contents()->ProceedWithCrossSiteNavigation(); | 768 contents()->ProceedWithCrossSiteNavigation(); |
| 767 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); | 769 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); |
| 768 rvh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); | 770 rvh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); |
| 769 EXPECT_EQ(rvh2, rvh()); | 771 EXPECT_EQ(rvh2, rvh()); |
| 770 EXPECT_FALSE(rvh2->is_swapped_out()); | 772 EXPECT_FALSE(rvh2->is_swapped_out()); |
| 771 EXPECT_TRUE(rvh1->is_swapped_out()); | 773 EXPECT_TRUE(rvh1->is_swapped_out()); |
| 772 } | 774 } |
| OLD | NEW |