• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium OS 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 LIBBRILLO_POLICY_MOCK_DEVICE_POLICY_H_
6 #define LIBBRILLO_POLICY_MOCK_DEVICE_POLICY_H_
7 
8 #include <set>
9 #include <string>
10 #include <vector>
11 
12 #include <gmock/gmock.h>
13 
14 #include "policy/device_policy.h"
15 
16 #pragma GCC visibility push(default)
17 
18 namespace policy {
19 
20 // This is a generic mock class for the DevicePolicy that can be used by other
21 // subsystems for tests. It allows to mock out the reading of a real policy
22 // file and to simulate different policy values.
23 // The test that needs policies would then do something like this :
24 // // Prepare the action that would return a predefined policy value:
25 // ACTION_P(SetMetricsPolicy, enabled) {
26 //   *arg0 = enabled;
27 //   return true;
28 // }
29 // ...
30 // // Initialize the Mock class
31 // policy::MockDevicePolicy* device_policy = new policy::MockDevicePolicy();
32 // // We should expect calls to LoadPolicy almost always and return true.
33 // EXPECT_CALL(*device_policy_, LoadPolicy())
34 //     .Times(AnyNumber())
35 //     .WillRepeatedly(Return(true));
36 // // This example needs to simulate the Metrics Enabled policy being set.
37 // EXPECT_CALL(*device_policy_, GetMetricsEnabled(_))
38 //     .Times(AnyNumber())
39 //     .WillRepeatedly(SetMetricsPolicy(true));
40 // policy::PolicyProvider provider(device_policy);
41 // ...
42 // // In a test that needs other value of that policy we can do that:
43 // EXPECT_CALL(*device_policy_, GetMetricsEnabled(_))
44 //     .WillOnce(SetMetricsPolicy(false));
45 //
46 // See metrics_library_test.cc for example.
47 class MockDevicePolicy : public DevicePolicy {
48  public:
MockDevicePolicy()49   MockDevicePolicy() {
50     ON_CALL(*this, LoadPolicy()).WillByDefault(testing::Return(true));
51   }
52   ~MockDevicePolicy() override = default;
53 
54   MOCK_METHOD0(LoadPolicy, bool(void));
55 
56   MOCK_CONST_METHOD1(GetPolicyRefreshRate,
57                      bool(int*));  // NOLINT(readability/function)
58   MOCK_CONST_METHOD1(GetUserWhitelist, bool(std::vector<std::string>*));
59   MOCK_CONST_METHOD1(GetGuestModeEnabled,
60                      bool(bool*));  // NOLINT(readability/function)
61   MOCK_CONST_METHOD1(GetCameraEnabled,
62                      bool(bool*));  // NOLINT(readability/function)
63   MOCK_CONST_METHOD1(GetShowUserNames,
64                      bool(bool*));  // NOLINT(readability/function)
65   MOCK_CONST_METHOD1(GetDataRoamingEnabled,
66                      bool(bool*));  // NOLINT(readability/function)
67   MOCK_CONST_METHOD1(GetAllowNewUsers,
68                      bool(bool*));  // NOLINT(readability/function)
69   MOCK_CONST_METHOD1(GetMetricsEnabled,
70                      bool(bool*));  // NOLINT(readability/function)
71   MOCK_CONST_METHOD1(GetReportVersionInfo,
72                      bool(bool*));  // NOLINT(readability/function)
73   MOCK_CONST_METHOD1(GetReportActivityTimes,
74                      bool(bool*));  // NOLINT(readability/function)
75   MOCK_CONST_METHOD1(GetReportBootMode,
76                      bool(bool*));  // NOLINT(readability/function)
77   MOCK_CONST_METHOD1(GetEphemeralUsersEnabled,
78                      bool(bool*));  // NOLINT(readability/function)
79   MOCK_CONST_METHOD1(GetReleaseChannel, bool(std::string*));
80   MOCK_CONST_METHOD1(GetReleaseChannelDelegated,
81                      bool(bool*));  // NOLINT(readability/function)
82   MOCK_CONST_METHOD1(GetUpdateDisabled,
83                      bool(bool*));  // NOLINT(readability/function)
84   MOCK_CONST_METHOD1(GetTargetVersionPrefix, bool(std::string*));
85   MOCK_CONST_METHOD1(GetScatterFactorInSeconds,
86                      bool(int64_t*));  // NOLINT(readability/function)
87   MOCK_CONST_METHOD1(GetAllowedConnectionTypesForUpdate,
88                      bool(std::set<std::string>*));
89   MOCK_CONST_METHOD1(GetOpenNetworkConfiguration, bool(std::string*));
90   MOCK_CONST_METHOD1(GetOwner, bool(std::string*));
91   MOCK_CONST_METHOD1(GetHttpDownloadsEnabled,
92                      bool(bool*));  // NOLINT(readability/function)
93   MOCK_CONST_METHOD1(GetAuP2PEnabled,
94                      bool(bool*));  // NOLINT(readability/function)
95   MOCK_CONST_METHOD1(GetAllowKioskAppControlChromeVersion,
96                      bool(bool*));  // NOLINT(readability/function)
97   MOCK_CONST_METHOD1(GetUsbDetachableWhitelist,
98                      bool(std::vector<DevicePolicy::UsbDeviceId>*));
99 
100   MOCK_METHOD0(VerifyPolicyFiles, bool(void));
101   MOCK_METHOD0(VerifyPolicySignature, bool(void));
102 };
103 }  // namespace policy
104 
105 #pragma GCC visibility pop
106 
107 #endif  // LIBBRILLO_POLICY_MOCK_DEVICE_POLICY_H_
108