fake_p2p_manager.h revision 3ff6e6ec99106c997db7c352828a02d9bbacc663
1// Copyright (c) 2013 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 CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_P2P_MANAGER_H__ 6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_P2P_MANAGER_H__ 7 8#include "p2p_manager.h" 9 10namespace chromeos_update_engine { 11 12// A fake implementation of P2PManager. 13class FakeP2PManager : public P2PManager { 14public: 15 FakeP2PManager() : 16 is_p2p_enabled_(false), 17 ensure_p2p_running_result_(false), 18 ensure_p2p_not_running_result_(false), 19 perform_housekeeping_result_(false), 20 count_shared_files_result_(0) {} 21 22 virtual ~FakeP2PManager() {} 23 24 // P2PManager overrides. 25 virtual bool IsP2PEnabled() { 26 return is_p2p_enabled_; 27 } 28 29 virtual bool EnsureP2PRunning() { 30 return ensure_p2p_running_result_; 31 } 32 33 virtual bool EnsureP2PNotRunning() { 34 return ensure_p2p_not_running_result_; 35 } 36 37 virtual bool PerformHousekeeping() { 38 return perform_housekeeping_result_; 39 } 40 41 virtual void LookupUrlForFile(const std::string& file_id, 42 size_t minimum_size, 43 base::TimeDelta max_time_to_wait, 44 LookupCallback callback) { 45 callback.Run(lookup_url_for_file_result_); 46 } 47 48 virtual bool FileShare(const std::string& file_id, 49 size_t expected_size) { 50 return false; 51 } 52 53 virtual base::FilePath FileGetPath(const std::string& file_id) { 54 return base::FilePath(); 55 } 56 57 virtual ssize_t FileGetSize(const std::string& file_id) { 58 return -1; 59 } 60 61 virtual ssize_t FileGetExpectedSize(const std::string& file_id) { 62 return -1; 63 } 64 65 virtual bool FileGetVisible(const std::string& file_id, 66 bool *out_result) { 67 return false; 68 } 69 70 virtual bool FileMakeVisible(const std::string& file_id) { 71 return false; 72 } 73 74 virtual int CountSharedFiles() { 75 return count_shared_files_result_; 76 } 77 78 // Methods for controlling what the fake returns and how it acts. 79 void SetP2PEnabled(bool is_p2p_enabled) { 80 is_p2p_enabled_ = is_p2p_enabled; 81 } 82 83 void SetEnsureP2PRunningResult(bool ensure_p2p_running_result) { 84 ensure_p2p_running_result_ = ensure_p2p_running_result; 85 } 86 87 void SetEnsureP2PNotRunningResult(bool ensure_p2p_not_running_result) { 88 ensure_p2p_not_running_result_ = ensure_p2p_not_running_result; 89 } 90 91 void SetPerformHousekeepingResult(bool perform_housekeeping_result) { 92 perform_housekeeping_result_ = perform_housekeeping_result; 93 } 94 95 void SetCountSharedFilesResult(int count_shared_files_result) { 96 count_shared_files_result_ = count_shared_files_result; 97 } 98 99 void SetLookupUrlForFileResult(const std::string& url) { 100 lookup_url_for_file_result_ = url; 101 } 102 103private: 104 bool is_p2p_enabled_; 105 bool ensure_p2p_running_result_; 106 bool ensure_p2p_not_running_result_; 107 bool perform_housekeeping_result_; 108 int count_shared_files_result_; 109 std::string lookup_url_for_file_result_; 110 111 DISALLOW_COPY_AND_ASSIGN(FakeP2PManager); 112}; 113 114} // namespace chromeos_update_engine 115 116#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_P2P_MANAGER_H__ 117