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

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

Issue 7892007: Add ChromeRenderViewHostTestHarness to get rid of the dependency from RVHTH to profile (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix mac Created 9 years, 3 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) 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/test/base/chrome_render_view_host_test_harness.h"
5 #include "chrome/test/base/testing_profile.h" 6 #include "chrome/test/base/testing_profile.h"
6 #include "content/browser/browser_thread.h" 7 #include "content/browser/browser_thread.h"
7 #include "content/browser/browser_url_handler.h" 8 #include "content/browser/browser_url_handler.h"
8 #include "content/browser/renderer_host/test_render_view_host.h"
9 #include "content/browser/site_instance.h" 9 #include "content/browser/site_instance.h"
10 #include "content/browser/tab_contents/navigation_controller.h" 10 #include "content/browser/tab_contents/navigation_controller.h"
11 #include "content/browser/tab_contents/navigation_entry.h" 11 #include "content/browser/tab_contents/navigation_entry.h"
12 #include "content/browser/tab_contents/render_view_host_manager.h" 12 #include "content/browser/tab_contents/render_view_host_manager.h"
13 #include "content/browser/tab_contents/test_tab_contents.h" 13 #include "content/browser/tab_contents/test_tab_contents.h"
14 #include "content/common/notification_details.h" 14 #include "content/common/notification_details.h"
15 #include "content/common/notification_source.h" 15 #include "content/common/notification_source.h"
16 #include "content/common/page_transition_types.h" 16 #include "content/common/page_transition_types.h"
17 #include "content/common/test_url_constants.h" 17 #include "content/common/test_url_constants.h"
18 #include "content/common/view_messages.h" 18 #include "content/common/view_messages.h"
19 #include "content/test/test_notification_tracker.h" 19 #include "content/test/test_notification_tracker.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "webkit/glue/webkit_glue.h" 21 #include "webkit/glue/webkit_glue.h"
22 22
23 class RenderViewHostManagerTest : public RenderViewHostTestHarness { 23 class RenderViewHostManagerTest : public ChromeRenderViewHostTestHarness {
24 public: 24 public:
25 void NavigateActiveAndCommit(const GURL& url) { 25 void NavigateActiveAndCommit(const GURL& url) {
26 // Note: we navigate the active RenderViewHost because previous navigations 26 // Note: we navigate the active RenderViewHost because previous navigations
27 // won't have committed yet, so NavigateAndCommit does the wrong thing 27 // won't have committed yet, so NavigateAndCommit does the wrong thing
28 // for us. 28 // for us.
29 controller().LoadURL(url, GURL(), PageTransition::LINK, std::string()); 29 controller().LoadURL(url, GURL(), PageTransition::LINK, std::string());
30 TestRenderViewHost* old_rvh = rvh(); 30 TestRenderViewHost* old_rvh = rvh();
31 31
32 // Simulate the ShouldClose_ACK that is received from the current renderer 32 // Simulate the ShouldClose_ACK that is received from the current renderer
33 // for a cross-site navigation. 33 // for a cross-site navigation.
(...skipping 26 matching lines...) Expand all
60 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { 60 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) {
61 BrowserThread ui_thread(BrowserThread::UI, MessageLoop::current()); 61 BrowserThread ui_thread(BrowserThread::UI, MessageLoop::current());
62 const GURL kNtpUrl(chrome::kTestNewTabURL); 62 const GURL kNtpUrl(chrome::kTestNewTabURL);
63 const GURL kDestUrl("http://www.google.com/"); 63 const GURL kDestUrl("http://www.google.com/");
64 64
65 // Navigate our first tab to the new tab page and then to the destination. 65 // Navigate our first tab to the new tab page and then to the destination.
66 NavigateActiveAndCommit(kNtpUrl); 66 NavigateActiveAndCommit(kNtpUrl);
67 NavigateActiveAndCommit(kDestUrl); 67 NavigateActiveAndCommit(kDestUrl);
68 68
69 // Make a second tab. 69 // Make a second tab.
70 TestTabContents contents2(profile_.get(), NULL); 70 TestTabContents contents2(profile(), NULL);
71 71
72 // Load the two URLs in the second tab. Note that the first navigation creates 72 // Load the two URLs in the second tab. Note that the first navigation creates
73 // a RVH that's not pending (since there is no cross-site transition), so 73 // a RVH that's not pending (since there is no cross-site transition), so
74 // we use the committed one. 74 // we use the committed one.
75 contents2.controller().LoadURL(kNtpUrl, GURL(), PageTransition::LINK, 75 contents2.controller().LoadURL(kNtpUrl, GURL(), PageTransition::LINK,
76 std::string()); 76 std::string());
77 TestRenderViewHost* ntp_rvh2 = static_cast<TestRenderViewHost*>( 77 TestRenderViewHost* ntp_rvh2 = static_cast<TestRenderViewHost*>(
78 contents2.render_manager()->current_host()); 78 contents2.render_manager()->current_host());
79 EXPECT_FALSE(contents2.cross_navigation_pending()); 79 EXPECT_FALSE(contents2.cross_navigation_pending());
80 ntp_rvh2->SendNavigate(100, kNtpUrl); 80 ntp_rvh2->SendNavigate(100, kNtpUrl);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 EXPECT_EQ(controller().last_committed_entry_index(), 1); 160 EXPECT_EQ(controller().last_committed_entry_index(), 1);
161 EXPECT_FALSE(controller().pending_entry()); 161 EXPECT_FALSE(controller().pending_entry());
162 // New message should be sent out to make sure to enter view-source mode. 162 // New message should be sent out to make sure to enter view-source mode.
163 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( 163 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching(
164 ViewMsg_EnableViewSourceMode::ID)); 164 ViewMsg_EnableViewSourceMode::ID));
165 } 165 }
166 166
167 // Tests the Init function by checking the initial RenderViewHost. 167 // Tests the Init function by checking the initial RenderViewHost.
168 TEST_F(RenderViewHostManagerTest, Init) { 168 TEST_F(RenderViewHostManagerTest, Init) {
169 // Using TestingProfile. 169 // Using TestingProfile.
170 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get()); 170 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile());
171 EXPECT_FALSE(instance->has_site()); 171 EXPECT_FALSE(instance->has_site());
172 172
173 TestTabContents tab_contents(profile_.get(), instance); 173 TestTabContents tab_contents(profile(), instance);
174 RenderViewHostManager manager(&tab_contents, &tab_contents); 174 RenderViewHostManager manager(&tab_contents, &tab_contents);
175 175
176 manager.Init(profile_.get(), instance, MSG_ROUTING_NONE); 176 manager.Init(profile(), instance, MSG_ROUTING_NONE);
177 177
178 RenderViewHost* host = manager.current_host(); 178 RenderViewHost* host = manager.current_host();
179 ASSERT_TRUE(host); 179 ASSERT_TRUE(host);
180 EXPECT_TRUE(instance == host->site_instance()); 180 EXPECT_TRUE(instance == host->site_instance());
181 EXPECT_TRUE(&tab_contents == host->delegate()); 181 EXPECT_TRUE(&tab_contents == host->delegate());
182 EXPECT_TRUE(manager.GetRenderWidgetHostView()); 182 EXPECT_TRUE(manager.GetRenderWidgetHostView());
183 EXPECT_FALSE(manager.pending_render_view_host()); 183 EXPECT_FALSE(manager.pending_render_view_host());
184 } 184 }
185 185
186 // Tests the Navigate function. We navigate three sites consecutively and check 186 // Tests the Navigate function. We navigate three sites consecutively and check
187 // how the pending/committed RenderViewHost are modified. 187 // how the pending/committed RenderViewHost are modified.
188 TEST_F(RenderViewHostManagerTest, Navigate) { 188 TEST_F(RenderViewHostManagerTest, Navigate) {
189 TestNotificationTracker notifications; 189 TestNotificationTracker notifications;
190 190
191 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get()); 191 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile());
192 192
193 TestTabContents tab_contents(profile_.get(), instance); 193 TestTabContents tab_contents(profile(), instance);
194 notifications.ListenFor(content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 194 notifications.ListenFor(content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
195 Source<NavigationController>(&tab_contents.controller())); 195 Source<NavigationController>(&tab_contents.controller()));
196 196
197 // Create. 197 // Create.
198 RenderViewHostManager manager(&tab_contents, &tab_contents); 198 RenderViewHostManager manager(&tab_contents, &tab_contents);
199 199
200 manager.Init(profile_.get(), instance, MSG_ROUTING_NONE); 200 manager.Init(profile(), instance, MSG_ROUTING_NONE);
201 201
202 RenderViewHost* host; 202 RenderViewHost* host;
203 203
204 // 1) The first navigation. -------------------------- 204 // 1) The first navigation. --------------------------
205 const GURL kUrl1("http://www.google.com/"); 205 const GURL kUrl1("http://www.google.com/");
206 NavigationEntry entry1(NULL /* instance */, -1 /* page_id */, kUrl1, 206 NavigationEntry entry1(NULL /* instance */, -1 /* page_id */, kUrl1,
207 GURL() /* referrer */, string16() /* title */, 207 GURL() /* referrer */, string16() /* title */,
208 PageTransition::TYPED); 208 PageTransition::TYPED);
209 host = manager.Navigate(entry1); 209 host = manager.Navigate(entry1);
210 210
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 EXPECT_FALSE(manager.pending_render_view_host()); 259 EXPECT_FALSE(manager.pending_render_view_host());
260 260
261 // We should observe a notification. 261 // We should observe a notification.
262 EXPECT_TRUE(notifications.Check1AndReset( 262 EXPECT_TRUE(notifications.Check1AndReset(
263 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); 263 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
264 } 264 }
265 265
266 // Tests WebUI creation. 266 // Tests WebUI creation.
267 TEST_F(RenderViewHostManagerTest, WebUI) { 267 TEST_F(RenderViewHostManagerTest, WebUI) {
268 BrowserThread ui_thread(BrowserThread::UI, MessageLoop::current()); 268 BrowserThread ui_thread(BrowserThread::UI, MessageLoop::current());
269 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get()); 269 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile());
270 270
271 TestTabContents tab_contents(profile_.get(), instance); 271 TestTabContents tab_contents(profile(), instance);
272 RenderViewHostManager manager(&tab_contents, &tab_contents); 272 RenderViewHostManager manager(&tab_contents, &tab_contents);
273 273
274 manager.Init(profile_.get(), instance, MSG_ROUTING_NONE); 274 manager.Init(profile(), instance, MSG_ROUTING_NONE);
275 275
276 const GURL kUrl(chrome::kTestNewTabURL); 276 const GURL kUrl(chrome::kTestNewTabURL);
277 NavigationEntry entry(NULL /* instance */, -1 /* page_id */, kUrl, 277 NavigationEntry entry(NULL /* instance */, -1 /* page_id */, kUrl,
278 GURL() /* referrer */, string16() /* title */, 278 GURL() /* referrer */, string16() /* title */,
279 PageTransition::TYPED); 279 PageTransition::TYPED);
280 RenderViewHost* host = manager.Navigate(entry); 280 RenderViewHost* host = manager.Navigate(entry);
281 281
282 EXPECT_TRUE(host); 282 EXPECT_TRUE(host);
283 EXPECT_TRUE(host == manager.current_host()); 283 EXPECT_TRUE(host == manager.current_host());
284 EXPECT_FALSE(manager.pending_render_view_host()); 284 EXPECT_FALSE(manager.pending_render_view_host());
(...skipping 13 matching lines...) Expand all
298 // Commit. 298 // Commit.
299 manager.DidNavigateMainFrame(host); 299 manager.DidNavigateMainFrame(host);
300 } 300 }
301 301
302 // Tests that chrome: URLs that are not Web UI pages do not get grouped into 302 // Tests that chrome: URLs that are not Web UI pages do not get grouped into
303 // Web UI renderers, even if --process-per-tab is enabled. In that mode, we 303 // Web UI renderers, even if --process-per-tab is enabled. In that mode, we
304 // still swap processes if ShouldSwapProcessesForNavigation is true. 304 // still swap processes if ShouldSwapProcessesForNavigation is true.
305 // Regression test for bug 46290. 305 // Regression test for bug 46290.
306 TEST_F(RenderViewHostManagerTest, NonWebUIChromeURLs) { 306 TEST_F(RenderViewHostManagerTest, NonWebUIChromeURLs) {
307 BrowserThread thread(BrowserThread::UI, &message_loop_); 307 BrowserThread thread(BrowserThread::UI, &message_loop_);
308 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get()); 308 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile());
309 TestTabContents tab_contents(profile_.get(), instance); 309 TestTabContents tab_contents(profile(), instance);
310 RenderViewHostManager manager(&tab_contents, &tab_contents); 310 RenderViewHostManager manager(&tab_contents, &tab_contents);
311 manager.Init(profile_.get(), instance, MSG_ROUTING_NONE); 311 manager.Init(profile(), instance, MSG_ROUTING_NONE);
312 312
313 // NTP is a Web UI page. 313 // NTP is a Web UI page.
314 const GURL kNtpUrl(chrome::kTestNewTabURL); 314 const GURL kNtpUrl(chrome::kTestNewTabURL);
315 NavigationEntry ntp_entry(NULL /* instance */, -1 /* page_id */, kNtpUrl, 315 NavigationEntry ntp_entry(NULL /* instance */, -1 /* page_id */, kNtpUrl,
316 GURL() /* referrer */, string16() /* title */, 316 GURL() /* referrer */, string16() /* title */,
317 PageTransition::TYPED); 317 PageTransition::TYPED);
318 318
319 // about: URLs are not Web UI pages. 319 // about: URLs are not Web UI pages.
320 GURL about_url(chrome::kTestMemoryURL); 320 GURL about_url(chrome::kTestMemoryURL);
321 // Rewrite so it looks like chrome://about/memory 321 // Rewrite so it looks like chrome://about/memory
322 bool reverse_on_redirect = false; 322 bool reverse_on_redirect = false;
323 BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( 323 BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
324 &about_url, profile_.get(), &reverse_on_redirect); 324 &about_url, profile(), &reverse_on_redirect);
325 NavigationEntry about_entry(NULL /* instance */, -1 /* page_id */, about_url, 325 NavigationEntry about_entry(NULL /* instance */, -1 /* page_id */, about_url,
326 GURL() /* referrer */, string16() /* title */, 326 GURL() /* referrer */, string16() /* title */,
327 PageTransition::TYPED); 327 PageTransition::TYPED);
328 328
329 EXPECT_TRUE(ShouldSwapProcesses(&manager, &ntp_entry, &about_entry)); 329 EXPECT_TRUE(ShouldSwapProcesses(&manager, &ntp_entry, &about_entry));
330 } 330 }
331 331
332 // Tests that we don't end up in an inconsistent state if a page does a back and 332 // Tests that we don't end up in an inconsistent state if a page does a back and
333 // then reload. http://crbug.com/51680 333 // then reload. http://crbug.com/51680
334 TEST_F(RenderViewHostManagerTest, PageDoesBackAndReload) { 334 TEST_F(RenderViewHostManagerTest, PageDoesBackAndReload) {
(...skipping 30 matching lines...) Expand all
365 // That should have cancelled the pending RVH, and the evil RVH should be the 365 // That should have cancelled the pending RVH, and the evil RVH should be the
366 // current one. 366 // current one.
367 EXPECT_TRUE(contents()->render_manager()->pending_render_view_host() == NULL); 367 EXPECT_TRUE(contents()->render_manager()->pending_render_view_host() == NULL);
368 EXPECT_EQ(evil_rvh, contents()->render_manager()->current_host()); 368 EXPECT_EQ(evil_rvh, contents()->render_manager()->current_host());
369 369
370 // Also we should not have a pending navigation entry. 370 // Also we should not have a pending navigation entry.
371 NavigationEntry* entry = contents()->controller().GetActiveEntry(); 371 NavigationEntry* entry = contents()->controller().GetActiveEntry();
372 ASSERT_TRUE(entry != NULL); 372 ASSERT_TRUE(entry != NULL);
373 EXPECT_EQ(kUrl2, entry->url()); 373 EXPECT_EQ(kUrl2, entry->url());
374 } 374 }
OLDNEW
« no previous file with comments | « content/browser/tab_contents/navigation_controller_unittest.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698