summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/sync/test/integration/sync_test.cc5
-rw-r--r--chrome/browser/sync/test/integration/sync_test.h4
-rw-r--r--net/net.gyp2
-rw-r--r--net/test/OWNERS4
-rw-r--r--net/test/local_sync_test_server.cc40
-rw-r--r--net/test/local_sync_test_server.h43
-rw-r--r--net/test/local_test_server.h8
-rw-r--r--net/tools/testserver/run_testserver.cc60
-rwxr-xr-xnet/tools/testserver/testserver.py10
9 files changed, 154 insertions, 22 deletions
diff --git a/chrome/browser/sync/test/integration/sync_test.cc b/chrome/browser/sync/test/integration/sync_test.cc
index 8c39568..9a449a0 100644
--- a/chrome/browser/sync/test/integration/sync_test.cc
+++ b/chrome/browser/sync/test/integration/sync_test.cc
@@ -95,10 +95,7 @@ void SetProxyConfigCallback(
}
SyncTest::SyncTest(TestType test_type)
- : sync_server_(net::TestServer::TYPE_SYNC,
- net::TestServer::kLocalhost,
- FilePath()),
- test_type_(test_type),
+ : test_type_(test_type),
server_type_(SERVER_TYPE_UNDECIDED),
num_clients_(-1),
use_verifier_(true),
diff --git a/chrome/browser/sync/test/integration/sync_test.h b/chrome/browser/sync/test/integration/sync_test.h
index bc3d385..8283636 100644
--- a/chrome/browser/sync/test/integration/sync_test.h
+++ b/chrome/browser/sync/test/integration/sync_test.h
@@ -18,7 +18,7 @@
#include "base/memory/scoped_vector.h"
#include "base/process_util.h"
#include "net/base/mock_host_resolver.h"
-#include "net/test/test_server.h"
+#include "net/test/local_sync_test_server.h"
#include "sync/protocol/sync_protocol_error.h"
#include "sync/syncable/model_type.h"
@@ -298,7 +298,7 @@ class SyncTest : public InProcessBrowserTest {
void SetupMockGaiaResponses();
// Test server of type sync, started on demand.
- net::TestServer sync_server_;
+ net::LocalSyncTestServer sync_server_;
// Helper class to whitelist the notification port.
scoped_ptr<net::ScopedPortException> xmpp_port_;
diff --git a/net/net.gyp b/net/net.gyp
index 7bf527f..9178ba4 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -1533,6 +1533,8 @@
'socket/socket_test_util.h',
'test/base_test_server.cc',
'test/base_test_server.h',
+ 'test/local_sync_test_server.cc',
+ 'test/local_sync_test_server.h',
'test/local_test_server_posix.cc',
'test/local_test_server_win.cc',
'test/local_test_server.cc',
diff --git a/net/test/OWNERS b/net/test/OWNERS
index 92ecc88..5b08e34 100644
--- a/net/test/OWNERS
+++ b/net/test/OWNERS
@@ -1 +1,5 @@
+# General reviewer, except sync-specific bits.
phajdan.jr@chromium.org
+
+# For changes to local_sync_test_server.{h|cc}.
+akalin@chromium.org
diff --git a/net/test/local_sync_test_server.cc b/net/test/local_sync_test_server.cc
new file mode 100644
index 0000000..8d757f8
--- /dev/null
+++ b/net/test/local_sync_test_server.cc
@@ -0,0 +1,40 @@
+// 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.
+
+#include "net/test/local_sync_test_server.h"
+
+#include "base/command_line.h"
+#include "base/string_number_conversions.h"
+#include "base/values.h"
+#include "net/test/test_server.h"
+
+namespace net {
+
+LocalSyncTestServer::LocalSyncTestServer()
+ : LocalTestServer(net::TestServer::TYPE_SYNC,
+ net::TestServer::kLocalhost,
+ FilePath()),
+ xmpp_port_(0) {}
+
+LocalSyncTestServer::LocalSyncTestServer(uint16 port, uint16 xmpp_port)
+ : LocalTestServer(net::TestServer::TYPE_SYNC,
+ net::TestServer::kLocalhost,
+ FilePath()),
+ xmpp_port_(xmpp_port) {
+ SetPort(port);
+}
+
+LocalSyncTestServer::~LocalSyncTestServer() {}
+
+bool LocalSyncTestServer::AddCommandLineArguments(
+ CommandLine* command_line) const {
+ LocalTestServer::AddCommandLineArguments(command_line);
+ if (xmpp_port_ != 0) {
+ std::string xmpp_port_str = base::IntToString(xmpp_port_);
+ command_line->AppendArg("--xmpp-port=" + xmpp_port_str);
+ }
+ return true;
+}
+
+} // namespace net
diff --git a/net/test/local_sync_test_server.h b/net/test/local_sync_test_server.h
new file mode 100644
index 0000000..839fd1e
--- /dev/null
+++ b/net/test/local_sync_test_server.h
@@ -0,0 +1,43 @@
+// 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_LOCAL_SYNC_TEST_SERVER_H_
+#define NET_TEST_LOCAL_SYNC_TEST_SERVER_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "net/test/local_test_server.h"
+
+namespace net {
+
+// Runs a Python-based sync test server on the same machine in which the
+// LocalSyncTestServer runs.
+class LocalSyncTestServer : public LocalTestServer {
+ public:
+ // Initialize a sync server that listens on localhost using ephemeral ports
+ // for sync and p2p notifications.
+ LocalSyncTestServer();
+
+ // Initialize a sync server that listens on |port| for sync updates and
+ // |xmpp_port| for p2p notifications.
+ LocalSyncTestServer(uint16 port, uint16 xmpp_port);
+
+ virtual ~LocalSyncTestServer();
+
+ // Calls LocalTestServer::AddCommandLineArguments and then appends the
+ // --xmpp-port flag to |command_line| if required. Returns true on success.
+ virtual bool AddCommandLineArguments(
+ CommandLine* command_line) const OVERRIDE;
+
+ private:
+ // Port on which the Sync XMPP server listens.
+ uint16 xmpp_port_;
+
+ DISALLOW_COPY_AND_ASSIGN(LocalSyncTestServer);
+};
+
+} // namespace net
+
+#endif // NET_TEST_LOCAL_SYNC_TEST_SERVER_H_
diff --git a/net/test/local_test_server.h b/net/test/local_test_server.h
index 63ea00e..6aa1990 100644
--- a/net/test/local_test_server.h
+++ b/net/test/local_test_server.h
@@ -49,6 +49,10 @@ class LocalTestServer : public BaseTestServer {
// testserver python script in |*directory|.
static bool GetTestServerDirectory(FilePath* directory) WARN_UNUSED_RESULT;
+ // Adds the command line arguments for the Python test server to
+ // |command_line|. Returns true on success.
+ virtual bool AddCommandLineArguments(CommandLine* command_line) const;
+
private:
bool Init(const FilePath& document_root);
@@ -58,10 +62,6 @@ class LocalTestServer : public BaseTestServer {
// Waits for the server to start. Returns true on success.
bool WaitToStart() WARN_UNUSED_RESULT;
- // Add the command line arguments for the Python test server to
- // |command_line|. Return true on success.
- bool AddCommandLineArguments(CommandLine* command_line) const;
-
// Handle of the Python process running the test server.
base::ProcessHandle process_handle_;
diff --git a/net/tools/testserver/run_testserver.cc b/net/tools/testserver/run_testserver.cc
index f00f9f2..f1e4362 100644
--- a/net/tools/testserver/run_testserver.cc
+++ b/net/tools/testserver/run_testserver.cc
@@ -10,15 +10,19 @@
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/process_util.h"
+#include "base/string_number_conversions.h"
#include "base/test/test_timeouts.h"
#include "base/utf_string_conversions.h"
+#include "net/test/local_sync_test_server.h"
#include "net/test/python_utils.h"
#include "net/test/test_server.h"
static void PrintUsage() {
printf("run_testserver --doc-root=relpath [--http|--https|--ftp|--sync]\n"
- " [--https-cert=ok|mismatched-name|expired]\n");
- printf("(NOTE: relpath should be relative to the 'src' directory)\n");
+ " [--https-cert=ok|mismatched-name|expired]\n"
+ " [--port=<port>] [--xmpp-port=<xmpp_port>]\n");
+ printf("(NOTE: relpath should be relative to the 'src' directory.\n");
+ printf(" --port and --xmpp-port only work with the --sync flag.)\n");
}
// Launches the chromiumsync_test script, testing the --sync functionality.
@@ -51,6 +55,23 @@ static bool RunSyncTest() {
return true;
}
+// Gets a port value from the switch with name |switch_name| and writes it to
+// |port|. Returns true if successful and false otherwise.
+static bool GetPortFromSwitch(const std::string& switch_name, uint16* port) {
+ DCHECK(port != NULL) << "|port| is NULL";
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ int port_int = 0;
+ if (command_line->HasSwitch(switch_name)) {
+ std::string port_str = command_line->GetSwitchValueASCII(switch_name);
+ if (!base::StringToInt(port_str, &port_int)) {
+ LOG(WARNING) << "Could not extract port from switch " << switch_name;
+ return false;
+ }
+ }
+ *port = static_cast<uint16>(port_int);
+ return true;
+}
+
int main(int argc, const char* argv[]) {
base::AtExitManager at_exit_manager;
MessageLoopForIO message_loop;
@@ -71,7 +92,11 @@ int main(int argc, const char* argv[]) {
TestTimeouts::Initialize();
- if (command_line->GetSwitches().empty() || command_line->HasSwitch("help")) {
+ if (command_line->GetSwitches().empty() ||
+ command_line->HasSwitch("help") ||
+ ((command_line->HasSwitch("port") ||
+ command_line->HasSwitch("xmpp-port")) &&
+ !command_line->HasSwitch("sync"))) {
PrintUsage();
return -1;
}
@@ -114,12 +139,29 @@ int main(int argc, const char* argv[]) {
}
scoped_ptr<net::TestServer> test_server;
- if (server_type == net::TestServer::TYPE_HTTPS)
- test_server.reset(new net::TestServer(https_options, doc_root));
- else
- test_server.reset(new net::TestServer(server_type,
- net::TestServer::kLocalhost,
- doc_root));
+ switch (server_type) {
+ case net::TestServer::TYPE_HTTPS: {
+ test_server.reset(new net::TestServer(https_options, doc_root));
+ break;
+ }
+ case net::TestServer::TYPE_SYNC: {
+ uint16 port = 0;
+ uint16 xmpp_port = 0;
+ if (!GetPortFromSwitch("port", &port) ||
+ !GetPortFromSwitch("xmpp-port", &xmpp_port)) {
+ printf("Error: Could not extract --port and/or --xmpp-port.\n");
+ return -1;
+ }
+ test_server.reset(new net::LocalSyncTestServer(port, xmpp_port));
+ break;
+ }
+ default: {
+ test_server.reset(new net::TestServer(server_type,
+ net::TestServer::kLocalhost,
+ doc_root));
+ break;
+ }
+ }
if (!test_server->Start()) {
printf("Error: failed to start test server. Exiting.\n");
diff --git a/net/tools/testserver/testserver.py b/net/tools/testserver/testserver.py
index 82e9b61..2a0284a 100755
--- a/net/tools/testserver/testserver.py
+++ b/net/tools/testserver/testserver.py
@@ -180,7 +180,7 @@ class HTTPSServer(tlslite.api.TLSSocketServerMixIn,
class SyncHTTPServer(ClientRestrictingServerMixIn, StoppableHTTPServer):
"""An HTTP server that handles sync commands."""
- def __init__(self, server_address, request_handler_class):
+ def __init__(self, server_address, xmpp_port, request_handler_class):
# We import here to avoid pulling in chromiumsync's dependencies
# unless strictly necessary.
import chromiumsync
@@ -189,7 +189,7 @@ class SyncHTTPServer(ClientRestrictingServerMixIn, StoppableHTTPServer):
self._sync_handler = chromiumsync.TestServer()
self._xmpp_socket_map = {}
self._xmpp_server = xmppserver.XmppServer(
- self._xmpp_socket_map, ('localhost', 0))
+ self._xmpp_socket_map, ('localhost', xmpp_port))
self.xmpp_port = self._xmpp_server.getsockname()[1]
self.authenticated = True
@@ -2063,7 +2063,8 @@ def main(options, args):
server.policy_user = options.policy_user
server.gdata_auth_token = options.auth_token
elif options.server_type == SERVER_SYNC:
- server = SyncHTTPServer((host, port), SyncPageHandler)
+ xmpp_port = options.xmpp_port
+ server = SyncHTTPServer((host, port), xmpp_port, SyncPageHandler)
print 'Sync HTTP server started on port %d...' % server.server_port
print 'Sync XMPP server started on port %d...' % server.xmpp_port
server_data['port'] = server.server_port
@@ -2164,6 +2165,9 @@ if __name__ == '__main__':
option_parser.add_option('', '--port', default='0', type='int',
help='Port used by the server. If unspecified, the '
'server will listen on an ephemeral port.')
+ option_parser.add_option('', '--xmpp-port', default='0', type='int',
+ help='Port used by the XMPP server. If unspecified, '
+ 'the XMPP server will listen on an ephemeral port.')
option_parser.add_option('', '--data-dir', dest='data_dir',
help='Directory from which to read the files.')
option_parser.add_option('', '--https', action='store_true', dest='https',