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/renderer_host/test_render_view_host.h" | 7 #include "content/browser/renderer_host/test_render_view_host.h" |
8 #include "content/browser/site_instance_impl.h" | 8 #include "content/browser/site_instance_impl.h" |
9 #include "content/browser/web_contents/navigation_controller_impl.h" | 9 #include "content/browser/web_contents/navigation_controller_impl.h" |
10 #include "content/browser/web_contents/navigation_entry_impl.h" | 10 #include "content/browser/web_contents/navigation_entry_impl.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 content::ContentClient* old_client_; | 190 content::ContentClient* old_client_; |
191 content::ContentBrowserClient* old_browser_client_; | 191 content::ContentBrowserClient* old_browser_client_; |
192 }; | 192 }; |
193 | 193 |
194 // Tests that when you navigate from the New TabPage to another page, and | 194 // Tests that when you navigate from the New TabPage to another page, and |
195 // then do that same thing in another tab, that the two resulting pages have | 195 // then do that same thing in another tab, that the two resulting pages have |
196 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is | 196 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is |
197 // a regression test for bug 9364. | 197 // a regression test for bug 9364. |
198 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { | 198 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { |
199 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); | 199 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); |
200 const GURL kNtpUrl(chrome::kTestNewTabURL); | 200 const GURL kNtpUrl(content::kTestNewTabURL); |
201 const GURL kDestUrl("http://www.google.com/"); | 201 const GURL kDestUrl("http://www.google.com/"); |
202 | 202 |
203 // Navigate our first tab to the new tab page and then to the destination. | 203 // Navigate our first tab to the new tab page and then to the destination. |
204 NavigateActiveAndCommit(kNtpUrl); | 204 NavigateActiveAndCommit(kNtpUrl); |
205 NavigateActiveAndCommit(kDestUrl); | 205 NavigateActiveAndCommit(kDestUrl); |
206 | 206 |
207 // Make a second tab. | 207 // Make a second tab. |
208 TestWebContents contents2(browser_context(), NULL); | 208 TestWebContents contents2(browser_context(), NULL); |
209 | 209 |
210 // Load the two URLs in the second tab. Note that the first navigation creates | 210 // Load the two URLs in the second tab. Note that the first navigation creates |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 contents2.GetRenderViewHost()->GetSiteInstance()->GetProcess()); | 255 contents2.GetRenderViewHost()->GetSiteInstance()->GetProcess()); |
256 } | 256 } |
257 | 257 |
258 // Ensure that the browser ignores most IPC messages that arrive from a | 258 // Ensure that the browser ignores most IPC messages that arrive from a |
259 // RenderViewHost that has been swapped out. We do not want to take | 259 // RenderViewHost that has been swapped out. We do not want to take |
260 // action on requests from a non-active renderer. The main exception is | 260 // action on requests from a non-active renderer. The main exception is |
261 // for synchronous messages, which cannot be ignored without leaving the | 261 // for synchronous messages, which cannot be ignored without leaving the |
262 // renderer in a stuck state. See http://crbug.com/93427. | 262 // renderer in a stuck state. See http://crbug.com/93427. |
263 TEST_F(RenderViewHostManagerTest, FilterMessagesWhileSwappedOut) { | 263 TEST_F(RenderViewHostManagerTest, FilterMessagesWhileSwappedOut) { |
264 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); | 264 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); |
265 const GURL kNtpUrl(chrome::kTestNewTabURL); | 265 const GURL kNtpUrl(content::kTestNewTabURL); |
266 const GURL kDestUrl("http://www.google.com/"); | 266 const GURL kDestUrl("http://www.google.com/"); |
267 | 267 |
268 // Navigate our first tab to the new tab page and then to the destination. | 268 // Navigate our first tab to the new tab page and then to the destination. |
269 NavigateActiveAndCommit(kNtpUrl); | 269 NavigateActiveAndCommit(kNtpUrl); |
270 TestRenderViewHost* ntp_rvh = static_cast<TestRenderViewHost*>( | 270 TestRenderViewHost* ntp_rvh = static_cast<TestRenderViewHost*>( |
271 contents()->GetRenderManagerForTesting()->current_host()); | 271 contents()->GetRenderManagerForTesting()->current_host()); |
272 | 272 |
273 // Send an update title message and make sure it works. | 273 // Send an update title message and make sure it works. |
274 const string16 ntp_title = ASCIIToUTF16("NTP Title"); | 274 const string16 ntp_title = ASCIIToUTF16("NTP Title"); |
275 WebKit::WebTextDirection direction = WebKit::WebTextDirectionLeftToRight; | 275 WebKit::WebTextDirection direction = WebKit::WebTextDirectionLeftToRight; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 EXPECT_TRUE(ntp_rvh->OnMessageReceived(js_msg)); | 333 EXPECT_TRUE(ntp_rvh->OnMessageReceived(js_msg)); |
334 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID)); | 334 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID)); |
335 } | 335 } |
336 | 336 |
337 // When there is an error with the specified page, renderer exits view-source | 337 // When there is an error with the specified page, renderer exits view-source |
338 // mode. See WebFrameImpl::DidFail(). We check by this test that | 338 // mode. See WebFrameImpl::DidFail(). We check by this test that |
339 // EnableViewSourceMode message is sent on every navigation regardless | 339 // EnableViewSourceMode message is sent on every navigation regardless |
340 // RenderView is being newly created or reused. | 340 // RenderView is being newly created or reused. |
341 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { | 341 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { |
342 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); | 342 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); |
343 const GURL kNtpUrl(chrome::kTestNewTabURL); | 343 const GURL kNtpUrl(content::kTestNewTabURL); |
344 const GURL kUrl("view-source:http://foo"); | 344 const GURL kUrl("view-source:http://foo"); |
345 | 345 |
346 // We have to navigate to some page at first since without this, the first | 346 // We have to navigate to some page at first since without this, the first |
347 // navigation will reuse the SiteInstance created by Init(), and the second | 347 // navigation will reuse the SiteInstance created by Init(), and the second |
348 // one will create a new SiteInstance. Because current_instance and | 348 // one will create a new SiteInstance. Because current_instance and |
349 // new_instance will be different, a new RenderViewHost will be created for | 349 // new_instance will be different, a new RenderViewHost will be created for |
350 // the second navigation. We have to avoid this in order to exercise the | 350 // the second navigation. We have to avoid this in order to exercise the |
351 // target code patch. | 351 // target code patch. |
352 NavigateActiveAndCommit(kNtpUrl); | 352 NavigateActiveAndCommit(kNtpUrl); |
353 | 353 |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 TEST_F(RenderViewHostManagerTest, WebUI) { | 654 TEST_F(RenderViewHostManagerTest, WebUI) { |
655 set_should_create_webui(true); | 655 set_should_create_webui(true); |
656 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); | 656 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); |
657 SiteInstance* instance = SiteInstance::Create(browser_context()); | 657 SiteInstance* instance = SiteInstance::Create(browser_context()); |
658 | 658 |
659 TestWebContents web_contents(browser_context(), instance); | 659 TestWebContents web_contents(browser_context(), instance); |
660 RenderViewHostManager manager(&web_contents, &web_contents, &web_contents); | 660 RenderViewHostManager manager(&web_contents, &web_contents, &web_contents); |
661 | 661 |
662 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); | 662 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); |
663 | 663 |
664 const GURL kUrl(chrome::kTestNewTabURL); | 664 const GURL kUrl(content::kTestNewTabURL); |
665 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | 665 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, |
666 content::Referrer(), string16() /* title */, | 666 content::Referrer(), string16() /* title */, |
667 content::PAGE_TRANSITION_TYPED, | 667 content::PAGE_TRANSITION_TYPED, |
668 false /* is_renderer_init */); | 668 false /* is_renderer_init */); |
669 RenderViewHost* host = manager.Navigate(entry); | 669 RenderViewHost* host = manager.Navigate(entry); |
670 | 670 |
671 EXPECT_TRUE(host); | 671 EXPECT_TRUE(host); |
672 EXPECT_TRUE(host == manager.current_host()); | 672 EXPECT_TRUE(host == manager.current_host()); |
673 EXPECT_FALSE(manager.pending_render_view_host()); | 673 EXPECT_FALSE(manager.pending_render_view_host()); |
674 | 674 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 EXPECT_FALSE(rvh2->is_swapped_out()); | 774 EXPECT_FALSE(rvh2->is_swapped_out()); |
775 EXPECT_TRUE(rvh1->is_swapped_out()); | 775 EXPECT_TRUE(rvh1->is_swapped_out()); |
776 } | 776 } |
777 | 777 |
778 // Test that we create swapped out RVHs for the opener chain when navigating an | 778 // Test that we create swapped out RVHs for the opener chain when navigating an |
779 // opened tab cross-process. This allows us to support certain cross-process | 779 // opened tab cross-process. This allows us to support certain cross-process |
780 // JavaScript calls (http://crbug.com/99202). | 780 // JavaScript calls (http://crbug.com/99202). |
781 TEST_F(RenderViewHostManagerTest, CreateSwappedOutOpenerRVHs) { | 781 TEST_F(RenderViewHostManagerTest, CreateSwappedOutOpenerRVHs) { |
782 const GURL kUrl1("http://www.google.com/"); | 782 const GURL kUrl1("http://www.google.com/"); |
783 const GURL kUrl2("http://www.chromium.org/"); | 783 const GURL kUrl2("http://www.chromium.org/"); |
784 const GURL kNtpUrl(chrome::kTestNewTabURL); | 784 const GURL kNtpUrl(content::kTestNewTabURL); |
785 | 785 |
786 // Navigate to an initial URL. | 786 // Navigate to an initial URL. |
787 contents()->NavigateAndCommit(kUrl1); | 787 contents()->NavigateAndCommit(kUrl1); |
788 RenderViewHostManager* manager = contents()->GetRenderManagerForTesting(); | 788 RenderViewHostManager* manager = contents()->GetRenderManagerForTesting(); |
789 TestRenderViewHost* rvh1 = test_rvh(); | 789 TestRenderViewHost* rvh1 = test_rvh(); |
790 | 790 |
791 // Create 2 new tabs and simulate them being the opener chain for the main | 791 // Create 2 new tabs and simulate them being the opener chain for the main |
792 // tab. They should be in the same SiteInstance. | 792 // tab. They should be in the same SiteInstance. |
793 TestWebContents opener1(browser_context(), rvh1->GetSiteInstance()); | 793 TestWebContents opener1(browser_context(), rvh1->GetSiteInstance()); |
794 RenderViewHostManager* opener1_manager = opener1.GetRenderManagerForTesting(); | 794 RenderViewHostManager* opener1_manager = opener1.GetRenderManagerForTesting(); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 EXPECT_FALSE(manager.pending_render_view_host()); | 929 EXPECT_FALSE(manager.pending_render_view_host()); |
930 | 930 |
931 // Commit. | 931 // Commit. |
932 manager.DidNavigateMainFrame(host); | 932 manager.DidNavigateMainFrame(host); |
933 EXPECT_EQ(host, manager.current_host()); | 933 EXPECT_EQ(host, manager.current_host()); |
934 ASSERT_TRUE(host); | 934 ASSERT_TRUE(host); |
935 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()), | 935 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()), |
936 instance); | 936 instance); |
937 | 937 |
938 } | 938 } |
OLD | NEW |