aboutsummaryrefslogtreecommitdiffstats
path: root/policy/mock_device_policy.h
blob: 5cd9ce823eb03c369ae6948a8b6c9088493179e8 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// 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 <utility>
#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_METHOD(bool, LoadPolicy, (), (override));
  MOCK_METHOD(bool, IsEnterpriseEnrolled, (), (const, override));

  MOCK_METHOD(bool, GetPolicyRefreshRate, (int*), (const, override));
  MOCK_METHOD(bool,
              GetUserWhitelist,
              (std::vector<std::string>*),
              (const, override));
  MOCK_METHOD(bool, GetGuestModeEnabled, (bool*), (const, override));
  MOCK_METHOD(bool, GetCameraEnabled, (bool*), (const, override));
  MOCK_METHOD(bool, GetShowUserNames, (bool*), (const, override));
  MOCK_METHOD(bool, GetDataRoamingEnabled, (bool*), (const, override));
  MOCK_METHOD(bool, GetAllowNewUsers, (bool*), (const, override));
  MOCK_METHOD(bool, GetMetricsEnabled, (bool*), (const, override));
  MOCK_METHOD(bool, GetReportVersionInfo, (bool*), (const, override));
  MOCK_METHOD(bool, GetReportActivityTimes, (bool*), (const, override));
  MOCK_METHOD(bool, GetReportBootMode, (bool*), (const, override));
  MOCK_METHOD(bool, GetEphemeralUsersEnabled, (bool*), (const, override));
  MOCK_METHOD(bool, GetReleaseChannel, (std::string*), (const, override));
  MOCK_METHOD(bool, GetReleaseChannelDelegated, (bool*), (const, override));
  MOCK_METHOD(bool, GetUpdateDisabled, (bool*), (const, override));
  MOCK_METHOD(bool, GetTargetVersionPrefix, (std::string*), (const, override));
  MOCK_METHOD(bool, GetRollbackToTargetVersion, (int*), (const, override));
  MOCK_METHOD(bool, GetRollbackAllowedMilestones, (int*), (const, override));
  MOCK_METHOD(bool, GetScatterFactorInSeconds, (int64_t*), (const, override));
  MOCK_METHOD(bool,
              GetAllowedConnectionTypesForUpdate,
              (std::set<std::string>*),
              (const, override));
  MOCK_METHOD(bool,
              GetOpenNetworkConfiguration,
              (std::string*),
              (const, override));
  MOCK_METHOD(bool, GetOwner, (std::string*), (const, override));
  MOCK_METHOD(bool, GetHttpDownloadsEnabled, (bool*), (const, override));
  MOCK_METHOD(bool, GetAuP2PEnabled, (bool*), (const, override));
  MOCK_METHOD(bool,
              GetAllowKioskAppControlChromeVersion,
              (bool*),
              (const, override));
  MOCK_METHOD(bool,
              GetUsbDetachableWhitelist,
              (std::vector<DevicePolicy::UsbDeviceId>*),
              (const, override));
  MOCK_METHOD(bool,
              GetAutoLaunchedKioskAppId,
              (std::string*),
              (const, override));
  MOCK_METHOD(bool, IsEnterpriseManaged, (), (const, override));
  MOCK_METHOD(bool,
              GetSecondFactorAuthenticationMode,
              (int*),
              (const, override));
  MOCK_METHOD(bool,
              GetDisallowedTimeIntervals,
              (std::vector<WeeklyTimeInterval>*),
              (const, override));
  MOCK_METHOD(bool,
              GetDeviceUpdateStagingSchedule,
              (std::vector<DayPercentagePair>*),
              (const, override));
  MOCK_METHOD(bool,
              GetDeviceQuickFixBuildToken,
              (std::string*),
              (const, override));
  MOCK_METHOD(bool, VerifyPolicySignature, (), (override));
};
}  // namespace policy

#pragma GCC visibility pop

#endif  // LIBBRILLO_POLICY_MOCK_DEVICE_POLICY_H_