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