| Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // | 
|  | 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 Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 16 |  | 
| Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_CROS_MOCK_OMAHA_REQUEST_PARAMS_H_ | 
|  | 18 | #define UPDATE_ENGINE_CROS_MOCK_OMAHA_REQUEST_PARAMS_H_ | 
| Alex Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 19 |  | 
|  | 20 | #include <string> | 
|  | 21 |  | 
|  | 22 | #include <gmock/gmock.h> | 
|  | 23 |  | 
| Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 24 | #include "update_engine/cros/omaha_request_params.h" | 
| Alex Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 25 |  | 
|  | 26 | namespace chromeos_update_engine { | 
|  | 27 |  | 
|  | 28 | class MockOmahaRequestParams : public OmahaRequestParams { | 
|  | 29 | public: | 
| Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 30 | MockOmahaRequestParams() : OmahaRequestParams() { | 
| Alex Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 31 | // Delegate all calls to the parent instance by default. This helps the | 
|  | 32 | // migration from tests using the real RequestParams when they should have | 
|  | 33 | // use a fake or mock. | 
| Alex Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 34 | ON_CALL(*this, GetAppId()) | 
| Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 35 | .WillByDefault( | 
|  | 36 | testing::Invoke(this, &MockOmahaRequestParams::FakeGetAppId)); | 
| Alex Deymo | d942f9d | 2015-11-06 16:11:50 -0800 | [diff] [blame] | 37 | ON_CALL(*this, SetTargetChannel(testing::_, testing::_, testing::_)) | 
| Alex Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 38 | .WillByDefault(testing::Invoke( | 
|  | 39 | this, &MockOmahaRequestParams::FakeSetTargetChannel)); | 
|  | 40 | ON_CALL(*this, UpdateDownloadChannel()) | 
|  | 41 | .WillByDefault(testing::Invoke( | 
|  | 42 | this, &MockOmahaRequestParams::FakeUpdateDownloadChannel)); | 
| Sen Jiang | 8500d3a | 2018-02-08 12:04:05 -0800 | [diff] [blame] | 43 | ON_CALL(*this, ShouldPowerwash()) | 
| Alex Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 44 | .WillByDefault(testing::Invoke( | 
| Sen Jiang | 8500d3a | 2018-02-08 12:04:05 -0800 | [diff] [blame] | 45 | this, &MockOmahaRequestParams::FakeShouldPowerwash)); | 
| Alex Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 46 | } | 
|  | 47 |  | 
| Alex Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 48 | MOCK_CONST_METHOD0(GetAppId, std::string(void)); | 
| Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 49 | MOCK_METHOD3(SetTargetChannel, | 
|  | 50 | bool(const std::string& channel, | 
|  | 51 | bool is_powerwash_allowed, | 
|  | 52 | std::string* error)); | 
| Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 53 | MOCK_CONST_METHOD0(target_version_prefix, std::string(void)); | 
| Alex Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 54 | MOCK_METHOD0(UpdateDownloadChannel, void(void)); | 
| David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 55 | MOCK_CONST_METHOD0(IsUpdateUrlOfficial, bool(void)); | 
| Sen Jiang | 8500d3a | 2018-02-08 12:04:05 -0800 | [diff] [blame] | 56 | MOCK_CONST_METHOD0(ShouldPowerwash, bool(void)); | 
| Alex Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 57 |  | 
|  | 58 | private: | 
|  | 59 | // Wrappers to call the parent class and behave like the real object by | 
|  | 60 | // default. See "Delegating Calls to a Parent Class" in gmock's documentation. | 
| Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 61 | std::string FakeGetAppId() const { return OmahaRequestParams::GetAppId(); } | 
| Alex Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 62 |  | 
|  | 63 | bool FakeSetTargetChannel(const std::string& channel, | 
| Alex Deymo | d942f9d | 2015-11-06 16:11:50 -0800 | [diff] [blame] | 64 | bool is_powerwash_allowed, | 
|  | 65 | std::string* error) { | 
| Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 66 | return OmahaRequestParams::SetTargetChannel( | 
|  | 67 | channel, is_powerwash_allowed, error); | 
| Alex Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 68 | } | 
|  | 69 |  | 
|  | 70 | void FakeUpdateDownloadChannel() { | 
|  | 71 | return OmahaRequestParams::UpdateDownloadChannel(); | 
|  | 72 | } | 
|  | 73 |  | 
| Sen Jiang | 8500d3a | 2018-02-08 12:04:05 -0800 | [diff] [blame] | 74 | bool FakeShouldPowerwash() const { | 
|  | 75 | return OmahaRequestParams::ShouldPowerwash(); | 
| Alex Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 76 | } | 
|  | 77 | }; | 
|  | 78 |  | 
|  | 79 | }  // namespace chromeos_update_engine | 
|  | 80 |  | 
| Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 81 | #endif  // UPDATE_ENGINE_CROS_MOCK_OMAHA_REQUEST_PARAMS_H_ |