blob: 41bdc195a43d495b7ff5c838801c97593a412b02 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2014 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
Alex Deymo560ae1d2014-10-28 02:17:54 -070016
17#ifndef UPDATE_ENGINE_MOCK_OMAHA_REQUEST_PARAMS_H_
18#define UPDATE_ENGINE_MOCK_OMAHA_REQUEST_PARAMS_H_
19
20#include <string>
21
22#include <gmock/gmock.h>
23
24#include "update_engine/omaha_request_params.h"
25
26namespace chromeos_update_engine {
27
28class MockOmahaRequestParams : public OmahaRequestParams {
29 public:
30 explicit MockOmahaRequestParams(SystemState* system_state)
31 : OmahaRequestParams(system_state) {
32 // Delegate all calls to the parent instance by default. This helps the
33 // migration from tests using the real RequestParams when they should have
34 // use a fake or mock.
Alex Deymo560ae1d2014-10-28 02:17:54 -070035 ON_CALL(*this, GetAppId())
Amin Hassani7cc8bb02019-01-14 16:29:47 -080036 .WillByDefault(
37 testing::Invoke(this, &MockOmahaRequestParams::FakeGetAppId));
Alex Deymod942f9d2015-11-06 16:11:50 -080038 ON_CALL(*this, SetTargetChannel(testing::_, testing::_, testing::_))
Alex Deymo560ae1d2014-10-28 02:17:54 -070039 .WillByDefault(testing::Invoke(
40 this, &MockOmahaRequestParams::FakeSetTargetChannel));
41 ON_CALL(*this, UpdateDownloadChannel())
42 .WillByDefault(testing::Invoke(
43 this, &MockOmahaRequestParams::FakeUpdateDownloadChannel));
Sen Jiang8500d3a2018-02-08 12:04:05 -080044 ON_CALL(*this, ShouldPowerwash())
Alex Deymo560ae1d2014-10-28 02:17:54 -070045 .WillByDefault(testing::Invoke(
Sen Jiang8500d3a2018-02-08 12:04:05 -080046 this, &MockOmahaRequestParams::FakeShouldPowerwash));
Alex Deymo560ae1d2014-10-28 02:17:54 -070047 }
48
Alex Deymo560ae1d2014-10-28 02:17:54 -070049 MOCK_CONST_METHOD0(GetAppId, std::string(void));
Amin Hassani7cc8bb02019-01-14 16:29:47 -080050 MOCK_METHOD3(SetTargetChannel,
51 bool(const std::string& channel,
52 bool is_powerwash_allowed,
53 std::string* error));
Marton Hunyadya0302682018-05-16 18:52:13 +020054 MOCK_CONST_METHOD0(target_version_prefix, std::string(void));
Alex Deymo560ae1d2014-10-28 02:17:54 -070055 MOCK_METHOD0(UpdateDownloadChannel, void(void));
David Pursell02c18642014-11-06 11:26:11 -080056 MOCK_CONST_METHOD0(IsUpdateUrlOfficial, bool(void));
Sen Jiang8500d3a2018-02-08 12:04:05 -080057 MOCK_CONST_METHOD0(ShouldPowerwash, bool(void));
Alex Deymo560ae1d2014-10-28 02:17:54 -070058
59 private:
60 // Wrappers to call the parent class and behave like the real object by
61 // default. See "Delegating Calls to a Parent Class" in gmock's documentation.
Amin Hassani7cc8bb02019-01-14 16:29:47 -080062 std::string FakeGetAppId() const { return OmahaRequestParams::GetAppId(); }
Alex Deymo560ae1d2014-10-28 02:17:54 -070063
64 bool FakeSetTargetChannel(const std::string& channel,
Alex Deymod942f9d2015-11-06 16:11:50 -080065 bool is_powerwash_allowed,
66 std::string* error) {
Amin Hassani7cc8bb02019-01-14 16:29:47 -080067 return OmahaRequestParams::SetTargetChannel(
68 channel, is_powerwash_allowed, error);
Alex Deymo560ae1d2014-10-28 02:17:54 -070069 }
70
71 void FakeUpdateDownloadChannel() {
72 return OmahaRequestParams::UpdateDownloadChannel();
73 }
74
Sen Jiang8500d3a2018-02-08 12:04:05 -080075 bool FakeShouldPowerwash() const {
76 return OmahaRequestParams::ShouldPowerwash();
Alex Deymo560ae1d2014-10-28 02:17:54 -070077 }
78};
79
80} // namespace chromeos_update_engine
81
82#endif // UPDATE_ENGINE_MOCK_OMAHA_REQUEST_PARAMS_H_