update_engine: Mock out UpdateAttempter and OmahaRequestParams.
These classes are used by other classes so we need to have a way to
unit test those. This patch converts some public methods on these
classes to virtual methods so they can be mocked. It implements a
new MockOmahaRequestParams with all the public methods behaving like
the real object by default. This is now the default class used by the
FakeSystemState. Finally, the UpdateAttempterMock is renamed to
MockUpdateAttempter to be more consistent with other classes in
the project.
BUG=None
TEST=Unittest pass. Follow up CL using these classes also passes.
Change-Id: Iacb7e19d10c1526cea9659c27ab798cad126816f
Reviewed-on: https://chromium-review.googlesource.com/225855
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
diff --git a/fake_system_state.h b/fake_system_state.h
index 3a4f6b7..520b1a0 100644
--- a/fake_system_state.h
+++ b/fake_system_state.h
@@ -14,11 +14,12 @@
#include "update_engine/fake_hardware.h"
#include "update_engine/mock_connection_manager.h"
#include "update_engine/mock_dbus_wrapper.h"
+#include "update_engine/mock_omaha_request_params.h"
#include "update_engine/mock_p2p_manager.h"
#include "update_engine/mock_payload_state.h"
+#include "update_engine/mock_update_attempter.h"
#include "update_engine/prefs_mock.h"
#include "update_engine/system_state.h"
-#include "update_engine/update_attempter_mock.h"
#include "update_engine/update_manager/fake_update_manager.h"
namespace chromeos_update_engine {
@@ -121,7 +122,7 @@
inline void set_request_params(OmahaRequestParams* request_params) {
request_params_ = (request_params ? request_params :
- &default_request_params_);
+ &mock_request_params_);
}
inline void set_p2p_manager(P2PManager *p2p_manager) {
@@ -177,14 +178,14 @@
return &mock_payload_state_;
}
- inline testing::NiceMock<UpdateAttempterMock>* mock_update_attempter() {
+ inline testing::NiceMock<MockUpdateAttempter>* mock_update_attempter() {
CHECK(update_attempter_ == &mock_update_attempter_);
return &mock_update_attempter_;
}
- inline OmahaRequestParams* default_request_params() {
- CHECK(request_params_ == &default_request_params_);
- return &default_request_params_;
+ inline testing::NiceMock<MockOmahaRequestParams>* mock_request_params() {
+ CHECK(request_params_ == &mock_request_params_);
+ return &mock_request_params_;
}
inline testing::NiceMock<MockP2PManager>* mock_p2p_manager() {
@@ -206,8 +207,8 @@
testing::NiceMock<PrefsMock> mock_prefs_;
testing::NiceMock<PrefsMock> mock_powerwash_safe_prefs_;
testing::NiceMock<MockPayloadState> mock_payload_state_;
- testing::NiceMock<UpdateAttempterMock> mock_update_attempter_;
- OmahaRequestParams default_request_params_;
+ testing::NiceMock<MockUpdateAttempter> mock_update_attempter_;
+ testing::NiceMock<MockOmahaRequestParams> mock_request_params_;
testing::NiceMock<MockP2PManager> mock_p2p_manager_;
chromeos_update_manager::FakeUpdateManager fake_update_manager_;