1 // Copyright 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.
5 #include "chrome/browser/policy/policy_test_utils.h"
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"
16 bool PolicyServiceIsEmpty(const PolicyService* service) {
17 const PolicyMap& map = service->GetPolicies(
18 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
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;
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;
41 std::ostream& operator<<(std::ostream& os, policy::PolicyScope scope) {
43 case policy::POLICY_SCOPE_USER: {
44 os << "POLICY_SCOPE_USER";
47 case policy::POLICY_SCOPE_MACHINE: {
48 os << "POLICY_SCOPE_MACHINE";
52 os << "POLICY_SCOPE_UNKNOWN(" << int(scope) << ")";
58 std::ostream& operator<<(std::ostream& os, policy::PolicyLevel level) {
60 case policy::POLICY_LEVEL_RECOMMENDED: {
61 os << "POLICY_LEVEL_RECOMMENDED";
64 case policy::POLICY_LEVEL_MANDATORY: {
65 os << "POLICY_LEVEL_MANDATORY";
69 os << "POLICY_LEVEL_UNKNOWN(" << int(level) << ")";
75 std::ostream& operator<<(std::ostream& os, policy::PolicyDomain domain) {
77 case policy::POLICY_DOMAIN_CHROME: {
78 os << "POLICY_DOMAIN_CHROME";
81 case policy::POLICY_DOMAIN_EXTENSIONS: {
82 os << "POLICY_DOMAIN_EXTENSIONS";
86 os << "POLICY_DOMAIN_UNKNOWN(" << int(domain) << ")";
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;
102 std::ostream& operator<<(std::ostream& os, const policy::PolicyMap::Entry& e) {
104 base::JSONWriter::WriteWithOptions(e.value,
105 base::JSONWriter::OPTIONS_PRETTY_PRINT,
107 os << "{" << std::endl
108 << " \"level\": " << e.level << "," << std::endl
109 << " \"scope\": " << e.scope << "," << std::endl
110 << " \"value\": " << value
115 std::ostream& operator<<(std::ostream& os, const policy::PolicyNamespace& ns) {
116 os << ns.domain << "/" << ns.component_id;