| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/download/download_manager_impl.h" | 5 #include "content/browser/download/download_manager_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 26 #include "build/build_config.h" | 26 #include "build/build_config.h" |
| 27 #include "content/browser/byte_stream.h" | 27 #include "content/browser/byte_stream.h" |
| 28 #include "content/browser/download/download_create_info.h" | 28 #include "content/browser/download/download_create_info.h" |
| 29 #include "content/browser/download/download_file_factory.h" | 29 #include "content/browser/download/download_file_factory.h" |
| 30 #include "content/browser/download/download_item_factory.h" | 30 #include "content/browser/download/download_item_factory.h" |
| 31 #include "content/browser/download/download_item_impl.h" | 31 #include "content/browser/download/download_item_impl.h" |
| 32 #include "content/browser/download/download_item_impl_delegate.h" | 32 #include "content/browser/download/download_item_impl_delegate.h" |
| 33 #include "content/browser/download/download_request_handle.h" | 33 #include "content/browser/download/download_request_handle.h" |
| 34 #include "content/browser/download/mock_download_file.h" | 34 #include "content/browser/download/mock_download_file.h" |
| 35 #include "content/browser/download/mock_download_item_impl.h" |
| 35 #include "content/public/browser/browser_context.h" | 36 #include "content/public/browser/browser_context.h" |
| 36 #include "content/public/browser/download_interrupt_reasons.h" | 37 #include "content/public/browser/download_interrupt_reasons.h" |
| 37 #include "content/public/browser/download_item.h" | 38 #include "content/public/browser/download_item.h" |
| 38 #include "content/public/browser/download_manager_delegate.h" | 39 #include "content/public/browser/download_manager_delegate.h" |
| 39 #include "content/public/browser/zoom_level_delegate.h" | 40 #include "content/public/browser/zoom_level_delegate.h" |
| 40 #include "content/public/test/mock_download_item.h" | 41 #include "content/public/test/mock_download_item.h" |
| 41 #include "content/public/test/test_browser_context.h" | 42 #include "content/public/test/test_browser_context.h" |
| 42 #include "content/public/test/test_browser_thread.h" | 43 #include "content/public/test/test_browser_thread.h" |
| 43 #include "net/log/net_log_with_source.h" | 44 #include "net/log/net_log_with_source.h" |
| 44 #include "testing/gmock/include/gmock/gmock.h" | 45 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 68 | 69 |
| 69 namespace { | 70 namespace { |
| 70 | 71 |
| 71 // Matches a DownloadCreateInfo* that points to the same object as |info| and | 72 // Matches a DownloadCreateInfo* that points to the same object as |info| and |
| 72 // has a |default_download_directory| that matches |download_directory|. | 73 // has a |default_download_directory| that matches |download_directory|. |
| 73 MATCHER_P2(DownloadCreateInfoWithDefaultPath, info, download_directory, "") { | 74 MATCHER_P2(DownloadCreateInfoWithDefaultPath, info, download_directory, "") { |
| 74 return arg == info && | 75 return arg == info && |
| 75 arg->default_download_directory == download_directory; | 76 arg->default_download_directory == download_directory; |
| 76 } | 77 } |
| 77 | 78 |
| 78 class MockDownloadItemImpl : public DownloadItemImpl { | |
| 79 public: | |
| 80 // Use history constructor for minimal base object. | |
| 81 explicit MockDownloadItemImpl(DownloadItemImplDelegate* delegate) | |
| 82 : DownloadItemImpl(delegate, | |
| 83 std::string("7d122682-55b5-4a47-a253-36cadc3e5bee"), | |
| 84 content::DownloadItem::kInvalidId, | |
| 85 base::FilePath(), | |
| 86 base::FilePath(), | |
| 87 std::vector<GURL>(), | |
| 88 GURL(), | |
| 89 GURL(), | |
| 90 GURL(), | |
| 91 GURL(), | |
| 92 "application/octet-stream", | |
| 93 "application/octet-stream", | |
| 94 base::Time(), | |
| 95 base::Time(), | |
| 96 std::string(), | |
| 97 std::string(), | |
| 98 0, | |
| 99 0, | |
| 100 std::string(), | |
| 101 DownloadItem::COMPLETE, | |
| 102 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | |
| 103 DOWNLOAD_INTERRUPT_REASON_NONE, | |
| 104 false, | |
| 105 std::vector<DownloadItem::ReceivedSlice>(), | |
| 106 net::NetLogWithSource()) {} | |
| 107 virtual ~MockDownloadItemImpl() {} | |
| 108 | |
| 109 MOCK_METHOD4(OnDownloadTargetDetermined, | |
| 110 void(const base::FilePath&, TargetDisposition, | |
| 111 DownloadDangerType, const base::FilePath&)); | |
| 112 MOCK_METHOD1(AddObserver, void(DownloadItem::Observer*)); | |
| 113 MOCK_METHOD1(RemoveObserver, void(DownloadItem::Observer*)); | |
| 114 MOCK_METHOD0(UpdateObservers, void()); | |
| 115 MOCK_METHOD0(CanShowInFolder, bool()); | |
| 116 MOCK_METHOD0(CanOpenDownload, bool()); | |
| 117 MOCK_METHOD0(ShouldOpenFileBasedOnExtension, bool()); | |
| 118 MOCK_METHOD0(OpenDownload, void()); | |
| 119 MOCK_METHOD0(ShowDownloadInShell, void()); | |
| 120 MOCK_METHOD0(ValidateDangerousDownload, void()); | |
| 121 MOCK_METHOD2(StealDangerousDownload, void(bool, const AcquireFileCallback&)); | |
| 122 MOCK_METHOD3(UpdateProgress, void(int64_t, int64_t, const std::string&)); | |
| 123 MOCK_METHOD1(Cancel, void(bool)); | |
| 124 MOCK_METHOD0(MarkAsComplete, void()); | |
| 125 void OnAllDataSaved(int64_t, std::unique_ptr<crypto::SecureHash>) override { | |
| 126 NOTREACHED(); | |
| 127 } | |
| 128 MOCK_METHOD0(OnDownloadedFileRemoved, void()); | |
| 129 void Start(std::unique_ptr<DownloadFile> download_file, | |
| 130 std::unique_ptr<DownloadRequestHandleInterface> req_handle, | |
| 131 const DownloadCreateInfo& create_info) override { | |
| 132 MockStart(download_file.get(), req_handle.get()); | |
| 133 } | |
| 134 | |
| 135 MOCK_METHOD2(MockStart, void(DownloadFile*, DownloadRequestHandleInterface*)); | |
| 136 | |
| 137 MOCK_METHOD0(Remove, void()); | |
| 138 MOCK_CONST_METHOD1(TimeRemaining, bool(base::TimeDelta*)); | |
| 139 MOCK_CONST_METHOD0(CurrentSpeed, int64_t()); | |
| 140 MOCK_CONST_METHOD0(PercentComplete, int()); | |
| 141 MOCK_CONST_METHOD0(AllDataSaved, bool()); | |
| 142 MOCK_CONST_METHOD1(MatchesQuery, bool(const base::string16& query)); | |
| 143 MOCK_CONST_METHOD0(IsDone, bool()); | |
| 144 MOCK_CONST_METHOD0(GetFullPath, const base::FilePath&()); | |
| 145 MOCK_CONST_METHOD0(GetTargetFilePath, const base::FilePath&()); | |
| 146 MOCK_CONST_METHOD0(GetTargetDisposition, TargetDisposition()); | |
| 147 MOCK_METHOD1(OnContentCheckCompleted, void(DownloadDangerType)); | |
| 148 MOCK_CONST_METHOD0(GetState, DownloadState()); | |
| 149 MOCK_CONST_METHOD0(GetUrlChain, const std::vector<GURL>&()); | |
| 150 MOCK_METHOD1(SetTotalBytes, void(int64_t)); | |
| 151 MOCK_CONST_METHOD0(GetURL, const GURL&()); | |
| 152 MOCK_CONST_METHOD0(GetOriginalUrl, const GURL&()); | |
| 153 MOCK_CONST_METHOD0(GetReferrerUrl, const GURL&()); | |
| 154 MOCK_CONST_METHOD0(GetTabUrl, const GURL&()); | |
| 155 MOCK_CONST_METHOD0(GetTabReferrerUrl, const GURL&()); | |
| 156 MOCK_CONST_METHOD0(GetSuggestedFilename, std::string()); | |
| 157 MOCK_CONST_METHOD0(GetContentDisposition, std::string()); | |
| 158 MOCK_CONST_METHOD0(GetMimeType, std::string()); | |
| 159 MOCK_CONST_METHOD0(GetOriginalMimeType, std::string()); | |
| 160 MOCK_CONST_METHOD0(GetReferrerCharset, std::string()); | |
| 161 MOCK_CONST_METHOD0(GetRemoteAddress, std::string()); | |
| 162 MOCK_CONST_METHOD0(GetTotalBytes, int64_t()); | |
| 163 MOCK_CONST_METHOD0(GetReceivedBytes, int64_t()); | |
| 164 MOCK_CONST_METHOD0(GetHashState, const std::string&()); | |
| 165 MOCK_CONST_METHOD0(GetHash, const std::string&()); | |
| 166 MOCK_CONST_METHOD0(GetId, uint32_t()); | |
| 167 MOCK_CONST_METHOD0(GetGuid, const std::string&()); | |
| 168 MOCK_CONST_METHOD0(GetStartTime, base::Time()); | |
| 169 MOCK_CONST_METHOD0(GetEndTime, base::Time()); | |
| 170 MOCK_METHOD0(GetDownloadManager, DownloadManager*()); | |
| 171 MOCK_CONST_METHOD0(IsPaused, bool()); | |
| 172 MOCK_CONST_METHOD0(GetOpenWhenComplete, bool()); | |
| 173 MOCK_METHOD1(SetOpenWhenComplete, void(bool)); | |
| 174 MOCK_CONST_METHOD0(GetFileExternallyRemoved, bool()); | |
| 175 MOCK_CONST_METHOD0(GetDangerType, DownloadDangerType()); | |
| 176 MOCK_CONST_METHOD0(IsDangerous, bool()); | |
| 177 MOCK_METHOD0(GetAutoOpened, bool()); | |
| 178 MOCK_CONST_METHOD0(GetForcedFilePath, const base::FilePath&()); | |
| 179 MOCK_CONST_METHOD0(HasUserGesture, bool()); | |
| 180 MOCK_CONST_METHOD0(GetTransitionType, ui::PageTransition()); | |
| 181 MOCK_CONST_METHOD0(IsTemporary, bool()); | |
| 182 MOCK_METHOD1(SetOpened, void(bool)); | |
| 183 MOCK_CONST_METHOD0(GetOpened, bool()); | |
| 184 MOCK_CONST_METHOD0(GetLastModifiedTime, const std::string&()); | |
| 185 MOCK_CONST_METHOD0(GetETag, const std::string&()); | |
| 186 MOCK_CONST_METHOD0(GetLastReason, DownloadInterruptReason()); | |
| 187 MOCK_CONST_METHOD0(GetBrowserContext, BrowserContext*()); | |
| 188 MOCK_CONST_METHOD0(GetWebContents, WebContents*()); | |
| 189 MOCK_CONST_METHOD0(GetFileNameToReportUser, base::FilePath()); | |
| 190 MOCK_METHOD1(SetDisplayName, void(const base::FilePath&)); | |
| 191 MOCK_METHOD0(NotifyRemoved, void()); | |
| 192 // May be called when vlog is on. | |
| 193 std::string DebugString(bool verbose) const override { | |
| 194 return std::string(); | |
| 195 } | |
| 196 }; | |
| 197 | |
| 198 class MockDownloadManagerDelegate : public DownloadManagerDelegate { | 79 class MockDownloadManagerDelegate : public DownloadManagerDelegate { |
| 199 public: | 80 public: |
| 200 MockDownloadManagerDelegate(); | 81 MockDownloadManagerDelegate(); |
| 201 virtual ~MockDownloadManagerDelegate(); | 82 virtual ~MockDownloadManagerDelegate(); |
| 202 | 83 |
| 203 MOCK_METHOD0(Shutdown, void()); | 84 MOCK_METHOD0(Shutdown, void()); |
| 204 MOCK_METHOD1(GetNextId, void(const DownloadIdCallback&)); | 85 MOCK_METHOD1(GetNextId, void(const DownloadIdCallback&)); |
| 205 MOCK_METHOD2(DetermineDownloadTarget, | 86 MOCK_METHOD2(DetermineDownloadTarget, |
| 206 bool(DownloadItem* item, | 87 bool(DownloadItem* item, |
| 207 const DownloadTargetCallback&)); | 88 const DownloadTargetCallback&)); |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 EXPECT_CALL(GetMockDownloadItem(1), Remove()).Times(0); | 637 EXPECT_CALL(GetMockDownloadItem(1), Remove()).Times(0); |
| 757 | 638 |
| 758 base::Callback<bool(const GURL&)> url_filter = | 639 base::Callback<bool(const GURL&)> url_filter = |
| 759 GetSingleURLFilter(download_urls_[0]); | 640 GetSingleURLFilter(download_urls_[0]); |
| 760 int remove_count = download_manager_->RemoveDownloadsByURLAndTime( | 641 int remove_count = download_manager_->RemoveDownloadsByURLAndTime( |
| 761 url_filter, base::Time(), base::Time::Max()); | 642 url_filter, base::Time(), base::Time::Max()); |
| 762 EXPECT_EQ(remove_count, 1); | 643 EXPECT_EQ(remove_count, 1); |
| 763 } | 644 } |
| 764 | 645 |
| 765 } // namespace content | 646 } // namespace content |
| OLD | NEW |