Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(474)

Side by Side Diff: content/browser/web_contents/render_view_host_manager_unittest.cc

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address jyasskin's comments\ Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
7 #include "content/browser/renderer_host/test_render_view_host.h" 6 #include "content/browser/renderer_host/test_render_view_host.h"
8 #include "content/browser/site_instance_impl.h" 7 #include "content/browser/site_instance_impl.h"
9 #include "content/browser/web_contents/navigation_controller_impl.h" 8 #include "content/browser/web_contents/navigation_controller_impl.h"
10 #include "content/browser/web_contents/navigation_entry_impl.h" 9 #include "content/browser/web_contents/navigation_entry_impl.h"
11 #include "content/browser/web_contents/render_view_host_manager.h" 10 #include "content/browser/web_contents/render_view_host_manager.h"
12 #include "content/browser/webui/web_ui_controller_factory_registry.h" 11 #include "content/browser/webui/web_ui_controller_factory_registry.h"
13 #include "content/common/view_messages.h" 12 #include "content/common/view_messages.h"
14 #include "content/public/browser/notification_details.h" 13 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_source.h" 14 #include "content/public/browser/notification_source.h"
16 #include "content/public/browser/notification_types.h" 15 #include "content/public/browser/notification_types.h"
17 #include "content/public/browser/web_ui_controller.h" 16 #include "content/public/browser/web_ui_controller.h"
18 #include "content/public/common/bindings_policy.h" 17 #include "content/public/common/bindings_policy.h"
19 #include "content/public/common/javascript_message_type.h" 18 #include "content/public/common/javascript_message_type.h"
20 #include "content/public/common/page_transition_types.h" 19 #include "content/public/common/page_transition_types.h"
21 #include "content/public/common/url_constants.h" 20 #include "content/public/common/url_constants.h"
22 #include "content/public/common/url_utils.h" 21 #include "content/public/common/url_utils.h"
23 #include "content/public/test/mock_render_process_host.h" 22 #include "content/public/test/mock_render_process_host.h"
24 #include "content/public/test/test_browser_context.h"
25 #include "content/public/test/test_notification_tracker.h" 23 #include "content/public/test/test_notification_tracker.h"
26 #include "content/test/test_content_browser_client.h" 24 #include "content/test/test_content_browser_client.h"
27 #include "content/test/test_content_client.h" 25 #include "content/test/test_content_client.h"
28 #include "content/test/test_web_contents.h" 26 #include "content/test/test_web_contents.h"
29 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
30 #include "webkit/glue/glue_serialize.h" 28 #include "webkit/glue/glue_serialize.h"
31 29
32 namespace content { 30 namespace content {
33 namespace { 31 namespace {
34 32
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 private: 122 private:
125 RenderViewHostManagerTestWebUIControllerFactory factory_; 123 RenderViewHostManagerTestWebUIControllerFactory factory_;
126 }; 124 };
127 125
128 // Tests that when you navigate from a chrome:// url to another page, and 126 // Tests that when you navigate from a chrome:// url to another page, and
129 // then do that same thing in another tab, that the two resulting pages have 127 // then do that same thing in another tab, that the two resulting pages have
130 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is 128 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is
131 // a regression test for bug 9364. 129 // a regression test for bug 9364.
132 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { 130 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) {
133 set_should_create_webui(true); 131 set_should_create_webui(true);
134 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current());
135 const GURL kChromeUrl("chrome://foo"); 132 const GURL kChromeUrl("chrome://foo");
136 const GURL kDestUrl("http://www.google.com/"); 133 const GURL kDestUrl("http://www.google.com/");
137 134
138 // Navigate our first tab to the chrome url and then to the destination, 135 // Navigate our first tab to the chrome url and then to the destination,
139 // ensuring we grant bindings to the chrome URL. 136 // ensuring we grant bindings to the chrome URL.
140 NavigateActiveAndCommit(kChromeUrl); 137 NavigateActiveAndCommit(kChromeUrl);
141 EXPECT_TRUE(active_rvh()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 138 EXPECT_TRUE(active_rvh()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
142 NavigateActiveAndCommit(kDestUrl); 139 NavigateActiveAndCommit(kDestUrl);
143 140
144 // Make a second tab. 141 // Make a second tab.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 EXPECT_EQ(active_rvh()->GetSiteInstance()->GetProcess(), 186 EXPECT_EQ(active_rvh()->GetSiteInstance()->GetProcess(),
190 contents2->GetRenderViewHost()->GetSiteInstance()->GetProcess()); 187 contents2->GetRenderViewHost()->GetSiteInstance()->GetProcess());
191 } 188 }
192 189
193 // Ensure that the browser ignores most IPC messages that arrive from a 190 // Ensure that the browser ignores most IPC messages that arrive from a
194 // RenderViewHost that has been swapped out. We do not want to take 191 // RenderViewHost that has been swapped out. We do not want to take
195 // action on requests from a non-active renderer. The main exception is 192 // action on requests from a non-active renderer. The main exception is
196 // for synchronous messages, which cannot be ignored without leaving the 193 // for synchronous messages, which cannot be ignored without leaving the
197 // renderer in a stuck state. See http://crbug.com/93427. 194 // renderer in a stuck state. See http://crbug.com/93427.
198 TEST_F(RenderViewHostManagerTest, FilterMessagesWhileSwappedOut) { 195 TEST_F(RenderViewHostManagerTest, FilterMessagesWhileSwappedOut) {
199 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current());
200 const GURL kChromeURL("chrome://foo"); 196 const GURL kChromeURL("chrome://foo");
201 const GURL kDestUrl("http://www.google.com/"); 197 const GURL kDestUrl("http://www.google.com/");
202 198
203 // Navigate our first tab to a chrome url and then to the destination. 199 // Navigate our first tab to a chrome url and then to the destination.
204 NavigateActiveAndCommit(kChromeURL); 200 NavigateActiveAndCommit(kChromeURL);
205 TestRenderViewHost* ntp_rvh = static_cast<TestRenderViewHost*>( 201 TestRenderViewHost* ntp_rvh = static_cast<TestRenderViewHost*>(
206 contents()->GetRenderManagerForTesting()->current_host()); 202 contents()->GetRenderManagerForTesting()->current_host());
207 203
208 // Send an update title message and make sure it works. 204 // Send an update title message and make sure it works.
209 const string16 ntp_title = ASCIIToUTF16("NTP Title"); 205 const string16 ntp_title = ASCIIToUTF16("NTP Title");
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 js_msg.EnableMessagePumping(); 262 js_msg.EnableMessagePumping();
267 EXPECT_TRUE(ntp_rvh->OnMessageReceived(js_msg)); 263 EXPECT_TRUE(ntp_rvh->OnMessageReceived(js_msg));
268 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID)); 264 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID));
269 } 265 }
270 266
271 // When there is an error with the specified page, renderer exits view-source 267 // When there is an error with the specified page, renderer exits view-source
272 // mode. See WebFrameImpl::DidFail(). We check by this test that 268 // mode. See WebFrameImpl::DidFail(). We check by this test that
273 // EnableViewSourceMode message is sent on every navigation regardless 269 // EnableViewSourceMode message is sent on every navigation regardless
274 // RenderView is being newly created or reused. 270 // RenderView is being newly created or reused.
275 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { 271 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) {
276 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current());
277 const GURL kChromeUrl("chrome://foo"); 272 const GURL kChromeUrl("chrome://foo");
278 const GURL kUrl("view-source:http://foo"); 273 const GURL kUrl("view-source:http://foo");
279 274
280 // We have to navigate to some page at first since without this, the first 275 // We have to navigate to some page at first since without this, the first
281 // navigation will reuse the SiteInstance created by Init(), and the second 276 // navigation will reuse the SiteInstance created by Init(), and the second
282 // one will create a new SiteInstance. Because current_instance and 277 // one will create a new SiteInstance. Because current_instance and
283 // new_instance will be different, a new RenderViewHost will be created for 278 // new_instance will be different, a new RenderViewHost will be created for
284 // the second navigation. We have to avoid this in order to exercise the 279 // the second navigation. We have to avoid this in order to exercise the
285 // target code patch. 280 // target code patch.
286 NavigateActiveAndCommit(kChromeUrl); 281 NavigateActiveAndCommit(kChromeUrl);
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 EXPECT_FALSE(manager.pending_render_view_host()); 580 EXPECT_FALSE(manager.pending_render_view_host());
586 581
587 // We should observe a notification. 582 // We should observe a notification.
588 EXPECT_TRUE(notifications.Check1AndReset( 583 EXPECT_TRUE(notifications.Check1AndReset(
589 NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); 584 NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
590 } 585 }
591 586
592 // Tests WebUI creation. 587 // Tests WebUI creation.
593 TEST_F(RenderViewHostManagerTest, WebUI) { 588 TEST_F(RenderViewHostManagerTest, WebUI) {
594 set_should_create_webui(true); 589 set_should_create_webui(true);
595 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current());
596 SiteInstance* instance = SiteInstance::Create(browser_context()); 590 SiteInstance* instance = SiteInstance::Create(browser_context());
597 591
598 scoped_ptr<TestWebContents> web_contents( 592 scoped_ptr<TestWebContents> web_contents(
599 TestWebContents::Create(browser_context(), instance)); 593 TestWebContents::Create(browser_context(), instance));
600 RenderViewHostManager manager(web_contents.get(), web_contents.get(), 594 RenderViewHostManager manager(web_contents.get(), web_contents.get(),
601 web_contents.get()); 595 web_contents.get());
602 596
603 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); 597 manager.Init(browser_context(), instance, MSG_ROUTING_NONE);
604 EXPECT_FALSE(manager.current_host()->IsRenderViewLive()); 598 EXPECT_FALSE(manager.current_host()->IsRenderViewLive());
605 599
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 937
944 // Commit. 938 // Commit.
945 manager.DidNavigateMainFrame(host); 939 manager.DidNavigateMainFrame(host);
946 EXPECT_EQ(host, manager.current_host()); 940 EXPECT_EQ(host, manager.current_host());
947 ASSERT_TRUE(host); 941 ASSERT_TRUE(host);
948 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()), 942 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()),
949 instance); 943 instance);
950 } 944 }
951 945
952 } // namespace content 946 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698