blob: 3f1c60846c0ec5b389fd7910de2e7a90bf8ccbe0 [file] [log] [blame]
Alex Deymo560ae1d2014-10-28 02:17:54 -07001// Copyright 2014 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef UPDATE_ENGINE_MOCK_OMAHA_REQUEST_PARAMS_H_
6#define UPDATE_ENGINE_MOCK_OMAHA_REQUEST_PARAMS_H_
7
8#include <string>
9
10#include <gmock/gmock.h>
11
12#include "update_engine/omaha_request_params.h"
13
14namespace chromeos_update_engine {
15
16class MockOmahaRequestParams : public OmahaRequestParams {
17 public:
18 explicit MockOmahaRequestParams(SystemState* system_state)
19 : OmahaRequestParams(system_state) {
20 // Delegate all calls to the parent instance by default. This helps the
21 // migration from tests using the real RequestParams when they should have
22 // use a fake or mock.
23 ON_CALL(*this, to_more_stable_channel())
24 .WillByDefault(testing::Invoke(
25 this, &MockOmahaRequestParams::fake_to_more_stable_channel));
26 ON_CALL(*this, GetAppId())
27 .WillByDefault(testing::Invoke(
28 this, &MockOmahaRequestParams::FakeGetAppId));
29 ON_CALL(*this, SetTargetChannel(testing::_, testing::_))
30 .WillByDefault(testing::Invoke(
31 this, &MockOmahaRequestParams::FakeSetTargetChannel));
32 ON_CALL(*this, UpdateDownloadChannel())
33 .WillByDefault(testing::Invoke(
34 this, &MockOmahaRequestParams::FakeUpdateDownloadChannel));
35 ON_CALL(*this, is_powerwash_allowed())
36 .WillByDefault(testing::Invoke(
37 this, &MockOmahaRequestParams::fake_is_powerwash_allowed));
38 }
39
40 MOCK_CONST_METHOD0(to_more_stable_channel, bool(void));
41 MOCK_CONST_METHOD0(GetAppId, std::string(void));
42 MOCK_METHOD2(SetTargetChannel, bool(const std::string& channel,
43 bool is_powerwash_allowed));
44 MOCK_METHOD0(UpdateDownloadChannel, void(void));
45 MOCK_CONST_METHOD0(is_powerwash_allowed, bool(void));
46
47 private:
48 // Wrappers to call the parent class and behave like the real object by
49 // default. See "Delegating Calls to a Parent Class" in gmock's documentation.
50 bool fake_to_more_stable_channel() const {
51 return OmahaRequestParams::to_more_stable_channel();
52 }
53
54 std::string FakeGetAppId() const {
55 return OmahaRequestParams::GetAppId();
56 }
57
58 bool FakeSetTargetChannel(const std::string& channel,
59 bool is_powerwash_allowed) {
60 return OmahaRequestParams::SetTargetChannel(channel, is_powerwash_allowed);
61 }
62
63 void FakeUpdateDownloadChannel() {
64 return OmahaRequestParams::UpdateDownloadChannel();
65 }
66
67 bool fake_is_powerwash_allowed() const {
68 return OmahaRequestParams::is_powerwash_allowed();
69 }
70};
71
72} // namespace chromeos_update_engine
73
74#endif // UPDATE_ENGINE_MOCK_OMAHA_REQUEST_PARAMS_H_