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