Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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 "chrome/browser/policy/test/local_policy_test_server.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
|
Joao da Silva
2013/02/12 19:06:05
not used
Mattias Nissler (ping if slow)
2013/02/13 11:54:10
Done.
| |
| 8 #include "base/path_service.h" | |
| 9 #include "base/stringprintf.h" | |
| 10 #include "base/values.h" | |
| 11 #include "net/test/base_test_server.h" | |
| 12 #include "net/test/python_utils.h" | |
| 13 | |
| 14 namespace policy { | |
| 15 | |
| 16 LocalPolicyTestServer::LocalPolicyTestServer(const FilePath& config_file) | |
| 17 : net::LocalTestServer(net::BaseTestServer::TYPE_HTTP, | |
| 18 net::BaseTestServer::kLocalhost, | |
| 19 FilePath()), | |
| 20 config_file_(config_file) {} | |
| 21 | |
| 22 LocalPolicyTestServer::LocalPolicyTestServer(const std::string& test_name) | |
| 23 : net::LocalTestServer(net::BaseTestServer::TYPE_HTTP, | |
| 24 net::BaseTestServer::kLocalhost, | |
| 25 FilePath()) { | |
| 26 // Read configuration from a file in chrome/test/data/policy. | |
| 27 FilePath source_root; | |
| 28 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &source_root)); | |
| 29 config_file_ = source_root | |
| 30 .AppendASCII("chrome") | |
| 31 .AppendASCII("test") | |
| 32 .AppendASCII("data") | |
|
Joao da Silva
2013/02/12 19:06:05
FWIW there's also chrome::DIR_TEST_DATA
Mattias Nissler (ping if slow)
2013/02/13 11:54:10
Done.
| |
| 33 .AppendASCII("policy") | |
| 34 .AppendASCII(base::StringPrintf("policy_%s.json", test_name.c_str())); | |
| 35 } | |
| 36 | |
| 37 LocalPolicyTestServer::~LocalPolicyTestServer() {} | |
| 38 | |
| 39 GURL LocalPolicyTestServer::GetServiceURL() const { | |
| 40 return GetURL("device_management"); | |
| 41 } | |
| 42 | |
| 43 bool LocalPolicyTestServer::SetPythonPath() const { | |
| 44 if (!net::LocalTestServer::SetPythonPath()) | |
| 45 return false; | |
| 46 | |
| 47 // Add the net/tools/testserver directory to the path. | |
| 48 FilePath net_testserver_path; | |
| 49 if (!LocalTestServer::GetTestServerPath(&net_testserver_path)) { | |
| 50 LOG(ERROR) << "Failed to get net testserver path."; | |
| 51 return false; | |
| 52 } | |
| 53 AppendToPythonPath(net_testserver_path.DirName()); | |
| 54 | |
| 55 // Add the generated python protocol buffer bindings. | |
| 56 FilePath pyproto_dir; | |
| 57 if (!GetPyProtoPath(&pyproto_dir)) { | |
| 58 LOG(ERROR) << "Cannot find pyproto dir for generated code."; | |
| 59 return false; | |
| 60 } | |
| 61 | |
| 62 AppendToPythonPath(pyproto_dir | |
| 63 .AppendASCII("chrome") | |
| 64 .AppendASCII("browser") | |
| 65 .AppendASCII("policy") | |
| 66 .AppendASCII("proto")); | |
| 67 return true; | |
| 68 } | |
| 69 | |
| 70 bool LocalPolicyTestServer::GetTestServerPath(FilePath* testserver_path) const { | |
| 71 FilePath source_root; | |
| 72 if (!PathService::Get(base::DIR_SOURCE_ROOT, &source_root)) { | |
| 73 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; | |
| 74 return false; | |
| 75 } | |
| 76 *testserver_path = source_root | |
| 77 .AppendASCII("chrome") | |
| 78 .AppendASCII("browser") | |
| 79 .AppendASCII("policy") | |
| 80 .AppendASCII("test") | |
| 81 .AppendASCII("policy_testserver.py"); | |
| 82 return true; | |
| 83 } | |
| 84 | |
| 85 bool LocalPolicyTestServer::GenerateAdditionalArguments( | |
| 86 base::DictionaryValue* arguments) const { | |
| 87 if (!net::LocalTestServer::GenerateAdditionalArguments(arguments)) | |
| 88 return false; | |
| 89 | |
| 90 arguments->SetString("config-file", config_file_.AsUTF8Unsafe()); | |
| 91 return true; | |
| 92 } | |
| 93 | |
| 94 } // namespace policy; | |
|
Joao da Silva
2013/02/12 19:06:05
remove ;
| |
| OLD | NEW |