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

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

Issue 8340028: Salient parts of http://codereview.chromium.org/8392042/ (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 years, 1 month 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
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/chrome_render_view_host_test_harness.h"
6 #include "chrome/test/base/testing_profile.h" 6 #include "chrome/test/base/testing_profile.h"
7 #include "content/browser/browser_thread.h"
8 #include "content/browser/browser_url_handler.h" 7 #include "content/browser/browser_url_handler.h"
9 #include "content/browser/site_instance.h" 8 #include "content/browser/site_instance.h"
10 #include "content/browser/tab_contents/navigation_controller.h" 9 #include "content/browser/tab_contents/navigation_controller.h"
11 #include "content/browser/tab_contents/navigation_entry.h" 10 #include "content/browser/tab_contents/navigation_entry.h"
12 #include "content/browser/tab_contents/render_view_host_manager.h" 11 #include "content/browser/tab_contents/render_view_host_manager.h"
13 #include "content/browser/tab_contents/test_tab_contents.h" 12 #include "content/browser/tab_contents/test_tab_contents.h"
14 #include "content/common/test_url_constants.h" 13 #include "content/common/test_url_constants.h"
15 #include "content/common/view_messages.h" 14 #include "content/common/view_messages.h"
16 #include "content/public/browser/notification_details.h" 15 #include "content/public/browser/notification_details.h"
17 #include "content/public/browser/notification_source.h" 16 #include "content/public/browser/notification_source.h"
18 #include "content/public/browser/notification_types.h" 17 #include "content/public/browser/notification_types.h"
19 #include "content/public/common/page_transition_types.h" 18 #include "content/public/common/page_transition_types.h"
19 #include "content/test/test_browser_thread.h"
20 #include "content/test/test_browser_thread.h"
20 #include "content/test/test_notification_tracker.h" 21 #include "content/test/test_notification_tracker.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 #include "webkit/glue/webkit_glue.h" 23 #include "webkit/glue/webkit_glue.h"
23 24
24 class RenderViewHostManagerTest : public ChromeRenderViewHostTestHarness { 25 class RenderViewHostManagerTest : public ChromeRenderViewHostTestHarness {
25 public: 26 public:
26 void NavigateActiveAndCommit(const GURL& url) { 27 void NavigateActiveAndCommit(const GURL& url) {
27 // Note: we navigate the active RenderViewHost because previous navigations 28 // Note: we navigate the active RenderViewHost because previous navigations
28 // won't have committed yet, so NavigateAndCommit does the wrong thing 29 // won't have committed yet, so NavigateAndCommit does the wrong thing
29 // for us. 30 // for us.
(...skipping 23 matching lines...) Expand all
53 const NavigationEntry* new_entry) const { 54 const NavigationEntry* new_entry) const {
54 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry); 55 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry);
55 } 56 }
56 }; 57 };
57 58
58 // Tests that when you navigate from the New TabPage to another page, and 59 // Tests that when you navigate from the New TabPage to another page, and
59 // then do that same thing in another tab, that the two resulting pages have 60 // then do that same thing in another tab, that the two resulting pages have
60 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is 61 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is
61 // a regression test for bug 9364. 62 // a regression test for bug 9364.
62 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { 63 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) {
63 BrowserThread ui_thread(BrowserThread::UI, MessageLoop::current()); 64 content::TestBrowserThread ui_thread(BrowserThread::UI,
65 MessageLoop::current());
64 const GURL kNtpUrl(chrome::kTestNewTabURL); 66 const GURL kNtpUrl(chrome::kTestNewTabURL);
65 const GURL kDestUrl("http://www.google.com/"); 67 const GURL kDestUrl("http://www.google.com/");
66 68
67 // Navigate our first tab to the new tab page and then to the destination. 69 // Navigate our first tab to the new tab page and then to the destination.
68 NavigateActiveAndCommit(kNtpUrl); 70 NavigateActiveAndCommit(kNtpUrl);
69 NavigateActiveAndCommit(kDestUrl); 71 NavigateActiveAndCommit(kDestUrl);
70 72
71 // Make a second tab. 73 // Make a second tab.
72 TestTabContents contents2(profile(), NULL); 74 TestTabContents contents2(profile(), NULL);
73 75
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 114
113 EXPECT_EQ(active_rvh()->site_instance(), 115 EXPECT_EQ(active_rvh()->site_instance(),
114 contents2.render_view_host()->site_instance()); 116 contents2.render_view_host()->site_instance());
115 } 117 }
116 118
117 // When there is an error with the specified page, renderer exits view-source 119 // When there is an error with the specified page, renderer exits view-source
118 // mode. See WebFrameImpl::DidFail(). We check by this test that 120 // mode. See WebFrameImpl::DidFail(). We check by this test that
119 // EnableViewSourceMode message is sent on every navigation regardless 121 // EnableViewSourceMode message is sent on every navigation regardless
120 // RenderView is being newly created or reused. 122 // RenderView is being newly created or reused.
121 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { 123 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) {
122 BrowserThread ui_thread(BrowserThread::UI, MessageLoop::current()); 124 content::TestBrowserThread ui_thread(BrowserThread::UI,
125 MessageLoop::current());
123 const GURL kNtpUrl(chrome::kTestNewTabURL); 126 const GURL kNtpUrl(chrome::kTestNewTabURL);
124 const GURL kUrl("view-source:http://foo"); 127 const GURL kUrl("view-source:http://foo");
125 128
126 // We have to navigate to some page at first since without this, the first 129 // We have to navigate to some page at first since without this, the first
127 // navigation will reuse the SiteInstance created by Init(), and the second 130 // navigation will reuse the SiteInstance created by Init(), and the second
128 // one will create a new SiteInstance. Because current_instance and 131 // one will create a new SiteInstance. Because current_instance and
129 // new_instance will be different, a new RenderViewHost will be created for 132 // new_instance will be different, a new RenderViewHost will be created for
130 // the second navigation. We have to avoid this in order to exercise the 133 // the second navigation. We have to avoid this in order to exercise the
131 // target code patch. 134 // target code patch.
132 NavigateActiveAndCommit(kNtpUrl); 135 NavigateActiveAndCommit(kNtpUrl);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 // Check the pending RenderViewHost has been committed. 267 // Check the pending RenderViewHost has been committed.
265 EXPECT_FALSE(manager.pending_render_view_host()); 268 EXPECT_FALSE(manager.pending_render_view_host());
266 269
267 // We should observe a notification. 270 // We should observe a notification.
268 EXPECT_TRUE(notifications.Check1AndReset( 271 EXPECT_TRUE(notifications.Check1AndReset(
269 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); 272 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
270 } 273 }
271 274
272 // Tests WebUI creation. 275 // Tests WebUI creation.
273 TEST_F(RenderViewHostManagerTest, WebUI) { 276 TEST_F(RenderViewHostManagerTest, WebUI) {
274 BrowserThread ui_thread(BrowserThread::UI, MessageLoop::current()); 277 content::TestBrowserThread ui_thread(BrowserThread::UI,
278 MessageLoop::current());
275 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile()); 279 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile());
276 280
277 TestTabContents tab_contents(profile(), instance); 281 TestTabContents tab_contents(profile(), instance);
278 RenderViewHostManager manager(&tab_contents, &tab_contents); 282 RenderViewHostManager manager(&tab_contents, &tab_contents);
279 283
280 manager.Init(profile(), instance, MSG_ROUTING_NONE); 284 manager.Init(profile(), instance, MSG_ROUTING_NONE);
281 285
282 const GURL kUrl(chrome::kTestNewTabURL); 286 const GURL kUrl(chrome::kTestNewTabURL);
283 NavigationEntry entry(NULL /* instance */, -1 /* page_id */, kUrl, 287 NavigationEntry entry(NULL /* instance */, -1 /* page_id */, kUrl,
284 GURL() /* referrer */, string16() /* title */, 288 GURL() /* referrer */, string16() /* title */,
(...skipping 19 matching lines...) Expand all
304 308
305 // Commit. 309 // Commit.
306 manager.DidNavigateMainFrame(host); 310 manager.DidNavigateMainFrame(host);
307 } 311 }
308 312
309 // Tests that chrome: URLs that are not Web UI pages do not get grouped into 313 // Tests that chrome: URLs that are not Web UI pages do not get grouped into
310 // Web UI renderers, even if --process-per-tab is enabled. In that mode, we 314 // Web UI renderers, even if --process-per-tab is enabled. In that mode, we
311 // still swap processes if ShouldSwapProcessesForNavigation is true. 315 // still swap processes if ShouldSwapProcessesForNavigation is true.
312 // Regression test for bug 46290. 316 // Regression test for bug 46290.
313 TEST_F(RenderViewHostManagerTest, NonWebUIChromeURLs) { 317 TEST_F(RenderViewHostManagerTest, NonWebUIChromeURLs) {
314 BrowserThread thread(BrowserThread::UI, &message_loop_); 318 content::TestBrowserThread thread(BrowserThread::UI, &message_loop_);
315 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile()); 319 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile());
316 TestTabContents tab_contents(profile(), instance); 320 TestTabContents tab_contents(profile(), instance);
317 RenderViewHostManager manager(&tab_contents, &tab_contents); 321 RenderViewHostManager manager(&tab_contents, &tab_contents);
318 manager.Init(profile(), instance, MSG_ROUTING_NONE); 322 manager.Init(profile(), instance, MSG_ROUTING_NONE);
319 323
320 // NTP is a Web UI page. 324 // NTP is a Web UI page.
321 const GURL kNtpUrl(chrome::kTestNewTabURL); 325 const GURL kNtpUrl(chrome::kTestNewTabURL);
322 NavigationEntry ntp_entry(NULL /* instance */, -1 /* page_id */, kNtpUrl, 326 NavigationEntry ntp_entry(NULL /* instance */, -1 /* page_id */, kNtpUrl,
323 GURL() /* referrer */, string16() /* title */, 327 GURL() /* referrer */, string16() /* title */,
324 content::PAGE_TRANSITION_TYPED, 328 content::PAGE_TRANSITION_TYPED,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 // current one. 380 // current one.
377 EXPECT_TRUE(contents()->render_manager_for_testing()-> 381 EXPECT_TRUE(contents()->render_manager_for_testing()->
378 pending_render_view_host() == NULL); 382 pending_render_view_host() == NULL);
379 EXPECT_EQ(evil_rvh, contents()->render_manager_for_testing()->current_host()); 383 EXPECT_EQ(evil_rvh, contents()->render_manager_for_testing()->current_host());
380 384
381 // Also we should not have a pending navigation entry. 385 // Also we should not have a pending navigation entry.
382 NavigationEntry* entry = contents()->controller().GetActiveEntry(); 386 NavigationEntry* entry = contents()->controller().GetActiveEntry();
383 ASSERT_TRUE(entry != NULL); 387 ASSERT_TRUE(entry != NULL);
384 EXPECT_EQ(kUrl2, entry->url()); 388 EXPECT_EQ(kUrl2, entry->url());
385 } 389 }
OLDNEW
« no previous file with comments | « content/browser/tab_contents/interstitial_page.cc ('k') | content/browser/tab_contents/web_drag_source_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698