mock_omaha_request_params.h revision 02c1864e204997175302b1aebe3e0be9c6699ea5
1560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo// Copyright 2014 The Chromium OS Authors. All rights reserved. 2560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo// Use of this source code is governed by a BSD-style license that can be 3560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo// found in the LICENSE file. 4560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 5560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo#ifndef UPDATE_ENGINE_MOCK_OMAHA_REQUEST_PARAMS_H_ 6560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo#define UPDATE_ENGINE_MOCK_OMAHA_REQUEST_PARAMS_H_ 7560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 8560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo#include <string> 9560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 10560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo#include <gmock/gmock.h> 11560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 12560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo#include "update_engine/omaha_request_params.h" 13560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 14560ae1da0e62f7897699f63631452f0c4144d413Alex Deymonamespace chromeos_update_engine { 15560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 16560ae1da0e62f7897699f63631452f0c4144d413Alex Deymoclass MockOmahaRequestParams : public OmahaRequestParams { 17560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo public: 18560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo explicit MockOmahaRequestParams(SystemState* system_state) 19560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo : OmahaRequestParams(system_state) { 20560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo // Delegate all calls to the parent instance by default. This helps the 21560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo // migration from tests using the real RequestParams when they should have 22560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo // use a fake or mock. 23560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo ON_CALL(*this, to_more_stable_channel()) 24560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo .WillByDefault(testing::Invoke( 25560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo this, &MockOmahaRequestParams::fake_to_more_stable_channel)); 26560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo ON_CALL(*this, GetAppId()) 27560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo .WillByDefault(testing::Invoke( 28560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo this, &MockOmahaRequestParams::FakeGetAppId)); 29560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo ON_CALL(*this, SetTargetChannel(testing::_, testing::_)) 30560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo .WillByDefault(testing::Invoke( 31560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo this, &MockOmahaRequestParams::FakeSetTargetChannel)); 32560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo ON_CALL(*this, UpdateDownloadChannel()) 33560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo .WillByDefault(testing::Invoke( 34560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo this, &MockOmahaRequestParams::FakeUpdateDownloadChannel)); 35560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo ON_CALL(*this, is_powerwash_allowed()) 36560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo .WillByDefault(testing::Invoke( 37560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo this, &MockOmahaRequestParams::fake_is_powerwash_allowed)); 38560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo } 39560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 40560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo MOCK_CONST_METHOD0(to_more_stable_channel, bool(void)); 41560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo MOCK_CONST_METHOD0(GetAppId, std::string(void)); 42560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo MOCK_METHOD2(SetTargetChannel, bool(const std::string& channel, 43560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo bool is_powerwash_allowed)); 44560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo MOCK_METHOD0(UpdateDownloadChannel, void(void)); 45560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo MOCK_CONST_METHOD0(is_powerwash_allowed, bool(void)); 4602c1864e204997175302b1aebe3e0be9c6699ea5David Pursell MOCK_CONST_METHOD0(IsUpdateUrlOfficial, bool(void)); 47560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 48560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo private: 49560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo // Wrappers to call the parent class and behave like the real object by 50560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo // default. See "Delegating Calls to a Parent Class" in gmock's documentation. 51560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo bool fake_to_more_stable_channel() const { 52560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo return OmahaRequestParams::to_more_stable_channel(); 53560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo } 54560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 55560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo std::string FakeGetAppId() const { 56560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo return OmahaRequestParams::GetAppId(); 57560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo } 58560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 59560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo bool FakeSetTargetChannel(const std::string& channel, 60560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo bool is_powerwash_allowed) { 61560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo return OmahaRequestParams::SetTargetChannel(channel, is_powerwash_allowed); 62560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo } 63560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 64560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo void FakeUpdateDownloadChannel() { 65560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo return OmahaRequestParams::UpdateDownloadChannel(); 66560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo } 67560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 68560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo bool fake_is_powerwash_allowed() const { 69560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo return OmahaRequestParams::is_powerwash_allowed(); 70560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo } 71560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo}; 72560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 73560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo} // namespace chromeos_update_engine 74560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo 75560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo#endif // UPDATE_ENGINE_MOCK_OMAHA_REQUEST_PARAMS_H_ 76