Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 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 | |
Alex Deymo | 759c275 | 2014-03-17 21:09:36 -0700 | [diff] [blame] | 5 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_SYSTEM_STATE_H_ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_SYSTEM_STATE_H_ |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 7 | |
| 8 | #include <gmock/gmock.h> |
| 9 | |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 10 | #include <metrics/metrics_library_mock.h> |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 11 | #include <policy/mock_device_policy.h> |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 12 | |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 13 | #include "update_engine/clock.h" |
| 14 | #include "update_engine/fake_hardware.h" |
David Zeuthen | 1cac5aa | 2014-04-02 10:18:00 -0700 | [diff] [blame] | 15 | #include "update_engine/mock_connection_manager.h" |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 16 | #include "update_engine/mock_dbus_wrapper.h" |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 17 | #include "update_engine/mock_gpio_handler.h" |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame] | 18 | #include "update_engine/mock_p2p_manager.h" |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 19 | #include "update_engine/mock_payload_state.h" |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 20 | #include "update_engine/policy_manager/fake_policy_manager.h" |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 21 | #include "update_engine/prefs_mock.h" |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 22 | #include "update_engine/system_state.h" |
Gilad Arnold | 76b2b48 | 2014-04-01 13:32:43 -0700 | [diff] [blame^] | 23 | #include "update_engine/update_attempter_mock.h" |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 24 | |
| 25 | namespace chromeos_update_engine { |
| 26 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 27 | class UpdateAttempterMock; |
| 28 | |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 29 | // Mock the SystemStateInterface so that we could lie that |
| 30 | // OOBE is completed even when there's no such marker file, etc. |
| 31 | class MockSystemState : public SystemState { |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 32 | public: |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 33 | MockSystemState(); |
| 34 | |
| 35 | virtual ~MockSystemState(); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 36 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 37 | MOCK_METHOD1(set_device_policy, void(const policy::DevicePolicy*)); |
| 38 | MOCK_CONST_METHOD0(device_policy, const policy::DevicePolicy*()); |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 39 | MOCK_METHOD0(system_rebooted, bool()); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 40 | |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 41 | inline virtual ClockInterface* clock() { |
| 42 | return clock_; |
| 43 | } |
| 44 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 45 | inline virtual ConnectionManager* connection_manager() { |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 46 | return connection_manager_; |
| 47 | } |
| 48 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 49 | inline virtual HardwareInterface* hardware() { |
| 50 | return hardware_; |
| 51 | } |
| 52 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 53 | inline virtual MetricsLibraryInterface* metrics_lib() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 54 | return &mock_metrics_lib_; |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 57 | inline virtual PrefsInterface* prefs() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 58 | return prefs_; |
| 59 | } |
| 60 | |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 61 | inline virtual PrefsInterface* powerwash_safe_prefs() { |
| 62 | return powerwash_safe_prefs_; |
| 63 | } |
| 64 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 65 | inline virtual PayloadStateInterface* payload_state() { |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame] | 66 | return payload_state_; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 69 | inline virtual GpioHandler* gpio_handler() const { |
| 70 | return mock_gpio_handler_; |
| 71 | } |
| 72 | |
Gilad Arnold | 76b2b48 | 2014-04-01 13:32:43 -0700 | [diff] [blame^] | 73 | inline virtual UpdateAttempterMock* update_attempter() const override { |
| 74 | return mock_update_attempter_; |
| 75 | } |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 76 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 77 | inline virtual OmahaRequestParams* request_params() { |
| 78 | return request_params_; |
| 79 | } |
| 80 | |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame] | 81 | inline virtual P2PManager* p2p_manager() { |
| 82 | return p2p_manager_; |
| 83 | } |
| 84 | |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 85 | inline virtual chromeos_policy_manager::PolicyManager* policy_manager() { |
| 86 | return policy_manager_; |
| 87 | } |
| 88 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 89 | // MockSystemState-specific public method. |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 90 | inline void set_connection_manager(ConnectionManager* connection_manager) { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 91 | connection_manager_ = connection_manager; |
| 92 | } |
| 93 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 94 | inline MetricsLibraryMock* mock_metrics_lib() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 95 | return &mock_metrics_lib_; |
| 96 | } |
| 97 | |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 98 | inline void set_clock(ClockInterface* clock) { |
| 99 | clock_ = clock; |
| 100 | } |
| 101 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 102 | inline void set_hardware(HardwareInterface* hardware) { |
| 103 | hardware_ = hardware; |
| 104 | } |
| 105 | |
Don Garrett | 6646b44 | 2013-11-13 15:29:11 -0800 | [diff] [blame] | 106 | inline FakeHardware* get_fake_hardware() { |
| 107 | return &default_hardware_; |
J. Richard Barnette | 4da2cc1 | 2013-10-28 16:11:10 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 110 | inline void set_prefs(PrefsInterface* prefs) { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 111 | prefs_ = prefs; |
| 112 | } |
| 113 | |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 114 | inline void set_powerwash_safe_prefs(PrefsInterface* prefs) { |
| 115 | powerwash_safe_prefs_ = prefs; |
| 116 | } |
| 117 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 118 | inline testing::NiceMock<PrefsMock> *mock_prefs() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 119 | return &mock_prefs_; |
| 120 | } |
| 121 | |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 122 | inline testing::NiceMock<PrefsMock> *mock_powerwash_safe_prefs() { |
| 123 | return &mock_powerwash_safe_prefs_; |
| 124 | } |
| 125 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 126 | inline MockPayloadState* mock_payload_state() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 127 | return &mock_payload_state_; |
| 128 | } |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 129 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 130 | inline void set_request_params(OmahaRequestParams* params) { |
| 131 | request_params_ = params; |
| 132 | } |
| 133 | |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame] | 134 | inline void set_p2p_manager(P2PManager *p2p_manager) { |
| 135 | p2p_manager_ = p2p_manager; |
| 136 | } |
| 137 | |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 138 | inline void set_policy_manager( |
| 139 | chromeos_policy_manager::PolicyManager *policy_manager) { |
| 140 | policy_manager_ = policy_manager; |
| 141 | } |
| 142 | |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame] | 143 | inline void set_payload_state(PayloadStateInterface *payload_state) { |
| 144 | payload_state_ = payload_state; |
| 145 | } |
| 146 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 147 | private: |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 148 | // These are Mock objects or objects we own. |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 149 | testing::NiceMock<MetricsLibraryMock> mock_metrics_lib_; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 150 | testing::NiceMock<PrefsMock> mock_prefs_; |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 151 | testing::NiceMock<PrefsMock> mock_powerwash_safe_prefs_; |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame] | 152 | testing::NiceMock<MockP2PManager> mock_p2p_manager_; |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 153 | testing::NiceMock<MockPayloadState> mock_payload_state_; |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 154 | testing::NiceMock<MockGpioHandler>* mock_gpio_handler_; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 155 | testing::NiceMock<UpdateAttempterMock>* mock_update_attempter_; |
David Zeuthen | 1cac5aa | 2014-04-02 10:18:00 -0700 | [diff] [blame] | 156 | testing::NiceMock<MockConnectionManager>* mock_connection_manager_; |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 157 | MockDBusWrapper dbus_; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 158 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 159 | // These are the other object we own. |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 160 | Clock default_clock_; |
Don Garrett | 6646b44 | 2013-11-13 15:29:11 -0800 | [diff] [blame] | 161 | FakeHardware default_hardware_; |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 162 | chromeos_policy_manager::FakePolicyManager fake_policy_manager_; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 163 | OmahaRequestParams default_request_params_; |
| 164 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 165 | // These are pointers to objects which caller can override. |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 166 | ClockInterface* clock_; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 167 | HardwareInterface* hardware_; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 168 | PrefsInterface* prefs_; |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 169 | PrefsInterface* powerwash_safe_prefs_; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 170 | ConnectionManager* connection_manager_; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 171 | OmahaRequestParams* request_params_; |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 172 | P2PManager* p2p_manager_; |
| 173 | PayloadStateInterface* payload_state_; |
| 174 | chromeos_policy_manager::PolicyManager* policy_manager_; |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 175 | }; |
| 176 | |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 177 | } // namespace chromeos_update_engine |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 178 | |
Alex Deymo | 759c275 | 2014-03-17 21:09:36 -0700 | [diff] [blame] | 179 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_SYSTEM_STATE_H_ |