Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Side by Side Diff: chrome/browser/policy/test/policy_test_utils.cc

Issue 109743002: Move policy code into components/policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar fixes Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/policy/test/policy_test_utils.h"
6
7 #include <string>
8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/callback.h"
12 #include "base/json/json_writer.h"
13 #include "base/logging.h"
14 #include "base/values.h"
15 #include "components/policy/core/common/policy_bundle.h"
16
17 namespace policy {
18
19 PolicyDetailsMap::PolicyDetailsMap() {}
20
21 PolicyDetailsMap::~PolicyDetailsMap() {}
22
23 GetChromePolicyDetailsCallback PolicyDetailsMap::GetCallback() const {
24 return base::Bind(&PolicyDetailsMap::Lookup, base::Unretained(this));
25 }
26
27 void PolicyDetailsMap::SetDetails(const std::string& policy,
28 const PolicyDetails* details) {
29 map_[policy] = details;
30 }
31
32 const PolicyDetails* PolicyDetailsMap::Lookup(const std::string& policy) const {
33 PolicyDetailsMapping::const_iterator it = map_.find(policy);
34 return it == map_.end() ? NULL : it->second;
35 }
36
37 bool PolicyServiceIsEmpty(const PolicyService* service) {
38 const PolicyMap& map = service->GetPolicies(
39 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
40 if (!map.empty()) {
41 base::DictionaryValue dict;
42 for (PolicyMap::const_iterator it = map.begin(); it != map.end(); ++it)
43 dict.SetWithoutPathExpansion(it->first, it->second.value->DeepCopy());
44 LOG(WARNING) << "There are pre-existing policies in this machine: " << dict;
45 }
46 return map.empty();
47 }
48
49 } // namespace policy
50
51 std::ostream& operator<<(std::ostream& os,
52 const policy::PolicyBundle& bundle) {
53 os << "{" << std::endl;
54 for (policy::PolicyBundle::const_iterator iter = bundle.begin();
55 iter != bundle.end(); ++iter) {
56 os << " \"" << iter->first << "\": " << *iter->second << "," << std::endl;
57 }
58 os << "}";
59 return os;
60 }
61
62 std::ostream& operator<<(std::ostream& os, policy::PolicyScope scope) {
63 switch (scope) {
64 case policy::POLICY_SCOPE_USER: {
65 os << "POLICY_SCOPE_USER";
66 break;
67 }
68 case policy::POLICY_SCOPE_MACHINE: {
69 os << "POLICY_SCOPE_MACHINE";
70 break;
71 }
72 default: {
73 os << "POLICY_SCOPE_UNKNOWN(" << int(scope) << ")";
74 }
75 }
76 return os;
77 }
78
79 std::ostream& operator<<(std::ostream& os, policy::PolicyLevel level) {
80 switch (level) {
81 case policy::POLICY_LEVEL_RECOMMENDED: {
82 os << "POLICY_LEVEL_RECOMMENDED";
83 break;
84 }
85 case policy::POLICY_LEVEL_MANDATORY: {
86 os << "POLICY_LEVEL_MANDATORY";
87 break;
88 }
89 default: {
90 os << "POLICY_LEVEL_UNKNOWN(" << int(level) << ")";
91 }
92 }
93 return os;
94 }
95
96 std::ostream& operator<<(std::ostream& os, policy::PolicyDomain domain) {
97 switch (domain) {
98 case policy::POLICY_DOMAIN_CHROME: {
99 os << "POLICY_DOMAIN_CHROME";
100 break;
101 }
102 case policy::POLICY_DOMAIN_EXTENSIONS: {
103 os << "POLICY_DOMAIN_EXTENSIONS";
104 break;
105 }
106 default: {
107 os << "POLICY_DOMAIN_UNKNOWN(" << int(domain) << ")";
108 }
109 }
110 return os;
111 }
112
113 std::ostream& operator<<(std::ostream& os, const policy::PolicyMap& policies) {
114 os << "{" << std::endl;
115 for (policy::PolicyMap::const_iterator iter = policies.begin();
116 iter != policies.end(); ++iter) {
117 os << " \"" << iter->first << "\": " << iter->second << "," << std::endl;
118 }
119 os << "}";
120 return os;
121 }
122
123 std::ostream& operator<<(std::ostream& os, const policy::PolicyMap::Entry& e) {
124 std::string value;
125 base::JSONWriter::WriteWithOptions(e.value,
126 base::JSONWriter::OPTIONS_PRETTY_PRINT,
127 &value);
128 os << "{" << std::endl
129 << " \"level\": " << e.level << "," << std::endl
130 << " \"scope\": " << e.scope << "," << std::endl
131 << " \"value\": " << value
132 << "}";
133 return os;
134 }
135
136 std::ostream& operator<<(std::ostream& os, const policy::PolicyNamespace& ns) {
137 os << ns.domain << "/" << ns.component_id;
138 return os;
139 }
OLDNEW
« no previous file with comments | « chrome/browser/policy/test/policy_test_utils.h ('k') | chrome/browser/policy/url_blacklist_policy_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698