Fix renderer process host backgrounding test on Windows.

Now that process backgrounding is controlled from within the renderer
process on Windows, we need to wait for the process to handle the IPC
message before the background state changes.

This fix changes the test to wait for the result of a script from
the renderer process before checking background status.  Doing so
ensures the renderer will process the background IPC before the
check is performed.

BUG=362294
TEST=Ran unittest on Windows.

Review URL: https://codereview.chromium.org/305373004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274778 0039d316-1c4b-4281-b951-d872f2087c98
parent 66a1b7cf
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "content/public/browser/render_widget_host_iterator.h" #include "content/public/browser/render_widget_host_iterator.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "content/public/test/browser_test_utils.h"
using content::RenderViewHost; using content::RenderViewHost;
using content::RenderWidgetHost; using content::RenderWidgetHost;
...@@ -72,6 +73,7 @@ class ChromeRenderProcessHostTest : public InProcessBrowserTest { ...@@ -72,6 +73,7 @@ class ChromeRenderProcessHostTest : public InProcessBrowserTest {
CHECK(wc->GetURL() == page); CHECK(wc->GetURL() == page);
WaitForLauncherThread(); WaitForLauncherThread();
WaitForMessageProcessing(wc);
return wc->GetRenderProcessHost()->GetHandle(); return wc->GetRenderProcessHost()->GetHandle();
} }
...@@ -87,6 +89,7 @@ class ChromeRenderProcessHostTest : public InProcessBrowserTest { ...@@ -87,6 +89,7 @@ class ChromeRenderProcessHostTest : public InProcessBrowserTest {
CHECK(wc->GetVisibleURL() == page); CHECK(wc->GetVisibleURL() == page);
WaitForLauncherThread(); WaitForLauncherThread();
WaitForMessageProcessing(wc);
return wc->GetRenderProcessHost()->GetHandle(); return wc->GetRenderProcessHost()->GetHandle();
} }
...@@ -98,6 +101,16 @@ class ChromeRenderProcessHostTest : public InProcessBrowserTest { ...@@ -98,6 +101,16 @@ class ChromeRenderProcessHostTest : public InProcessBrowserTest {
base::MessageLoop::current()->Run(); base::MessageLoop::current()->Run();
} }
// Implicitly waits for the renderer process associated with the specified
// WebContents to process outstanding IPC messages by running some JavaScript
// and waiting for the result.
void WaitForMessageProcessing(WebContents* wc) {
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
wc, "window.domAutomationController.send(true);", &result));
ASSERT_TRUE(result);
}
// When we hit the max number of renderers, verify that the way we do process // 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 // 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 // when we hit the max process limit, that renderers of each type will wind up
...@@ -252,9 +265,7 @@ IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, ProcessPerTab) { ...@@ -252,9 +265,7 @@ IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, ProcessPerTab) {
// We don't change process priorities on Mac or Posix because the user lacks the // 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. // permission to raise a process' priority even after lowering it.
// TODO(dalecurtis): Reenable this on Windows after figuring out how to reliably #if defined(OS_WIN) || defined(OS_LINUX)
// wait for the renderer process to process IPC messages.
#if defined(OS_LINUX)
IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, Backgrounding) { IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, Backgrounding) {
if (!base::Process::CanBackgroundProcesses()) { if (!base::Process::CanBackgroundProcesses()) {
LOG(ERROR) << "Can't background processes"; LOG(ERROR) << "Can't background processes";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment