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

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

Issue 8506036: Fix tab backgrounding on Linux / ChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated license Created 9 years 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
« no previous file with comments | « content/browser/renderer_host/render_process_host_browsertest.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/process.h"
8 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
9 #include "chrome/test/base/ui_test_utils.h" 11 #include "chrome/test/base/ui_test_utils.h"
10 #include "content/browser/renderer_host/render_process_host_impl.h" 12 #include "content/browser/renderer_host/render_process_host_impl.h"
11 #include "content/browser/tab_contents/tab_contents.h" 13 #include "content/browser/tab_contents/tab_contents.h"
12 #include "content/common/test_url_constants.h" 14 #include "content/common/test_url_constants.h"
15 #include "content/public/browser/browser_thread.h"
13 #include "content/public/common/content_switches.h" 16 #include "content/public/common/content_switches.h"
14 17
15 RenderProcessHostTest::RenderProcessHostTest() { 18 RenderProcessHostTest::RenderProcessHostTest() {
16 EnableDOMAutomation(); 19 EnableDOMAutomation();
17 } 20 }
18 21
19 int RenderProcessHostTest::RenderProcessHostCount() { 22 int RenderProcessHostTest::RenderProcessHostCount() {
20 content::RenderProcessHost::iterator hosts = 23 content::RenderProcessHost::iterator hosts =
21 content::RenderProcessHost::AllHostsIterator(); 24 content::RenderProcessHost::AllHostsIterator();
22 int count = 0; 25 int count = 0;
23 while (!hosts.IsAtEnd()) { 26 while (!hosts.IsAtEnd()) {
24 if (hosts.GetCurrentValue()->HasConnection()) 27 if (hosts.GetCurrentValue()->HasConnection())
25 count++; 28 count++;
26 hosts.Advance(); 29 hosts.Advance();
27 } 30 }
28 return count; 31 return count;
29 } 32 }
30 33
34 void PostQuit(MessageLoop* loop) {
35 loop->PostTask(FROM_HERE, new MessageLoop::QuitTask);
36 }
37
38 void DoNothing() {}
39
40 // 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
42 // handle.
43 base::ProcessHandle RenderProcessHostTest::ShowSingletonTab(const GURL& page) {
44 browser()->ShowSingletonTab(page);
45 TabContents* tc = browser()->GetSelectedTabContents();
46 CHECK(tc->GetURL() == page);
47
48 // Ensure that the backgrounding / foregrounding gets a chance to run.
49 content::BrowserThread::PostTaskAndReply(
50 content::BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
51 base::Bind(DoNothing), MessageLoop::QuitClosure());
52 MessageLoop::current()->Run();
53
54 return tc->GetRenderProcessHost()->GetHandle();
55 }
56
31 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) { 57 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) {
32 // Set max renderers to 1 to force running out of processes. 58 // Set max renderers to 1 to force running out of processes.
33 content::RenderProcessHost::SetMaxRendererProcessCountForTest(1); 59 content::RenderProcessHost::SetMaxRendererProcessCountForTest(1);
34 60
35 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 61 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
36 parsed_command_line.AppendSwitch(switches::kProcessPerTab); 62 parsed_command_line.AppendSwitch(switches::kProcessPerTab);
37 63
38 int tab_count = 1; 64 int tab_count = 1;
39 int host_count = 1; 65 int host_count = 1;
40 66
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 103
78 // Create another new tab. It should share the process with the other WebUI. 104 // Create another new tab. It should share the process with the other WebUI.
79 browser()->NewTab(); 105 browser()->NewTab();
80 if (browser()->tab_count() == tab_count) 106 if (browser()->tab_count() == tab_count)
81 ui_test_utils::WaitForNewTab(browser()); 107 ui_test_utils::WaitForNewTab(browser());
82 tab_count++; 108 tab_count++;
83 EXPECT_EQ(tab_count, browser()->tab_count()); 109 EXPECT_EQ(tab_count, browser()->tab_count());
84 EXPECT_EQ(host_count, RenderProcessHostCount()); 110 EXPECT_EQ(host_count, RenderProcessHostCount());
85 } 111 }
86 112
113 // We don't change process priorities on Mac or Posix because the user lacks the
114 // permission to raise a process' priority even after lowering it.
115 #if defined(OS_WIN) || defined(OS_LINUX)
116 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, Backgrounding) {
117 if (!base::Process::CanBackgroundProcesses()) {
118 LOG(ERROR) << "Can't background processes";
119 return;
120 }
121 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
122 parsed_command_line.AppendSwitch(switches::kProcessPerTab);
123
124 // Change the first tab to be the new tab page (TYPE_WEBUI).
125 GURL newtab(chrome::kTestNewTabURL);
126 ui_test_utils::NavigateToURL(browser(), newtab);
127
128 // Create a new tab. It should be foreground.
129 GURL page1("data:text/html,hello world1");
130 base::ProcessHandle pid1 = ShowSingletonTab(page1);
131 EXPECT_FALSE(base::Process(pid1).IsProcessBackgrounded());
132
133 // Create another tab. It should be foreground, and the first tab should
134 // now be background.
135 GURL page2("data:text/html,hello world2");
136 base::ProcessHandle pid2 = ShowSingletonTab(page2);
137 EXPECT_NE(pid1, pid2);
138 EXPECT_TRUE(base::Process(pid1).IsProcessBackgrounded());
139 EXPECT_FALSE(base::Process(pid2).IsProcessBackgrounded());
140
141 // Navigate back to first page. It should be foreground again, and the second
142 // tab should be background.
143 EXPECT_EQ(pid1, ShowSingletonTab(page1));
144 EXPECT_FALSE(base::Process(pid1).IsProcessBackgrounded());
145 EXPECT_TRUE(base::Process(pid2).IsProcessBackgrounded());
146 }
147 #endif
148
87 // When we hit the max number of renderers, verify that the way we do process 149 // When we hit the max number of renderers, verify that the way we do process
88 // sharing behaves correctly. In particular, this test is verifying that even 150 // sharing behaves correctly. In particular, this test is verifying that even
89 // when we hit the max process limit, that renderers of each type will wind up 151 // when we hit the max process limit, that renderers of each type will wind up
90 // in a process of that type, even if that means creating a new process. 152 // in a process of that type, even if that means creating a new process.
91 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessOverflow) { 153 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessOverflow) {
92 // Set max renderers to 1 to force running out of processes. 154 // Set max renderers to 1 to force running out of processes.
93 content::RenderProcessHost::SetMaxRendererProcessCountForTest(1); 155 content::RenderProcessHost::SetMaxRendererProcessCountForTest(1);
94 156
95 int tab_count = 1; 157 int tab_count = 1;
96 int host_count = 1; 158 int host_count = 1;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 host_count++; 229 host_count++;
168 #endif 230 #endif
169 EXPECT_EQ(tab_count, browser()->tab_count()); 231 EXPECT_EQ(tab_count, browser()->tab_count());
170 tab1 = browser()->GetTabContentsAt(tab_count - 1); 232 tab1 = browser()->GetTabContentsAt(tab_count - 1);
171 rph3 = tab1->GetRenderProcessHost(); 233 rph3 = tab1->GetRenderProcessHost();
172 EXPECT_EQ(tab1->GetURL(), bookmarks); 234 EXPECT_EQ(tab1->GetURL(), bookmarks);
173 EXPECT_EQ(host_count, RenderProcessHostCount()); 235 EXPECT_EQ(host_count, RenderProcessHostCount());
174 EXPECT_NE(rph1, rph3); 236 EXPECT_NE(rph1, rph3);
175 EXPECT_NE(rph2, rph3); 237 EXPECT_NE(rph2, rph3);
176 } 238 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host_browsertest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698