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

Unified Diff: chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc

Issue 2454073003: Allow backgrounding processes on Mac (Closed)
Patch Set: Remove unnecessary forward declare Created 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc
diff --git a/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc b/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc
index 55131068ee774bee6c14168147d234e82217ca95..018553eba2efe0c403aaad367104f7ff1d84e075 100644
--- a/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc
+++ b/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc
@@ -32,6 +32,11 @@
#include "net/base/filename_util.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
+#if defined(OS_MACOSX)
+#include "content/public/browser/browser_child_process_host.h"
+#include "content/public/common/content_features.h"
+#endif // defined(OS_MACOSX)
+
using content::RenderViewHost;
using content::RenderWidgetHost;
using content::WebContents;
@@ -296,14 +301,21 @@ IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, MAYBE_ProcessPerTab) {
EXPECT_EQ(host_count, RenderProcessHostCount());
}
-// We don't change process priorities on Mac or Posix because the user lacks the
+// We don't change process priorities on Posix because the user lacks the
// permission to raise a process' priority even after lowering it.
-#if defined(OS_WIN) || defined(OS_LINUX)
+#if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX)
IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, Backgrounding) {
if (!base::Process::CanBackgroundProcesses()) {
LOG(ERROR) << "Can't background processes";
return;
}
+#if defined(OS_MACOSX)
+ if (!base::FeatureList::IsEnabled(features::kMacBackgroundInactiveTabs))
+ return;
+ base::PortProvider* port_provider =
+ content::BrowserChildProcessHost::GetPortProvider();
+#endif // defined(OS_MACOSX)
+
base::CommandLine& parsed_command_line =
*base::CommandLine::ForCurrentProcess();
parsed_command_line.AppendSwitch(switches::kProcessPerTab);
@@ -316,7 +328,11 @@ IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, Backgrounding) {
GURL page1("data:text/html,hello world1");
base::Process process1 = ShowSingletonTab(page1);
ASSERT_TRUE(process1.IsValid());
+#if defined(OS_MACOSX)
+ EXPECT_FALSE(process1.IsProcessBackgrounded(port_provider));
+#else
EXPECT_FALSE(process1.IsProcessBackgrounded());
+#endif
// Create another tab. It should be foreground, and the first tab should
// now be background.
@@ -324,8 +340,13 @@ IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, Backgrounding) {
base::Process process2 = ShowSingletonTab(page2);
ASSERT_TRUE(process2.IsValid());
EXPECT_NE(process1.Pid(), process2.Pid());
+#if defined(OS_MACOSX)
+ EXPECT_TRUE(process1.IsProcessBackgrounded(port_provider));
+ EXPECT_FALSE(process2.IsProcessBackgrounded(port_provider));
+#else
EXPECT_TRUE(process1.IsProcessBackgrounded());
EXPECT_FALSE(process2.IsProcessBackgrounded());
+#endif // defined(OS_MACOSX)
// Load another tab in background. The renderer of the new tab should be
// backgrounded, while visibility of the other renderers should not change.
@@ -334,6 +355,32 @@ IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, Backgrounding) {
ASSERT_TRUE(process3.IsValid());
EXPECT_NE(process3.Pid(), process1.Pid());
EXPECT_NE(process3.Pid(), process2.Pid());
+#if defined(OS_MACOSX)
+ EXPECT_TRUE(process1.IsProcessBackgrounded(port_provider));
+ EXPECT_FALSE(process2.IsProcessBackgrounded(port_provider));
+ // TODO(gab): The new background tab should be backgrounded but it currently
+ // intentionally isn't per a workaround to https://crbug.com/560446 in
+ // RenderProcessHostImpl::OnProcessLaunched().
+ EXPECT_FALSE(process3.IsProcessBackgrounded(port_provider));
+
+ // Navigate back to the first page. Its renderer should be in foreground
+ // again while the other renderers should be backgrounded.
+
+ EXPECT_EQ(process1.Pid(), ShowSingletonTab(page1).Pid());
+ EXPECT_FALSE(process1.IsProcessBackgrounded(port_provider));
+ EXPECT_TRUE(process2.IsProcessBackgrounded(port_provider));
+ // TODO(gab): Same as above.
+ EXPECT_FALSE(process3.IsProcessBackgrounded(port_provider));
+
+ // TODO(gab): Remove this when https://crbug.com/560446 is fixed, but for now
+ // confirm that the correct state is at least achieved when tab #3 is
+ // explicitly foregrounded and re-backgrounded.
+ EXPECT_EQ(process3.Pid(), ShowSingletonTab(page3).Pid());
+ EXPECT_EQ(process1.Pid(), ShowSingletonTab(page1).Pid());
+ EXPECT_FALSE(process1.IsProcessBackgrounded(port_provider));
+ EXPECT_TRUE(process2.IsProcessBackgrounded(port_provider));
+ EXPECT_TRUE(process3.IsProcessBackgrounded(port_provider));
+#else
EXPECT_TRUE(process1.IsProcessBackgrounded());
EXPECT_FALSE(process2.IsProcessBackgrounded());
// TODO(gab): The new background tab should be backgrounded but it currently
@@ -343,6 +390,7 @@ IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, Backgrounding) {
// Navigate back to the first page. Its renderer should be in foreground
// again while the other renderers should be backgrounded.
+
EXPECT_EQ(process1.Pid(), ShowSingletonTab(page1).Pid());
EXPECT_FALSE(process1.IsProcessBackgrounded());
EXPECT_TRUE(process2.IsProcessBackgrounded());
@@ -357,6 +405,7 @@ IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, Backgrounding) {
EXPECT_FALSE(process1.IsProcessBackgrounded());
EXPECT_TRUE(process2.IsProcessBackgrounded());
EXPECT_TRUE(process3.IsProcessBackgrounded());
+#endif
}
#endif
@@ -599,16 +648,31 @@ IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostBackgroundingTest,
if (!base::Process::CanBackgroundProcesses())
return;
+#if defined(OS_MACOSX)
+ if (!base::FeatureList::IsEnabled(features::kMacBackgroundInactiveTabs))
+ return;
+#endif
+
ShowSingletonTab(audio_url_);
// Wait until the no audio page is backgrounded and the audio page is not
// backgrounded.
+#if defined(OS_MACOSX)
+ base::PortProvider* port_provider =
+ content::BrowserChildProcessHost::GetPortProvider();
+ DLOG(ERROR) << "Port provider " << (port_provider != nullptr);
Robert Sesek 2016/10/31 18:45:39 Remove.
lgrey 2016/10/31 19:22:01 Whoops! Done
+ while (!no_audio_process_.IsProcessBackgrounded(port_provider) ||
+ audio_process_.IsProcessBackgrounded(port_provider)) {
+ base::RunLoop().RunUntilIdle();
+ base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
+ }
+#else
while (!no_audio_process_.IsProcessBackgrounded() ||
audio_process_.IsProcessBackgrounded()) {
base::RunLoop().RunUntilIdle();
base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
}
-
+#endif // defined(OS_MACOSX)
// Pause the audio and immediately switch to the no audio tab.
ASSERT_TRUE(content::ExecuteScript(
audio_tab_web_contents_,
@@ -617,11 +681,19 @@ IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostBackgroundingTest,
// Wait until the no audio page is not backgrounded and the audio page is
// backgrounded.
+#if defined(OS_MACOSX)
+ while (no_audio_process_.IsProcessBackgrounded(port_provider) ||
+ !audio_process_.IsProcessBackgrounded(port_provider)) {
+ base::RunLoop().RunUntilIdle();
+ base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
+ }
+#else
while (no_audio_process_.IsProcessBackgrounded() ||
!audio_process_.IsProcessBackgrounded()) {
base::RunLoop().RunUntilIdle();
base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
}
+#endif // defined(OS_MACOSX)
}
// Test to make sure that a process is backgrounded automatically when audio
@@ -632,57 +704,102 @@ IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostBackgroundingTest,
if (!base::Process::CanBackgroundProcesses())
return;
- // Wait until the two pages are not backgrounded.
+#if defined(OS_MACOSX)
+ if (!base::FeatureList::IsEnabled(features::kMacBackgroundInactiveTabs))
+ return;
+#endif
+
+// Wait until the two pages are not backgrounded.
+#if defined(OS_MACOSX)
+ base::PortProvider* port_provider =
+ content::BrowserChildProcessHost::GetPortProvider();
+ while (no_audio_process_.IsProcessBackgrounded(port_provider) ||
+ audio_process_.IsProcessBackgrounded(port_provider)) {
+ base::RunLoop().RunUntilIdle();
+ base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
+ }
+#else
while (no_audio_process_.IsProcessBackgrounded() ||
audio_process_.IsProcessBackgrounded()) {
base::RunLoop().RunUntilIdle();
base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
}
+#endif // defined(OS_MACOSX)
// Stop the audio.
ASSERT_TRUE(content::ExecuteScript(
audio_tab_web_contents_,
"document.getElementById('audioPlayer').pause();"));
- // Wait until the no audio page is not backgrounded and the audio page is
- // backgrounded.
+// Wait until the no audio page is not backgrounded and the audio page is
+// backgrounded.
+#if defined(OS_MACOSX)
+ while (no_audio_process_.IsProcessBackgrounded(port_provider) ||
+ !audio_process_.IsProcessBackgrounded(port_provider)) {
+ base::RunLoop().RunUntilIdle();
+ base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
+ }
+#else
while (no_audio_process_.IsProcessBackgrounded() ||
!audio_process_.IsProcessBackgrounded()) {
base::RunLoop().RunUntilIdle();
base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
}
+#endif // defined(OS_MACOSX)
}
-// Test to make sure that a process is un-backgrounded automatically when audio
+// Test to make sure that a process is un-backgrounded automatically when
+// audio
// starts playing from a backgrounded tab.
IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostBackgroundingTest,
ProcessPriorityAfterAudioStartsFromBackgroundTab) {
// This test is invalid on platforms that can't background.
if (!base::Process::CanBackgroundProcesses())
return;
+#if defined(OS_MACOSX)
+ if (!base::FeatureList::IsEnabled(features::kMacBackgroundInactiveTabs))
+ return;
+#endif
// Stop the audio.
ASSERT_TRUE(content::ExecuteScript(
audio_tab_web_contents_,
"document.getElementById('audioPlayer').pause();"));
- // Wait until the no audio page is not backgrounded and the audio page is
- // backgrounded.
+#if defined(OS_MACOSX)
+ base::PortProvider* port_provider =
+ content::BrowserChildProcessHost::GetPortProvider();
+ while (no_audio_process_.IsProcessBackgrounded(port_provider) ||
+ !audio_process_.IsProcessBackgrounded(port_provider)) {
+ base::RunLoop().RunUntilIdle();
+ base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
+ }
+#else
while (no_audio_process_.IsProcessBackgrounded() ||
!audio_process_.IsProcessBackgrounded()) {
base::RunLoop().RunUntilIdle();
base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
}
+#endif // defined(OS_MACOSX)
// Start the audio from the backgrounded tab.
ASSERT_TRUE(
content::ExecuteScript(audio_tab_web_contents_,
"document.getElementById('audioPlayer').play();"));
- // Wait until the two pages are not backgrounded.
+// Wait until the two pages are not backgrounded.
+// Wait until the two pages are not backgrounded.
Robert Sesek 2016/10/31 18:45:39 Duplicate comment.
lgrey 2016/10/31 19:22:02 Done.
+#if defined(OS_MACOSX)
+ while (no_audio_process_.IsProcessBackgrounded(port_provider) ||
+ audio_process_.IsProcessBackgrounded(port_provider)) {
+ base::RunLoop().RunUntilIdle();
+ base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
+ }
+#else
while (no_audio_process_.IsProcessBackgrounded() ||
audio_process_.IsProcessBackgrounded()) {
base::RunLoop().RunUntilIdle();
base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
}
+#endif // defined(OS_MACOSX)
}

Powered by Google App Engine
This is Rietveld 408576698