blob: f04d361f1a039c224b3e47ee9af4527ac5db2b80 [file] [log] [blame]
Alex Deymo560ae1d2014-10-28 02:17:54 -07001// Copyright 2014 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 UPDATE_ENGINE_MOCK_OMAHA_REQUEST_PARAMS_H_
6#define UPDATE_ENGINE_MOCK_OMAHA_REQUEST_PARAMS_H_
7
8#include <string>
9
10#include <gmock/gmock.h>
11
12#include "update_engine/omaha_request_params.h"
13
14namespace chromeos_update_engine {
15
16class MockOmahaRequestParams : public OmahaRequestParams {
17 public:
18 explicit MockOmahaRequestParams(SystemState* system_state)
19 : OmahaRequestParams(system_state) {
20 // Delegate all calls to the parent instance by default. This helps the
21 // migration from tests using the real RequestParams when they should have
22 // use a fake or mock.
23 ON_CALL(*this, to_more_stable_channel())
24 .WillByDefault(testing::Invoke(
25 this, &MockOmahaRequestParams::fake_to_more_stable_channel));
26 ON_CALL(*this, GetAppId())
27 .WillByDefault(testing::Invoke(
28 this, &MockOmahaRequestParams::FakeGetAppId));
29 ON_CALL(*this, SetTargetChannel(testing::_, testing::_))
30 .WillByDefault(testing::Invoke(
31 this, &MockOmahaRequestParams::FakeSetTargetChannel));
32 ON_CALL(*this, UpdateDownloadChannel())
33 .WillByDefault(testing::Invoke(
34 this, &MockOmahaRequestParams::FakeUpdateDownloadChannel));
35 ON_CALL(*this, is_powerwash_allowed())
36 .WillByDefault(testing::Invoke(
37 this, &MockOmahaRequestParams::fake_is_powerwash_allowed));
38 }
39
40 MOCK_CONST_METHOD0(to_more_stable_channel, bool(void));
41 MOCK_CONST_METHOD0(GetAppId, std::string(void));
42 MOCK_METHOD2(SetTargetChannel, bool(const std::string& channel,
43 bool is_powerwash_allowed));
44 MOCK_METHOD0(UpdateDownloadChannel, void(void));
45 MOCK_CONST_METHOD0(is_powerwash_allowed, bool(void));
David Pursell02c18642014-11-06 11:26:11 -080046 MOCK_CONST_METHOD0(IsUpdateUrlOfficial, bool(void));
Alex Deymo560ae1d2014-10-28 02:17:54 -070047
48 private:
49 // Wrappers to call the parent class and behave like the real object by
50 // default. See "Delegating Calls to a Parent Class" in gmock's documentation.
51 bool fake_to_more_stable_channel() const {
52 return OmahaRequestParams::to_more_stable_channel();
53 }
54
55 std::string FakeGetAppId() const {
56 return OmahaRequestParams::GetAppId();
57 }
58
59 bool FakeSetTargetChannel(const std::string& channel,
60 bool is_powerwash_allowed) {
61 return OmahaRequestParams::SetTargetChannel(channel, is_powerwash_allowed);
62 }
63
64 void FakeUpdateDownloadChannel() {
65 return OmahaRequestParams::UpdateDownloadChannel();
66 }
67
68 bool fake_is_powerwash_allowed() const {
69 return OmahaRequestParams::is_powerwash_allowed();
70 }
71};
72
73} // namespace chromeos_update_engine
74
75#endif // UPDATE_ENGINE_MOCK_OMAHA_REQUEST_PARAMS_H_