Chromium Code Reviews| Index: content/browser/renderer_host/render_process_host_browsertest.cc |
| diff --git a/content/browser/renderer_host/render_process_host_browsertest.cc b/content/browser/renderer_host/render_process_host_browsertest.cc |
| index 3d25b02834d8cbe17bed33e4b9b261f54214e6ba..4094369a24f6628a5546466b2a387adc563df62a 100644 |
| --- a/content/browser/renderer_host/render_process_host_browsertest.cc |
| +++ b/content/browser/renderer_host/render_process_host_browsertest.cc |
| @@ -5,11 +5,13 @@ |
| #include "content/browser/renderer_host/render_process_host_browsertest.h" |
| #include "base/command_line.h" |
| +#include "base/process.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/test/base/ui_test_utils.h" |
| #include "content/browser/renderer_host/render_process_host_impl.h" |
| #include "content/browser/tab_contents/tab_contents.h" |
| #include "content/common/test_url_constants.h" |
| +#include "content/public/browser/browser_thread.h" |
| #include "content/public/common/content_switches.h" |
| RenderProcessHostTest::RenderProcessHostTest() { |
| @@ -28,6 +30,24 @@ int RenderProcessHostTest::RenderProcessHostCount() { |
| return count; |
| } |
| +void PostQuit(MessageLoop* loop) { |
| + loop->PostTask(FROM_HERE, new MessageLoop::QuitTask); |
| +} |
| + |
| +base::ProcessHandle RenderProcessHostTest::ShowSingletonTab(GURL page) { |
| + browser()->ShowSingletonTab(page); |
| + TabContents* tc = browser()->GetSelectedTabContents(); |
| + CHECK(tc->GetURL() == page); |
| + |
| + // Ensure that the backgrounding / forgrounding gets a chance to run. |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
| + NewRunnableFunction(&PostQuit, MessageLoop::current())); |
|
willchan no longer on Chromium
2011/11/29 22:23:35
I'd use
content::BrowserThread::PostTaskAndReply(
|
| + MessageLoop::current()->Run(); |
| + |
| + return tc->GetRenderProcessHost()->GetHandle(); |
| +} |
| + |
| IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) { |
| // Set max renderers to 1 to force running out of processes. |
| content::RenderProcessHost::SetMaxRendererProcessCountForTest(1); |
| @@ -84,6 +104,42 @@ IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) { |
| EXPECT_EQ(host_count, RenderProcessHostCount()); |
| } |
| +// We don't change process priorities on Mac or Posix because the user lacks the |
| +// permission to raise a process' priority even after lowering it. |
| +#if defined(OS_WIN) || defined(OS_LINUX) |
| +IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, Backgrounding) { |
| + if (!base::Process::CanBackgroundProcesses()) { |
| + LOG(ERROR) << "Can't background processes"; |
| + return; |
| + } |
| + CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
| + parsed_command_line.AppendSwitch(switches::kProcessPerTab); |
| + |
| + // Change the first tab to be the new tab page (TYPE_WEBUI). |
| + GURL newtab(chrome::kTestNewTabURL); |
| + ui_test_utils::NavigateToURL(browser(), newtab); |
| + |
| + // Create a new tab. It should be foreground. |
| + GURL page1("data:text/html,hello world1"); |
| + base::ProcessHandle pid1 = ShowSingletonTab(page1); |
| + EXPECT_FALSE(base::Process(pid1).IsProcessBackgrounded()); |
| + |
| + // Create another tab. It should be foreground, and the first tab should |
| + // now be background. |
| + GURL page2("data:text/html,hello world2"); |
| + base::ProcessHandle pid2 = ShowSingletonTab(page2); |
| + EXPECT_NE(pid1, pid2); |
| + EXPECT_TRUE(base::Process(pid1).IsProcessBackgrounded()); |
| + EXPECT_FALSE(base::Process(pid2).IsProcessBackgrounded()); |
| + |
| + // Navigate back to first page. It should be foreground again, and the second |
| + // tab should be background. |
| + EXPECT_EQ(pid1, ShowSingletonTab(page1)); |
| + EXPECT_FALSE(base::Process(pid1).IsProcessBackgrounded()); |
| + EXPECT_TRUE(base::Process(pid2).IsProcessBackgrounded()); |
| +} |
| +#endif |
| + |
| // When we hit the max number of renderers, verify that the way we do process |
| // sharing behaves correctly. In particular, this test is verifying that even |
| // when we hit the max process limit, that renderers of each type will wind up |