Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: content/browser/download/mock_download_manager.cc

Issue 8351052: Created a DownloadManager interface, for use in unit tests.. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed Mac & Clang issues. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 #include "content/browser/download/mock_download_manager.h"
6
7 MockDownloadManager::MockDownloadManager(
8 content::DownloadManagerDelegate* delegate,
9 DownloadIdFactory* id_factory,
10 DownloadStatusUpdater* updater)
11 : delegate_(delegate), id_factory_(id_factory), updater_(updater) {
12 }
13
14 // Shutdown the download manager. Must be called before destruction.
15 void MockDownloadManager::Shutdown() {
16 }
17
18 // Return all temporary downloads that reside in the specified directory.
19 void MockDownloadManager::GetTemporaryDownloads(const FilePath& dir_path,
20 DownloadVector* result) {
21 }
22
23 // Return all non-temporary downloads in the specified directory that are
24 // are in progress or have completed.
25 void MockDownloadManager::GetAllDownloads(const FilePath& dir_path,
26 DownloadVector* result) {
27 }
28
29 // Returns all non-temporary downloads matching |query|. Empty query matches
30 // everything.
31 void MockDownloadManager::SearchDownloads(const string16& query,
32 DownloadVector* result) {
33 }
34
35 // Returns true if initialized properly.
36 bool MockDownloadManager::Init(content::BrowserContext* browser_context) {
37 return true;
38 }
39
40 // Notifications sent from the download thread to the UI thread
41 void MockDownloadManager::StartDownload(int32 id) {
42 }
43 void MockDownloadManager::UpdateDownload(int32 download_id, int64 size) {
44 }
45
46 // |download_id| is the ID of the download.
47 // |size| is the number of bytes that have been downloaded.
48 // |hash| is sha256 hash for the downloaded file. It is empty when the hash
49 // is not available.
50 void MockDownloadManager::OnResponseCompleted(int32 download_id, int64 size,
51 const std::string& hash) {
52 }
53
54 // Offthread target for cancelling a particular download. Will be a no-op
55 // if the download has already been cancelled.
56 void MockDownloadManager::CancelDownload(int32 download_id) {
57 }
58
59 // Called when there is an error in the download.
60 // |download_id| is the ID of the download.
61 // |size| is the number of bytes that are currently downloaded.
62 // |reason| is a download interrupt reason code.
63 void MockDownloadManager::OnDownloadInterrupted(int32 download_id, int64 size,
64 InterruptReason reason) {
65 }
66
67 // Called from DownloadItem to handle the DownloadManager portion of a
68 // Cancel; should not be called from other locations.
69 void MockDownloadManager::DownloadCancelledInternal(DownloadItem* download) {
70 }
71
72 // Called from a view when a user clicks a UI button or link.
73 void MockDownloadManager::RemoveDownload(int64 download_handle) {
74 }
75
76 // Determine if the download is ready for completion, i.e. has had
77 // all data saved, and completed the filename determination and
78 // history insertion.
79 bool MockDownloadManager::IsDownloadReadyForCompletion(DownloadItem* download) {
80 return true;
81 }
82
83 // If all pre-requisites have been met, complete download processing, i.e.
84 // do internal cleanup, file rename, and potentially auto-open.
85 // (Dangerous downloads still may block on user acceptance after this
86 // point.)
87 void MockDownloadManager::MaybeCompleteDownload(DownloadItem* download) {
88 }
89
90 // Called when the download is renamed to its final name.
91 // |uniquifier| is a number used to make unique names for the file. It is
92 // only valid for the DANGEROUS_BUT_VALIDATED state of the download item.
93 void MockDownloadManager::OnDownloadRenamedToFinalName(int download_id,
94 const FilePath& full_path,
95 int uniquifier) {
96 }
97
98 // Remove downloads after remove_begin (inclusive) and before remove_end
99 // (exclusive). You may pass in null Time values to do an unbounded delete
100 // in either direction.
101 int MockDownloadManager::RemoveDownloadsBetween(const base::Time remove_begin,
102 const base::Time remove_end) {
103 return 0;
104 }
105
106 // Remove downloads will delete all downloads that have a timestamp that is
107 // the same or more recent than |remove_begin|. The number of downloads
108 // deleted is returned back to the caller.
109 int MockDownloadManager::RemoveDownloads(const base::Time remove_begin) {
110 return 0;
111 }
112
113 // Remove all downloads will delete all downloads. The number of downloads
114 // deleted is returned back to the caller.
115 int MockDownloadManager::RemoveAllDownloads() {
116 return 1;
117 }
118
119 // Final download manager transition for download: Update the download
120 // history and remove the download from |active_downloads_|.
121 void MockDownloadManager::DownloadCompleted(int32 download_id) {
122 }
123
124 // Download the object at the URL. Used in cases such as "Save Link As..."
125 void MockDownloadManager::DownloadUrl(const GURL& url,
126 const GURL& referrer,
127 const std::string& referrer_encoding,
128 TabContents* tab_contents) {
129 }
130
131 // Download the object at the URL and save it to the specified path. The
132 // download is treated as the temporary download and thus will not appear
133 // in the download history. Used in cases such as drag and drop.
134 void MockDownloadManager::DownloadUrlToFile(const GURL& url,
135 const GURL& referrer,
136 const std::string& referrer_encoding,
137 const DownloadSaveInfo& save_info,
138 TabContents* tab_contents) {
139 }
140
141 // Allow objects to observe the download creation process.
142 void MockDownloadManager::AddObserver(Observer* observer) {
143 }
144
145 // Remove a download observer from ourself.
146 void MockDownloadManager::RemoveObserver(Observer* observer) {
147 }
148
149 // Called by the embedder, after creating the download manager, to let it know
150 // about downloads from previous runs of the browser.
151 void MockDownloadManager::OnPersistentStoreQueryComplete(
152 std::vector<DownloadPersistentStoreInfo>* entries) {
153 }
154
155 // Called by the embedder, in response to
156 // DownloadManagerDelegate::AddItemToPersistentStore.
157 void MockDownloadManager::OnItemAddedToPersistentStore(int32 download_id,
158 int64 db_handle) {
159 }
160
161 // Display a new download in the appropriate browser UI.
162 void MockDownloadManager::ShowDownloadInBrowser(DownloadItem* download) {
163 }
164
165 // The number of in progress (including paused) downloads.
166 int MockDownloadManager::InProgressCount() const {
167 return 1;
168 }
169
170 content::BrowserContext* MockDownloadManager::BrowserContext() {
171 return NULL;
172 }
173
174 FilePath MockDownloadManager::LastDownloadPath() {
175 return FilePath();
176 }
177
178 // Creates the download item. Must be called on the UI thread.
179 void MockDownloadManager::CreateDownloadItem(DownloadCreateInfo* info,
180 const DownloadRequestHandle& request_handle) {
181 }
182
183 // Clears the last download path, used to initialize "save as" dialogs.
184 void MockDownloadManager::ClearLastDownloadPath() {
185 }
186
187 // Called by the delegate after the save as dialog is closed.
188 void MockDownloadManager::FileSelected(const FilePath& path, void* params) {
189 }
190 void MockDownloadManager::FileSelectionCanceled(void* params) {
191 }
192
193 // Called by the delegate if it delayed the download in
194 // DownloadManagerDelegate::ShouldStartDownload and now is ready.
195 void MockDownloadManager::RestartDownload(int32 download_id) {
196 }
197
198 // Mark the download opened in the persistent store.
199 void MockDownloadManager::MarkDownloadOpened(DownloadItem* download) {
200 }
201
202 // Checks whether downloaded files still exist. Updates state of downloads
203 // that refer to removed files. The check runs in the background and may
204 // finish asynchronously after this method returns.
205 void MockDownloadManager::CheckForHistoryFilesRemoval() {
206 }
207
208 // Checks whether a downloaded file still exists and updates the file's state
209 // if the file is already removed. The check runs in the background and may
210 // finish asynchronously after this method returns.
211 void MockDownloadManager::CheckForFileRemoval(DownloadItem* download_item) {
212 }
213
214 // Assert the named download item is on the correct queues
215 // in the DownloadManager. For debugging.
216 void MockDownloadManager::AssertQueueStateConsistent(DownloadItem* download) {
217 }
218
219 // Get the download item from the history map. Useful after the item has
220 // been removed from the active map, or was retrieved from the history DB.
221 DownloadItem* MockDownloadManager::GetDownloadItem(int id) {
222 return NULL;
223 }
224
225 // Called when Save Page download starts. Transfers ownership of |download|
226 // to the DownloadManager.
227 void MockDownloadManager::SavePageDownloadStarted(DownloadItem* download) {
228 }
229
230 // Called when Save Page download is done.
231 void MockDownloadManager::SavePageDownloadFinished(DownloadItem* download) {
232 }
233
234 // Get the download item from the active map. Useful when the item is not
235 // yet in the history map.
236 DownloadItem* MockDownloadManager::GetActiveDownloadItem(int id) {
237 return NULL;
238 }
239
240 content::DownloadManagerDelegate* MockDownloadManager::delegate() const {
241 return delegate_;
242 }
243
244 // For testing only. May be called from tests indirectly (through
245 // other for testing only methods).
246 void MockDownloadManager::SetDownloadManagerDelegate(
247 content::DownloadManagerDelegate* delegate) {
248 }
249
250 DownloadId MockDownloadManager::GetNextId() {
251 return DownloadId(this, 1);
252 }
253
254 void MockDownloadManager::ContinueDownloadWithPath(DownloadItem* download,
255 const FilePath& chosen_file) {
256 }
257
258 // Retrieves the download from the |download_id|.
259 // Returns NULL if the download is not active.
260 DownloadItem* MockDownloadManager::GetActiveDownload(int32 download_id) {
261 return NULL;
262 }
263
264 void MockDownloadManager::SetFileManager(DownloadFileManager* file_manager) {
265 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698