blob: 5d5d47be2f654a7466c5386e95b61683c47f78cb [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.
35 ON_CALL(*this, to_more_stable_channel())
36 .WillByDefault(testing::Invoke(
37 this, &MockOmahaRequestParams::fake_to_more_stable_channel));
38 ON_CALL(*this, GetAppId())
39 .WillByDefault(testing::Invoke(
40 this, &MockOmahaRequestParams::FakeGetAppId));
Alex Deymod942f9d2015-11-06 16:11:50 -080041 ON_CALL(*this, SetTargetChannel(testing::_, testing::_, testing::_))
Alex Deymo560ae1d2014-10-28 02:17:54 -070042 .WillByDefault(testing::Invoke(
43 this, &MockOmahaRequestParams::FakeSetTargetChannel));
44 ON_CALL(*this, UpdateDownloadChannel())
45 .WillByDefault(testing::Invoke(
46 this, &MockOmahaRequestParams::FakeUpdateDownloadChannel));
47 ON_CALL(*this, is_powerwash_allowed())
48 .WillByDefault(testing::Invoke(
49 this, &MockOmahaRequestParams::fake_is_powerwash_allowed));
50 }
51
52 MOCK_CONST_METHOD0(to_more_stable_channel, bool(void));
53 MOCK_CONST_METHOD0(GetAppId, std::string(void));
Alex Deymod942f9d2015-11-06 16:11:50 -080054 MOCK_METHOD3(SetTargetChannel, bool(const std::string& channel,
55 bool is_powerwash_allowed,
56 std::string* error));
Alex Deymo560ae1d2014-10-28 02:17:54 -070057 MOCK_METHOD0(UpdateDownloadChannel, void(void));
58 MOCK_CONST_METHOD0(is_powerwash_allowed, bool(void));
David Pursell02c18642014-11-06 11:26:11 -080059 MOCK_CONST_METHOD0(IsUpdateUrlOfficial, bool(void));
Alex Deymo560ae1d2014-10-28 02:17:54 -070060
61 private:
62 // Wrappers to call the parent class and behave like the real object by
63 // default. See "Delegating Calls to a Parent Class" in gmock's documentation.
64 bool fake_to_more_stable_channel() const {
65 return OmahaRequestParams::to_more_stable_channel();
66 }
67
68 std::string FakeGetAppId() const {
69 return OmahaRequestParams::GetAppId();
70 }
71
72 bool FakeSetTargetChannel(const std::string& channel,
Alex Deymod942f9d2015-11-06 16:11:50 -080073 bool is_powerwash_allowed,
74 std::string* error) {
75 return OmahaRequestParams::SetTargetChannel(channel,
76 is_powerwash_allowed,
77 error);
Alex Deymo560ae1d2014-10-28 02:17:54 -070078 }
79
80 void FakeUpdateDownloadChannel() {
81 return OmahaRequestParams::UpdateDownloadChannel();
82 }
83
84 bool fake_is_powerwash_allowed() const {
85 return OmahaRequestParams::is_powerwash_allowed();
86 }
87};
88
89} // namespace chromeos_update_engine
90
91#endif // UPDATE_ENGINE_MOCK_OMAHA_REQUEST_PARAMS_H_