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.
5 #include "chrome/browser/safe_browsing/local_safebrowsing_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 LocalSafeBrowsingTestServer::LocalSafeBrowsingTestServer(
15 const base::FilePath
& data_file
)
16 : net::LocalTestServer(net::SpawnedTestServer::TYPE_HTTP
,
17 net::SpawnedTestServer::kLocalhost
,
19 data_file_(data_file
) {
22 LocalSafeBrowsingTestServer::~LocalSafeBrowsingTestServer() {}
24 bool LocalSafeBrowsingTestServer::GetTestServerPath(
25 base::FilePath
* testserver_path
) const {
26 base::FilePath testserver_dir
;
27 if (!PathService::Get(base::DIR_SOURCE_ROOT
, &testserver_dir
)) {
28 LOG(ERROR
) << "Failed to get DIR_SOURCE_ROOT";
32 testserver_dir
= testserver_dir
33 .Append(FILE_PATH_LITERAL("chrome"))
34 .Append(FILE_PATH_LITERAL("browser"))
35 .Append(FILE_PATH_LITERAL("safe_browsing"));
37 *testserver_path
= testserver_dir
.Append(FILE_PATH_LITERAL(
38 "safe_browsing_testserver.py"));
42 bool LocalSafeBrowsingTestServer::SetPythonPath() const {
43 if (!net::LocalTestServer::SetPythonPath())
46 // Locate the Python code generated by the protocol buffers compiler.
47 base::FilePath pyproto_dir
;
48 if (!GetPyProtoPath(&pyproto_dir
)) {
49 LOG(ERROR
) << "Cannot find pyproto dir for generated code.";
53 AppendToPythonPath(pyproto_dir
.AppendASCII("google"));
57 bool LocalSafeBrowsingTestServer::GenerateAdditionalArguments(
58 base::DictionaryValue
* arguments
) const {
59 arguments
->SetString("data-file", data_file_
.value());