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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 base::Time(), | 95 base::Time(), |
96 std::string(), | 96 std::string(), |
97 std::string(), | 97 std::string(), |
98 0, | 98 0, |
99 0, | 99 0, |
100 std::string(), | 100 std::string(), |
101 DownloadItem::COMPLETE, | 101 DownloadItem::COMPLETE, |
102 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 102 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
103 DOWNLOAD_INTERRUPT_REASON_NONE, | 103 DOWNLOAD_INTERRUPT_REASON_NONE, |
104 false, | 104 false, |
105 net::BoundNetLog()) {} | 105 net::NetLogWithSource()) {} |
106 virtual ~MockDownloadItemImpl() {} | 106 virtual ~MockDownloadItemImpl() {} |
107 | 107 |
108 MOCK_METHOD4(OnDownloadTargetDetermined, | 108 MOCK_METHOD4(OnDownloadTargetDetermined, |
109 void(const base::FilePath&, TargetDisposition, | 109 void(const base::FilePath&, TargetDisposition, |
110 DownloadDangerType, const base::FilePath&)); | 110 DownloadDangerType, const base::FilePath&)); |
111 MOCK_METHOD1(AddObserver, void(DownloadItem::Observer*)); | 111 MOCK_METHOD1(AddObserver, void(DownloadItem::Observer*)); |
112 MOCK_METHOD1(RemoveObserver, void(DownloadItem::Observer*)); | 112 MOCK_METHOD1(RemoveObserver, void(DownloadItem::Observer*)); |
113 MOCK_METHOD0(UpdateObservers, void()); | 113 MOCK_METHOD0(UpdateObservers, void()); |
114 MOCK_METHOD0(CanShowInFolder, bool()); | 114 MOCK_METHOD0(CanShowInFolder, bool()); |
115 MOCK_METHOD0(CanOpenDownload, bool()); | 115 MOCK_METHOD0(CanOpenDownload, bool()); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 const base::Time& end_time, | 261 const base::Time& end_time, |
262 const std::string& etag, | 262 const std::string& etag, |
263 const std::string& last_modofied, | 263 const std::string& last_modofied, |
264 int64_t received_bytes, | 264 int64_t received_bytes, |
265 int64_t total_bytes, | 265 int64_t total_bytes, |
266 const std::string& hash, | 266 const std::string& hash, |
267 DownloadItem::DownloadState state, | 267 DownloadItem::DownloadState state, |
268 DownloadDangerType danger_type, | 268 DownloadDangerType danger_type, |
269 DownloadInterruptReason interrupt_reason, | 269 DownloadInterruptReason interrupt_reason, |
270 bool opened, | 270 bool opened, |
271 const net::BoundNetLog& bound_net_log) override; | 271 const net::NetLogWithSource& net_log) override; |
272 DownloadItemImpl* CreateActiveItem( | 272 DownloadItemImpl* CreateActiveItem( |
273 DownloadItemImplDelegate* delegate, | 273 DownloadItemImplDelegate* delegate, |
274 uint32_t download_id, | 274 uint32_t download_id, |
275 const DownloadCreateInfo& info, | 275 const DownloadCreateInfo& info, |
276 const net::BoundNetLog& bound_net_log) override; | 276 const net::NetLogWithSource& net_log) override; |
277 DownloadItemImpl* CreateSavePageItem( | 277 DownloadItemImpl* CreateSavePageItem( |
278 DownloadItemImplDelegate* delegate, | 278 DownloadItemImplDelegate* delegate, |
279 uint32_t download_id, | 279 uint32_t download_id, |
280 const base::FilePath& path, | 280 const base::FilePath& path, |
281 const GURL& url, | 281 const GURL& url, |
282 const std::string& mime_type, | 282 const std::string& mime_type, |
283 std::unique_ptr<DownloadRequestHandleInterface> request_handle, | 283 std::unique_ptr<DownloadRequestHandleInterface> request_handle, |
284 const net::BoundNetLog& bound_net_log) override; | 284 const net::NetLogWithSource& net_log) override; |
285 | 285 |
286 private: | 286 private: |
287 std::map<uint32_t, MockDownloadItemImpl*> items_; | 287 std::map<uint32_t, MockDownloadItemImpl*> items_; |
288 DownloadItemImplDelegate item_delegate_; | 288 DownloadItemImplDelegate item_delegate_; |
289 | 289 |
290 DISALLOW_COPY_AND_ASSIGN(MockDownloadItemFactory); | 290 DISALLOW_COPY_AND_ASSIGN(MockDownloadItemFactory); |
291 }; | 291 }; |
292 | 292 |
293 MockDownloadItemFactory::MockDownloadItemFactory() {} | 293 MockDownloadItemFactory::MockDownloadItemFactory() {} |
294 | 294 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 const base::Time& end_time, | 333 const base::Time& end_time, |
334 const std::string& etag, | 334 const std::string& etag, |
335 const std::string& last_modified, | 335 const std::string& last_modified, |
336 int64_t received_bytes, | 336 int64_t received_bytes, |
337 int64_t total_bytes, | 337 int64_t total_bytes, |
338 const std::string& hash, | 338 const std::string& hash, |
339 DownloadItem::DownloadState state, | 339 DownloadItem::DownloadState state, |
340 DownloadDangerType danger_type, | 340 DownloadDangerType danger_type, |
341 DownloadInterruptReason interrupt_reason, | 341 DownloadInterruptReason interrupt_reason, |
342 bool opened, | 342 bool opened, |
343 const net::BoundNetLog& bound_net_log) { | 343 const net::NetLogWithSource& net_log) { |
344 DCHECK(items_.find(download_id) == items_.end()); | 344 DCHECK(items_.find(download_id) == items_.end()); |
345 MockDownloadItemImpl* result = | 345 MockDownloadItemImpl* result = |
346 new StrictMock<MockDownloadItemImpl>(&item_delegate_); | 346 new StrictMock<MockDownloadItemImpl>(&item_delegate_); |
347 EXPECT_CALL(*result, GetId()) | 347 EXPECT_CALL(*result, GetId()) |
348 .WillRepeatedly(Return(download_id)); | 348 .WillRepeatedly(Return(download_id)); |
349 EXPECT_CALL(*result, GetGuid()).WillRepeatedly(ReturnRefOfCopy(guid)); | 349 EXPECT_CALL(*result, GetGuid()).WillRepeatedly(ReturnRefOfCopy(guid)); |
350 items_[download_id] = result; | 350 items_[download_id] = result; |
351 return result; | 351 return result; |
352 } | 352 } |
353 | 353 |
354 DownloadItemImpl* MockDownloadItemFactory::CreateActiveItem( | 354 DownloadItemImpl* MockDownloadItemFactory::CreateActiveItem( |
355 DownloadItemImplDelegate* delegate, | 355 DownloadItemImplDelegate* delegate, |
356 uint32_t download_id, | 356 uint32_t download_id, |
357 const DownloadCreateInfo& info, | 357 const DownloadCreateInfo& info, |
358 const net::BoundNetLog& bound_net_log) { | 358 const net::NetLogWithSource& net_log) { |
359 DCHECK(items_.find(download_id) == items_.end()); | 359 DCHECK(items_.find(download_id) == items_.end()); |
360 | 360 |
361 MockDownloadItemImpl* result = | 361 MockDownloadItemImpl* result = |
362 new StrictMock<MockDownloadItemImpl>(&item_delegate_); | 362 new StrictMock<MockDownloadItemImpl>(&item_delegate_); |
363 EXPECT_CALL(*result, GetId()) | 363 EXPECT_CALL(*result, GetId()) |
364 .WillRepeatedly(Return(download_id)); | 364 .WillRepeatedly(Return(download_id)); |
365 EXPECT_CALL(*result, GetGuid()) | 365 EXPECT_CALL(*result, GetGuid()) |
366 .WillRepeatedly( | 366 .WillRepeatedly( |
367 ReturnRefOfCopy(base::ToUpperASCII(base::GenerateGUID()))); | 367 ReturnRefOfCopy(base::ToUpperASCII(base::GenerateGUID()))); |
368 items_[download_id] = result; | 368 items_[download_id] = result; |
369 | 369 |
370 // Active items are created and then immediately are called to start | 370 // Active items are created and then immediately are called to start |
371 // the download. | 371 // the download. |
372 EXPECT_CALL(*result, MockStart(_, _)); | 372 EXPECT_CALL(*result, MockStart(_, _)); |
373 | 373 |
374 return result; | 374 return result; |
375 } | 375 } |
376 | 376 |
377 DownloadItemImpl* MockDownloadItemFactory::CreateSavePageItem( | 377 DownloadItemImpl* MockDownloadItemFactory::CreateSavePageItem( |
378 DownloadItemImplDelegate* delegate, | 378 DownloadItemImplDelegate* delegate, |
379 uint32_t download_id, | 379 uint32_t download_id, |
380 const base::FilePath& path, | 380 const base::FilePath& path, |
381 const GURL& url, | 381 const GURL& url, |
382 const std::string& mime_type, | 382 const std::string& mime_type, |
383 std::unique_ptr<DownloadRequestHandleInterface> request_handle, | 383 std::unique_ptr<DownloadRequestHandleInterface> request_handle, |
384 const net::BoundNetLog& bound_net_log) { | 384 const net::NetLogWithSource& net_log) { |
385 DCHECK(items_.find(download_id) == items_.end()); | 385 DCHECK(items_.find(download_id) == items_.end()); |
386 | 386 |
387 MockDownloadItemImpl* result = | 387 MockDownloadItemImpl* result = |
388 new StrictMock<MockDownloadItemImpl>(&item_delegate_); | 388 new StrictMock<MockDownloadItemImpl>(&item_delegate_); |
389 EXPECT_CALL(*result, GetId()) | 389 EXPECT_CALL(*result, GetId()) |
390 .WillRepeatedly(Return(download_id)); | 390 .WillRepeatedly(Return(download_id)); |
391 items_[download_id] = result; | 391 items_[download_id] = result; |
392 | 392 |
393 return result; | 393 return result; |
394 } | 394 } |
395 | 395 |
396 class MockDownloadFileFactory | 396 class MockDownloadFileFactory |
397 : public DownloadFileFactory, | 397 : public DownloadFileFactory, |
398 public base::SupportsWeakPtr<MockDownloadFileFactory> { | 398 public base::SupportsWeakPtr<MockDownloadFileFactory> { |
399 public: | 399 public: |
400 MockDownloadFileFactory() {} | 400 MockDownloadFileFactory() {} |
401 virtual ~MockDownloadFileFactory() {} | 401 virtual ~MockDownloadFileFactory() {} |
402 | 402 |
403 // Overridden method from DownloadFileFactory | 403 // Overridden method from DownloadFileFactory |
404 MOCK_METHOD2(MockCreateFile, | 404 MOCK_METHOD2(MockCreateFile, |
405 MockDownloadFile*(const DownloadSaveInfo&, ByteStreamReader*)); | 405 MockDownloadFile*(const DownloadSaveInfo&, ByteStreamReader*)); |
406 | 406 |
407 virtual DownloadFile* CreateFile( | 407 virtual DownloadFile* CreateFile( |
408 std::unique_ptr<DownloadSaveInfo> save_info, | 408 std::unique_ptr<DownloadSaveInfo> save_info, |
409 const base::FilePath& default_download_directory, | 409 const base::FilePath& default_download_directory, |
410 std::unique_ptr<ByteStreamReader> byte_stream, | 410 std::unique_ptr<ByteStreamReader> byte_stream, |
411 const net::BoundNetLog& bound_net_log, | 411 const net::NetLogWithSource& net_log, |
412 base::WeakPtr<DownloadDestinationObserver> observer) override { | 412 base::WeakPtr<DownloadDestinationObserver> observer) override { |
413 return MockCreateFile(*save_info, byte_stream.get()); | 413 return MockCreateFile(*save_info, byte_stream.get()); |
414 } | 414 } |
415 }; | 415 }; |
416 | 416 |
417 class MockBrowserContext : public BrowserContext { | 417 class MockBrowserContext : public BrowserContext { |
418 public: | 418 public: |
419 MockBrowserContext() { | 419 MockBrowserContext() { |
420 content::BrowserContext::Initialize(this, base::FilePath()); | 420 content::BrowserContext::Initialize(this, base::FilePath()); |
421 } | 421 } |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 EXPECT_CALL(GetMockDownloadItem(1), Remove()).Times(0); | 786 EXPECT_CALL(GetMockDownloadItem(1), Remove()).Times(0); |
787 | 787 |
788 base::Callback<bool(const GURL&)> url_filter = | 788 base::Callback<bool(const GURL&)> url_filter = |
789 GetSingleURLFilter(download_urls_[0]); | 789 GetSingleURLFilter(download_urls_[0]); |
790 int remove_count = download_manager_->RemoveDownloadsByURLAndTime( | 790 int remove_count = download_manager_->RemoveDownloadsByURLAndTime( |
791 url_filter, base::Time(), base::Time::Max()); | 791 url_filter, base::Time(), base::Time::Max()); |
792 EXPECT_EQ(remove_count, 1); | 792 EXPECT_EQ(remove_count, 1); |
793 } | 793 } |
794 | 794 |
795 } // namespace content | 795 } // namespace content |
OLD | NEW |