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/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 using ::testing::StrictMock; | 47 using ::testing::StrictMock; |
48 using ::testing::_; | 48 using ::testing::_; |
49 | 49 |
50 ACTION_TEMPLATE(RunCallback, | 50 ACTION_TEMPLATE(RunCallback, |
51 HAS_1_TEMPLATE_PARAMS(int, k), | 51 HAS_1_TEMPLATE_PARAMS(int, k), |
52 AND_1_VALUE_PARAMS(p0)) { | 52 AND_1_VALUE_PARAMS(p0)) { |
53 return ::std::tr1::get<k>(args).Run(p0); | 53 return ::std::tr1::get<k>(args).Run(p0); |
54 } | 54 } |
55 | 55 |
56 namespace content { | 56 namespace content { |
| 57 template <typename StatusType> |
57 class ByteStreamReader; | 58 class ByteStreamReader; |
58 | 59 |
59 namespace { | 60 namespace { |
60 | 61 |
61 // Matches a DownloadCreateInfo* that points to the same object as |info| and | 62 // Matches a DownloadCreateInfo* that points to the same object as |info| and |
62 // has a |default_download_directory| that matches |download_directory|. | 63 // has a |default_download_directory| that matches |download_directory|. |
63 MATCHER_P2(DownloadCreateInfoWithDefaultPath, info, download_directory, "") { | 64 MATCHER_P2(DownloadCreateInfoWithDefaultPath, info, download_directory, "") { |
64 return arg == info && | 65 return arg == info && |
65 arg->default_download_directory == download_directory; | 66 arg->default_download_directory == download_directory; |
66 } | 67 } |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 public base::SupportsWeakPtr<MockDownloadFileFactory> { | 355 public base::SupportsWeakPtr<MockDownloadFileFactory> { |
355 public: | 356 public: |
356 MockDownloadFileFactory() {} | 357 MockDownloadFileFactory() {} |
357 virtual ~MockDownloadFileFactory() {} | 358 virtual ~MockDownloadFileFactory() {} |
358 | 359 |
359 // Overridden method from DownloadFileFactory | 360 // Overridden method from DownloadFileFactory |
360 MOCK_METHOD8(MockCreateFile, DownloadFile*( | 361 MOCK_METHOD8(MockCreateFile, DownloadFile*( |
361 const DownloadSaveInfo&, | 362 const DownloadSaveInfo&, |
362 const base::FilePath&, | 363 const base::FilePath&, |
363 const GURL&, const GURL&, bool, | 364 const GURL&, const GURL&, bool, |
364 ByteStreamReader*, | 365 ByteStreamReader<DownloadInterruptReason>*, |
365 const net::BoundNetLog&, | 366 const net::BoundNetLog&, |
366 base::WeakPtr<DownloadDestinationObserver>)); | 367 base::WeakPtr<DownloadDestinationObserver>)); |
367 | 368 |
368 virtual DownloadFile* CreateFile( | 369 virtual DownloadFile* CreateFile( |
369 scoped_ptr<DownloadSaveInfo> save_info, | 370 scoped_ptr<DownloadSaveInfo> save_info, |
370 const base::FilePath& default_download_directory, | 371 const base::FilePath& default_download_directory, |
371 const GURL& url, | 372 const GURL& url, |
372 const GURL& referrer_url, | 373 const GURL& referrer_url, |
373 bool calculate_hash, | 374 bool calculate_hash, |
374 scoped_ptr<ByteStreamReader> stream, | 375 scoped_ptr<ByteStreamReader<DownloadInterruptReason> > stream, |
375 const net::BoundNetLog& bound_net_log, | 376 const net::BoundNetLog& bound_net_log, |
376 base::WeakPtr<DownloadDestinationObserver> observer) { | 377 base::WeakPtr<DownloadDestinationObserver> observer) { |
377 return MockCreateFile(*save_info.get(), default_download_directory, url, | 378 return MockCreateFile(*save_info.get(), default_download_directory, url, |
378 referrer_url, calculate_hash, | 379 referrer_url, calculate_hash, |
379 stream.get(), bound_net_log, observer); | 380 stream.get(), bound_net_log, observer); |
380 } | 381 } |
381 }; | 382 }; |
382 | 383 |
383 class MockBrowserContext : public BrowserContext { | 384 class MockBrowserContext : public BrowserContext { |
384 public: | 385 public: |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 scoped_ptr<MockBrowserContext> mock_browser_context_; | 566 scoped_ptr<MockBrowserContext> mock_browser_context_; |
566 scoped_ptr<MockDownloadManagerObserver> observer_; | 567 scoped_ptr<MockDownloadManagerObserver> observer_; |
567 uint32 next_download_id_; | 568 uint32 next_download_id_; |
568 | 569 |
569 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); | 570 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); |
570 }; | 571 }; |
571 | 572 |
572 // Confirm the appropriate invocations occur when you start a download. | 573 // Confirm the appropriate invocations occur when you start a download. |
573 TEST_F(DownloadManagerTest, StartDownload) { | 574 TEST_F(DownloadManagerTest, StartDownload) { |
574 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); | 575 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); |
575 scoped_ptr<ByteStreamReader> stream; | 576 scoped_ptr<ByteStreamReader<DownloadInterruptReason> > stream; |
576 uint32 local_id(5); // Random value | 577 uint32 local_id(5); // Random value |
577 base::FilePath download_path(FILE_PATH_LITERAL("download/path")); | 578 base::FilePath download_path(FILE_PATH_LITERAL("download/path")); |
578 | 579 |
579 EXPECT_FALSE(download_manager_->GetDownload(local_id)); | 580 EXPECT_FALSE(download_manager_->GetDownload(local_id)); |
580 | 581 |
581 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) | 582 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
582 .WillOnce(Return()); | 583 .WillOnce(Return()); |
583 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId(_)) | 584 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId(_)) |
584 .WillOnce(RunCallback<0>(local_id)); | 585 .WillOnce(RunCallback<0>(local_id)); |
585 | 586 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 .WillOnce(Return()); | 663 .WillOnce(Return()); |
663 EXPECT_CALL(GetMockDownloadItem(3), Remove()) | 664 EXPECT_CALL(GetMockDownloadItem(3), Remove()) |
664 .Times(0); | 665 .Times(0); |
665 | 666 |
666 download_manager_->RemoveAllDownloads(); | 667 download_manager_->RemoveAllDownloads(); |
667 // Because we're mocking the download item, the Remove call doesn't | 668 // Because we're mocking the download item, the Remove call doesn't |
668 // result in them being removed from the DownloadManager list. | 669 // result in them being removed from the DownloadManager list. |
669 } | 670 } |
670 | 671 |
671 } // namespace content | 672 } // namespace content |
OLD | NEW |