OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "sync/test/local_sync_test_server.h" | |
6 | |
7 #include <stdint.h> | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/command_line.h" | |
12 #include "base/path_service.h" | |
13 #include "base/strings/string_number_conversions.h" | |
14 #include "base/values.h" | |
15 #include "net/test/python_utils.h" | |
16 #include "net/test/spawned_test_server/spawned_test_server.h" | |
17 | |
18 namespace syncer { | |
19 | |
20 LocalSyncTestServer::LocalSyncTestServer() | |
21 : LocalTestServer( | |
22 net::SpawnedTestServer::TYPE_HTTP, // Sync uses the HTTP scheme. | |
23 net::SpawnedTestServer::kLocalhost, | |
24 base::FilePath()), | |
25 xmpp_port_(0) {} | |
26 | |
27 LocalSyncTestServer::LocalSyncTestServer(uint16_t port, uint16_t xmpp_port) | |
28 : LocalTestServer( | |
29 net::SpawnedTestServer::TYPE_HTTP, // Sync uses the HTTP scheme. | |
30 net::SpawnedTestServer::kLocalhost, | |
31 base::FilePath()), | |
32 xmpp_port_(xmpp_port) { | |
33 SetPort(port); | |
34 } | |
35 | |
36 LocalSyncTestServer::~LocalSyncTestServer() {} | |
37 | |
38 bool LocalSyncTestServer::AddCommandLineArguments( | |
39 base::CommandLine* command_line) const { | |
40 if (!LocalTestServer::AddCommandLineArguments(command_line)) | |
41 return false; | |
42 if (xmpp_port_ != 0) { | |
43 std::string xmpp_port_str = base::UintToString(xmpp_port_); | |
44 command_line->AppendArg("--xmpp-port=" + xmpp_port_str); | |
45 } | |
46 return true; | |
47 } | |
48 | |
49 bool LocalSyncTestServer::GetTestServerPath( | |
50 base::FilePath* testserver_path) const { | |
51 base::FilePath testserver_dir; | |
52 if (!PathService::Get(base::DIR_SOURCE_ROOT, &testserver_dir)) { | |
53 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; | |
54 return false; | |
55 } | |
56 testserver_dir = testserver_dir.Append(FILE_PATH_LITERAL("sync")) | |
57 .Append(FILE_PATH_LITERAL("tools")) | |
58 .Append(FILE_PATH_LITERAL("testserver")); | |
59 | |
60 *testserver_path = | |
61 testserver_dir.Append(FILE_PATH_LITERAL("sync_testserver.py")); | |
62 return true; | |
63 } | |
64 | |
65 bool LocalSyncTestServer::GetTestScriptPath( | |
66 const base::FilePath::StringType& test_script_name, | |
67 base::FilePath* test_script_path) const { | |
68 base::FilePath testserver_path; | |
69 if (!GetTestServerPath(&testserver_path)) | |
70 return false; | |
71 *test_script_path = testserver_path.DirName().Append(test_script_name); | |
72 return true; | |
73 } | |
74 | |
75 bool LocalSyncTestServer::SetPythonPath() const { | |
76 if (!LocalTestServer::SetPythonPath()) | |
77 return false; | |
78 | |
79 // Add the net/tools/testserver directory to the path, so that testserver_base | |
80 // can be imported. | |
81 base::FilePath net_testserver_path; | |
82 if (!LocalTestServer::GetTestServerPath(&net_testserver_path)) { | |
83 LOG(ERROR) << "Failed to get net testserver path."; | |
84 return false; | |
85 } | |
86 AppendToPythonPath(net_testserver_path.DirName()); | |
87 | |
88 // Locate the Python code generated by the sync protocol buffers compiler. | |
89 base::FilePath pyproto_dir; | |
90 if (!GetPyProtoPath(&pyproto_dir)) { | |
91 LOG(WARNING) << "Cannot find pyproto dir for generated code. " | |
92 << "Testserver features that rely on it will not work"; | |
93 return true; | |
94 } | |
95 AppendToPythonPath(pyproto_dir.AppendASCII("sync").AppendASCII("protocol")); | |
96 return true; | |
97 } | |
98 | |
99 } // namespace syncer | |
OLD | NEW |