blob: aff74f53575c2b17418095d5338bddfd856833c1 [file] [log] [blame]
Alex Deymoc705cc82014-02-19 11:15:00 -08001// Copyright (c) 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
Gilad Arnold48415f12014-06-27 07:10:58 -07005#ifndef UPDATE_ENGINE_UPDATE_MANAGER_MOCK_POLICY_H_
6#define UPDATE_ENGINE_UPDATE_MANAGER_MOCK_POLICY_H_
7
8#include <string>
Alex Deymoc705cc82014-02-19 11:15:00 -08009
10#include <gmock/gmock.h>
11
Gilad Arnold7fb6e252014-10-29 11:49:19 -070012#include "update_engine/update_manager/default_policy.h"
Alex Deymo63784a52014-05-28 10:46:14 -070013#include "update_engine/update_manager/policy.h"
Alex Deymoc705cc82014-02-19 11:15:00 -080014
Alex Deymo63784a52014-05-28 10:46:14 -070015namespace chromeos_update_manager {
Alex Deymoc705cc82014-02-19 11:15:00 -080016
17// A mocked implementation of Policy.
18class MockPolicy : public Policy {
Alex Deymo0d11c602014-04-23 20:12:20 -070019 public:
Gilad Arnold7fb6e252014-10-29 11:49:19 -070020 explicit MockPolicy(chromeos_update_engine::ClockInterface* clock)
21 : default_policy_(clock) {
22 // We defer to the corresponding DefaultPolicy methods, by default.
23 ON_CALL(*this, UpdateCheckAllowed(testing::_, testing::_, testing::_,
24 testing::_))
25 .WillByDefault(testing::Invoke(
26 &default_policy_, &DefaultPolicy::UpdateCheckAllowed));
27 ON_CALL(*this, UpdateCanStart(testing::_, testing::_, testing::_,
28 testing::_, testing::_))
29 .WillByDefault(testing::Invoke(
30 &default_policy_, &DefaultPolicy::UpdateCanStart));
31 ON_CALL(*this, UpdateDownloadAllowed(testing::_, testing::_, testing::_,
32 testing::_))
33 .WillByDefault(testing::Invoke(
34 &default_policy_, &DefaultPolicy::UpdateDownloadAllowed));
35 ON_CALL(*this, P2PEnabled(testing::_, testing::_, testing::_, testing::_))
36 .WillByDefault(testing::Invoke(
37 &default_policy_, &DefaultPolicy::P2PEnabled));
38 ON_CALL(*this, P2PEnabledChanged(testing::_, testing::_, testing::_,
39 testing::_, testing::_))
40 .WillByDefault(testing::Invoke(
41 &default_policy_, &DefaultPolicy::P2PEnabledChanged));
42 }
43
44 MockPolicy() : MockPolicy(nullptr) {}
Alex Deymoc705cc82014-02-19 11:15:00 -080045 virtual ~MockPolicy() {}
46
47 // Policy overrides.
Alex Deymo2de23f52014-02-26 14:30:13 -080048 MOCK_CONST_METHOD4(UpdateCheckAllowed,
49 EvalStatus(EvaluationContext*, State*, std::string*,
Alex Deymo0d11c602014-04-23 20:12:20 -070050 UpdateCheckParams*));
Alex Deymoc705cc82014-02-19 11:15:00 -080051
Gilad Arnolddc4bb262014-07-23 10:45:19 -070052 MOCK_CONST_METHOD5(UpdateCanStart,
Gilad Arnoldaf2f6ae2014-04-28 14:14:52 -070053 EvalStatus(EvaluationContext*, State*, std::string*,
Gilad Arnold78ecbfc2014-10-22 14:38:25 -070054 UpdateDownloadParams*, UpdateState));
Gilad Arnoldaf2f6ae2014-04-28 14:14:52 -070055
Gilad Arnoldd78caf92014-09-24 09:28:14 -070056 MOCK_CONST_METHOD4(UpdateDownloadAllowed,
Gilad Arnold0adbc942014-05-12 10:35:43 -070057 EvalStatus(EvaluationContext*, State*, std::string*,
58 bool*));
59
Gilad Arnold78ecbfc2014-10-22 14:38:25 -070060 MOCK_CONST_METHOD4(P2PEnabled,
61 EvalStatus(EvaluationContext*, State*, std::string*,
62 bool*));
63
64 MOCK_CONST_METHOD5(P2PEnabledChanged,
65 EvalStatus(EvaluationContext*, State*, std::string*,
66 bool*, bool));
67
Gilad Arnold7fb6e252014-10-29 11:49:19 -070068 protected:
69 // Policy override.
70 std::string PolicyName() const override { return "MockPolicy"; }
71
Alex Deymo0d11c602014-04-23 20:12:20 -070072 private:
Gilad Arnold7fb6e252014-10-29 11:49:19 -070073 DefaultPolicy default_policy_;
74
Alex Deymoc705cc82014-02-19 11:15:00 -080075 DISALLOW_COPY_AND_ASSIGN(MockPolicy);
76};
77
Alex Deymo63784a52014-05-28 10:46:14 -070078} // namespace chromeos_update_manager
Alex Deymoc705cc82014-02-19 11:15:00 -080079
Gilad Arnold48415f12014-06-27 07:10:58 -070080#endif // UPDATE_ENGINE_UPDATE_MANAGER_MOCK_POLICY_H_