Home | History | Annotate | Download | only in spawned_test_server
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef NET_TEST_SPAWNED_TEST_SERVER_REMOTE_TEST_SERVER_H_
      6 #define NET_TEST_SPAWNED_TEST_SERVER_REMOTE_TEST_SERVER_H_
      7 
      8 #include <string>
      9 
     10 #include "net/test/spawned_test_server/base_test_server.h"
     11 
     12 namespace net {
     13 
     14 class SpawnerCommunicator;
     15 
     16 // The RemoteTestServer runs an external Python-based test server in another
     17 // machine that is different from the machine in which RemoteTestServer runs.
     18 class RemoteTestServer : public BaseTestServer {
     19  public:
     20   // Initialize a TestServer listening on a specific host (IP or hostname).
     21   // |document_root| must be a relative path under the root tree.
     22   RemoteTestServer(Type type,
     23                    const std::string& host,
     24                    const base::FilePath& document_root);
     25 
     26   // Initialize a TestServer with a specific set of SSLOptions.
     27   // |document_root| must be a relative path under the root tree.
     28   RemoteTestServer(Type type,
     29                    const SSLOptions& ssl_options,
     30                    const base::FilePath& document_root);
     31 
     32   virtual ~RemoteTestServer();
     33 
     34   // Starts the Python test server on the host, instead of on the device, and
     35   // blocks until the server is ready.
     36   bool Start() WARN_UNUSED_RESULT;
     37 
     38   // These are currently unused and unimplemented for RemoteTestServer. See
     39   // the same methods in LocalTestServer for more information.
     40   bool StartInBackground() WARN_UNUSED_RESULT;
     41   bool BlockUntilStarted() WARN_UNUSED_RESULT;
     42 
     43   // Stops the Python test server that is running on the host machine.
     44   bool Stop();
     45 
     46   // Returns the actual path of document root for the test cases. This function
     47   // should be called by test cases to retrieve the actual document root path
     48   // on the Android device, otherwise document_root() function is used to get
     49   // the document root.
     50   base::FilePath GetDocumentRoot() const;
     51 
     52  private:
     53   bool Init(const base::FilePath& document_root);
     54 
     55   // The local port used to communicate with the TestServer spawner. This is
     56   // used to control the startup and shutdown of the Python TestServer running
     57   // on the remote machine. On Android, this port will be redirected to the
     58   // same port on the host machine.
     59   int spawner_server_port_;
     60 
     61   // Helper to start and stop instances of the Python test server that runs on
     62   // the host machine.
     63   scoped_ptr<SpawnerCommunicator> spawner_communicator_;
     64 
     65   DISALLOW_COPY_AND_ASSIGN(RemoteTestServer);
     66 };
     67 
     68 }  // namespace net
     69 
     70 #endif  // NET_TEST_SPAWNED_TEST_SERVER_REMOTE_TEST_SERVER_H_
     71 
     72