| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/test/layout_test_http_server.h" | 5 #include "content/test/layout_test_http_server.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "content/public/common/content_paths.h" | 12 #include "content/public/common/content_paths.h" |
| 13 #include "net/test/python_utils.h" | 13 #include "net/test/python_utils.h" |
| 14 | 14 |
| 15 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
| 16 #include "base/win/windows_version.h" | 16 #include "base/win/windows_version.h" |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 bool PrepareCommandLine(CommandLine* cmd_line) { | 22 bool PrepareCommandLine(CommandLine* cmd_line) { |
| 23 FilePath src_path; | 23 base::FilePath src_path; |
| 24 if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_path)) | 24 if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_path)) |
| 25 return false; | 25 return false; |
| 26 | 26 |
| 27 if (!GetPythonCommand(cmd_line)) | 27 if (!GetPythonCommand(cmd_line)) |
| 28 return false; | 28 return false; |
| 29 | 29 |
| 30 FilePath script_path(src_path); | 30 base::FilePath script_path(src_path); |
| 31 script_path = script_path.AppendASCII("third_party"); | 31 script_path = script_path.AppendASCII("third_party"); |
| 32 script_path = script_path.AppendASCII("WebKit"); | 32 script_path = script_path.AppendASCII("WebKit"); |
| 33 script_path = script_path.AppendASCII("Tools"); | 33 script_path = script_path.AppendASCII("Tools"); |
| 34 script_path = script_path.AppendASCII("Scripts"); | 34 script_path = script_path.AppendASCII("Scripts"); |
| 35 script_path = script_path.AppendASCII("new-run-webkit-httpd"); | 35 script_path = script_path.AppendASCII("new-run-webkit-httpd"); |
| 36 | 36 |
| 37 cmd_line->AppendArgPath(script_path); | 37 cmd_line->AppendArgPath(script_path); |
| 38 return true; | 38 return true; |
| 39 } | 39 } |
| 40 | 40 |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 LayoutTestHttpServer::LayoutTestHttpServer(const FilePath& root_directory, | 43 LayoutTestHttpServer::LayoutTestHttpServer(const base::FilePath& root_directory, |
| 44 int port) | 44 int port) |
| 45 : root_directory_(root_directory), | 45 : root_directory_(root_directory), |
| 46 port_(port), | 46 port_(port), |
| 47 running_(false) { | 47 running_(false) { |
| 48 } | 48 } |
| 49 | 49 |
| 50 LayoutTestHttpServer::~LayoutTestHttpServer() { | 50 LayoutTestHttpServer::~LayoutTestHttpServer() { |
| 51 if (running_ && !Stop()) | 51 if (running_ && !Stop()) |
| 52 LOG(ERROR) << "LayoutTestHttpServer failed to stop."; | 52 LOG(ERROR) << "LayoutTestHttpServer failed to stop."; |
| 53 } | 53 } |
| 54 | 54 |
| 55 bool LayoutTestHttpServer::Start() { | 55 bool LayoutTestHttpServer::Start() { |
| 56 if (running_) { | 56 if (running_) { |
| 57 LOG(ERROR) << "LayoutTestHttpServer already running."; | 57 LOG(ERROR) << "LayoutTestHttpServer already running."; |
| 58 return false; | 58 return false; |
| 59 } | 59 } |
| 60 | 60 |
| 61 CommandLine cmd_line(CommandLine::NO_PROGRAM); | 61 CommandLine cmd_line(CommandLine::NO_PROGRAM); |
| 62 if (!PrepareCommandLine(&cmd_line)) | 62 if (!PrepareCommandLine(&cmd_line)) |
| 63 return false; | 63 return false; |
| 64 cmd_line.AppendArg("--server=start"); | 64 cmd_line.AppendArg("--server=start"); |
| 65 cmd_line.AppendArg("--register_cygwin"); | 65 cmd_line.AppendArg("--register_cygwin"); |
| 66 cmd_line.AppendArgNative(FILE_PATH_LITERAL("--root=") + | 66 cmd_line.AppendArgNative(FILE_PATH_LITERAL("--root=") + |
| 67 root_directory_.value()); | 67 root_directory_.value()); |
| 68 cmd_line.AppendArg("--port=" + base::IntToString(port_)); | 68 cmd_line.AppendArg("--port=" + base::IntToString(port_)); |
| 69 | 69 |
| 70 FilePath layout_tests_dir; | 70 base::FilePath layout_tests_dir; |
| 71 if (!PathService::Get(DIR_LAYOUT_TESTS, &layout_tests_dir)) | 71 if (!PathService::Get(DIR_LAYOUT_TESTS, &layout_tests_dir)) |
| 72 return false; | 72 return false; |
| 73 cmd_line.AppendArgNative(FILE_PATH_LITERAL("--layout_tests_dir=") + | 73 cmd_line.AppendArgNative(FILE_PATH_LITERAL("--layout_tests_dir=") + |
| 74 layout_tests_dir.value()); | 74 layout_tests_dir.value()); |
| 75 | 75 |
| 76 #if defined(OS_WIN) | 76 #if defined(OS_WIN) |
| 77 // For Windows 7, if we start the lighttpd server on the foreground mode, | 77 // For Windows 7, if we start the lighttpd server on the foreground mode, |
| 78 // it will mess up with the command window and cause conhost.exe to crash. To | 78 // it will mess up with the command window and cause conhost.exe to crash. To |
| 79 // work around this, we start the http server on the background mode. | 79 // work around this, we start the http server on the background mode. |
| 80 if (base::win::GetVersion() >= base::win::VERSION_WIN7) | 80 if (base::win::GetVersion() >= base::win::VERSION_WIN7) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 #if defined(OS_WIN) | 126 #if defined(OS_WIN) |
| 127 // Close the job object handle now. This should clean up | 127 // Close the job object handle now. This should clean up |
| 128 // any orphaned processes. | 128 // any orphaned processes. |
| 129 job_handle_.Close(); | 129 job_handle_.Close(); |
| 130 #endif | 130 #endif |
| 131 | 131 |
| 132 return stopped; | 132 return stopped; |
| 133 } | 133 } |
| 134 | 134 |
| 135 } // namespace content | 135 } // namespace content |
| OLD | NEW |