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" |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 15 | #include "update_engine/mock_payload_state.h" |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame^] | 16 | #include "update_engine/clock.h" |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 17 | #include "update_engine/prefs_mock.h" |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 18 | #include "update_engine/system_state.h" |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 19 | |
| 20 | namespace chromeos_update_engine { |
| 21 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 22 | class UpdateAttempterMock; |
| 23 | |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 24 | // Mock the SystemStateInterface so that we could lie that |
| 25 | // OOBE is completed even when there's no such marker file, etc. |
| 26 | class MockSystemState : public SystemState { |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 27 | public: |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 28 | MockSystemState(); |
| 29 | |
| 30 | virtual ~MockSystemState(); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 31 | |
| 32 | MOCK_METHOD0(IsOOBEComplete, bool()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 33 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 34 | MOCK_METHOD1(set_device_policy, void(const policy::DevicePolicy*)); |
| 35 | MOCK_CONST_METHOD0(device_policy, const policy::DevicePolicy*()); |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 36 | MOCK_METHOD0(system_rebooted, bool()); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 37 | |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame^] | 38 | inline virtual ClockInterface* clock() { |
| 39 | return clock_; |
| 40 | } |
| 41 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 42 | inline virtual ConnectionManager* connection_manager() { |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 43 | return connection_manager_; |
| 44 | } |
| 45 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 46 | inline virtual MetricsLibraryInterface* metrics_lib() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 47 | return &mock_metrics_lib_; |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 50 | inline virtual PrefsInterface* prefs() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 51 | return prefs_; |
| 52 | } |
| 53 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 54 | inline virtual PayloadStateInterface* payload_state() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 55 | return &mock_payload_state_; |
| 56 | } |
| 57 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 58 | inline virtual GpioHandler* gpio_handler() const { |
| 59 | return mock_gpio_handler_; |
| 60 | } |
| 61 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 62 | virtual UpdateAttempter* update_attempter(); |
| 63 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 64 | inline virtual OmahaRequestParams* request_params() { |
| 65 | return request_params_; |
| 66 | } |
| 67 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 68 | // MockSystemState-specific public method. |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 69 | inline void set_connection_manager(ConnectionManager* connection_manager) { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 70 | connection_manager_ = connection_manager; |
| 71 | } |
| 72 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 73 | inline MetricsLibraryMock* mock_metrics_lib() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 74 | return &mock_metrics_lib_; |
| 75 | } |
| 76 | |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame^] | 77 | inline void set_clock(ClockInterface* clock) { |
| 78 | clock_ = clock; |
| 79 | } |
| 80 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 81 | inline void set_prefs(PrefsInterface* prefs) { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 82 | prefs_ = prefs; |
| 83 | } |
| 84 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 85 | inline testing::NiceMock<PrefsMock> *mock_prefs() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 86 | return &mock_prefs_; |
| 87 | } |
| 88 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 89 | inline MockPayloadState* mock_payload_state() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 90 | return &mock_payload_state_; |
| 91 | } |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 92 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 93 | inline void set_request_params(OmahaRequestParams* params) { |
| 94 | request_params_ = params; |
| 95 | } |
| 96 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 97 | private: |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 98 | // These are Mock objects or objects we own. |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 99 | testing::NiceMock<MetricsLibraryMock> mock_metrics_lib_; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 100 | testing::NiceMock<PrefsMock> mock_prefs_; |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 101 | testing::NiceMock<MockPayloadState> mock_payload_state_; |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 102 | testing::NiceMock<MockGpioHandler>* mock_gpio_handler_; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 103 | testing::NiceMock<UpdateAttempterMock>* mock_update_attempter_; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 104 | MockDbusGlib dbus_; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 105 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 106 | // These are the other object we own. |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame^] | 107 | Clock default_clock_; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 108 | OmahaRequestParams default_request_params_; |
| 109 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 110 | // These are pointers to objects which caller can override. |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame^] | 111 | ClockInterface* clock_; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 112 | PrefsInterface* prefs_; |
| 113 | ConnectionManager* connection_manager_; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 114 | OmahaRequestParams* request_params_; |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | } // namespeace chromeos_update_engine |
| 118 | |
| 119 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_SYSTEM_STATE_H__ |