Commit cd96c509 authored by Ilia Samsonov's avatar Ilia Samsonov Committed by Commit Bot

Removed unused code [TestState, OnLaunch]

This CL removes unused code, and does not change the
TestLauncher behavior.

This code was introduced here https://codereview.chromium.org/1806353003
to allow launching unit tests in Mash.

The Mash tests launcher no longer exist, and no other implementation of
PreRunTest exist.

Bug: 936248
Change-Id: Ie7e968d52904b249d57f23dc7c404d477265ed47
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1626023
Commit-Queue: Ilia Samsonov <isamsonov@google.com>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663778}
parent f635de14
...@@ -401,9 +401,6 @@ int LaunchChildTestProcessWithOptions(const CommandLine& command_line, ...@@ -401,9 +401,6 @@ int LaunchChildTestProcessWithOptions(const CommandLine& command_line,
GetLiveProcesses()->insert(std::make_pair(process.Handle(), command_line)); GetLiveProcesses()->insert(std::make_pair(process.Handle(), command_line));
} }
if (observer)
observer->OnLaunched(process.Handle(), process.Pid());
int exit_code = 0; int exit_code = 0;
bool did_exit = false; bool did_exit = false;
......
...@@ -88,12 +88,6 @@ class ProcessLifetimeObserver { ...@@ -88,12 +88,6 @@ class ProcessLifetimeObserver {
public: public:
virtual ~ProcessLifetimeObserver() = default; virtual ~ProcessLifetimeObserver() = default;
// Invoked once the child process is started. |handle| is a handle to the
// child process and |id| is its pid. NOTE: this method is invoked on the
// thread the process is launched on immediately after it is launched. The
// caller owns the ProcessHandle.
virtual void OnLaunched(ProcessHandle handle, ProcessId id) {}
// Invoked when a test process exceeds its runtime, immediately before it is // Invoked when a test process exceeds its runtime, immediately before it is
// terminated. |command_line| is the command line used to launch the process. // terminated. |command_line| is the command line used to launch the process.
// NOTE: this method is invoked on the thread the process is launched on. // NOTE: this method is invoked on the thread the process is launched on.
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/test/base/chrome_test_launcher.h" #include "chrome/test/base/chrome_test_launcher.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/test/launcher/test_launcher.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/test/base/chrome_test_suite.h" #include "chrome/test/base/chrome_test_suite.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
...@@ -103,14 +104,9 @@ class InteractiveUITestLauncherDelegate : public ChromeTestLauncherDelegate { ...@@ -103,14 +104,9 @@ class InteractiveUITestLauncherDelegate : public ChromeTestLauncherDelegate {
} }
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
std::unique_ptr<content::TestState> PreRunTest( void PreRunTest() override {
base::CommandLine* command_line,
base::TestLauncher::LaunchOptions* test_launch_options) override {
auto test_state = ChromeTestLauncherDelegate::PreRunTest(
command_line, test_launch_options);
// Clear currently pressed modifier keys (if any) before the test starts. // Clear currently pressed modifier keys (if any) before the test starts.
ui_test_utils::ClearKeyEventModifiers(); ui_test_utils::ClearKeyEventModifiers();
return test_state;
} }
void PostRunTest(base::TestResult* test_result) override { void PostRunTest(base::TestResult* test_result) override {
......
...@@ -158,25 +158,18 @@ class WrapperTestLauncherDelegate : public base::TestLauncherDelegate { ...@@ -158,25 +158,18 @@ class WrapperTestLauncherDelegate : public base::TestLauncherDelegate {
base::TestLauncher* test_launcher, base::TestLauncher* test_launcher,
std::vector<std::string>&& next_test_names, std::vector<std::string>&& next_test_names,
const std::string& test_name, const std::string& test_name,
const base::FilePath& output_file, const base::FilePath& output_file)
std::unique_ptr<TestState> test_state)
: base::ProcessLifetimeObserver(), : base::ProcessLifetimeObserver(),
test_launcher_delegate_(test_launcher_delegate), test_launcher_delegate_(test_launcher_delegate),
test_launcher_(test_launcher), test_launcher_(test_launcher),
next_test_names_(std::move(next_test_names)), next_test_names_(std::move(next_test_names)),
test_name_(test_name), test_name_(test_name),
output_file_(output_file), output_file_(output_file) {}
test_state_(std::move(test_state)) {}
~ChildProcessLifetimeObserver() override { ~ChildProcessLifetimeObserver() override {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
} }
private: private:
// base::ProcessLifetimeObserver:
void OnLaunched(base::ProcessHandle handle, base::ProcessId id) override {
if (test_state_)
test_state_->ChildProcessLaunched(handle, id);
}
void OnTimedOut(const base::CommandLine& command_line) override { void OnTimedOut(const base::CommandLine& command_line) override {
test_launcher_delegate_->OnTestTimedOut(command_line); test_launcher_delegate_->OnTestTimedOut(command_line);
...@@ -188,8 +181,8 @@ class WrapperTestLauncherDelegate : public base::TestLauncherDelegate { ...@@ -188,8 +181,8 @@ class WrapperTestLauncherDelegate : public base::TestLauncherDelegate {
const std::string& output) override { const std::string& output) override {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
test_launcher_delegate_->GTestCallback( test_launcher_delegate_->GTestCallback(
test_launcher_, next_test_names_, test_name_, output_file_, test_launcher_, next_test_names_, test_name_, output_file_, exit_code,
std::move(test_state_), exit_code, elapsed_time, was_timeout, output); elapsed_time, was_timeout, output);
} }
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
...@@ -198,7 +191,6 @@ class WrapperTestLauncherDelegate : public base::TestLauncherDelegate { ...@@ -198,7 +191,6 @@ class WrapperTestLauncherDelegate : public base::TestLauncherDelegate {
std::vector<std::string> next_test_names_; std::vector<std::string> next_test_names_;
std::string test_name_; std::string test_name_;
base::FilePath output_file_; base::FilePath output_file_;
std::unique_ptr<TestState> test_state_;
DISALLOW_COPY_AND_ASSIGN(ChildProcessLifetimeObserver); DISALLOW_COPY_AND_ASSIGN(ChildProcessLifetimeObserver);
}; };
...@@ -226,7 +218,6 @@ class WrapperTestLauncherDelegate : public base::TestLauncherDelegate { ...@@ -226,7 +218,6 @@ class WrapperTestLauncherDelegate : public base::TestLauncherDelegate {
const std::vector<std::string>& test_names, const std::vector<std::string>& test_names,
const std::string& test_name, const std::string& test_name,
const base::FilePath& output_file, const base::FilePath& output_file,
std::unique_ptr<TestState> test_state,
int exit_code, int exit_code,
const base::TimeDelta& elapsed_time, const base::TimeDelta& elapsed_time,
bool was_timeout, bool was_timeout,
...@@ -423,11 +414,9 @@ void WrapperTestLauncherDelegate::DoRunTests( ...@@ -423,11 +414,9 @@ void WrapperTestLauncherDelegate::DoRunTests(
base::TestLauncher::LaunchOptions test_launch_options; base::TestLauncher::LaunchOptions test_launch_options;
test_launch_options.flags = base::TestLauncher::USE_JOB_OBJECTS | test_launch_options.flags = base::TestLauncher::USE_JOB_OBJECTS |
base::TestLauncher::ALLOW_BREAKAWAY_FROM_JOB; base::TestLauncher::ALLOW_BREAKAWAY_FROM_JOB;
std::unique_ptr<TestState> test_state_ptr = launcher_delegate_->PreRunTest();
launcher_delegate_->PreRunTest(&cmd_line, &test_launch_options);
CHECK(launcher_delegate_->AdjustChildProcessCommandLine( CHECK(launcher_delegate_->AdjustChildProcessCommandLine(
&cmd_line, user_data_dir_map_[test_name_no_pre])); &cmd_line, user_data_dir_map_[test_name_no_pre]));
base::CommandLine new_cmd_line(cmd_line.GetProgram()); base::CommandLine new_cmd_line(cmd_line.GetProgram());
base::CommandLine::SwitchMap switches = cmd_line.GetSwitches(); base::CommandLine::SwitchMap switches = cmd_line.GetSwitches();
...@@ -459,8 +448,7 @@ void WrapperTestLauncherDelegate::DoRunTests( ...@@ -459,8 +448,7 @@ void WrapperTestLauncherDelegate::DoRunTests(
char* browser_wrapper = getenv("BROWSER_WRAPPER"); char* browser_wrapper = getenv("BROWSER_WRAPPER");
auto observer = std::make_unique<ChildProcessLifetimeObserver>( auto observer = std::make_unique<ChildProcessLifetimeObserver>(
this, test_launcher, std::move(test_names_copy), test_name, output_file, this, test_launcher, std::move(test_names_copy), test_name, output_file);
std::move(test_state_ptr));
test_launcher->LaunchChildGTestProcess( test_launcher->LaunchChildGTestProcess(
new_cmd_line, browser_wrapper ? browser_wrapper : std::string(), new_cmd_line, browser_wrapper ? browser_wrapper : std::string(),
TestTimeouts::action_max_timeout(), test_launch_options, TestTimeouts::action_max_timeout(), test_launch_options,
...@@ -501,7 +489,6 @@ void WrapperTestLauncherDelegate::GTestCallback( ...@@ -501,7 +489,6 @@ void WrapperTestLauncherDelegate::GTestCallback(
const std::vector<std::string>& test_names, const std::vector<std::string>& test_names,
const std::string& test_name, const std::string& test_name,
const base::FilePath& output_file, const base::FilePath& output_file,
std::unique_ptr<TestState> test_state,
int exit_code, int exit_code,
const base::TimeDelta& elapsed_time, const base::TimeDelta& elapsed_time,
bool was_timeout, bool was_timeout,
...@@ -589,12 +576,6 @@ const char kSingleProcessTestsFlag[] = "single_process"; ...@@ -589,12 +576,6 @@ const char kSingleProcessTestsFlag[] = "single_process";
const char kWaitForDebuggerWebUI[] = "wait-for-debugger-webui"; const char kWaitForDebuggerWebUI[] = "wait-for-debugger-webui";
std::unique_ptr<TestState> TestLauncherDelegate::PreRunTest(
base::CommandLine* command_line,
base::TestLauncher::LaunchOptions* test_launch_options) {
return nullptr;
}
void AppendCommandLineSwitches() { void AppendCommandLineSwitches() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
......
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
#include <string> #include <string>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/test/launcher/test_launcher.h"
#include "build/build_config.h" #include "build/build_config.h"
namespace base { namespace base {
class CommandLine; class CommandLine;
class FilePath; class FilePath;
struct TestResult;
} }
namespace content { namespace content {
...@@ -33,17 +33,6 @@ extern const char kWarmupFlag[]; ...@@ -33,17 +33,6 @@ extern const char kWarmupFlag[];
// Flag used by WebUI test runners to wait for debugger to be attached. // Flag used by WebUI test runners to wait for debugger to be attached.
extern const char kWaitForDebuggerWebUI[]; extern const char kWaitForDebuggerWebUI[];
// See details in PreRunTest().
class TestState {
public:
virtual ~TestState() {}
// Called once test process has launched (and is still running).
// NOTE: this is called on a background thread.
virtual void ChildProcessLaunched(base::ProcessHandle handle,
base::ProcessId pid) = 0;
};
class TestLauncherDelegate { class TestLauncherDelegate {
public: public:
virtual int RunTestSuite(int argc, char** argv) = 0; virtual int RunTestSuite(int argc, char** argv) = 0;
...@@ -56,15 +45,10 @@ class TestLauncherDelegate { ...@@ -56,15 +45,10 @@ class TestLauncherDelegate {
virtual ContentMainDelegate* CreateContentMainDelegate() = 0; virtual ContentMainDelegate* CreateContentMainDelegate() = 0;
#endif #endif
// Called prior to running each test. The delegate may alter the CommandLine // Called prior to running each test.
// and options used to launch the subprocess. Additionally the client may
// return a TestState that is destroyed once the test completes as well as
// once the test process is launched.
// //
// NOTE: this is not called if --single_process is supplied. // NOTE: this is not called if --single_process is supplied.
virtual std::unique_ptr<TestState> PreRunTest( virtual void PreRunTest() {}
base::CommandLine* command_line,
base::TestLauncher::LaunchOptions* test_launch_options);
// Called after running each test. Can modify test result. // Called after running each test. Can modify test result.
// //
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/fuchsia/fuchsia_logging.h" #include "base/fuchsia/fuchsia_logging.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/test/launcher/test_launcher.h"
#include "base/test/test_suite.h" #include "base/test/test_suite.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/test/test_launcher.h" #include "content/public/test/test_launcher.h"
......
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