Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: chrome/test/layout_test_http_server.cc

Issue 7474025: Move more files from chrome/test to chrome/test/base, part #2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/layout_test_http_server.h ('k') | chrome/test/live_sync/live_autofill_sync_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/test/layout_test_http_server.h"
6
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/path_service.h"
10 #include "base/process_util.h"
11 #include "base/string_number_conversions.h"
12
13 #if defined(OS_WIN)
14 #include "base/win/windows_version.h"
15 #endif
16
17 namespace {
18
19 bool PrepareCommandLine(CommandLine* cmd_line) {
20 FilePath src_path;
21 if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_path))
22 return false;
23
24 cmd_line->SetProgram(FilePath(FILE_PATH_LITERAL("python")));
25
26 FilePath script_path(src_path);
27 script_path = script_path.AppendASCII("third_party");
28 script_path = script_path.AppendASCII("WebKit");
29 script_path = script_path.AppendASCII("Tools");
30 script_path = script_path.AppendASCII("Scripts");
31 script_path = script_path.AppendASCII("new-run-webkit-httpd");
32
33 cmd_line->AppendArgPath(script_path);
34 return true;
35 }
36
37 } // namespace
38
39 LayoutTestHttpServer::LayoutTestHttpServer(const FilePath& root_directory,
40 int port)
41 : root_directory_(root_directory),
42 port_(port),
43 running_(false) {
44 }
45
46 LayoutTestHttpServer::~LayoutTestHttpServer() {
47 if (running_ && !Stop())
48 LOG(ERROR) << "LayoutTestHttpServer failed to stop.";
49 }
50
51 bool LayoutTestHttpServer::Start() {
52 if (running_) {
53 LOG(ERROR) << "LayoutTestHttpServer already running.";
54 return false;
55 }
56
57 CommandLine cmd_line(CommandLine::NO_PROGRAM);
58 if (!PrepareCommandLine(&cmd_line))
59 return false;
60 cmd_line.AppendArg("--server=start");
61 cmd_line.AppendArg("--register_cygwin");
62 cmd_line.AppendArgNative(FILE_PATH_LITERAL("--root=") +
63 root_directory_.value());
64 cmd_line.AppendArg("--port=" + base::IntToString(port_));
65
66 FilePath layout_tests_dir;
67 if (!PathService::Get(base::DIR_SOURCE_ROOT, &layout_tests_dir))
68 return false;
69 layout_tests_dir = layout_tests_dir.AppendASCII("chrome")
70 .AppendASCII("test")
71 .AppendASCII("data")
72 .AppendASCII("layout_tests")
73 .AppendASCII("LayoutTests");
74 cmd_line.AppendArgNative(FILE_PATH_LITERAL("--layout_tests_dir=") +
75 layout_tests_dir.value());
76
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
79 // work around this, we start the http server on the background mode.
80 #if defined(OS_WIN)
81 if (base::win::GetVersion() >= base::win::VERSION_WIN7)
82 cmd_line.AppendArg("--run_background");
83 #endif
84
85 // The Python script waits for the server to start responding to requests,
86 // then exits. So we want to wait for the Python script to exit before
87 // continuing.
88 base::LaunchOptions options;
89 options.wait = true;
90 running_ = base::LaunchProcess(cmd_line, options, NULL);
91 return running_;
92 }
93
94 bool LayoutTestHttpServer::Stop() {
95 if (!running_) {
96 LOG(ERROR) << "LayoutTestHttpServer not running.";
97 return false;
98 }
99
100 CommandLine cmd_line(CommandLine::NO_PROGRAM);
101 if (!PrepareCommandLine(&cmd_line))
102 return false;
103 cmd_line.AppendArg("--server=stop");
104
105 base::LaunchOptions options;
106 options.wait = true;
107 bool stopped = base::LaunchProcess(cmd_line, options, NULL);
108 running_ = !stopped;
109 return stopped;
110 }
111
OLDNEW
« no previous file with comments | « chrome/test/layout_test_http_server.h ('k') | chrome/test/live_sync/live_autofill_sync_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698