policy: Add ostream operator overloads to policy types for testing.

BUG=none

Review URL: https://chromiumcodereview.appspot.com/23532033

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221472 0039d316-1c4b-4281-b951-d872f2087c98
parent d5368090
......@@ -21,10 +21,10 @@
#include "chrome/browser/policy/external_data_fetcher.h"
#include "chrome/browser/policy/policy_map.h"
#include "chrome/browser/policy/policy_service.h"
#include "chrome/browser/policy/policy_test_utils.h"
#include "chrome/browser/policy/profile_policy_connector.h"
#include "chrome/browser/policy/profile_policy_connector_factory.h"
#include "chrome/browser/policy/test/local_policy_test_server.h"
#include "chrome/browser/policy/test_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_switches.h"
......
......@@ -10,8 +10,8 @@
#include "chrome/browser/policy/cloud/cloud_policy_client.h"
#include "chrome/browser/policy/cloud/mock_cloud_policy_client.h"
#include "chrome/browser/policy/cloud/test_request_interceptor.h"
#include "chrome/browser/policy/policy_test_utils.h"
#include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h"
#include "chrome/browser/policy/test_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_switches.h"
......
......@@ -16,11 +16,11 @@
#include "chrome/browser/policy/cloud/cloud_policy_constants.h"
#include "chrome/browser/policy/cloud/mock_cloud_policy_client.h"
#include "chrome/browser/policy/policy_service.h"
#include "chrome/browser/policy/policy_test_utils.h"
#include "chrome/browser/policy/profile_policy_connector.h"
#include "chrome/browser/policy/profile_policy_connector_factory.h"
#include "chrome/browser/policy/proto/cloud/chrome_extension_policy.pb.h"
#include "chrome/browser/policy/test/local_policy_test_server.h"
#include "chrome/browser/policy/test_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/policy/policy_test_utils.h"
#include <string>
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/values.h"
#include "chrome/browser/policy/policy_bundle.h"
namespace policy {
bool PolicyServiceIsEmpty(const PolicyService* service) {
const PolicyMap& map = service->GetPolicies(
PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
if (!map.empty()) {
base::DictionaryValue dict;
for (PolicyMap::const_iterator it = map.begin(); it != map.end(); ++it)
dict.SetWithoutPathExpansion(it->first, it->second.value->DeepCopy());
LOG(WARNING) << "There are pre-existing policies in this machine: " << dict;
}
return map.empty();
}
} // namespace policy
std::ostream& operator<<(std::ostream& os,
const policy::PolicyBundle& bundle) {
os << "{" << std::endl;
for (policy::PolicyBundle::const_iterator iter = bundle.begin();
iter != bundle.end(); ++iter) {
os << " \"" << iter->first << "\": " << *iter->second << "," << std::endl;
}
os << "}";
return os;
}
std::ostream& operator<<(std::ostream& os, policy::PolicyScope scope) {
switch (scope) {
case policy::POLICY_SCOPE_USER: {
os << "POLICY_SCOPE_USER";
break;
}
case policy::POLICY_SCOPE_MACHINE: {
os << "POLICY_SCOPE_MACHINE";
break;
}
default: {
os << "POLICY_SCOPE_UNKNOWN(" << int(scope) << ")";
}
}
return os;
}
std::ostream& operator<<(std::ostream& os, policy::PolicyLevel level) {
switch (level) {
case policy::POLICY_LEVEL_RECOMMENDED: {
os << "POLICY_LEVEL_RECOMMENDED";
break;
}
case policy::POLICY_LEVEL_MANDATORY: {
os << "POLICY_LEVEL_MANDATORY";
break;
}
default: {
os << "POLICY_LEVEL_UNKNOWN(" << int(level) << ")";
}
}
return os;
}
std::ostream& operator<<(std::ostream& os, policy::PolicyDomain domain) {
switch (domain) {
case policy::POLICY_DOMAIN_CHROME: {
os << "POLICY_DOMAIN_CHROME";
break;
}
case policy::POLICY_DOMAIN_EXTENSIONS: {
os << "POLICY_DOMAIN_EXTENSIONS";
break;
}
default: {
os << "POLICY_DOMAIN_UNKNOWN(" << int(domain) << ")";
}
}
return os;
}
std::ostream& operator<<(std::ostream& os, const policy::PolicyMap& policies) {
os << "{" << std::endl;
for (policy::PolicyMap::const_iterator iter = policies.begin();
iter != policies.end(); ++iter) {
os << " \"" << iter->first << "\": " << iter->second << "," << std::endl;
}
os << "}";
return os;
}
std::ostream& operator<<(std::ostream& os, const policy::PolicyMap::Entry& e) {
std::string value;
base::JSONWriter::WriteWithOptions(e.value,
base::JSONWriter::OPTIONS_PRETTY_PRINT,
&value);
os << "{" << std::endl
<< " \"level\": " << e.level << "," << std::endl
<< " \"scope\": " << e.scope << "," << std::endl
<< " \"value\": " << value
<< "}";
return os;
}
std::ostream& operator<<(std::ostream& os, const policy::PolicyNamespace& ns) {
os << ns.domain << "/" << ns.component_id;
return os;
}
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_POLICY_POLICY_TEST_UTILS_H_
#define CHROME_BROWSER_POLICY_POLICY_TEST_UTILS_H_
#include <ostream>
#include "chrome/browser/policy/policy_map.h"
#include "chrome/browser/policy/policy_service.h"
#include "chrome/browser/policy/policy_types.h"
namespace policy {
class PolicyBundle;
struct PolicyNamespace;
// Returns true if |service| is not serving any policies. Otherwise logs the
// current policies and returns false.
bool PolicyServiceIsEmpty(const PolicyService* service);
} // namespace policy
std::ostream& operator<<(std::ostream& os, const policy::PolicyBundle& bundle);
std::ostream& operator<<(std::ostream& os, policy::PolicyScope scope);
std::ostream& operator<<(std::ostream& os, policy::PolicyLevel level);
std::ostream& operator<<(std::ostream& os, policy::PolicyDomain domain);
std::ostream& operator<<(std::ostream& os, const policy::PolicyMap& policies);
std::ostream& operator<<(std::ostream& os, const policy::PolicyMap::Entry& e);
std::ostream& operator<<(std::ostream& os, const policy::PolicyNamespace& ns);
#endif // CHROME_BROWSER_POLICY_POLICY_TEST_UTILS_H_
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/policy/test_utils.h"
#include <string>
#include "base/logging.h"
#include "base/values.h"
#include "chrome/browser/policy/policy_map.h"
#include "chrome/browser/policy/policy_service.h"
namespace policy {
bool PolicyServiceIsEmpty(const PolicyService* service) {
const PolicyMap& map = service->GetPolicies(
PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
if (!map.empty()) {
base::DictionaryValue dict;
for (PolicyMap::const_iterator it = map.begin(); it != map.end(); ++it)
dict.SetWithoutPathExpansion(it->first, it->second.value->DeepCopy());
LOG(WARNING) << "There are pre-existing policies in this machine: " << dict;
}
return map.empty();
}
} // namespace policy
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_POLICY_TEST_UTILS_H_
#define CHROME_BROWSER_POLICY_TEST_UTILS_H_
namespace policy {
class PolicyService;
// Returns true if |service| is not serving any policies. Otherwise logs the
// current policies and returns false.
bool PolicyServiceIsEmpty(const PolicyService* service);
} // namespace policy
#endif // CHROME_BROWSER_POLICY_TEST_UTILS_H_
......@@ -1517,8 +1517,6 @@
'browser/policy/mock_policy_service.h',
'browser/policy/policy_browsertest.cc',
'browser/policy/policy_prefs_browsertest.cc',
'browser/policy/test_utils.cc',
'browser/policy/test_utils.h',
'browser/prefs/pref_functional_browsertest.cc',
'browser/prefs/pref_service_browsertest.cc',
'browser/prefs/synced_pref_change_registrar_browsertest.cc',
......
......@@ -152,6 +152,8 @@
'browser/policy/cloud/policy_builder.h',
'browser/policy/mock_configuration_policy_provider.cc',
'browser/policy/mock_configuration_policy_provider.h',
'browser/policy/policy_test_utils.cc',
'browser/policy/policy_test_utils.h',
'browser/policy/test/local_policy_test_server.cc',
'browser/policy/test/local_policy_test_server.h',
'browser/prefs/pref_service_mock_builder.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment