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/policy_test_utils.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/json/json_writer.h" |
| 10 #include "base/logging.h" |
| 11 #include "base/values.h" |
| 12 #include "chrome/browser/policy/policy_bundle.h" |
| 13 |
| 14 namespace policy { |
| 15 |
| 16 bool PolicyServiceIsEmpty(const PolicyService* service) { |
| 17 const PolicyMap& map = service->GetPolicies( |
| 18 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
| 19 if (!map.empty()) { |
| 20 base::DictionaryValue dict; |
| 21 for (PolicyMap::const_iterator it = map.begin(); it != map.end(); ++it) |
| 22 dict.SetWithoutPathExpansion(it->first, it->second.value->DeepCopy()); |
| 23 LOG(WARNING) << "There are pre-existing policies in this machine: " << dict; |
| 24 } |
| 25 return map.empty(); |
| 26 } |
| 27 |
| 28 } // namespace policy |
| 29 |
| 30 std::ostream& operator<<(std::ostream& os, |
| 31 const policy::PolicyBundle& bundle) { |
| 32 os << "{" << std::endl; |
| 33 for (policy::PolicyBundle::const_iterator iter = bundle.begin(); |
| 34 iter != bundle.end(); ++iter) { |
| 35 os << " \"" << iter->first << "\": " << *iter->second << "," << std::endl; |
| 36 } |
| 37 os << "}"; |
| 38 return os; |
| 39 } |
| 40 |
| 41 std::ostream& operator<<(std::ostream& os, policy::PolicyScope scope) { |
| 42 switch (scope) { |
| 43 case policy::POLICY_SCOPE_USER: { |
| 44 os << "POLICY_SCOPE_USER"; |
| 45 break; |
| 46 } |
| 47 case policy::POLICY_SCOPE_MACHINE: { |
| 48 os << "POLICY_SCOPE_MACHINE"; |
| 49 break; |
| 50 } |
| 51 default: { |
| 52 os << "POLICY_SCOPE_UNKNOWN(" << int(scope) << ")"; |
| 53 } |
| 54 } |
| 55 return os; |
| 56 } |
| 57 |
| 58 std::ostream& operator<<(std::ostream& os, policy::PolicyLevel level) { |
| 59 switch (level) { |
| 60 case policy::POLICY_LEVEL_RECOMMENDED: { |
| 61 os << "POLICY_LEVEL_RECOMMENDED"; |
| 62 break; |
| 63 } |
| 64 case policy::POLICY_LEVEL_MANDATORY: { |
| 65 os << "POLICY_LEVEL_MANDATORY"; |
| 66 break; |
| 67 } |
| 68 default: { |
| 69 os << "POLICY_LEVEL_UNKNOWN(" << int(level) << ")"; |
| 70 } |
| 71 } |
| 72 return os; |
| 73 } |
| 74 |
| 75 std::ostream& operator<<(std::ostream& os, policy::PolicyDomain domain) { |
| 76 switch (domain) { |
| 77 case policy::POLICY_DOMAIN_CHROME: { |
| 78 os << "POLICY_DOMAIN_CHROME"; |
| 79 break; |
| 80 } |
| 81 case policy::POLICY_DOMAIN_EXTENSIONS: { |
| 82 os << "POLICY_DOMAIN_EXTENSIONS"; |
| 83 break; |
| 84 } |
| 85 default: { |
| 86 os << "POLICY_DOMAIN_UNKNOWN(" << int(domain) << ")"; |
| 87 } |
| 88 } |
| 89 return os; |
| 90 } |
| 91 |
| 92 std::ostream& operator<<(std::ostream& os, const policy::PolicyMap& policies) { |
| 93 os << "{" << std::endl; |
| 94 for (policy::PolicyMap::const_iterator iter = policies.begin(); |
| 95 iter != policies.end(); ++iter) { |
| 96 os << " \"" << iter->first << "\": " << iter->second << "," << std::endl; |
| 97 } |
| 98 os << "}"; |
| 99 return os; |
| 100 } |
| 101 |
| 102 std::ostream& operator<<(std::ostream& os, const policy::PolicyMap::Entry& e) { |
| 103 std::string value; |
| 104 base::JSONWriter::WriteWithOptions(e.value, |
| 105 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 106 &value); |
| 107 os << "{" << std::endl |
| 108 << " \"level\": " << e.level << "," << std::endl |
| 109 << " \"scope\": " << e.scope << "," << std::endl |
| 110 << " \"value\": " << value |
| 111 << "}"; |
| 112 return os; |
| 113 } |
| 114 |
| 115 std::ostream& operator<<(std::ostream& os, const policy::PolicyNamespace& ns) { |
| 116 os << ns.domain << "/" << ns.component_id; |
| 117 return os; |
| 118 } |
OLD | NEW |