diff options
-rw-r--r-- | content/public/test/browser_test_utils.cc | 149 | ||||
-rw-r--r-- | content/public/test/browser_test_utils.h | 64 |
2 files changed, 0 insertions, 213 deletions
diff --git a/content/public/test/browser_test_utils.cc b/content/public/test/browser_test_utils.cc index bf7e3db..6efa0a6 100644 --- a/content/public/test/browser_test_utils.cc +++ b/content/public/test/browser_test_utils.cc @@ -424,155 +424,6 @@ void TitleWatcher::Observe(int type, } } -TestWebSocketServer::TestWebSocketServer() - : started_(false), - port_(kDefaultWsPort), - secure_(false) { -#if defined(OS_POSIX) - process_group_id_ = base::kNullProcessHandle; -#endif -} - -int TestWebSocketServer::UseRandomPort() { - port_ = base::RandInt(1024, 65535); - return port_; -} - -void TestWebSocketServer::UseTLS() { - secure_ = true; -} - -bool TestWebSocketServer::Start(const FilePath& root_directory) { - if (started_) - return true; - // Append CommandLine arguments after the server script, switches won't work. - scoped_ptr<CommandLine> cmd_line(CreateWebSocketServerCommandLine()); - cmd_line->AppendArg("--server=start"); - cmd_line->AppendArg("--chromium"); - cmd_line->AppendArg("--register_cygwin"); - cmd_line->AppendArgNative(FILE_PATH_LITERAL("--root=") + - root_directory.value()); - cmd_line->AppendArg("--port=" + base::IntToString(port_)); - if (secure_) - cmd_line->AppendArg("--tls"); - if (!temp_dir_.CreateUniqueTempDir()) { - LOG(ERROR) << "Unable to create a temporary directory."; - return false; - } - cmd_line->AppendArgNative(FILE_PATH_LITERAL("--output-dir=") + - temp_dir_.path().value()); - websocket_pid_file_ = temp_dir_.path().AppendASCII("websocket.pid"); - cmd_line->AppendArgNative(FILE_PATH_LITERAL("--pidfile=") + - websocket_pid_file_.value()); - SetPythonPath(); - - base::LaunchOptions options; - base::ProcessHandle process_handle; - -#if defined(OS_POSIX) - options.new_process_group = true; -#elif defined(OS_WIN) - job_handle_.Set(CreateJobObject(NULL, NULL)); - if (!job_handle_.IsValid()) { - LOG(ERROR) << "Could not create JobObject."; - return false; - } - - if (!base::SetJobObjectAsKillOnJobClose(job_handle_.Get())) { - LOG(ERROR) << "Could not SetInformationJobObject."; - return false; - } - - options.inherit_handles = true; - options.job_handle = job_handle_.Get(); -#endif - - // Launch a new WebSocket server process. - if (!base::LaunchProcess(*cmd_line.get(), options, &process_handle)) { - LOG(ERROR) << "Unable to launch websocket server:\n" - << cmd_line.get()->GetCommandLineString(); - return false; - } -#if defined(OS_POSIX) - process_group_id_ = process_handle; -#endif - int exit_code; - bool wait_success = base::WaitForExitCodeWithTimeout( - process_handle, - &exit_code, - TestTimeouts::action_max_timeout()); - base::CloseProcessHandle(process_handle); - - if (!wait_success || exit_code != 0) { - LOG(ERROR) << "Failed to run new-run-webkit-websocketserver: " - << "wait_success = " << wait_success << ", " - << "exit_code = " << exit_code << ", " - << "command_line = " << cmd_line.get()->GetCommandLineString(); - return false; - } - - started_ = true; - return true; -} - -CommandLine* TestWebSocketServer::CreatePythonCommandLine() { - // Note: Python's first argument must be the script; do not append CommandLine - // switches, as they would precede the script path and break this CommandLine. - CommandLine* cmd_line = new CommandLine(CommandLine::NO_PROGRAM); - // TODO(phajdan.jr): Instead of CHECKing, return a boolean indicating success. - CHECK(GetPythonCommand(cmd_line)); - return cmd_line; -} - -void TestWebSocketServer::SetPythonPath() { - FilePath scripts_path; - PathService::Get(base::DIR_SOURCE_ROOT, &scripts_path); - - scripts_path = scripts_path - .Append(FILE_PATH_LITERAL("third_party")) - .Append(FILE_PATH_LITERAL("WebKit")) - .Append(FILE_PATH_LITERAL("Tools")) - .Append(FILE_PATH_LITERAL("Scripts")); - AppendToPythonPath(scripts_path); -} - -CommandLine* TestWebSocketServer::CreateWebSocketServerCommandLine() { - FilePath src_path; - // Get to 'src' dir. - PathService::Get(base::DIR_SOURCE_ROOT, &src_path); - - FilePath script_path(src_path); - script_path = script_path.AppendASCII("third_party"); - script_path = script_path.AppendASCII("WebKit"); - script_path = script_path.AppendASCII("Tools"); - script_path = script_path.AppendASCII("Scripts"); - script_path = script_path.AppendASCII("new-run-webkit-websocketserver"); - - CommandLine* cmd_line = CreatePythonCommandLine(); - cmd_line->AppendArgPath(script_path); - return cmd_line; -} - -TestWebSocketServer::~TestWebSocketServer() { - if (!started_) - return; - // Append CommandLine arguments after the server script, switches won't work. - scoped_ptr<CommandLine> cmd_line(CreateWebSocketServerCommandLine()); - cmd_line->AppendArg("--server=stop"); - cmd_line->AppendArg("--chromium"); - cmd_line->AppendArgNative(FILE_PATH_LITERAL("--pidfile=") + - websocket_pid_file_.value()); - base::LaunchOptions options; - options.wait = true; - base::LaunchProcess(*cmd_line.get(), options, NULL); - -#if defined(OS_POSIX) - // Just to make sure that the server process terminates certainly. - if (process_group_id_ != base::kNullProcessHandle) - base::KillProcessGroup(process_group_id_); -#endif -} - DOMMessageQueue::DOMMessageQueue() : waiting_for_message_(false) { registrar_.Add(this, NOTIFICATION_DOM_OPERATION_RESPONSE, NotificationService::AllSources()); diff --git a/content/public/test/browser_test_utils.h b/content/public/test/browser_test_utils.h index 09d84be..d86dff5 100644 --- a/content/public/test/browser_test_utils.h +++ b/content/public/test/browser_test_utils.h @@ -152,70 +152,6 @@ class TitleWatcher : public NotificationObserver { DISALLOW_COPY_AND_ASSIGN(TitleWatcher); }; -// This is a utility class for running a python websocket server -// during tests. The server is started during the construction of the -// object, and is stopped when the destructor is called. Note that -// because of the underlying script that is used: -// -// third_paty/WebKit/Tools/Scripts/new-run-webkit-websocketserver -// -// Only *_wsh.py handlers found under "http/tests/websocket/tests" from the -// |root_directory| will be found and active while running the test -// server. -class TestWebSocketServer { - public: - TestWebSocketServer(); - - // Stops the python websocket server if it was already started. - ~TestWebSocketServer(); - - // Use a random port, useful for tests that are sharded. Returns the port. - int UseRandomPort(); - - // Serves with TLS. - void UseTLS(); - - // Starts the python websocket server using |root_directory|. Returns whether - // the server was successfully started. - bool Start(const FilePath& root_directory); - - private: - // Sets up PYTHONPATH to run websocket_server.py. - void SetPythonPath(); - - // Creates a CommandLine for invoking the python interpreter. - CommandLine* CreatePythonCommandLine(); - - // Creates a CommandLine for invoking the python websocker server. - CommandLine* CreateWebSocketServerCommandLine(); - - // Has the server been started? - bool started_; - - // A Scoped temporary directory for holding the python pid file. - ScopedTempDir temp_dir_; - - // Used to close the same python interpreter when server falls out - // scope. - FilePath websocket_pid_file_; - -#if defined(OS_POSIX) - // ProcessHandle used to terminate child process. - base::ProcessHandle process_group_id_; -#elif defined(OS_WIN) - // JobObject used to clean up orphaned child process. - base::win::ScopedHandle job_handle_; -#endif - - // Holds port number which the python websocket server uses. - int port_; - - // If the python websocket server serves with TLS. - bool secure_; - - DISALLOW_COPY_AND_ASSIGN(TestWebSocketServer); -}; - // Watches for responses from the DOMAutomationController and keeps them in a // queue. Useful for waiting for a message to be received. class DOMMessageQueue : public NotificationObserver { |