summaryrefslogtreecommitdiffstats
path: root/content/test/layout_test_http_server.h
blob: 5b76685ddddfb95c592d40d620712c8369484cc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_TEST_LAYOUT_TEST_HTTP_SERVER_H_
#define CONTENT_TEST_LAYOUT_TEST_HTTP_SERVER_H_

#include "base/compiler_specific.h"
#include "base/file_path.h"

#if defined(OS_WIN)
#include "base/win/scoped_handle.h"
#endif

// This object bounds the lifetime of an external HTTP server
// used for layout tests.
//
// NOTE: If you're not running a layout test, you probably want
// a more lightweight net/test/test_server HTTP server.
class LayoutTestHttpServer {
 public:
  LayoutTestHttpServer(const FilePath& root_directory, int port);
  ~LayoutTestHttpServer();

  // Starts the server. Returns true on success.
  bool Start() WARN_UNUSED_RESULT;

  // Stops the server. Returns true on success.
  //
  // NOTE: It is recommended to explicitly call Stop and check its return value.
  // If Stop fails, the server is most likely still running and future attempts
  // to bind to the same port will fail, possibly resulting in further test
  // failures.
  bool Stop() WARN_UNUSED_RESULT;

  int port() const { return port_; }

 private:
  FilePath root_directory_;  // Root directory of the server.

  int port_;  // Port on which the server should listen.

  bool running_;  // True if the server is currently running.

#if defined(OS_WIN)
  // JobObject used to clean up orphaned child processes.
  base::win::ScopedHandle job_handle_;
#endif

  DISALLOW_COPY_AND_ASSIGN(LayoutTestHttpServer);
};

#endif  // CONTENT_TEST_LAYOUT_TEST_HTTP_SERVER_H_