| 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 arg->default_download_directory == download_directory; | 61 arg->default_download_directory == download_directory; |
| 62 } | 62 } |
| 63 | 63 |
| 64 class MockDownloadItemImpl : public DownloadItemImpl { | 64 class MockDownloadItemImpl : public DownloadItemImpl { |
| 65 public: | 65 public: |
| 66 // Use history constructor for minimal base object. | 66 // Use history constructor for minimal base object. |
| 67 MockDownloadItemImpl(DownloadItemImplDelegate* delegate) | 67 MockDownloadItemImpl(DownloadItemImplDelegate* delegate) |
| 68 : DownloadItemImpl( | 68 : DownloadItemImpl( |
| 69 delegate, | 69 delegate, |
| 70 content::DownloadId(), | 70 content::DownloadId(), |
| 71 FilePath(), | 71 base::FilePath(), |
| 72 FilePath(), | 72 base::FilePath(), |
| 73 std::vector<GURL>(), | 73 std::vector<GURL>(), |
| 74 GURL(), | 74 GURL(), |
| 75 base::Time(), | 75 base::Time(), |
| 76 base::Time(), | 76 base::Time(), |
| 77 0, | 77 0, |
| 78 0, | 78 0, |
| 79 DownloadItem::IN_PROGRESS, | 79 DownloadItem::IN_PROGRESS, |
| 80 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 80 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 81 DOWNLOAD_INTERRUPT_REASON_NONE, | 81 DOWNLOAD_INTERRUPT_REASON_NONE, |
| 82 false, | 82 false, |
| 83 net::BoundNetLog()) {} | 83 net::BoundNetLog()) {} |
| 84 virtual ~MockDownloadItemImpl() {} | 84 virtual ~MockDownloadItemImpl() {} |
| 85 | 85 |
| 86 MOCK_METHOD4(OnDownloadTargetDetermined, | 86 MOCK_METHOD4(OnDownloadTargetDetermined, |
| 87 void(const FilePath&, TargetDisposition, | 87 void(const base::FilePath&, TargetDisposition, |
| 88 DownloadDangerType, const FilePath&)); | 88 DownloadDangerType, const base::FilePath&)); |
| 89 MOCK_METHOD1(AddObserver, void(DownloadItem::Observer*)); | 89 MOCK_METHOD1(AddObserver, void(DownloadItem::Observer*)); |
| 90 MOCK_METHOD1(RemoveObserver, void(DownloadItem::Observer*)); | 90 MOCK_METHOD1(RemoveObserver, void(DownloadItem::Observer*)); |
| 91 MOCK_METHOD0(UpdateObservers, void()); | 91 MOCK_METHOD0(UpdateObservers, void()); |
| 92 MOCK_METHOD0(CanShowInFolder, bool()); | 92 MOCK_METHOD0(CanShowInFolder, bool()); |
| 93 MOCK_METHOD0(CanOpenDownload, bool()); | 93 MOCK_METHOD0(CanOpenDownload, bool()); |
| 94 MOCK_METHOD0(ShouldOpenFileBasedOnExtension, bool()); | 94 MOCK_METHOD0(ShouldOpenFileBasedOnExtension, bool()); |
| 95 MOCK_METHOD0(OpenDownload, void()); | 95 MOCK_METHOD0(OpenDownload, void()); |
| 96 MOCK_METHOD0(ShowDownloadInShell, void()); | 96 MOCK_METHOD0(ShowDownloadInShell, void()); |
| 97 MOCK_METHOD0(DangerousDownloadValidated, void()); | 97 MOCK_METHOD0(DangerousDownloadValidated, void()); |
| 98 MOCK_METHOD3(UpdateProgress, void(int64, int64, const std::string&)); | 98 MOCK_METHOD3(UpdateProgress, void(int64, int64, const std::string&)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 113 MOCK_CONST_METHOD1(TimeRemaining, bool(base::TimeDelta*)); | 113 MOCK_CONST_METHOD1(TimeRemaining, bool(base::TimeDelta*)); |
| 114 MOCK_CONST_METHOD0(CurrentSpeed, int64()); | 114 MOCK_CONST_METHOD0(CurrentSpeed, int64()); |
| 115 MOCK_CONST_METHOD0(PercentComplete, int()); | 115 MOCK_CONST_METHOD0(PercentComplete, int()); |
| 116 MOCK_CONST_METHOD0(AllDataSaved, bool()); | 116 MOCK_CONST_METHOD0(AllDataSaved, bool()); |
| 117 MOCK_CONST_METHOD1(MatchesQuery, bool(const string16& query)); | 117 MOCK_CONST_METHOD1(MatchesQuery, bool(const string16& query)); |
| 118 MOCK_CONST_METHOD0(IsPartialDownload, bool()); | 118 MOCK_CONST_METHOD0(IsPartialDownload, bool()); |
| 119 MOCK_CONST_METHOD0(IsInProgress, bool()); | 119 MOCK_CONST_METHOD0(IsInProgress, bool()); |
| 120 MOCK_CONST_METHOD0(IsCancelled, bool()); | 120 MOCK_CONST_METHOD0(IsCancelled, bool()); |
| 121 MOCK_CONST_METHOD0(IsInterrupted, bool()); | 121 MOCK_CONST_METHOD0(IsInterrupted, bool()); |
| 122 MOCK_CONST_METHOD0(IsComplete, bool()); | 122 MOCK_CONST_METHOD0(IsComplete, bool()); |
| 123 MOCK_CONST_METHOD0(GetFullPath, const FilePath&()); | 123 MOCK_CONST_METHOD0(GetFullPath, const base::FilePath&()); |
| 124 MOCK_CONST_METHOD0(GetTargetFilePath, const FilePath&()); | 124 MOCK_CONST_METHOD0(GetTargetFilePath, const base::FilePath&()); |
| 125 MOCK_CONST_METHOD0(GetTargetDisposition, TargetDisposition()); | 125 MOCK_CONST_METHOD0(GetTargetDisposition, TargetDisposition()); |
| 126 MOCK_METHOD1(OnContentCheckCompleted, void(DownloadDangerType)); | 126 MOCK_METHOD1(OnContentCheckCompleted, void(DownloadDangerType)); |
| 127 MOCK_CONST_METHOD0(GetState, DownloadState()); | 127 MOCK_CONST_METHOD0(GetState, DownloadState()); |
| 128 MOCK_CONST_METHOD0(GetUrlChain, const std::vector<GURL>&()); | 128 MOCK_CONST_METHOD0(GetUrlChain, const std::vector<GURL>&()); |
| 129 MOCK_METHOD1(SetTotalBytes, void(int64)); | 129 MOCK_METHOD1(SetTotalBytes, void(int64)); |
| 130 MOCK_CONST_METHOD0(GetURL, const GURL&()); | 130 MOCK_CONST_METHOD0(GetURL, const GURL&()); |
| 131 MOCK_CONST_METHOD0(GetOriginalUrl, const GURL&()); | 131 MOCK_CONST_METHOD0(GetOriginalUrl, const GURL&()); |
| 132 MOCK_CONST_METHOD0(GetReferrerUrl, const GURL&()); | 132 MOCK_CONST_METHOD0(GetReferrerUrl, const GURL&()); |
| 133 MOCK_CONST_METHOD0(GetSuggestedFilename, std::string()); | 133 MOCK_CONST_METHOD0(GetSuggestedFilename, std::string()); |
| 134 MOCK_CONST_METHOD0(GetContentDisposition, std::string()); | 134 MOCK_CONST_METHOD0(GetContentDisposition, std::string()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 145 MOCK_CONST_METHOD0(GetStartTime, base::Time()); | 145 MOCK_CONST_METHOD0(GetStartTime, base::Time()); |
| 146 MOCK_CONST_METHOD0(GetEndTime, base::Time()); | 146 MOCK_CONST_METHOD0(GetEndTime, base::Time()); |
| 147 MOCK_METHOD0(GetDownloadManager, DownloadManager*()); | 147 MOCK_METHOD0(GetDownloadManager, DownloadManager*()); |
| 148 MOCK_CONST_METHOD0(IsPaused, bool()); | 148 MOCK_CONST_METHOD0(IsPaused, bool()); |
| 149 MOCK_CONST_METHOD0(GetOpenWhenComplete, bool()); | 149 MOCK_CONST_METHOD0(GetOpenWhenComplete, bool()); |
| 150 MOCK_METHOD1(SetOpenWhenComplete, void(bool)); | 150 MOCK_METHOD1(SetOpenWhenComplete, void(bool)); |
| 151 MOCK_CONST_METHOD0(GetFileExternallyRemoved, bool()); | 151 MOCK_CONST_METHOD0(GetFileExternallyRemoved, bool()); |
| 152 MOCK_CONST_METHOD0(GetDangerType, DownloadDangerType()); | 152 MOCK_CONST_METHOD0(GetDangerType, DownloadDangerType()); |
| 153 MOCK_CONST_METHOD0(IsDangerous, bool()); | 153 MOCK_CONST_METHOD0(IsDangerous, bool()); |
| 154 MOCK_METHOD0(GetAutoOpened, bool()); | 154 MOCK_METHOD0(GetAutoOpened, bool()); |
| 155 MOCK_CONST_METHOD0(GetForcedFilePath, const FilePath&()); | 155 MOCK_CONST_METHOD0(GetForcedFilePath, const base::FilePath&()); |
| 156 MOCK_CONST_METHOD0(HasUserGesture, bool()); | 156 MOCK_CONST_METHOD0(HasUserGesture, bool()); |
| 157 MOCK_CONST_METHOD0(GetTransitionType, PageTransition()); | 157 MOCK_CONST_METHOD0(GetTransitionType, PageTransition()); |
| 158 MOCK_CONST_METHOD0(IsTemporary, bool()); | 158 MOCK_CONST_METHOD0(IsTemporary, bool()); |
| 159 MOCK_METHOD1(SetIsTemporary, void(bool)); | 159 MOCK_METHOD1(SetIsTemporary, void(bool)); |
| 160 MOCK_METHOD1(SetOpened, void(bool)); | 160 MOCK_METHOD1(SetOpened, void(bool)); |
| 161 MOCK_CONST_METHOD0(GetOpened, bool()); | 161 MOCK_CONST_METHOD0(GetOpened, bool()); |
| 162 MOCK_CONST_METHOD0(GetLastModifiedTime, const std::string&()); | 162 MOCK_CONST_METHOD0(GetLastModifiedTime, const std::string&()); |
| 163 MOCK_CONST_METHOD0(GetETag, const std::string&()); | 163 MOCK_CONST_METHOD0(GetETag, const std::string&()); |
| 164 MOCK_CONST_METHOD0(GetLastReason, DownloadInterruptReason()); | 164 MOCK_CONST_METHOD0(GetLastReason, DownloadInterruptReason()); |
| 165 MOCK_CONST_METHOD0(GetBrowserContext, BrowserContext*()); | 165 MOCK_CONST_METHOD0(GetBrowserContext, BrowserContext*()); |
| 166 MOCK_CONST_METHOD0(GetWebContents, WebContents*()); | 166 MOCK_CONST_METHOD0(GetWebContents, WebContents*()); |
| 167 MOCK_CONST_METHOD0(GetFileNameToReportUser, FilePath()); | 167 MOCK_CONST_METHOD0(GetFileNameToReportUser, base::FilePath()); |
| 168 MOCK_METHOD1(SetDisplayName, void(const FilePath&)); | 168 MOCK_METHOD1(SetDisplayName, void(const base::FilePath&)); |
| 169 MOCK_CONST_METHOD0(GetUserVerifiedFilePath, FilePath()); | 169 MOCK_CONST_METHOD0(GetUserVerifiedFilePath, base::FilePath()); |
| 170 // May be called when vlog is on. | 170 // May be called when vlog is on. |
| 171 virtual std::string DebugString(bool verbose) const OVERRIDE { return ""; } | 171 virtual std::string DebugString(bool verbose) const OVERRIDE { return ""; } |
| 172 }; | 172 }; |
| 173 | 173 |
| 174 class MockDownloadManagerDelegate : public DownloadManagerDelegate { | 174 class MockDownloadManagerDelegate : public DownloadManagerDelegate { |
| 175 public: | 175 public: |
| 176 MockDownloadManagerDelegate(); | 176 MockDownloadManagerDelegate(); |
| 177 virtual ~MockDownloadManagerDelegate(); | 177 virtual ~MockDownloadManagerDelegate(); |
| 178 | 178 |
| 179 MOCK_METHOD0(Shutdown, void()); | 179 MOCK_METHOD0(Shutdown, void()); |
| 180 MOCK_METHOD0(GetNextId, DownloadId()); | 180 MOCK_METHOD0(GetNextId, DownloadId()); |
| 181 MOCK_METHOD2(DetermineDownloadTarget, | 181 MOCK_METHOD2(DetermineDownloadTarget, |
| 182 bool(DownloadItem* item, | 182 bool(DownloadItem* item, |
| 183 const DownloadTargetCallback&)); | 183 const DownloadTargetCallback&)); |
| 184 MOCK_METHOD0(GetAlternativeWebContentsToNotifyForDownload, WebContents*()); | 184 MOCK_METHOD0(GetAlternativeWebContentsToNotifyForDownload, WebContents*()); |
| 185 MOCK_METHOD1(ShouldOpenFileBasedOnExtension, bool(const FilePath&)); | 185 MOCK_METHOD1(ShouldOpenFileBasedOnExtension, bool(const base::FilePath&)); |
| 186 MOCK_METHOD2(ShouldCompleteDownload, | 186 MOCK_METHOD2(ShouldCompleteDownload, |
| 187 bool(DownloadItem*, const base::Closure&)); | 187 bool(DownloadItem*, const base::Closure&)); |
| 188 MOCK_METHOD2(ShouldOpenDownload, | 188 MOCK_METHOD2(ShouldOpenDownload, |
| 189 bool(DownloadItem*, const DownloadOpenDelayedCallback&)); | 189 bool(DownloadItem*, const DownloadOpenDelayedCallback&)); |
| 190 MOCK_METHOD0(GenerateFileHash, bool()); | 190 MOCK_METHOD0(GenerateFileHash, bool()); |
| 191 MOCK_METHOD4(GetSaveDir, void(BrowserContext*, | 191 MOCK_METHOD4(GetSaveDir, void(BrowserContext*, |
| 192 FilePath*, FilePath*, bool*)); | 192 base::FilePath*, base::FilePath*, bool*)); |
| 193 MOCK_METHOD5(ChooseSavePath, void( | 193 MOCK_METHOD5(ChooseSavePath, void( |
| 194 WebContents*, const FilePath&, const FilePath::StringType&, | 194 WebContents*, const base::FilePath&, const base::FilePath::StringType&, |
| 195 bool, const SavePackagePathPickedCallback&)); | 195 bool, const SavePackagePathPickedCallback&)); |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 MockDownloadManagerDelegate::MockDownloadManagerDelegate() {} | 198 MockDownloadManagerDelegate::MockDownloadManagerDelegate() {} |
| 199 | 199 |
| 200 MockDownloadManagerDelegate::~MockDownloadManagerDelegate() {} | 200 MockDownloadManagerDelegate::~MockDownloadManagerDelegate() {} |
| 201 | 201 |
| 202 class MockDownloadItemFactory | 202 class MockDownloadItemFactory |
| 203 : public DownloadItemFactory, | 203 : public DownloadItemFactory, |
| 204 public base::SupportsWeakPtr<MockDownloadItemFactory> { | 204 public base::SupportsWeakPtr<MockDownloadItemFactory> { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 218 MockDownloadItemImpl* PopItem(); | 218 MockDownloadItemImpl* PopItem(); |
| 219 | 219 |
| 220 // Should be called when the item of this id is removed so that | 220 // Should be called when the item of this id is removed so that |
| 221 // we don't keep dangling pointers. | 221 // we don't keep dangling pointers. |
| 222 void RemoveItem(int id); | 222 void RemoveItem(int id); |
| 223 | 223 |
| 224 // Overridden methods from DownloadItemFactory. | 224 // Overridden methods from DownloadItemFactory. |
| 225 virtual DownloadItemImpl* CreatePersistedItem( | 225 virtual DownloadItemImpl* CreatePersistedItem( |
| 226 DownloadItemImplDelegate* delegate, | 226 DownloadItemImplDelegate* delegate, |
| 227 DownloadId download_id, | 227 DownloadId download_id, |
| 228 const FilePath& current_path, | 228 const base::FilePath& current_path, |
| 229 const FilePath& target_path, | 229 const base::FilePath& target_path, |
| 230 const std::vector<GURL>& url_chain, | 230 const std::vector<GURL>& url_chain, |
| 231 const GURL& referrer_url, | 231 const GURL& referrer_url, |
| 232 const base::Time& start_time, | 232 const base::Time& start_time, |
| 233 const base::Time& end_time, | 233 const base::Time& end_time, |
| 234 int64 received_bytes, | 234 int64 received_bytes, |
| 235 int64 total_bytes, | 235 int64 total_bytes, |
| 236 DownloadItem::DownloadState state, | 236 DownloadItem::DownloadState state, |
| 237 DownloadDangerType danger_type, | 237 DownloadDangerType danger_type, |
| 238 DownloadInterruptReason interrupt_reason, | 238 DownloadInterruptReason interrupt_reason, |
| 239 bool opened, | 239 bool opened, |
| 240 const net::BoundNetLog& bound_net_log) OVERRIDE; | 240 const net::BoundNetLog& bound_net_log) OVERRIDE; |
| 241 virtual DownloadItemImpl* CreateActiveItem( | 241 virtual DownloadItemImpl* CreateActiveItem( |
| 242 DownloadItemImplDelegate* delegate, | 242 DownloadItemImplDelegate* delegate, |
| 243 const DownloadCreateInfo& info, | 243 const DownloadCreateInfo& info, |
| 244 const net::BoundNetLog& bound_net_log) OVERRIDE; | 244 const net::BoundNetLog& bound_net_log) OVERRIDE; |
| 245 virtual DownloadItemImpl* CreateSavePageItem( | 245 virtual DownloadItemImpl* CreateSavePageItem( |
| 246 DownloadItemImplDelegate* delegate, | 246 DownloadItemImplDelegate* delegate, |
| 247 const FilePath& path, | 247 const base::FilePath& path, |
| 248 const GURL& url, | 248 const GURL& url, |
| 249 DownloadId download_id, | 249 DownloadId download_id, |
| 250 const std::string& mime_type, | 250 const std::string& mime_type, |
| 251 const net::BoundNetLog& bound_net_log) OVERRIDE; | 251 const net::BoundNetLog& bound_net_log) OVERRIDE; |
| 252 | 252 |
| 253 private: | 253 private: |
| 254 std::map<int32, MockDownloadItemImpl*> items_; | 254 std::map<int32, MockDownloadItemImpl*> items_; |
| 255 DownloadItemImplDelegate item_delegate_; | 255 DownloadItemImplDelegate item_delegate_; |
| 256 | 256 |
| 257 DISALLOW_COPY_AND_ASSIGN(MockDownloadItemFactory); | 257 DISALLOW_COPY_AND_ASSIGN(MockDownloadItemFactory); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 279 } | 279 } |
| 280 | 280 |
| 281 void MockDownloadItemFactory::RemoveItem(int id) { | 281 void MockDownloadItemFactory::RemoveItem(int id) { |
| 282 DCHECK(items_.find(id) != items_.end()); | 282 DCHECK(items_.find(id) != items_.end()); |
| 283 items_.erase(id); | 283 items_.erase(id); |
| 284 } | 284 } |
| 285 | 285 |
| 286 DownloadItemImpl* MockDownloadItemFactory::CreatePersistedItem( | 286 DownloadItemImpl* MockDownloadItemFactory::CreatePersistedItem( |
| 287 DownloadItemImplDelegate* delegate, | 287 DownloadItemImplDelegate* delegate, |
| 288 DownloadId download_id, | 288 DownloadId download_id, |
| 289 const FilePath& current_path, | 289 const base::FilePath& current_path, |
| 290 const FilePath& target_path, | 290 const base::FilePath& target_path, |
| 291 const std::vector<GURL>& url_chain, | 291 const std::vector<GURL>& url_chain, |
| 292 const GURL& referrer_url, | 292 const GURL& referrer_url, |
| 293 const base::Time& start_time, | 293 const base::Time& start_time, |
| 294 const base::Time& end_time, | 294 const base::Time& end_time, |
| 295 int64 received_bytes, | 295 int64 received_bytes, |
| 296 int64 total_bytes, | 296 int64 total_bytes, |
| 297 DownloadItem::DownloadState state, | 297 DownloadItem::DownloadState state, |
| 298 DownloadDangerType danger_type, | 298 DownloadDangerType danger_type, |
| 299 DownloadInterruptReason interrupt_reason, | 299 DownloadInterruptReason interrupt_reason, |
| 300 bool opened, | 300 bool opened, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 328 | 328 |
| 329 // Active items are created and then immediately are called to start | 329 // Active items are created and then immediately are called to start |
| 330 // the download. | 330 // the download. |
| 331 EXPECT_CALL(*result, MockStart(_, _)); | 331 EXPECT_CALL(*result, MockStart(_, _)); |
| 332 | 332 |
| 333 return result; | 333 return result; |
| 334 } | 334 } |
| 335 | 335 |
| 336 DownloadItemImpl* MockDownloadItemFactory::CreateSavePageItem( | 336 DownloadItemImpl* MockDownloadItemFactory::CreateSavePageItem( |
| 337 DownloadItemImplDelegate* delegate, | 337 DownloadItemImplDelegate* delegate, |
| 338 const FilePath& path, | 338 const base::FilePath& path, |
| 339 const GURL& url, | 339 const GURL& url, |
| 340 DownloadId download_id, | 340 DownloadId download_id, |
| 341 const std::string& mime_type, | 341 const std::string& mime_type, |
| 342 const net::BoundNetLog& bound_net_log) { | 342 const net::BoundNetLog& bound_net_log) { |
| 343 int local_id = download_id.local(); | 343 int local_id = download_id.local(); |
| 344 DCHECK(items_.find(local_id) == items_.end()); | 344 DCHECK(items_.find(local_id) == items_.end()); |
| 345 | 345 |
| 346 MockDownloadItemImpl* result = | 346 MockDownloadItemImpl* result = |
| 347 new StrictMock<MockDownloadItemImpl>(&item_delegate_); | 347 new StrictMock<MockDownloadItemImpl>(&item_delegate_); |
| 348 EXPECT_CALL(*result, GetId()) | 348 EXPECT_CALL(*result, GetId()) |
| 349 .WillRepeatedly(Return(local_id)); | 349 .WillRepeatedly(Return(local_id)); |
| 350 items_[local_id] = result; | 350 items_[local_id] = result; |
| 351 | 351 |
| 352 return result; | 352 return result; |
| 353 } | 353 } |
| 354 | 354 |
| 355 class MockDownloadFileFactory | 355 class MockDownloadFileFactory |
| 356 : public DownloadFileFactory, | 356 : public DownloadFileFactory, |
| 357 public base::SupportsWeakPtr<MockDownloadFileFactory> { | 357 public base::SupportsWeakPtr<MockDownloadFileFactory> { |
| 358 public: | 358 public: |
| 359 MockDownloadFileFactory() {} | 359 MockDownloadFileFactory() {} |
| 360 virtual ~MockDownloadFileFactory() {} | 360 virtual ~MockDownloadFileFactory() {} |
| 361 | 361 |
| 362 // Overridden method from DownloadFileFactory | 362 // Overridden method from DownloadFileFactory |
| 363 MOCK_METHOD8(MockCreateFile, DownloadFile*( | 363 MOCK_METHOD8(MockCreateFile, DownloadFile*( |
| 364 const DownloadSaveInfo&, | 364 const DownloadSaveInfo&, |
| 365 const FilePath&, | 365 const base::FilePath&, |
| 366 const GURL&, const GURL&, bool, | 366 const GURL&, const GURL&, bool, |
| 367 ByteStreamReader*, | 367 ByteStreamReader*, |
| 368 const net::BoundNetLog&, | 368 const net::BoundNetLog&, |
| 369 base::WeakPtr<DownloadDestinationObserver>)); | 369 base::WeakPtr<DownloadDestinationObserver>)); |
| 370 | 370 |
| 371 virtual DownloadFile* CreateFile( | 371 virtual DownloadFile* CreateFile( |
| 372 scoped_ptr<DownloadSaveInfo> save_info, | 372 scoped_ptr<DownloadSaveInfo> save_info, |
| 373 const FilePath& default_download_directory, | 373 const base::FilePath& default_download_directory, |
| 374 const GURL& url, | 374 const GURL& url, |
| 375 const GURL& referrer_url, | 375 const GURL& referrer_url, |
| 376 bool calculate_hash, | 376 bool calculate_hash, |
| 377 scoped_ptr<ByteStreamReader> stream, | 377 scoped_ptr<ByteStreamReader> stream, |
| 378 const net::BoundNetLog& bound_net_log, | 378 const net::BoundNetLog& bound_net_log, |
| 379 base::WeakPtr<DownloadDestinationObserver> observer) { | 379 base::WeakPtr<DownloadDestinationObserver> observer) { |
| 380 return MockCreateFile(*save_info.get(), default_download_directory, url, | 380 return MockCreateFile(*save_info.get(), default_download_directory, url, |
| 381 referrer_url, calculate_hash, | 381 referrer_url, calculate_hash, |
| 382 stream.get(), bound_net_log, observer); | 382 stream.get(), bound_net_log, observer); |
| 383 } | 383 } |
| 384 }; | 384 }; |
| 385 | 385 |
| 386 class MockBrowserContext : public BrowserContext { | 386 class MockBrowserContext : public BrowserContext { |
| 387 public: | 387 public: |
| 388 MockBrowserContext() {} | 388 MockBrowserContext() {} |
| 389 ~MockBrowserContext() {} | 389 ~MockBrowserContext() {} |
| 390 | 390 |
| 391 MOCK_METHOD0(GetPath, FilePath()); | 391 MOCK_METHOD0(GetPath, base::FilePath()); |
| 392 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); | 392 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); |
| 393 MOCK_METHOD0(GetRequestContext, net::URLRequestContextGetter*()); | 393 MOCK_METHOD0(GetRequestContext, net::URLRequestContextGetter*()); |
| 394 MOCK_METHOD1(GetRequestContextForRenderProcess, | 394 MOCK_METHOD1(GetRequestContextForRenderProcess, |
| 395 net::URLRequestContextGetter*(int renderer_child_id)); | 395 net::URLRequestContextGetter*(int renderer_child_id)); |
| 396 MOCK_METHOD2(GetRequestContextForStoragePartition, | 396 MOCK_METHOD2(GetRequestContextForStoragePartition, |
| 397 net::URLRequestContextGetter*( | 397 net::URLRequestContextGetter*( |
| 398 const FilePath& partition_path, bool in_memory)); | 398 const base::FilePath& partition_path, bool in_memory)); |
| 399 MOCK_METHOD0(GetMediaRequestContext, | 399 MOCK_METHOD0(GetMediaRequestContext, |
| 400 net::URLRequestContextGetter*()); | 400 net::URLRequestContextGetter*()); |
| 401 MOCK_METHOD1(GetMediaRequestContextForRenderProcess, | 401 MOCK_METHOD1(GetMediaRequestContextForRenderProcess, |
| 402 net::URLRequestContextGetter*(int renderer_child_id)); | 402 net::URLRequestContextGetter*(int renderer_child_id)); |
| 403 MOCK_METHOD2(GetMediaRequestContextForStoragePartition, | 403 MOCK_METHOD2(GetMediaRequestContextForStoragePartition, |
| 404 net::URLRequestContextGetter*( | 404 net::URLRequestContextGetter*( |
| 405 const FilePath& partition_path, bool in_memory)); | 405 const base::FilePath& partition_path, bool in_memory)); |
| 406 MOCK_METHOD0(GetResourceContext, ResourceContext*()); | 406 MOCK_METHOD0(GetResourceContext, ResourceContext*()); |
| 407 MOCK_METHOD0(GetDownloadManagerDelegate, DownloadManagerDelegate*()); | 407 MOCK_METHOD0(GetDownloadManagerDelegate, DownloadManagerDelegate*()); |
| 408 MOCK_METHOD0(GetGeolocationPermissionContext, | 408 MOCK_METHOD0(GetGeolocationPermissionContext, |
| 409 GeolocationPermissionContext* ()); | 409 GeolocationPermissionContext* ()); |
| 410 MOCK_METHOD0(GetSpeechRecognitionPreferences, | 410 MOCK_METHOD0(GetSpeechRecognitionPreferences, |
| 411 SpeechRecognitionPreferences* ()); | 411 SpeechRecognitionPreferences* ()); |
| 412 MOCK_METHOD0(GetSpecialStoragePolicy, quota::SpecialStoragePolicy*()); | 412 MOCK_METHOD0(GetSpecialStoragePolicy, quota::SpecialStoragePolicy*()); |
| 413 }; | 413 }; |
| 414 | 414 |
| 415 class MockDownloadManagerObserver : public DownloadManager::Observer { | 415 class MockDownloadManagerObserver : public DownloadManager::Observer { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 | 528 |
| 529 MockDownloadManagerDelegate& GetMockDownloadManagerDelegate() { | 529 MockDownloadManagerDelegate& GetMockDownloadManagerDelegate() { |
| 530 return *mock_download_manager_delegate_; | 530 return *mock_download_manager_delegate_; |
| 531 } | 531 } |
| 532 | 532 |
| 533 MockDownloadManagerObserver& GetMockObserver() { | 533 MockDownloadManagerObserver& GetMockObserver() { |
| 534 return *observer_; | 534 return *observer_; |
| 535 } | 535 } |
| 536 | 536 |
| 537 void DownloadTargetDeterminedCallback( | 537 void DownloadTargetDeterminedCallback( |
| 538 const FilePath& target_path, | 538 const base::FilePath& target_path, |
| 539 DownloadItem::TargetDisposition disposition, | 539 DownloadItem::TargetDisposition disposition, |
| 540 DownloadDangerType danger_type, | 540 DownloadDangerType danger_type, |
| 541 const FilePath& intermediate_path) { | 541 const base::FilePath& intermediate_path) { |
| 542 callback_called_ = true; | 542 callback_called_ = true; |
| 543 target_path_ = target_path; | 543 target_path_ = target_path; |
| 544 target_disposition_ = disposition; | 544 target_disposition_ = disposition; |
| 545 danger_type_ = danger_type; | 545 danger_type_ = danger_type; |
| 546 intermediate_path_ = intermediate_path; | 546 intermediate_path_ = intermediate_path; |
| 547 } | 547 } |
| 548 | 548 |
| 549 void DetermineDownloadTarget(DownloadItemImpl* item) { | 549 void DetermineDownloadTarget(DownloadItemImpl* item) { |
| 550 download_manager_->DetermineDownloadTarget( | 550 download_manager_->DetermineDownloadTarget( |
| 551 item, base::Bind( | 551 item, base::Bind( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 568 .WillOnce(Return(true)); | 568 .WillOnce(Return(true)); |
| 569 } | 569 } |
| 570 | 570 |
| 571 protected: | 571 protected: |
| 572 // Key test variable; we'll keep it available to sub-classes. | 572 // Key test variable; we'll keep it available to sub-classes. |
| 573 scoped_refptr<DownloadManagerImpl> download_manager_; | 573 scoped_refptr<DownloadManagerImpl> download_manager_; |
| 574 base::WeakPtr<MockDownloadFileFactory> mock_download_file_factory_; | 574 base::WeakPtr<MockDownloadFileFactory> mock_download_file_factory_; |
| 575 | 575 |
| 576 // Target detetermined callback. | 576 // Target detetermined callback. |
| 577 bool callback_called_; | 577 bool callback_called_; |
| 578 FilePath target_path_; | 578 base::FilePath target_path_; |
| 579 DownloadItem::TargetDisposition target_disposition_; | 579 DownloadItem::TargetDisposition target_disposition_; |
| 580 DownloadDangerType danger_type_; | 580 DownloadDangerType danger_type_; |
| 581 FilePath intermediate_path_; | 581 base::FilePath intermediate_path_; |
| 582 | 582 |
| 583 private: | 583 private: |
| 584 MessageLoopForUI message_loop_; | 584 MessageLoopForUI message_loop_; |
| 585 TestBrowserThread ui_thread_; | 585 TestBrowserThread ui_thread_; |
| 586 TestBrowserThread file_thread_; | 586 TestBrowserThread file_thread_; |
| 587 base::WeakPtr<MockDownloadItemFactory> mock_download_item_factory_; | 587 base::WeakPtr<MockDownloadItemFactory> mock_download_item_factory_; |
| 588 scoped_ptr<MockDownloadManagerDelegate> mock_download_manager_delegate_; | 588 scoped_ptr<MockDownloadManagerDelegate> mock_download_manager_delegate_; |
| 589 scoped_ptr<MockBrowserContext> mock_browser_context_; | 589 scoped_ptr<MockBrowserContext> mock_browser_context_; |
| 590 scoped_ptr<MockDownloadManagerObserver> observer_; | 590 scoped_ptr<MockDownloadManagerObserver> observer_; |
| 591 int next_download_id_; | 591 int next_download_id_; |
| 592 | 592 |
| 593 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); | 593 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); |
| 594 }; | 594 }; |
| 595 | 595 |
| 596 // Confirm the appropriate invocations occur when you start a download. | 596 // Confirm the appropriate invocations occur when you start a download. |
| 597 TEST_F(DownloadManagerTest, StartDownload) { | 597 TEST_F(DownloadManagerTest, StartDownload) { |
| 598 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); | 598 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); |
| 599 scoped_ptr<ByteStreamReader> stream; | 599 scoped_ptr<ByteStreamReader> stream; |
| 600 int32 local_id(5); // Random value | 600 int32 local_id(5); // Random value |
| 601 FilePath download_path(FILE_PATH_LITERAL("download/path")); | 601 base::FilePath download_path(FILE_PATH_LITERAL("download/path")); |
| 602 | 602 |
| 603 EXPECT_FALSE(download_manager_->GetDownload(local_id)); | 603 EXPECT_FALSE(download_manager_->GetDownload(local_id)); |
| 604 | 604 |
| 605 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) | 605 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
| 606 .WillOnce(Return()); | 606 .WillOnce(Return()); |
| 607 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId()) | 607 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId()) |
| 608 .WillOnce(Return(DownloadId(this, local_id))); | 608 .WillOnce(Return(DownloadId(this, local_id))); |
| 609 | 609 |
| 610 // Doing nothing will set the default download directory to null. | 610 // Doing nothing will set the default download directory to null. |
| 611 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetSaveDir(_, _, _, _)); | 611 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetSaveDir(_, _, _, _)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 632 .WillOnce(Return(true)); | 632 .WillOnce(Return(true)); |
| 633 DetermineDownloadTarget(&item); | 633 DetermineDownloadTarget(&item); |
| 634 } | 634 } |
| 635 | 635 |
| 636 // Confirm that calling DetermineDownloadTarget behaves properly if the delegate | 636 // Confirm that calling DetermineDownloadTarget behaves properly if the delegate |
| 637 // allows starting. This also tests OnDownloadTargetDetermined. | 637 // allows starting. This also tests OnDownloadTargetDetermined. |
| 638 TEST_F(DownloadManagerTest, DetermineDownloadTarget_False) { | 638 TEST_F(DownloadManagerTest, DetermineDownloadTarget_False) { |
| 639 // Put a mock we have a handle to on the download manager. | 639 // Put a mock we have a handle to on the download manager. |
| 640 MockDownloadItemImpl& item(AddItemToManager()); | 640 MockDownloadItemImpl& item(AddItemToManager()); |
| 641 | 641 |
| 642 FilePath path(FILE_PATH_LITERAL("random_filepath.txt")); | 642 base::FilePath path(FILE_PATH_LITERAL("random_filepath.txt")); |
| 643 EXPECT_CALL(GetMockDownloadManagerDelegate(), | 643 EXPECT_CALL(GetMockDownloadManagerDelegate(), |
| 644 DetermineDownloadTarget(&item, _)) | 644 DetermineDownloadTarget(&item, _)) |
| 645 .WillOnce(Return(false)); | 645 .WillOnce(Return(false)); |
| 646 EXPECT_CALL(item, GetForcedFilePath()) | 646 EXPECT_CALL(item, GetForcedFilePath()) |
| 647 .WillOnce(ReturnRef(path)); | 647 .WillOnce(ReturnRef(path)); |
| 648 | 648 |
| 649 // Confirm that the callback was called with the right values in this case. | 649 // Confirm that the callback was called with the right values in this case. |
| 650 callback_called_ = false; | 650 callback_called_ = false; |
| 651 DetermineDownloadTarget(&item); | 651 DetermineDownloadTarget(&item); |
| 652 EXPECT_TRUE(callback_called_); | 652 EXPECT_TRUE(callback_called_); |
| 653 EXPECT_EQ(path, target_path_); | 653 EXPECT_EQ(path, target_path_); |
| 654 EXPECT_EQ(DownloadItem::TARGET_DISPOSITION_OVERWRITE, target_disposition_); | 654 EXPECT_EQ(DownloadItem::TARGET_DISPOSITION_OVERWRITE, target_disposition_); |
| 655 EXPECT_EQ(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, danger_type_); | 655 EXPECT_EQ(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, danger_type_); |
| 656 EXPECT_EQ(path, intermediate_path_); | 656 EXPECT_EQ(path, intermediate_path_); |
| 657 } | 657 } |
| 658 | 658 |
| 659 } // namespace content | 659 } // namespace content |
| OLD | NEW |