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" |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 18 | #include "update_engine/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 | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 35 | MOCK_METHOD0(IsOfficialBuild, bool()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -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 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 73 | virtual UpdateAttempter* update_attempter(); |
| 74 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 75 | inline virtual OmahaRequestParams* request_params() { |
| 76 | return request_params_; |
| 77 | } |
| 78 | |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame^] | 79 | inline virtual P2PManager* p2p_manager() { |
| 80 | return p2p_manager_; |
| 81 | } |
| 82 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 83 | // MockSystemState-specific public method. |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 84 | inline void set_connection_manager(ConnectionManager* connection_manager) { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 85 | connection_manager_ = connection_manager; |
| 86 | } |
| 87 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 88 | inline MetricsLibraryMock* mock_metrics_lib() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 89 | return &mock_metrics_lib_; |
| 90 | } |
| 91 | |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 92 | inline void set_clock(ClockInterface* clock) { |
| 93 | clock_ = clock; |
| 94 | } |
| 95 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 96 | inline void set_hardware(HardwareInterface* hardware) { |
| 97 | hardware_ = hardware; |
| 98 | } |
| 99 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 100 | inline void set_prefs(PrefsInterface* prefs) { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 101 | prefs_ = prefs; |
| 102 | } |
| 103 | |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 104 | inline void set_powerwash_safe_prefs(PrefsInterface* prefs) { |
| 105 | powerwash_safe_prefs_ = prefs; |
| 106 | } |
| 107 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 108 | inline testing::NiceMock<PrefsMock> *mock_prefs() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 109 | return &mock_prefs_; |
| 110 | } |
| 111 | |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 112 | inline testing::NiceMock<PrefsMock> *mock_powerwash_safe_prefs() { |
| 113 | return &mock_powerwash_safe_prefs_; |
| 114 | } |
| 115 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 116 | inline MockPayloadState* mock_payload_state() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 117 | return &mock_payload_state_; |
| 118 | } |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 119 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 120 | inline void set_request_params(OmahaRequestParams* params) { |
| 121 | request_params_ = params; |
| 122 | } |
| 123 | |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame^] | 124 | inline void set_p2p_manager(P2PManager *p2p_manager) { |
| 125 | p2p_manager_ = p2p_manager; |
| 126 | } |
| 127 | |
| 128 | inline void set_payload_state(PayloadStateInterface *payload_state) { |
| 129 | payload_state_ = payload_state; |
| 130 | } |
| 131 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 132 | private: |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 133 | // These are Mock objects or objects we own. |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 134 | testing::NiceMock<MetricsLibraryMock> mock_metrics_lib_; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 135 | testing::NiceMock<PrefsMock> mock_prefs_; |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 136 | testing::NiceMock<PrefsMock> mock_powerwash_safe_prefs_; |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame^] | 137 | testing::NiceMock<MockP2PManager> mock_p2p_manager_; |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 138 | testing::NiceMock<MockPayloadState> mock_payload_state_; |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 139 | testing::NiceMock<MockGpioHandler>* mock_gpio_handler_; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 140 | testing::NiceMock<UpdateAttempterMock>* mock_update_attempter_; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 141 | MockDbusGlib dbus_; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 142 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 143 | // These are the other object we own. |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 144 | Clock default_clock_; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 145 | Hardware default_hardware_; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 146 | OmahaRequestParams default_request_params_; |
| 147 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 148 | // These are pointers to objects which caller can override. |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 149 | ClockInterface* clock_; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 150 | HardwareInterface* hardware_; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 151 | PrefsInterface* prefs_; |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 152 | PrefsInterface* powerwash_safe_prefs_; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 153 | ConnectionManager* connection_manager_; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 154 | OmahaRequestParams* request_params_; |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame^] | 155 | P2PManager *p2p_manager_; |
| 156 | PayloadStateInterface *payload_state_; |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | } // namespeace chromeos_update_engine |
| 160 | |
| 161 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_SYSTEM_STATE_H__ |