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

Side by Side Diff: content/browser/renderer_host/render_process_host_browsertest.cc

Issue 9015022: Replace most of Browser::GetSelectedTabContents calls into Browser::GetSelectedWebContents. I've ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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 "content/browser/renderer_host/render_process_host_browsertest.h" 5 #include "content/browser/renderer_host/render_process_host_browsertest.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/process.h" 9 #include "base/process.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/test/base/ui_test_utils.h" 11 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/browser/renderer_host/render_process_host_impl.h" 12 #include "content/browser/renderer_host/render_process_host_impl.h"
13 #include "content/browser/tab_contents/tab_contents.h" 13 #include "content/browser/tab_contents/tab_contents.h"
14 #include "content/common/test_url_constants.h" 14 #include "content/common/test_url_constants.h"
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/common/content_switches.h" 16 #include "content/public/common/content_switches.h"
17 17
18 using content::WebContents;
19
18 RenderProcessHostTest::RenderProcessHostTest() { 20 RenderProcessHostTest::RenderProcessHostTest() {
19 EnableDOMAutomation(); 21 EnableDOMAutomation();
20 } 22 }
21 23
22 int RenderProcessHostTest::RenderProcessHostCount() { 24 int RenderProcessHostTest::RenderProcessHostCount() {
23 content::RenderProcessHost::iterator hosts = 25 content::RenderProcessHost::iterator hosts =
24 content::RenderProcessHost::AllHostsIterator(); 26 content::RenderProcessHost::AllHostsIterator();
25 int count = 0; 27 int count = 0;
26 while (!hosts.IsAtEnd()) { 28 while (!hosts.IsAtEnd()) {
27 if (hosts.GetCurrentValue()->HasConnection()) 29 if (hosts.GetCurrentValue()->HasConnection())
28 count++; 30 count++;
29 hosts.Advance(); 31 hosts.Advance();
30 } 32 }
31 return count; 33 return count;
32 } 34 }
33 35
34 void PostQuit(MessageLoop* loop) { 36 void PostQuit(MessageLoop* loop) {
35 loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 37 loop->PostTask(FROM_HERE, MessageLoop::QuitClosure());
36 } 38 }
37 39
38 void DoNothing() {} 40 void DoNothing() {}
39 41
40 // Show a tab, activating the current one if there is one, and wait for 42 // Show a tab, activating the current one if there is one, and wait for
41 // the renderer process to be created or foregrounded, returning the process 43 // the renderer process to be created or foregrounded, returning the process
42 // handle. 44 // handle.
43 base::ProcessHandle RenderProcessHostTest::ShowSingletonTab(const GURL& page) { 45 base::ProcessHandle RenderProcessHostTest::ShowSingletonTab(const GURL& page) {
44 browser()->ShowSingletonTab(page); 46 browser()->ShowSingletonTab(page);
45 TabContents* tc = browser()->GetSelectedTabContents(); 47 WebContents* wc = browser()->GetSelectedWebContents();
46 CHECK(tc->GetURL() == page); 48 CHECK(wc->GetURL() == page);
47 49
48 // Ensure that the backgrounding / foregrounding gets a chance to run. 50 // Ensure that the backgrounding / foregrounding gets a chance to run.
49 content::BrowserThread::PostTaskAndReply( 51 content::BrowserThread::PostTaskAndReply(
50 content::BrowserThread::PROCESS_LAUNCHER, FROM_HERE, 52 content::BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
51 base::Bind(DoNothing), MessageLoop::QuitClosure()); 53 base::Bind(DoNothing), MessageLoop::QuitClosure());
52 MessageLoop::current()->Run(); 54 MessageLoop::current()->Run();
53 55
54 return tc->GetRenderProcessHost()->GetHandle(); 56 return wc->GetRenderProcessHost()->GetHandle();
55 } 57 }
56 58
57 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) { 59 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) {
58 // Set max renderers to 1 to force running out of processes. 60 // Set max renderers to 1 to force running out of processes.
59 content::RenderProcessHost::SetMaxRendererProcessCountForTest(1); 61 content::RenderProcessHost::SetMaxRendererProcessCountForTest(1);
60 62
61 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 63 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
62 parsed_command_line.AppendSwitch(switches::kProcessPerTab); 64 parsed_command_line.AppendSwitch(switches::kProcessPerTab);
63 65
64 int tab_count = 1; 66 int tab_count = 1;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 host_count++; 231 host_count++;
230 #endif 232 #endif
231 EXPECT_EQ(tab_count, browser()->tab_count()); 233 EXPECT_EQ(tab_count, browser()->tab_count());
232 tab1 = browser()->GetTabContentsAt(tab_count - 1); 234 tab1 = browser()->GetTabContentsAt(tab_count - 1);
233 rph3 = tab1->GetRenderProcessHost(); 235 rph3 = tab1->GetRenderProcessHost();
234 EXPECT_EQ(tab1->GetURL(), bookmarks); 236 EXPECT_EQ(tab1->GetURL(), bookmarks);
235 EXPECT_EQ(host_count, RenderProcessHostCount()); 237 EXPECT_EQ(host_count, RenderProcessHostCount());
236 EXPECT_NE(rph1, rph3); 238 EXPECT_NE(rph1, rph3);
237 EXPECT_NE(rph2, rph3); 239 EXPECT_NE(rph2, rph3);
238 } 240 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698