OLD | NEW |
| (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 #ifndef CONTENT_TEST_LAYOUT_TEST_HTTP_SERVER_H_ | |
6 #define CONTENT_TEST_LAYOUT_TEST_HTTP_SERVER_H_ | |
7 | |
8 #include "base/compiler_specific.h" | |
9 #include "base/files/file_path.h" | |
10 | |
11 #if defined(OS_WIN) | |
12 #include "base/win/scoped_handle.h" | |
13 #endif | |
14 | |
15 namespace content { | |
16 | |
17 // This object bounds the lifetime of an external HTTP server | |
18 // used for layout tests. | |
19 // | |
20 // NOTE: If you're not running a layout test, you probably want | |
21 // a more lightweight net/test/test_server HTTP server. | |
22 class LayoutTestHttpServer { | |
23 public: | |
24 LayoutTestHttpServer(const base::FilePath& root_directory, int port); | |
25 ~LayoutTestHttpServer(); | |
26 | |
27 // Starts the server. Returns true on success. | |
28 bool Start() WARN_UNUSED_RESULT; | |
29 | |
30 // Stops the server. Returns true on success. | |
31 // | |
32 // NOTE: It is recommended to explicitly call Stop and check its return value. | |
33 // If Stop fails, the server is most likely still running and future attempts | |
34 // to bind to the same port will fail, possibly resulting in further test | |
35 // failures. | |
36 bool Stop() WARN_UNUSED_RESULT; | |
37 | |
38 int port() const { return port_; } | |
39 | |
40 private: | |
41 base::FilePath root_directory_; // Root directory of the server. | |
42 | |
43 int port_; // Port on which the server should listen. | |
44 | |
45 bool running_; // True if the server is currently running. | |
46 | |
47 #if defined(OS_WIN) | |
48 // JobObject used to clean up orphaned child processes. | |
49 base::win::ScopedHandle job_handle_; | |
50 #endif | |
51 | |
52 DISALLOW_COPY_AND_ASSIGN(LayoutTestHttpServer); | |
53 }; | |
54 | |
55 } // namespace content | |
56 | |
57 #endif // CONTENT_TEST_LAYOUT_TEST_HTTP_SERVER_H_ | |
OLD | NEW |