| Index: sync/test/local_sync_test_server.cc
|
| diff --git a/sync/test/local_sync_test_server.cc b/sync/test/local_sync_test_server.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d5a9b5f76eaf2463b058f23e401d124aeeed777d
|
| --- /dev/null
|
| +++ b/sync/test/local_sync_test_server.cc
|
| @@ -0,0 +1,99 @@
|
| +// Copyright 2013 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 "sync/test/local_sync_test_server.h"
|
| +
|
| +#include "base/command_line.h"
|
| +#include "base/path_service.h"
|
| +#include "base/string_number_conversions.h"
|
| +#include "base/values.h"
|
| +#include "net/test/python_utils.h"
|
| +#include "net/test/test_server.h"
|
| +
|
| +namespace syncer {
|
| +
|
| +LocalSyncTestServer::LocalSyncTestServer()
|
| + : LocalTestServer(net::TestServer::TYPE_HTTP, // Sync uses the HTTP scheme.
|
| + net::TestServer::kLocalhost,
|
| + FilePath()),
|
| + xmpp_port_(0) {}
|
| +
|
| +LocalSyncTestServer::LocalSyncTestServer(uint16 port, uint16 xmpp_port)
|
| + : LocalTestServer(net::TestServer::TYPE_HTTP, // Sync uses the HTTP scheme.
|
| + net::TestServer::kLocalhost,
|
| + FilePath()),
|
| + xmpp_port_(xmpp_port) {
|
| + SetPort(port);
|
| +}
|
| +
|
| +LocalSyncTestServer::~LocalSyncTestServer() {}
|
| +
|
| +bool LocalSyncTestServer::AddCommandLineArguments(
|
| + CommandLine* command_line) const {
|
| + if (!LocalTestServer::AddCommandLineArguments(command_line))
|
| + return false;
|
| + if (xmpp_port_ != 0) {
|
| + std::string xmpp_port_str = base::IntToString(xmpp_port_);
|
| + command_line->AppendArg("--xmpp-port=" + xmpp_port_str);
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +bool LocalSyncTestServer::GetTestServerDirectory(FilePath* directory) const {
|
| + FilePath src_root_dir;
|
| + if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_root_dir)) {
|
| + LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT";
|
| + return false;
|
| + }
|
| +
|
| + FilePath sync_testserver_dir = src_root_dir
|
| + .Append(FILE_PATH_LITERAL("sync"))
|
| + .Append(FILE_PATH_LITERAL("tools"))
|
| + .Append(FILE_PATH_LITERAL("testserver"));
|
| + *directory = sync_testserver_dir;
|
| + return true;
|
| +}
|
| +
|
| +bool LocalSyncTestServer::GetTestServerPath(FilePath* testserver_path) const {
|
| + if (!GetTestServerDirectory(testserver_path))
|
| + return false;
|
| + *testserver_path = testserver_path->Append(FILE_PATH_LITERAL(
|
| + "sync_testserver.py"));
|
| + return true;
|
| +}
|
| +
|
| +bool LocalSyncTestServer::GetTestScriptPath(
|
| + const FilePath::StringType& test_script_name,
|
| + FilePath* test_script_path) const {
|
| + if (!GetTestServerDirectory(test_script_path))
|
| + return false;
|
| + *test_script_path = test_script_path->Append(test_script_name);
|
| + return true;
|
| +}
|
| +
|
| +bool LocalSyncTestServer::SetPythonPath() const {
|
| + if (!LocalTestServer::SetPythonPath())
|
| + return false;
|
| +
|
| + // Add the net/tools/testserver directory to the path, so that testserver_base
|
| + // can be imported.
|
| + FilePath net_testserver_dir;
|
| + if (!LocalTestServer::GetTestServerDirectory(&net_testserver_dir)) {
|
| + LOG(ERROR) << "Failed to get base testserver directory.";
|
| + return false;
|
| + }
|
| + AppendToPythonPath(net_testserver_dir);
|
| +
|
| + // Locate the Python code generated by the sync protocol buffers compiler.
|
| + FilePath pyproto_dir;
|
| + if (!GetPyProtoPath(&pyproto_dir)) {
|
| + LOG(WARNING) << "Cannot find pyproto dir for generated code. "
|
| + << "Testserver features that rely on it will not work";
|
| + return true;
|
| + }
|
| + AppendToPythonPath(pyproto_dir.AppendASCII("sync").AppendASCII("protocol"));
|
| + return true;
|
| +}
|
| +
|
| +} // namespace syncer
|
|
|