summaryrefslogtreecommitdiffstats
path: root/net/test/remote_test_server.h
blob: 417eda8bad69903cdef5f012de1bc93c048f677f (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
54
55
56
57
58
59
// Copyright (c) 2012 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 NET_TEST_REMOTE_TEST_SERVER_H_
#define NET_TEST_REMOTE_TEST_SERVER_H_

#include <string>

#include "net/test/base_test_server.h"

namespace net {

class SpawnerCommunicator;

// The RemoteTestServer runs an external Python-based test server in another
// machine that is different from the machine in which RemoteTestServer runs.
class RemoteTestServer : public BaseTestServer {
 public:
  // Initialize a TestServer listening on a specific host (IP or hostname).
  // |document_root| must be a relative path under the root tree.
  RemoteTestServer(Type type,
                   const std::string& host,
                   const FilePath& document_root);

  // Initialize a TestServer with a specific set of SSLOptions.
  // |document_root| must be a relative path under the root tree.
  RemoteTestServer(Type type,
                   const SSLOptions& ssl_options,
                   const FilePath& document_root);

  virtual ~RemoteTestServer();

  // Starts the Python test server on the host, instead of on the device.
  bool Start() WARN_UNUSED_RESULT;

  // Stops the Python test server that is running on the host machine.
  bool Stop();

 private:
  bool Init(const FilePath& document_root);

  // The local port used to communicate with the TestServer spawner. This is
  // used to control the startup and shutdown of the Python TestServer running
  // on the remote machine. On Android, this port will be redirected to the
  // same port on the host machine.
  int spawner_server_port_;

  // Helper to start and stop instances of the Python test server that runs on
  // the host machine.
  scoped_ptr<SpawnerCommunicator> spawner_communicator_;

  DISALLOW_COPY_AND_ASSIGN(RemoteTestServer);
};

}  // namespace net

#endif  // NET_TEST_REMOTE_TEST_SERVER_H_