15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#ifndef NET_TEST_SPAWNED_TEST_SERVER_REMOTE_TEST_SERVER_H_
6b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#define NET_TEST_SPAWNED_TEST_SERVER_REMOTE_TEST_SERVER_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "net/test/spawned_test_server/base_test_server.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SpawnerCommunicator;
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The RemoteTestServer runs an external Python-based test server in another
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// machine that is different from the machine in which RemoteTestServer runs.
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RemoteTestServer : public BaseTestServer {
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Initialize a TestServer listening on a specific host (IP or hostname).
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |document_root| must be a relative path under the root tree.
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RemoteTestServer(Type type,
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                   const std::string& host,
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                   const base::FilePath& document_root);
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Initialize a TestServer with a specific set of SSLOptions.
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |document_root| must be a relative path under the root tree.
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RemoteTestServer(Type type,
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                   const SSLOptions& ssl_options,
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                   const base::FilePath& document_root);
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~RemoteTestServer();
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Starts the Python test server on the host, instead of on the device, and
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // blocks until the server is ready.
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool Start() WARN_UNUSED_RESULT;
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // These are currently unused and unimplemented for RemoteTestServer. See
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // the same methods in LocalTestServer for more information.
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool StartInBackground() WARN_UNUSED_RESULT;
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool BlockUntilStarted() WARN_UNUSED_RESULT;
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stops the Python test server that is running on the host machine.
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool Stop();
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the actual path of document root for the test cases. This function
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // should be called by test cases to retrieve the actual document root path
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // on the Android device, otherwise document_root() function is used to get
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the document root.
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::FilePath GetDocumentRoot() const;
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool Init(const base::FilePath& document_root);
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The local port used to communicate with the TestServer spawner. This is
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // used to control the startup and shutdown of the Python TestServer running
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // on the remote machine. On Android, this port will be redirected to the
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // same port on the host machine.
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int spawner_server_port_;
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Helper to start and stop instances of the Python test server that runs on
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the host machine.
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<SpawnerCommunicator> spawner_communicator_;
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(RemoteTestServer);
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace net
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
70b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#endif  // NET_TEST_SPAWNED_TEST_SERVER_REMOTE_TEST_SERVER_H_
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
72