aboutsummaryrefslogtreecommitdiffstats
path: root/policy/mock_device_policy.h
blob: 0986bb6ddc8af67ae4727dae083f3d49d1488cfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright (c) 2012 The Chromium OS 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 LIBBRILLO_POLICY_MOCK_DEVICE_POLICY_H_
#define LIBBRILLO_POLICY_MOCK_DEVICE_POLICY_H_

#include <set>
#include <string>
#include <vector>

#include <gmock/gmock.h>

#include "policy/device_policy.h"

#pragma GCC visibility push(default)

namespace policy {

// This is a generic mock class for the DevicePolicy that can be used by other
// subsystems for tests. It allows to mock out the reading of a real policy
// file and to simulate different policy values.
// The test that needs policies would then do something like this :
// // Prepare the action that would return a predefined policy value:
// ACTION_P(SetMetricsPolicy, enabled) {
//   *arg0 = enabled;
//   return true;
// }
// ...
// // Initialize the Mock class
// policy::MockDevicePolicy* device_policy = new policy::MockDevicePolicy();
// // We should expect calls to LoadPolicy almost always and return true.
// EXPECT_CALL(*device_policy_, LoadPolicy())
//     .Times(AnyNumber())
//     .WillRepeatedly(Return(true));
// // This example needs to simulate the Metrics Enabled policy being set.
// EXPECT_CALL(*device_policy_, GetMetricsEnabled(_))
//     .Times(AnyNumber())
//     .WillRepeatedly(SetMetricsPolicy(true));
// policy::PolicyProvider provider(device_policy);
// ...
// // In a test that needs other value of that policy we can do that:
// EXPECT_CALL(*device_policy_, GetMetricsEnabled(_))
//     .WillOnce(SetMetricsPolicy(false));
//
// See metrics_library_test.cc for example.
class MockDevicePolicy : public DevicePolicy {
 public:
  MockDevicePolicy() {
    ON_CALL(*this, LoadPolicy()).WillByDefault(testing::Return(true));
  }
  ~MockDevicePolicy() override = default;

  MOCK_METHOD0(LoadPolicy, bool(void));

  MOCK_CONST_METHOD1(GetPolicyRefreshRate,
                     bool(int*));  // NOLINT(readability/function)
  MOCK_CONST_METHOD1(GetUserWhitelist, bool(std::vector<std::string>*));
  MOCK_CONST_METHOD1(GetGuestModeEnabled,
                     bool(bool*));  // NOLINT(readability/function)
  MOCK_CONST_METHOD1(GetCameraEnabled,
                     bool(bool*));  // NOLINT(readability/function)
  MOCK_CONST_METHOD1(GetShowUserNames,
                     bool(bool*));  // NOLINT(readability/function)
  MOCK_CONST_METHOD1(GetDataRoamingEnabled,
                     bool(bool*));  // NOLINT(readability/function)
  MOCK_CONST_METHOD1(GetAllowNewUsers,
                     bool(bool*));  // NOLINT(readability/function)
  MOCK_CONST_METHOD1(GetMetricsEnabled,
                     bool(bool*));  // NOLINT(readability/function)
  MOCK_CONST_METHOD1(GetReportVersionInfo,
                     bool(bool*));  // NOLINT(readability/function)
  MOCK_CONST_METHOD1(GetReportActivityTimes,
                     bool(bool*));  // NOLINT(readability/function)
  MOCK_CONST_METHOD1(GetReportBootMode,
                     bool(bool*));  // NOLINT(readability/function)
  MOCK_CONST_METHOD1(GetEphemeralUsersEnabled,
                     bool(bool*));  // NOLINT(readability/function)
  MOCK_CONST_METHOD1(GetReleaseChannel, bool(std::string*));
  MOCK_CONST_METHOD1(GetReleaseChannelDelegated,
                     bool(bool*));  // NOLINT(readability/function)
  MOCK_CONST_METHOD1(GetUpdateDisabled,
                     bool(bool*));  // NOLINT(readability/function)
  MOCK_CONST_METHOD1(GetTargetVersionPrefix, bool(std::string*));
  MOCK_CONST_METHOD1(GetScatterFactorInSeconds,
                     bool(int64_t*));  // NOLINT(readability/function)
  MOCK_CONST_METHOD1(GetAllowedConnectionTypesForUpdate,
                     bool(std::set<std::string>*));
  MOCK_CONST_METHOD1(GetOpenNetworkConfiguration, bool(std::string*));
  MOCK_CONST_METHOD1(GetOwner, bool(std::string*));
  MOCK_CONST_METHOD1(GetHttpDownloadsEnabled,
                     bool(bool*));  // NOLINT(readability/function)
  MOCK_CONST_METHOD1(GetAuP2PEnabled,
                     bool(bool*));  // NOLINT(readability/function)

  MOCK_METHOD0(VerifyPolicyFiles, bool(void));
  MOCK_METHOD0(VerifyPolicySignature, bool(void));
};
}  // namespace policy

#pragma GCC visibility pop

#endif  // LIBBRILLO_POLICY_MOCK_DEVICE_POLICY_H_