mock_omaha_request_params.h revision aea4c1cea20dda7ae7e85fc8924a2d784f70d806
1aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 2aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Copyright (C) 2014 The Android Open Source Project 3aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 4aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Licensed under the Apache License, Version 2.0 (the "License"); 5aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// you may not use this file except in compliance with the License. 6aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// You may obtain a copy of the License at 7aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 8aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// http://www.apache.org/licenses/LICENSE-2.0 9aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 10aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Unless required by applicable law or agreed to in writing, software 11aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// distributed under the License is distributed on an "AS IS" BASIS, 12aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// See the License for the specific language governing permissions and 14aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// limitations under the License. 15aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 16560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 17560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo#ifndef UPDATE_ENGINE_MOCK_OMAHA_REQUEST_PARAMS_H_ 18560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo#define UPDATE_ENGINE_MOCK_OMAHA_REQUEST_PARAMS_H_ 19560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 20560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo#include <string> 21560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 22560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo#include <gmock/gmock.h> 23560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 24560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo#include "update_engine/omaha_request_params.h" 25560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 26560ae1da0e62f7897699f63631452f0c4144d413Alex Deymonamespace chromeos_update_engine { 27560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 28560ae1da0e62f7897699f63631452f0c4144d413Alex Deymoclass MockOmahaRequestParams : public OmahaRequestParams { 29560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo public: 30560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo explicit MockOmahaRequestParams(SystemState* system_state) 31560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo : OmahaRequestParams(system_state) { 32560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo // Delegate all calls to the parent instance by default. This helps the 33560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo // migration from tests using the real RequestParams when they should have 34560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo // use a fake or mock. 35560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo ON_CALL(*this, to_more_stable_channel()) 36560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo .WillByDefault(testing::Invoke( 37560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo this, &MockOmahaRequestParams::fake_to_more_stable_channel)); 38560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo ON_CALL(*this, GetAppId()) 39560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo .WillByDefault(testing::Invoke( 40560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo this, &MockOmahaRequestParams::FakeGetAppId)); 41560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo ON_CALL(*this, SetTargetChannel(testing::_, testing::_)) 42560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo .WillByDefault(testing::Invoke( 43560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo this, &MockOmahaRequestParams::FakeSetTargetChannel)); 44560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo ON_CALL(*this, UpdateDownloadChannel()) 45560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo .WillByDefault(testing::Invoke( 46560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo this, &MockOmahaRequestParams::FakeUpdateDownloadChannel)); 47560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo ON_CALL(*this, is_powerwash_allowed()) 48560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo .WillByDefault(testing::Invoke( 49560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo this, &MockOmahaRequestParams::fake_is_powerwash_allowed)); 50560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo } 51560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 52560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo MOCK_CONST_METHOD0(to_more_stable_channel, bool(void)); 53560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo MOCK_CONST_METHOD0(GetAppId, std::string(void)); 54560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo MOCK_METHOD2(SetTargetChannel, bool(const std::string& channel, 55560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo bool is_powerwash_allowed)); 56560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo MOCK_METHOD0(UpdateDownloadChannel, void(void)); 57560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo MOCK_CONST_METHOD0(is_powerwash_allowed, bool(void)); 5802c1864e204997175302b1aebe3e0be9c6699ea5David Pursell MOCK_CONST_METHOD0(IsUpdateUrlOfficial, bool(void)); 59560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 60560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo private: 61560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo // Wrappers to call the parent class and behave like the real object by 62560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo // default. See "Delegating Calls to a Parent Class" in gmock's documentation. 63560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo bool fake_to_more_stable_channel() const { 64560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo return OmahaRequestParams::to_more_stable_channel(); 65560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo } 66560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 67560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo std::string FakeGetAppId() const { 68560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo return OmahaRequestParams::GetAppId(); 69560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo } 70560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 71560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo bool FakeSetTargetChannel(const std::string& channel, 72560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo bool is_powerwash_allowed) { 73560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo return OmahaRequestParams::SetTargetChannel(channel, is_powerwash_allowed); 74560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo } 75560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 76560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo void FakeUpdateDownloadChannel() { 77560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo return OmahaRequestParams::UpdateDownloadChannel(); 78560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo } 79560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 80560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo bool fake_is_powerwash_allowed() const { 81560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo return OmahaRequestParams::is_powerwash_allowed(); 82560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo } 83560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo}; 84560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 85560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo} // namespace chromeos_update_engine 86560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 87560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo#endif // UPDATE_ENGINE_MOCK_OMAHA_REQUEST_PARAMS_H_ 88