Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / public / test / mock_download_manager.h
bloba55bceeae06369d634129af7f33b13bc81347367
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"
17 #include "url/origin.h"
19 class DownloadRequestHandle;
21 namespace content {
23 // To avoid leaking download_request_handle.h to embedders.
24 void PrintTo(const DownloadRequestHandle& params, std::ostream* os);
26 class MockDownloadManager : public DownloadManager {
27 public:
28 // Structure to make it possible to match more than 10 arguments on
29 // CreateDownloadItem.
30 struct CreateDownloadItemAdapter {
31 uint32 id;
32 base::FilePath current_path;
33 base::FilePath target_path;
34 std::vector<GURL> url_chain;
35 GURL referrer_url;
36 std::string mime_type;
37 std::string original_mime_type;
38 base::Time start_time;
39 base::Time end_time;
40 std::string etag;
41 std::string last_modified;
42 int64 received_bytes;
43 int64 total_bytes;
44 DownloadItem::DownloadState state;
45 DownloadDangerType danger_type;
46 DownloadInterruptReason interrupt_reason;
47 bool opened;
49 CreateDownloadItemAdapter(
50 uint32 id,
51 const base::FilePath& current_path,
52 const base::FilePath& target_path,
53 const std::vector<GURL>& url_chain,
54 const GURL& referrer_url,
55 const std::string& mime_type,
56 const std::string& original_mime_type,
57 const base::Time& start_time,
58 const base::Time& end_time,
59 const std::string& etag,
60 const std::string& last_modified,
61 int64 received_bytes,
62 int64 total_bytes,
63 DownloadItem::DownloadState state,
64 DownloadDangerType danger_type,
65 DownloadInterruptReason interrupt_reason,
66 bool opened);
67 // Required by clang compiler.
68 CreateDownloadItemAdapter(const CreateDownloadItemAdapter& rhs);
69 ~CreateDownloadItemAdapter();
71 bool operator==(const CreateDownloadItemAdapter& rhs) const;
74 MockDownloadManager();
75 ~MockDownloadManager() override;
77 // DownloadManager:
78 MOCK_METHOD1(SetDelegate, void(DownloadManagerDelegate* delegate));
79 MOCK_CONST_METHOD0(GetDelegate, DownloadManagerDelegate*());
80 MOCK_METHOD0(Shutdown, void());
81 MOCK_METHOD1(GetAllDownloads, void(DownloadVector* downloads));
82 MOCK_METHOD1(Init, bool(BrowserContext* browser_context));
84 // Gasket for handling scoped_ptr arguments.
85 void StartDownload(
86 scoped_ptr<DownloadCreateInfo> info,
87 scoped_ptr<ByteStreamReader> stream,
88 const DownloadUrlParameters::OnStartedCallback& callback) override;
90 MOCK_METHOD2(MockStartDownload,
91 void(DownloadCreateInfo*, ByteStreamReader*));
92 MOCK_METHOD3(RemoveDownloadsByOriginAndTime,
93 int(const url::Origin& origin,
94 base::Time remove_begin,
95 base::Time remove_end));
96 MOCK_METHOD2(RemoveDownloadsBetween,
97 int(base::Time remove_begin, base::Time remove_end));
98 MOCK_METHOD1(RemoveDownloads, int(base::Time remove_begin));
99 MOCK_METHOD0(RemoveAllDownloads, int());
100 MOCK_METHOD1(DownloadUrlMock, void(DownloadUrlParameters*));
101 void DownloadUrl(scoped_ptr<DownloadUrlParameters> params) override {
102 DownloadUrlMock(params.get());
104 MOCK_METHOD1(AddObserver, void(Observer* observer));
105 MOCK_METHOD1(RemoveObserver, void(Observer* observer));
107 // Redirects to mock method to get around gmock 10 argument limit.
108 DownloadItem* CreateDownloadItem(
109 uint32 id,
110 const base::FilePath& current_path,
111 const base::FilePath& target_path,
112 const std::vector<GURL>& url_chain,
113 const GURL& referrer_url,
114 const std::string& mime_type,
115 const std::string& original_mime_type,
116 const base::Time& start_time,
117 const base::Time& end_time,
118 const std::string& etag,
119 const std::string& last_modified,
120 int64 received_bytes,
121 int64 total_bytes,
122 DownloadItem::DownloadState state,
123 DownloadDangerType danger_type,
124 DownloadInterruptReason interrupt_reason,
125 bool opened) override;
127 MOCK_METHOD1(MockCreateDownloadItem,
128 DownloadItem*(CreateDownloadItemAdapter adapter));
130 MOCK_CONST_METHOD0(InProgressCount, int());
131 MOCK_CONST_METHOD0(NonMaliciousInProgressCount, int());
132 MOCK_CONST_METHOD0(GetBrowserContext, BrowserContext*());
133 MOCK_METHOD0(CheckForHistoryFilesRemoval, void());
134 MOCK_METHOD1(GetDownload, DownloadItem*(uint32 id));
137 } // namespace content
139 #endif // CONTENT_PUBLIC_TEST_MOCK_DOWNLOAD_MANAGER_H_