1 // Copyright (c) 2012 The Chromium 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 CONTENT_PUBLIC_BROWSER_DOWNLOAD_MOCK_DOWNLOAD_MANAGER_H_ 6 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_MOCK_DOWNLOAD_MANAGER_H_ 7 8 #include <vector> 9 10 #include "content/public/browser/download_manager.h" 11 #include "content/public/browser/download_save_info.h" 12 #include "content/public/browser/download_url_parameters.h" 13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "url/gurl.h" 16 17 class DownloadRequestHandle; 18 19 namespace content { 20 21 // To avoid leaking download_request_handle.h to embedders. 22 void PrintTo(const DownloadRequestHandle& params, std::ostream* os); 23 24 class MockDownloadManager : public DownloadManager { 25 public: 26 // Structure to make it possible to match more than 10 arguments on 27 // CreateDownloadItem. 28 struct CreateDownloadItemAdapter { 29 uint32 id; 30 base::FilePath current_path; 31 base::FilePath target_path; 32 std::vector<GURL> url_chain; 33 GURL referrer_url; 34 base::Time start_time; 35 base::Time end_time; 36 std::string etag; 37 std::string last_modified; 38 int64 received_bytes; 39 int64 total_bytes; 40 DownloadItem::DownloadState state; 41 DownloadDangerType danger_type; 42 DownloadInterruptReason interrupt_reason; 43 bool opened; 44 45 CreateDownloadItemAdapter( 46 uint32 id, 47 const base::FilePath& current_path, 48 const base::FilePath& target_path, 49 const std::vector<GURL>& url_chain, 50 const GURL& referrer_url, 51 const base::Time& start_time, 52 const base::Time& end_time, 53 const std::string& etag, 54 const std::string& last_modified, 55 int64 received_bytes, 56 int64 total_bytes, 57 DownloadItem::DownloadState state, 58 DownloadDangerType danger_type, 59 DownloadInterruptReason interrupt_reason, 60 bool opened); 61 // Required by clang compiler. 62 CreateDownloadItemAdapter(const CreateDownloadItemAdapter& rhs); 63 ~CreateDownloadItemAdapter(); 64 65 bool operator==(const CreateDownloadItemAdapter& rhs); 66 }; 67 68 MockDownloadManager(); 69 virtual ~MockDownloadManager(); 70 71 // DownloadManager: 72 MOCK_METHOD1(SetDelegate, void(DownloadManagerDelegate* delegate)); 73 MOCK_CONST_METHOD0(GetDelegate, DownloadManagerDelegate*()); 74 MOCK_METHOD0(Shutdown, void()); 75 MOCK_METHOD1(GetAllDownloads, void(DownloadVector* downloads)); 76 MOCK_METHOD1(Init, bool(BrowserContext* browser_context)); 77 78 // Gasket for handling scoped_ptr arguments. 79 virtual void StartDownload( 80 scoped_ptr<DownloadCreateInfo> info, 81 scoped_ptr<ByteStreamReader> stream, 82 const DownloadUrlParameters::OnStartedCallback& callback) OVERRIDE; 83 84 MOCK_METHOD2(MockStartDownload, 85 void(DownloadCreateInfo*, ByteStreamReader*)); 86 MOCK_METHOD2(RemoveDownloadsBetween, int(base::Time remove_begin, 87 base::Time remove_end)); 88 MOCK_METHOD1(RemoveDownloads, int(base::Time remove_begin)); 89 MOCK_METHOD0(RemoveAllDownloads, int()); 90 MOCK_METHOD1(DownloadUrlMock, void(DownloadUrlParameters*)); DownloadUrl(scoped_ptr<DownloadUrlParameters> params)91 virtual void DownloadUrl(scoped_ptr<DownloadUrlParameters> params) OVERRIDE { 92 DownloadUrlMock(params.get()); 93 } 94 MOCK_METHOD1(AddObserver, void(Observer* observer)); 95 MOCK_METHOD1(RemoveObserver, void(Observer* observer)); 96 97 // Redirects to mock method to get around gmock 10 argument limit. 98 virtual DownloadItem* CreateDownloadItem( 99 uint32 id, 100 const base::FilePath& current_path, 101 const base::FilePath& target_path, 102 const std::vector<GURL>& url_chain, 103 const GURL& referrer_url, 104 const base::Time& start_time, 105 const base::Time& end_time, 106 const std::string& etag, 107 const std::string& last_modified, 108 int64 received_bytes, 109 int64 total_bytes, 110 DownloadItem::DownloadState state, 111 DownloadDangerType danger_type, 112 DownloadInterruptReason interrupt_reason, 113 bool opened) OVERRIDE; 114 115 MOCK_METHOD1(MockCreateDownloadItem, 116 DownloadItem*(CreateDownloadItemAdapter adapter)); 117 118 MOCK_CONST_METHOD0(InProgressCount, int()); 119 MOCK_CONST_METHOD0(NonMaliciousInProgressCount, int()); 120 MOCK_CONST_METHOD0(GetBrowserContext, BrowserContext*()); 121 MOCK_METHOD0(CheckForHistoryFilesRemoval, void()); 122 MOCK_METHOD1(GetDownload, DownloadItem*(uint32 id)); 123 }; 124 125 } // namespace content 126 127 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_MOCK_DOWNLOAD_MANAGER_H_ 128