OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 "chrome/browser/safe_browsing/local_safebrowsing_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 LocalSafeBrowsingTestServer::LocalSafeBrowsingTestServer( | |
15 const FilePath& data_file) | |
16 : net::LocalTestServer(net::TestServer::TYPE_HTTP, | |
17 net::TestServer::kLocalhost, | |
18 FilePath()), | |
19 data_file_(data_file) {} | |
20 | |
21 LocalSafeBrowsingTestServer::~LocalSafeBrowsingTestServer() {} | |
22 | |
23 bool LocalSafeBrowsingTestServer::GetTestServerPath( | |
24 FilePath* testserver_path) const { | |
25 FilePath testserver_dir; | |
26 if (!PathService::Get(base::DIR_SOURCE_ROOT, &testserver_dir)) { | |
27 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; | |
28 return false; | |
29 } | |
30 | |
31 testserver_dir = testserver_dir | |
32 .Append(FILE_PATH_LITERAL("chrome")) | |
33 .Append(FILE_PATH_LITERAL("browser")) | |
34 .Append(FILE_PATH_LITERAL("safe_browsing")); | |
35 | |
36 *testserver_path = testserver_dir.Append(FILE_PATH_LITERAL( | |
37 "safe_browsing_testserver.py")); | |
38 return true; | |
39 } | |
40 | |
41 bool LocalSafeBrowsingTestServer::SetPythonPath() const { | |
42 if (!net::LocalTestServer::SetPythonPath()) | |
43 return false; | |
44 | |
45 // Locate the Python code generated by the protocol buffers compiler. | |
46 FilePath pyproto_dir; | |
47 if (!GetPyProtoPath(&pyproto_dir)) { | |
48 LOG(ERROR) << "Cannot find pyproto dir for generated code."; | |
49 return false; | |
50 } | |
51 | |
52 AppendToPythonPath(pyproto_dir.AppendASCII("google")); | |
53 return true; | |
54 } | |
55 | |
56 bool LocalSafeBrowsingTestServer::AddCommandLineArguments( | |
Ryan Sleevi
2012/08/08 06:15:40
Perhaps that, instead of having to override AddCom
mattm
2012/08/30 21:50:47
That sounds reasonable, changed.
I'm still unsure
| |
57 CommandLine* command_line) const { | |
58 if (!net::LocalTestServer::AddCommandLineArguments(command_line)) | |
59 return false; | |
60 // We can't use AppendSwitchPath since it will stick the switch before the | |
61 // path to the python script. | |
62 std::string data_file_string = data_file_.MaybeAsASCII(); | |
63 if (data_file_string.empty()) { | |
64 LOG(ERROR) << "data_file path is non-ascii"; | |
65 return false; | |
66 } | |
67 command_line->AppendArg("--data-file=" + data_file_string); | |
68 return true; | |
69 } | |
OLD | NEW |