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_MOCK_CONFIGURATION_POLICY_PROVIDER_H_
6#define COMPONENTS_POLICY_CORE_COMMON_MOCK_CONFIGURATION_POLICY_PROVIDER_H_
7
8#include "base/basictypes.h"
9#include "components/policy/core/common/configuration_policy_provider.h"
10#include "components/policy/core/common/policy_map.h"
11#include "components/policy/core/common/schema_registry.h"
12#include "testing/gmock/include/gmock/gmock.h"
13
14namespace policy {
15
16// Mock ConfigurationPolicyProvider implementation that supplies canned
17// values for polices.
18// TODO(joaodasilva, mnissler): introduce an implementation that non-policy
19// code can use that doesn't require the usual boilerplate.
20// http://crbug.com/242087
21class MockConfigurationPolicyProvider : public ConfigurationPolicyProvider {
22 public:
23  MockConfigurationPolicyProvider();
24  virtual ~MockConfigurationPolicyProvider();
25
26  MOCK_CONST_METHOD1(IsInitializationComplete, bool(PolicyDomain domain));
27  MOCK_METHOD0(RefreshPolicies, void());
28
29  // Make public for tests.
30  using ConfigurationPolicyProvider::UpdatePolicy;
31
32  // Utility method that invokes UpdatePolicy() with a PolicyBundle that maps
33  // the Chrome namespace to a copy of |policy|.
34  void UpdateChromePolicy(const PolicyMap& policy);
35
36  // Convenience method so that tests don't need to create a registry to create
37  // this mock.
38  using ConfigurationPolicyProvider::Init;
39  void Init() {
40    ConfigurationPolicyProvider::Init(&registry_);
41  }
42
43  // Convenience method that installs an expectation on RefreshPolicies that
44  // just notifies the observers and serves the same policies.
45  void SetAutoRefresh();
46
47 private:
48  void RefreshWithSamePolicies();
49
50  SchemaRegistry registry_;
51
52  DISALLOW_COPY_AND_ASSIGN(MockConfigurationPolicyProvider);
53};
54
55class MockConfigurationPolicyObserver
56    : public ConfigurationPolicyProvider::Observer {
57 public:
58  MockConfigurationPolicyObserver();
59  virtual ~MockConfigurationPolicyObserver();
60
61  MOCK_METHOD1(OnUpdatePolicy, void(ConfigurationPolicyProvider*));
62};
63
64}  // namespace policy
65
66#endif  // COMPONENTS_POLICY_CORE_COMMON_MOCK_CONFIGURATION_POLICY_PROVIDER_H_
67