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