Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / sync / test / local_sync_test_server.cc
blobe8a10966724847edf6f9a0ba82c8c6fbc833858d
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"
14 namespace syncer {
16 LocalSyncTestServer::LocalSyncTestServer()
17 : LocalTestServer(
18 net::SpawnedTestServer::TYPE_HTTP, // Sync uses the HTTP scheme.
19 net::SpawnedTestServer::kLocalhost,
20 base::FilePath()),
21 xmpp_port_(0) {}
23 LocalSyncTestServer::LocalSyncTestServer(uint16 port, uint16 xmpp_port)
24 : LocalTestServer(
25 net::SpawnedTestServer::TYPE_HTTP, // Sync uses the HTTP scheme.
26 net::SpawnedTestServer::kLocalhost,
27 base::FilePath()),
28 xmpp_port_(xmpp_port) {
29 SetPort(port);
32 LocalSyncTestServer::~LocalSyncTestServer() {}
34 bool LocalSyncTestServer::AddCommandLineArguments(
35 base::CommandLine* command_line) const {
36 if (!LocalTestServer::AddCommandLineArguments(command_line))
37 return false;
38 if (xmpp_port_ != 0) {
39 std::string xmpp_port_str = base::IntToString(xmpp_port_);
40 command_line->AppendArg("--xmpp-port=" + xmpp_port_str);
42 return true;
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";
50 return false;
52 testserver_dir = testserver_dir.Append(FILE_PATH_LITERAL("sync"))
53 .Append(FILE_PATH_LITERAL("tools"))
54 .Append(FILE_PATH_LITERAL("testserver"));
56 *testserver_path =
57 testserver_dir.Append(FILE_PATH_LITERAL("sync_testserver.py"));
58 return true;
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))
66 return false;
67 *test_script_path = testserver_path.DirName().Append(test_script_name);
68 return true;
71 bool LocalSyncTestServer::SetPythonPath() const {
72 if (!LocalTestServer::SetPythonPath())
73 return false;
75 // Add the net/tools/testserver directory to the path, so that testserver_base
76 // can be imported.
77 base::FilePath net_testserver_path;
78 if (!LocalTestServer::GetTestServerPath(&net_testserver_path)) {
79 LOG(ERROR) << "Failed to get net testserver path.";
80 return false;
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";
89 return true;
91 AppendToPythonPath(pyproto_dir.AppendASCII("sync").AppendASCII("protocol"));
92 return true;
95 } // namespace syncer