Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: sync/test/local_sync_test_server.cc

Issue 11971025: [sync] Divorce python sync test server chromiumsync.py from testserver.py (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Philippe's comments. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "base/command_line.h"
8 #include "base/path_service.h"
9 #include "base/string_number_conversions.h"
10 #include "base/values.h"
11 #include "net/test/python_utils.h"
12 #include "net/test/test_server.h"
13
14 namespace syncer {
15
16 LocalSyncTestServer::LocalSyncTestServer()
17 : LocalTestServer(net::TestServer::TYPE_HTTP, // Sync uses the HTTP scheme.
18 net::TestServer::kLocalhost,
19 FilePath()),
20 xmpp_port_(0) {}
21
22 LocalSyncTestServer::LocalSyncTestServer(uint16 port, uint16 xmpp_port)
23 : LocalTestServer(net::TestServer::TYPE_HTTP, // Sync uses the HTTP scheme.
24 net::TestServer::kLocalhost,
25 FilePath()),
26 xmpp_port_(xmpp_port) {
27 SetPort(port);
28 }
29
30 LocalSyncTestServer::~LocalSyncTestServer() {}
31
32 bool LocalSyncTestServer::AddCommandLineArguments(
33 CommandLine* command_line) const {
34 if (!LocalTestServer::AddCommandLineArguments(command_line))
35 return false;
36 if (xmpp_port_ != 0) {
37 std::string xmpp_port_str = base::IntToString(xmpp_port_);
38 command_line->AppendArg("--xmpp-port=" + xmpp_port_str);
39 }
40 return true;
41 }
42
43 bool LocalSyncTestServer::GetTestServerDirectory(FilePath* directory) const {
44 FilePath src_root_dir;
45 if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_root_dir)) {
46 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT";
47 return false;
48 }
49
50 FilePath sync_testserver_dir = src_root_dir
51 .Append(FILE_PATH_LITERAL("sync"))
52 .Append(FILE_PATH_LITERAL("tools"))
53 .Append(FILE_PATH_LITERAL("testserver"));
54 *directory = sync_testserver_dir;
55 return true;
56 }
57
58 bool LocalSyncTestServer::GetTestServerPath(FilePath* testserver_path) const {
59 if (!GetTestServerDirectory(testserver_path))
60 return false;
61 *testserver_path = testserver_path->Append(FILE_PATH_LITERAL(
62 "sync_testserver.py"));
63 return true;
64 }
65
66 bool LocalSyncTestServer::GetTestScriptPath(
67 const FilePath::StringType& test_script_name,
68 FilePath* test_script_path) const {
69 if (!GetTestServerDirectory(test_script_path))
70 return false;
71 *test_script_path = test_script_path->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 FilePath net_testserver_dir;
82 if (!LocalTestServer::GetTestServerDirectory(&net_testserver_dir)) {
83 LOG(ERROR) << "Failed to get base testserver directory.";
84 return false;
85 }
86 AppendToPythonPath(net_testserver_dir);
87
88 // Locate the Python code generated by the sync protocol buffers compiler.
89 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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698