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

Side by Side Diff: chrome/browser/policy/test_utils.cc

Issue 23532033: policy: Add ostream operator overloads to policy types for testing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/policy/test_utils.h" 5 #include "chrome/browser/policy/test_utils.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/policy/policy_map.h" 11 #include "chrome/browser/policy/policy_bundle.h"
12 #include "chrome/browser/policy/policy_service.h"
13 12
14 namespace policy { 13 namespace policy {
15 14
16 bool PolicyServiceIsEmpty(const PolicyService* service) { 15 bool PolicyServiceIsEmpty(const PolicyService* service) {
17 const PolicyMap& map = service->GetPolicies( 16 const PolicyMap& map = service->GetPolicies(
18 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); 17 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
19 if (!map.empty()) { 18 if (!map.empty()) {
20 base::DictionaryValue dict; 19 base::DictionaryValue dict;
21 for (PolicyMap::const_iterator it = map.begin(); it != map.end(); ++it) 20 for (PolicyMap::const_iterator it = map.begin(); it != map.end(); ++it)
22 dict.SetWithoutPathExpansion(it->first, it->second.value->DeepCopy()); 21 dict.SetWithoutPathExpansion(it->first, it->second.value->DeepCopy());
23 LOG(WARNING) << "There are pre-existing policies in this machine: " << dict; 22 LOG(WARNING) << "There are pre-existing policies in this machine: " << dict;
24 } 23 }
25 return map.empty(); 24 return map.empty();
26 } 25 }
27 26
28 } // namespace policy 27 } // namespace policy
28
29 std::ostream& operator<<(std::ostream& os,
30 const policy::PolicyBundle& bundle) {
31 os << "{";
32 for (policy::PolicyBundle::const_iterator iter = bundle.begin();
33 iter != bundle.end(); ++iter) {
34 os << iter->first << ": " << *iter->second << std::endl;
35 }
36 os << "}" << std::endl;
37 return os;
38 }
39
40 std::ostream& operator<<(std::ostream& os, policy::PolicyDomain domain) {
41 switch (domain) {
42 case policy::POLICY_DOMAIN_CHROME: {
43 os << "POLICY_DOMAIN_CHROME";
44 break;
45 }
46 case policy::POLICY_DOMAIN_EXTENSIONS: {
47 os << "POLICY_DOMAIN_EXTENSIONS";
48 break;
49 }
50 default: {
51 os << "POLICY_DOMAIN_UNKNOWN";
Mattias Nissler (ping if slow) 2013/09/03 15:31:50 would probably be better to log the numerical valu
dconnelly 2013/09/04 17:43:02 Done.
52 }
53 }
54 return os;
55 }
56
57 std::ostream& operator<<(std::ostream& os, const policy::PolicyMap& policies) {
58 os << "{";
59 for (policy::PolicyMap::const_iterator iter = policies.begin();
60 iter != policies.end(); ++iter) {
61 os << iter->first << ": " << iter->second << std::endl;
62 }
63 os << "}" << std::endl;
64 return os;
65 }
66
67 std::ostream& operator<<(std::ostream& os, const policy::PolicyMap::Entry& e) {
68 os << "PolicyMap::Entry(" << e.level << ", " << e.scope
69 << ", " << *e.value << ")";
70 return os;
71 }
72
73 std::ostream& operator<<(std::ostream& os, const policy::PolicyNamespace& ns) {
74 os << "PolicyNamespace(" << ns.domain << ", " << ns.component_id << ")";
75 return os;
76 }
OLDNEW
« chrome/browser/policy/test_utils.h ('K') | « chrome/browser/policy/test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698