| 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/path_service.h" |
| 8 #include "base/stringprintf.h" |
| 9 #include "base/values.h" |
| 10 #include "chrome/common/chrome_paths.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 base::FilePath& config_file) |
| 17 : net::LocalTestServer(net::BaseTestServer::TYPE_HTTP, |
| 18 net::BaseTestServer::kLocalhost, |
| 19 base::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 base::FilePath()) { |
| 26 // Read configuration from a file in chrome/test/data/policy. |
| 27 base::FilePath source_root; |
| 28 CHECK(PathService::Get(chrome::DIR_TEST_DATA, &source_root)); |
| 29 config_file_ = source_root |
| 30 .AppendASCII("policy") |
| 31 .AppendASCII(base::StringPrintf("policy_%s.json", test_name.c_str())); |
| 32 } |
| 33 |
| 34 LocalPolicyTestServer::~LocalPolicyTestServer() {} |
| 35 |
| 36 GURL LocalPolicyTestServer::GetServiceURL() const { |
| 37 return GetURL("device_management"); |
| 38 } |
| 39 |
| 40 bool LocalPolicyTestServer::SetPythonPath() const { |
| 41 if (!net::LocalTestServer::SetPythonPath()) |
| 42 return false; |
| 43 |
| 44 // Add the net/tools/testserver directory to the path. |
| 45 base::FilePath net_testserver_path; |
| 46 if (!LocalTestServer::GetTestServerPath(&net_testserver_path)) { |
| 47 LOG(ERROR) << "Failed to get net testserver path."; |
| 48 return false; |
| 49 } |
| 50 AppendToPythonPath(net_testserver_path.DirName()); |
| 51 |
| 52 // Add the generated python protocol buffer bindings. |
| 53 base::FilePath pyproto_dir; |
| 54 if (!GetPyProtoPath(&pyproto_dir)) { |
| 55 LOG(ERROR) << "Cannot find pyproto dir for generated code."; |
| 56 return false; |
| 57 } |
| 58 |
| 59 AppendToPythonPath(pyproto_dir |
| 60 .AppendASCII("chrome") |
| 61 .AppendASCII("browser") |
| 62 .AppendASCII("policy") |
| 63 .AppendASCII("proto")); |
| 64 return true; |
| 65 } |
| 66 |
| 67 bool LocalPolicyTestServer::GetTestServerPath( |
| 68 base::FilePath* testserver_path) const { |
| 69 base::FilePath source_root; |
| 70 if (!PathService::Get(base::DIR_SOURCE_ROOT, &source_root)) { |
| 71 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; |
| 72 return false; |
| 73 } |
| 74 *testserver_path = source_root |
| 75 .AppendASCII("chrome") |
| 76 .AppendASCII("browser") |
| 77 .AppendASCII("policy") |
| 78 .AppendASCII("test") |
| 79 .AppendASCII("policy_testserver.py"); |
| 80 return true; |
| 81 } |
| 82 |
| 83 bool LocalPolicyTestServer::GenerateAdditionalArguments( |
| 84 base::DictionaryValue* arguments) const { |
| 85 if (!net::LocalTestServer::GenerateAdditionalArguments(arguments)) |
| 86 return false; |
| 87 |
| 88 arguments->SetString("config-file", config_file_.AsUTF8Unsafe()); |
| 89 return true; |
| 90 } |
| 91 |
| 92 } // namespace policy; |
| OLD | NEW |