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#ifndef COMPONENTS_POLICY_CORE_COMMON_POLICY_TEST_UTILS_H_
6#define COMPONENTS_POLICY_CORE_COMMON_POLICY_TEST_UTILS_H_
7
8#include <map>
9#include <ostream>
10#include <string>
11
12#include "base/basictypes.h"
13#include "components/policy/core/common/policy_details.h"
14#include "components/policy/core/common/policy_map.h"
15#include "components/policy/core/common/policy_service.h"
16#include "components/policy/core/common/policy_types.h"
17
18namespace policy {
19
20class PolicyBundle;
21struct PolicyNamespace;
22
23// A mapping of policy names to PolicyDetails that can be used to set the
24// PolicyDetails for test policies.
25class PolicyDetailsMap {
26 public:
27  PolicyDetailsMap();
28  ~PolicyDetailsMap();
29
30  // The returned callback's lifetime is tied to |this| object.
31  GetChromePolicyDetailsCallback GetCallback() const;
32
33  // Does not take ownership of |details|.
34  void SetDetails(const std::string& policy, const PolicyDetails* details);
35
36 private:
37  typedef std::map<std::string, const PolicyDetails*> PolicyDetailsMapping;
38
39  const PolicyDetails* Lookup(const std::string& policy) const;
40
41  PolicyDetailsMapping map_;
42
43  DISALLOW_COPY_AND_ASSIGN(PolicyDetailsMap);
44};
45
46// Returns true if |service| is not serving any policies. Otherwise logs the
47// current policies and returns false.
48bool PolicyServiceIsEmpty(const PolicyService* service);
49
50#if defined(OS_IOS) || defined(OS_MACOSX)
51
52// Converts a base::Value to the equivalent CFPropertyListRef.
53// The returned value is owned by the caller.
54CFPropertyListRef ValueToProperty(const base::Value* value);
55
56#endif
57
58}  // namespace policy
59
60std::ostream& operator<<(std::ostream& os, const policy::PolicyBundle& bundle);
61std::ostream& operator<<(std::ostream& os, policy::PolicyScope scope);
62std::ostream& operator<<(std::ostream& os, policy::PolicyLevel level);
63std::ostream& operator<<(std::ostream& os, policy::PolicyDomain domain);
64std::ostream& operator<<(std::ostream& os, const policy::PolicyMap& policies);
65std::ostream& operator<<(std::ostream& os, const policy::PolicyMap::Entry& e);
66std::ostream& operator<<(std::ostream& os, const policy::PolicyNamespace& ns);
67
68#endif  // COMPONENTS_POLICY_CORE_COMMON_POLICY_TEST_UTILS_H_
69