1 // Copyright 2013 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.
5 #include "sync/test/local_sync_test_server.h"
7 #include "base/command_line.h"
8 #include "base/path_service.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/values.h"
11 #include "net/test/python_utils.h"
12 #include "net/test/spawned_test_server/spawned_test_server.h"
16 LocalSyncTestServer::LocalSyncTestServer()
18 net::SpawnedTestServer::TYPE_HTTP
, // Sync uses the HTTP scheme.
19 net::SpawnedTestServer::kLocalhost
,
23 LocalSyncTestServer::LocalSyncTestServer(uint16 port
, uint16 xmpp_port
)
25 net::SpawnedTestServer::TYPE_HTTP
, // Sync uses the HTTP scheme.
26 net::SpawnedTestServer::kLocalhost
,
28 xmpp_port_(xmpp_port
) {
32 LocalSyncTestServer::~LocalSyncTestServer() {}
34 bool LocalSyncTestServer::AddCommandLineArguments(
35 base::CommandLine
* command_line
) const {
36 if (!LocalTestServer::AddCommandLineArguments(command_line
))
38 if (xmpp_port_
!= 0) {
39 std::string xmpp_port_str
= base::IntToString(xmpp_port_
);
40 command_line
->AppendArg("--xmpp-port=" + xmpp_port_str
);
45 bool LocalSyncTestServer::GetTestServerPath(
46 base::FilePath
* testserver_path
) const {
47 base::FilePath testserver_dir
;
48 if (!PathService::Get(base::DIR_SOURCE_ROOT
, &testserver_dir
)) {
49 LOG(ERROR
) << "Failed to get DIR_SOURCE_ROOT";
52 testserver_dir
= testserver_dir
.Append(FILE_PATH_LITERAL("sync"))
53 .Append(FILE_PATH_LITERAL("tools"))
54 .Append(FILE_PATH_LITERAL("testserver"));
57 testserver_dir
.Append(FILE_PATH_LITERAL("sync_testserver.py"));
61 bool LocalSyncTestServer::GetTestScriptPath(
62 const base::FilePath::StringType
& test_script_name
,
63 base::FilePath
* test_script_path
) const {
64 base::FilePath testserver_path
;
65 if (!GetTestServerPath(&testserver_path
))
67 *test_script_path
= testserver_path
.DirName().Append(test_script_name
);
71 bool LocalSyncTestServer::SetPythonPath() const {
72 if (!LocalTestServer::SetPythonPath())
75 // Add the net/tools/testserver directory to the path, so that testserver_base
77 base::FilePath net_testserver_path
;
78 if (!LocalTestServer::GetTestServerPath(&net_testserver_path
)) {
79 LOG(ERROR
) << "Failed to get net testserver path.";
82 AppendToPythonPath(net_testserver_path
.DirName());
84 // Locate the Python code generated by the sync protocol buffers compiler.
85 base::FilePath pyproto_dir
;
86 if (!GetPyProtoPath(&pyproto_dir
)) {
87 LOG(WARNING
) << "Cannot find pyproto dir for generated code. "
88 << "Testserver features that rely on it will not work";
91 AppendToPythonPath(pyproto_dir
.AppendASCII("sync").AppendASCII("protocol"));