1a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#ifndef COMPONENTS_POLICY_CORE_COMMON_MOCK_CONFIGURATION_POLICY_PROVIDER_H_
6a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#define COMPONENTS_POLICY_CORE_COMMON_MOCK_CONFIGURATION_POLICY_PROVIDER_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/basictypes.h"
9a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/policy/core/common/configuration_policy_provider.h"
10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "components/policy/core/common/policy_map.h"
11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "components/policy/core/common/schema_registry.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gmock/include/gmock/gmock.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace policy {
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Mock ConfigurationPolicyProvider implementation that supplies canned
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// values for polices.
1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// TODO(joaodasilva, mnissler): introduce an implementation that non-policy
1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// code can use that doesn't require the usual boilerplate.
2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// http://crbug.com/242087
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MockConfigurationPolicyProvider : public ConfigurationPolicyProvider {
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MockConfigurationPolicyProvider();
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~MockConfigurationPolicyProvider();
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  MOCK_CONST_METHOD1(IsInitializationComplete, bool(PolicyDomain domain));
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD0(RefreshPolicies, void());
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Make public for tests.
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  using ConfigurationPolicyProvider::UpdatePolicy;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Utility method that invokes UpdatePolicy() with a PolicyBundle that maps
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the Chrome namespace to a copy of |policy|.
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void UpdateChromePolicy(const PolicyMap& policy);
35f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Convenience method so that tests don't need to create a registry to create
37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // this mock.
38f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  using ConfigurationPolicyProvider::Init;
39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void Init() {
40f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    ConfigurationPolicyProvider::Init(&registry_);
41f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
42f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
43f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Convenience method that installs an expectation on RefreshPolicies that
44f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // just notifies the observers and serves the same policies.
45f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void SetAutoRefresh();
46f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
47f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) private:
48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void RefreshWithSamePolicies();
49f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
50f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  SchemaRegistry registry_;
51f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
52f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(MockConfigurationPolicyProvider);
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MockConfigurationPolicyObserver
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : public ConfigurationPolicyProvider::Observer {
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MockConfigurationPolicyObserver();
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~MockConfigurationPolicyObserver();
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD1(OnUpdatePolicy, void(ConfigurationPolicyProvider*));
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace policy
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
66a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif  // COMPONENTS_POLICY_CORE_COMMON_MOCK_CONFIGURATION_POLICY_PROVIDER_H_
67