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

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

Issue 14335017: content: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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" 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 private: 123 private:
124 RenderViewHostManagerTestWebUIControllerFactory factory_; 124 RenderViewHostManagerTestWebUIControllerFactory factory_;
125 }; 125 };
126 126
127 // Tests that when you navigate from a chrome:// url to another page, and 127 // Tests that when you navigate from a chrome:// url to another page, and
128 // then do that same thing in another tab, that the two resulting pages have 128 // then do that same thing in another tab, that the two resulting pages have
129 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is 129 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is
130 // a regression test for bug 9364. 130 // a regression test for bug 9364.
131 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { 131 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) {
132 set_should_create_webui(true); 132 set_should_create_webui(true);
133 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); 133 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current());
134 const GURL kChromeUrl("chrome://foo"); 134 const GURL kChromeUrl("chrome://foo");
135 const GURL kDestUrl("http://www.google.com/"); 135 const GURL kDestUrl("http://www.google.com/");
136 136
137 // Navigate our first tab to the chrome url and then to the destination, 137 // Navigate our first tab to the chrome url and then to the destination,
138 // ensuring we grant bindings to the chrome URL. 138 // ensuring we grant bindings to the chrome URL.
139 NavigateActiveAndCommit(kChromeUrl); 139 NavigateActiveAndCommit(kChromeUrl);
140 EXPECT_TRUE(active_rvh()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 140 EXPECT_TRUE(active_rvh()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
141 NavigateActiveAndCommit(kDestUrl); 141 NavigateActiveAndCommit(kDestUrl);
142 142
143 // Make a second tab. 143 // Make a second tab.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 EXPECT_EQ(active_rvh()->GetSiteInstance()->GetProcess(), 188 EXPECT_EQ(active_rvh()->GetSiteInstance()->GetProcess(),
189 contents2->GetRenderViewHost()->GetSiteInstance()->GetProcess()); 189 contents2->GetRenderViewHost()->GetSiteInstance()->GetProcess());
190 } 190 }
191 191
192 // Ensure that the browser ignores most IPC messages that arrive from a 192 // Ensure that the browser ignores most IPC messages that arrive from a
193 // RenderViewHost that has been swapped out. We do not want to take 193 // RenderViewHost that has been swapped out. We do not want to take
194 // action on requests from a non-active renderer. The main exception is 194 // action on requests from a non-active renderer. The main exception is
195 // for synchronous messages, which cannot be ignored without leaving the 195 // for synchronous messages, which cannot be ignored without leaving the
196 // renderer in a stuck state. See http://crbug.com/93427. 196 // renderer in a stuck state. See http://crbug.com/93427.
197 TEST_F(RenderViewHostManagerTest, FilterMessagesWhileSwappedOut) { 197 TEST_F(RenderViewHostManagerTest, FilterMessagesWhileSwappedOut) {
198 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); 198 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current());
199 const GURL kChromeURL("chrome://foo"); 199 const GURL kChromeURL("chrome://foo");
200 const GURL kDestUrl("http://www.google.com/"); 200 const GURL kDestUrl("http://www.google.com/");
201 201
202 // Navigate our first tab to a chrome url and then to the destination. 202 // Navigate our first tab to a chrome url and then to the destination.
203 NavigateActiveAndCommit(kChromeURL); 203 NavigateActiveAndCommit(kChromeURL);
204 TestRenderViewHost* ntp_rvh = static_cast<TestRenderViewHost*>( 204 TestRenderViewHost* ntp_rvh = static_cast<TestRenderViewHost*>(
205 contents()->GetRenderManagerForTesting()->current_host()); 205 contents()->GetRenderManagerForTesting()->current_host());
206 206
207 // Send an update title message and make sure it works. 207 // Send an update title message and make sure it works.
208 const string16 ntp_title = ASCIIToUTF16("NTP Title"); 208 const string16 ntp_title = ASCIIToUTF16("NTP Title");
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 js_msg.EnableMessagePumping(); 265 js_msg.EnableMessagePumping();
266 EXPECT_TRUE(ntp_rvh->OnMessageReceived(js_msg)); 266 EXPECT_TRUE(ntp_rvh->OnMessageReceived(js_msg));
267 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID)); 267 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID));
268 } 268 }
269 269
270 // When there is an error with the specified page, renderer exits view-source 270 // When there is an error with the specified page, renderer exits view-source
271 // mode. See WebFrameImpl::DidFail(). We check by this test that 271 // mode. See WebFrameImpl::DidFail(). We check by this test that
272 // EnableViewSourceMode message is sent on every navigation regardless 272 // EnableViewSourceMode message is sent on every navigation regardless
273 // RenderView is being newly created or reused. 273 // RenderView is being newly created or reused.
274 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { 274 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) {
275 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); 275 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current());
276 const GURL kChromeUrl("chrome://foo"); 276 const GURL kChromeUrl("chrome://foo");
277 const GURL kUrl("view-source:http://foo"); 277 const GURL kUrl("view-source:http://foo");
278 278
279 // We have to navigate to some page at first since without this, the first 279 // We have to navigate to some page at first since without this, the first
280 // navigation will reuse the SiteInstance created by Init(), and the second 280 // navigation will reuse the SiteInstance created by Init(), and the second
281 // one will create a new SiteInstance. Because current_instance and 281 // one will create a new SiteInstance. Because current_instance and
282 // new_instance will be different, a new RenderViewHost will be created for 282 // new_instance will be different, a new RenderViewHost will be created for
283 // the second navigation. We have to avoid this in order to exercise the 283 // the second navigation. We have to avoid this in order to exercise the
284 // target code patch. 284 // target code patch.
285 NavigateActiveAndCommit(kChromeUrl); 285 NavigateActiveAndCommit(kChromeUrl);
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 EXPECT_FALSE(manager.pending_render_view_host()); 584 EXPECT_FALSE(manager.pending_render_view_host());
585 585
586 // We should observe a notification. 586 // We should observe a notification.
587 EXPECT_TRUE(notifications.Check1AndReset( 587 EXPECT_TRUE(notifications.Check1AndReset(
588 NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); 588 NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
589 } 589 }
590 590
591 // Tests WebUI creation. 591 // Tests WebUI creation.
592 TEST_F(RenderViewHostManagerTest, WebUI) { 592 TEST_F(RenderViewHostManagerTest, WebUI) {
593 set_should_create_webui(true); 593 set_should_create_webui(true);
594 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); 594 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current());
595 SiteInstance* instance = SiteInstance::Create(browser_context()); 595 SiteInstance* instance = SiteInstance::Create(browser_context());
596 596
597 scoped_ptr<TestWebContents> web_contents( 597 scoped_ptr<TestWebContents> web_contents(
598 TestWebContents::Create(browser_context(), instance)); 598 TestWebContents::Create(browser_context(), instance));
599 RenderViewHostManager manager(web_contents.get(), web_contents.get(), 599 RenderViewHostManager manager(web_contents.get(), web_contents.get(),
600 web_contents.get()); 600 web_contents.get());
601 601
602 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); 602 manager.Init(browser_context(), instance, MSG_ROUTING_NONE);
603 EXPECT_FALSE(manager.current_host()->IsRenderViewLive()); 603 EXPECT_FALSE(manager.current_host()->IsRenderViewLive());
604 604
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 942
943 // Commit. 943 // Commit.
944 manager.DidNavigateMainFrame(host); 944 manager.DidNavigateMainFrame(host);
945 EXPECT_EQ(host, manager.current_host()); 945 EXPECT_EQ(host, manager.current_host());
946 ASSERT_TRUE(host); 946 ASSERT_TRUE(host);
947 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()), 947 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()),
948 instance); 948 instance);
949 } 949 }
950 950
951 } // namespace content 951 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698