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