blob: 73987d5325fa646d21df1c244baaa19e888a251e [file] [log] [blame]
Jay Srinivasan08fce042012-06-07 16:31:01 -07001// 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 Deymo759c2752014-03-17 21:09:36 -07005#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_SYSTEM_STATE_H_
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_SYSTEM_STATE_H_
Jay Srinivasan08fce042012-06-07 16:31:01 -07007
8#include <gmock/gmock.h>
9
Jay Srinivasanf0572052012-10-23 18:12:56 -070010#include <metrics/metrics_library_mock.h>
Jay Srinivasan43488792012-06-19 00:25:31 -070011#include <policy/mock_device_policy.h>
Jay Srinivasanf0572052012-10-23 18:12:56 -070012
Alex Deymo94c06162014-03-21 20:34:46 -070013#include "update_engine/clock.h"
14#include "update_engine/fake_hardware.h"
David Zeuthen1cac5aa2014-04-02 10:18:00 -070015#include "update_engine/mock_connection_manager.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080016#include "update_engine/mock_dbus_wrapper.h"
Gilad Arnoldbf7919b2013-01-08 13:07:37 -080017#include "update_engine/mock_gpio_handler.h"
David Zeuthen526cb582013-08-06 12:26:18 -070018#include "update_engine/mock_p2p_manager.h"
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080019#include "update_engine/mock_payload_state.h"
Alex Deymo94c06162014-03-21 20:34:46 -070020#include "update_engine/policy_manager/fake_policy_manager.h"
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080021#include "update_engine/prefs_mock.h"
Jay Srinivasan43488792012-06-19 00:25:31 -070022#include "update_engine/system_state.h"
Gilad Arnold76b2b482014-04-01 13:32:43 -070023#include "update_engine/update_attempter_mock.h"
Jay Srinivasan08fce042012-06-07 16:31:01 -070024
25namespace chromeos_update_engine {
26
Jay Srinivasan55f50c22013-01-10 19:24:35 -080027class UpdateAttempterMock;
28
Jay Srinivasan08fce042012-06-07 16:31:01 -070029// Mock the SystemStateInterface so that we could lie that
30// OOBE is completed even when there's no such marker file, etc.
31class MockSystemState : public SystemState {
Jay Srinivasan43488792012-06-19 00:25:31 -070032 public:
Jay Srinivasan55f50c22013-01-10 19:24:35 -080033 MockSystemState();
34
35 virtual ~MockSystemState();
Jay Srinivasan43488792012-06-19 00:25:31 -070036
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080037 MOCK_METHOD1(set_device_policy, void(const policy::DevicePolicy*));
38 MOCK_CONST_METHOD0(device_policy, const policy::DevicePolicy*());
Chris Sosabe45bef2013-04-09 18:25:12 -070039 MOCK_METHOD0(system_rebooted, bool());
Jay Srinivasan43488792012-06-19 00:25:31 -070040
David Zeuthenf413fe52013-04-22 14:04:39 -070041 inline virtual ClockInterface* clock() {
42 return clock_;
43 }
44
Gilad Arnoldbf7919b2013-01-08 13:07:37 -080045 inline virtual ConnectionManager* connection_manager() {
Jay Srinivasan43488792012-06-19 00:25:31 -070046 return connection_manager_;
47 }
48
Alex Deymo42432912013-07-12 20:21:15 -070049 inline virtual HardwareInterface* hardware() {
50 return hardware_;
51 }
52
Gilad Arnoldbf7919b2013-01-08 13:07:37 -080053 inline virtual MetricsLibraryInterface* metrics_lib() {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080054 return &mock_metrics_lib_;
Jay Srinivasanf0572052012-10-23 18:12:56 -070055 }
56
Gilad Arnoldbf7919b2013-01-08 13:07:37 -080057 inline virtual PrefsInterface* prefs() {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080058 return prefs_;
59 }
60
Chris Sosaaa18e162013-06-20 13:20:30 -070061 inline virtual PrefsInterface* powerwash_safe_prefs() {
62 return powerwash_safe_prefs_;
63 }
64
Gilad Arnoldbf7919b2013-01-08 13:07:37 -080065 inline virtual PayloadStateInterface* payload_state() {
David Zeuthen526cb582013-08-06 12:26:18 -070066 return payload_state_;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080067 }
68
Gilad Arnoldbf7919b2013-01-08 13:07:37 -080069 inline virtual GpioHandler* gpio_handler() const {
70 return mock_gpio_handler_;
71 }
72
Gilad Arnold76b2b482014-04-01 13:32:43 -070073 inline virtual UpdateAttempterMock* update_attempter() const override {
74 return mock_update_attempter_;
75 }
Jay Srinivasan55f50c22013-01-10 19:24:35 -080076
Jay Srinivasanae4697c2013-03-18 17:08:08 -070077 inline virtual OmahaRequestParams* request_params() {
78 return request_params_;
79 }
80
David Zeuthen526cb582013-08-06 12:26:18 -070081 inline virtual P2PManager* p2p_manager() {
82 return p2p_manager_;
83 }
84
Alex Deymo94c06162014-03-21 20:34:46 -070085 inline virtual chromeos_policy_manager::PolicyManager* policy_manager() {
86 return policy_manager_;
87 }
88
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080089 // MockSystemState-specific public method.
Gilad Arnoldbf7919b2013-01-08 13:07:37 -080090 inline void set_connection_manager(ConnectionManager* connection_manager) {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080091 connection_manager_ = connection_manager;
92 }
93
Gilad Arnoldbf7919b2013-01-08 13:07:37 -080094 inline MetricsLibraryMock* mock_metrics_lib() {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080095 return &mock_metrics_lib_;
96 }
97
David Zeuthenf413fe52013-04-22 14:04:39 -070098 inline void set_clock(ClockInterface* clock) {
99 clock_ = clock;
100 }
101
Alex Deymo42432912013-07-12 20:21:15 -0700102 inline void set_hardware(HardwareInterface* hardware) {
103 hardware_ = hardware;
104 }
105
Don Garrett6646b442013-11-13 15:29:11 -0800106 inline FakeHardware* get_fake_hardware() {
107 return &default_hardware_;
J. Richard Barnette4da2cc12013-10-28 16:11:10 -0700108 }
109
Gilad Arnoldbf7919b2013-01-08 13:07:37 -0800110 inline void set_prefs(PrefsInterface* prefs) {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800111 prefs_ = prefs;
112 }
113
Chris Sosaaa18e162013-06-20 13:20:30 -0700114 inline void set_powerwash_safe_prefs(PrefsInterface* prefs) {
115 powerwash_safe_prefs_ = prefs;
116 }
117
Gilad Arnoldbf7919b2013-01-08 13:07:37 -0800118 inline testing::NiceMock<PrefsMock> *mock_prefs() {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800119 return &mock_prefs_;
120 }
121
Chris Sosaaa18e162013-06-20 13:20:30 -0700122 inline testing::NiceMock<PrefsMock> *mock_powerwash_safe_prefs() {
123 return &mock_powerwash_safe_prefs_;
124 }
125
Gilad Arnoldbf7919b2013-01-08 13:07:37 -0800126 inline MockPayloadState* mock_payload_state() {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800127 return &mock_payload_state_;
128 }
Jay Srinivasanf0572052012-10-23 18:12:56 -0700129
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700130 inline void set_request_params(OmahaRequestParams* params) {
131 request_params_ = params;
132 }
133
David Zeuthen526cb582013-08-06 12:26:18 -0700134 inline void set_p2p_manager(P2PManager *p2p_manager) {
135 p2p_manager_ = p2p_manager;
136 }
137
Alex Deymo94c06162014-03-21 20:34:46 -0700138 inline void set_policy_manager(
139 chromeos_policy_manager::PolicyManager *policy_manager) {
140 policy_manager_ = policy_manager;
141 }
142
David Zeuthen526cb582013-08-06 12:26:18 -0700143 inline void set_payload_state(PayloadStateInterface *payload_state) {
144 payload_state_ = payload_state;
145 }
146
Jay Srinivasan43488792012-06-19 00:25:31 -0700147 private:
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800148 // These are Mock objects or objects we own.
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800149 testing::NiceMock<MetricsLibraryMock> mock_metrics_lib_;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800150 testing::NiceMock<PrefsMock> mock_prefs_;
Chris Sosaaa18e162013-06-20 13:20:30 -0700151 testing::NiceMock<PrefsMock> mock_powerwash_safe_prefs_;
David Zeuthen526cb582013-08-06 12:26:18 -0700152 testing::NiceMock<MockP2PManager> mock_p2p_manager_;
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800153 testing::NiceMock<MockPayloadState> mock_payload_state_;
Gilad Arnoldbf7919b2013-01-08 13:07:37 -0800154 testing::NiceMock<MockGpioHandler>* mock_gpio_handler_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800155 testing::NiceMock<UpdateAttempterMock>* mock_update_attempter_;
David Zeuthen1cac5aa2014-04-02 10:18:00 -0700156 testing::NiceMock<MockConnectionManager>* mock_connection_manager_;
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -0800157 MockDBusWrapper dbus_;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800158
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700159 // These are the other object we own.
David Zeuthenf413fe52013-04-22 14:04:39 -0700160 Clock default_clock_;
Don Garrett6646b442013-11-13 15:29:11 -0800161 FakeHardware default_hardware_;
Alex Deymo94c06162014-03-21 20:34:46 -0700162 chromeos_policy_manager::FakePolicyManager fake_policy_manager_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700163 OmahaRequestParams default_request_params_;
164
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800165 // These are pointers to objects which caller can override.
David Zeuthenf413fe52013-04-22 14:04:39 -0700166 ClockInterface* clock_;
Alex Deymo42432912013-07-12 20:21:15 -0700167 HardwareInterface* hardware_;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800168 PrefsInterface* prefs_;
Chris Sosaaa18e162013-06-20 13:20:30 -0700169 PrefsInterface* powerwash_safe_prefs_;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800170 ConnectionManager* connection_manager_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700171 OmahaRequestParams* request_params_;
Alex Deymo94c06162014-03-21 20:34:46 -0700172 P2PManager* p2p_manager_;
173 PayloadStateInterface* payload_state_;
174 chromeos_policy_manager::PolicyManager* policy_manager_;
Jay Srinivasan08fce042012-06-07 16:31:01 -0700175};
176
Alex Deymo94c06162014-03-21 20:34:46 -0700177} // namespace chromeos_update_engine
Jay Srinivasan08fce042012-06-07 16:31:01 -0700178
Alex Deymo759c2752014-03-17 21:09:36 -0700179#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_SYSTEM_STATE_H_