Commit 7d3eb016 authored by Wez's avatar Wez Committed by Commit Bot

Update LayoutTestBrowserMain and BlinkTestController loop quit logic.

Migrate the LayoutTestBrowserMain and BlinkTestController classes to use
the quit closure registered with the content::Shell by the default main
message loop, to exit it, rather than QuitCurrent*Deprecated().

Bug: 844016
Change-Id: I0b7e8249df6ed62757e5bb27c51dd16b35e0e4a6
Reviewed-on: https://chromium-review.googlesource.com/1106814Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Commit-Queue: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569063}
parent fb034084
...@@ -824,9 +824,8 @@ void BlinkTestController::DiscardMainWindow() { ...@@ -824,9 +824,8 @@ void BlinkTestController::DiscardMainWindow() {
devtools_protocol_test_bindings_.reset(); devtools_protocol_test_bindings_.reset();
WebContentsObserver::Observe(nullptr); WebContentsObserver::Observe(nullptr);
if (test_phase_ != BETWEEN_TESTS) { if (test_phase_ != BETWEEN_TESTS) {
// CloseAllWindows will also signal the main message loop to exit.
Shell::CloseAllWindows(); Shell::CloseAllWindows();
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::RunLoop::QuitCurrentWhenIdleClosureDeprecated());
test_phase_ = CLEAN_UP; test_phase_ = CLEAN_UP;
} else if (main_window_) { } else if (main_window_) {
main_window_->Close(); main_window_->Close();
...@@ -1192,14 +1191,14 @@ void BlinkTestController::OnResetDone() { ...@@ -1192,14 +1191,14 @@ void BlinkTestController::OnResetDone() {
} }
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::RunLoop::QuitCurrentWhenIdleClosureDeprecated()); FROM_HERE, base::BindOnce(&Shell::QuitMainMessageLoopForTesting));
} }
void BlinkTestController::OnLeakDetectionDone( void BlinkTestController::OnLeakDetectionDone(
const LeakDetector::LeakDetectionReport& report) { const LeakDetector::LeakDetectionReport& report) {
if (!report.leaked) { if (!report.leaked) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::RunLoop::QuitCurrentWhenIdleClosureDeprecated()); FROM_HERE, base::BindOnce(&Shell::QuitMainMessageLoopForTesting));
return; return;
} }
......
...@@ -98,8 +98,9 @@ int RunTests(const std::unique_ptr<content::BrowserMainRunner>& main_runner) { ...@@ -98,8 +98,9 @@ int RunTests(const std::unique_ptr<content::BrowserMainRunner>& main_runner) {
} }
} }
if (!ran_at_least_once) { if (!ran_at_least_once) {
// CloseAllWindows will cause the |main_runner| loop to quit.
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::RunLoop::QuitCurrentWhenIdleClosureDeprecated()); FROM_HERE, base::BindOnce(&content::Shell::CloseAllWindows));
main_runner->Run(); main_runner->Run();
} }
...@@ -149,9 +150,8 @@ int LayoutTestBrowserMain( ...@@ -149,9 +150,8 @@ int LayoutTestBrowserMain(
if (base::CommandLine::ForCurrentProcess()->HasSwitch( if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kCheckLayoutTestSysDeps)) { switches::kCheckLayoutTestSysDeps)) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::RunLoop::QuitCurrentWhenIdleClosureDeprecated()); FROM_HERE, base::BindOnce(&content::Shell::CloseAllWindows));
main_runner->Run(); main_runner->Run();
content::Shell::CloseAllWindows();
main_runner->Shutdown(); main_runner->Shutdown();
return 0; return 0;
} }
......
...@@ -174,6 +174,11 @@ void Shell::CloseAllWindows() { ...@@ -174,6 +174,11 @@ void Shell::CloseAllWindows() {
// Pump the message loop to allow window teardown tasks to run. // Pump the message loop to allow window teardown tasks to run.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// If there were no windows open then the message loop quit closure will
// not have been run.
if (*g_quit_main_message_loop)
std::move(*g_quit_main_message_loop).Run();
PlatformExit(); PlatformExit();
} }
...@@ -181,6 +186,10 @@ void Shell::SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure) { ...@@ -181,6 +186,10 @@ void Shell::SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure) {
*g_quit_main_message_loop = std::move(quit_closure); *g_quit_main_message_loop = std::move(quit_closure);
} }
void Shell::QuitMainMessageLoopForTesting() {
std::move(*g_quit_main_message_loop).Run();
}
void Shell::SetShellCreatedCallback( void Shell::SetShellCreatedCallback(
base::Callback<void(Shell*)> shell_created_callback) { base::Callback<void(Shell*)> shell_created_callback) {
DCHECK(shell_created_callback_.is_null()); DCHECK(shell_created_callback_.is_null());
......
...@@ -113,13 +113,19 @@ class Shell : public WebContentsDelegate, ...@@ -113,13 +113,19 @@ class Shell : public WebContentsDelegate,
// Returns the currently open windows. // Returns the currently open windows.
static std::vector<Shell*>& windows() { return windows_; } static std::vector<Shell*>& windows() { return windows_; }
// Closes all windows and returns. // Closes all windows, pumps teardown tasks, then returns. The main message
// loop will be signalled to quit, before the call returns.
static void CloseAllWindows(); static void CloseAllWindows();
// Stores the supplied |quit_closure|, to be run when the last Shell instance // Stores the supplied |quit_closure|, to be run when the last Shell instance
// is destroyed. // is destroyed.
static void SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure); static void SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure);
// Used by the BlinkTestController to stop the message loop before closing all
// windows, for specific tests. Fails if called after the message loop has
// already been signalled to quit.
static void QuitMainMessageLoopForTesting();
// Used for content_browsertests. Called once. // Used for content_browsertests. Called once.
static void SetShellCreatedCallback( static void SetShellCreatedCallback(
base::Callback<void(Shell*)> shell_created_callback); base::Callback<void(Shell*)> shell_created_callback);
......
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