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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 next_download_id_(0) { | 438 next_download_id_(0) { |
439 } | 439 } |
440 | 440 |
441 // We tear down everything in TearDown(). | 441 // We tear down everything in TearDown(). |
442 virtual ~DownloadManagerTest() {} | 442 virtual ~DownloadManagerTest() {} |
443 | 443 |
444 // Create a MockDownloadItemFactory and MockDownloadManagerDelegate, | 444 // Create a MockDownloadItemFactory and MockDownloadManagerDelegate, |
445 // then create a DownloadManager that points | 445 // then create a DownloadManager that points |
446 // at all of those. | 446 // at all of those. |
447 virtual void SetUp() { | 447 virtual void SetUp() { |
448 DCHECK(!download_manager_.get()); | 448 DCHECK(!download_manager_); |
449 | 449 |
450 mock_download_item_factory_ = (new MockDownloadItemFactory())->AsWeakPtr(); | 450 mock_download_item_factory_ = (new MockDownloadItemFactory())->AsWeakPtr(); |
451 mock_download_file_factory_ = (new MockDownloadFileFactory())->AsWeakPtr(); | 451 mock_download_file_factory_ = (new MockDownloadFileFactory())->AsWeakPtr(); |
452 mock_download_manager_delegate_.reset( | 452 mock_download_manager_delegate_.reset( |
453 new StrictMock<MockDownloadManagerDelegate>); | 453 new StrictMock<MockDownloadManagerDelegate>); |
454 EXPECT_CALL(*mock_download_manager_delegate_.get(), Shutdown()) | 454 EXPECT_CALL(*mock_download_manager_delegate_.get(), Shutdown()) |
455 .WillOnce(Return()); | 455 .WillOnce(Return()); |
456 mock_browser_context_.reset(new StrictMock<MockBrowserContext>); | 456 mock_browser_context_.reset(new StrictMock<MockBrowserContext>); |
457 EXPECT_CALL(*mock_browser_context_.get(), IsOffTheRecord()) | 457 EXPECT_CALL(*mock_browser_context_.get(), IsOffTheRecord()) |
458 .WillRepeatedly(Return(false)); | 458 .WillRepeatedly(Return(false)); |
459 | 459 |
460 download_manager_ = new DownloadManagerImpl( | 460 download_manager_.reset(new DownloadManagerImpl( |
461 NULL, mock_browser_context_.get()); | 461 NULL, mock_browser_context_.get())); |
462 download_manager_->SetDownloadItemFactoryForTesting( | 462 download_manager_->SetDownloadItemFactoryForTesting( |
463 scoped_ptr<DownloadItemFactory>( | 463 scoped_ptr<DownloadItemFactory>( |
464 mock_download_item_factory_.get()).Pass()); | 464 mock_download_item_factory_.get()).Pass()); |
465 download_manager_->SetDownloadFileFactoryForTesting( | 465 download_manager_->SetDownloadFileFactoryForTesting( |
466 scoped_ptr<DownloadFileFactory>( | 466 scoped_ptr<DownloadFileFactory>( |
467 mock_download_file_factory_.get()).Pass()); | 467 mock_download_file_factory_.get()).Pass()); |
468 observer_.reset(new MockDownloadManagerObserver()); | 468 observer_.reset(new MockDownloadManagerObserver()); |
469 download_manager_->AddObserver(observer_.get()); | 469 download_manager_->AddObserver(observer_.get()); |
470 download_manager_->SetDelegate(mock_download_manager_delegate_.get()); | 470 download_manager_->SetDelegate(mock_download_manager_delegate_.get()); |
471 } | 471 } |
472 | 472 |
473 virtual void TearDown() { | 473 virtual void TearDown() { |
474 while (MockDownloadItemImpl* | 474 while (MockDownloadItemImpl* |
475 item = mock_download_item_factory_->PopItem()) { | 475 item = mock_download_item_factory_->PopItem()) { |
476 EXPECT_CALL(*item, IsDangerous()) | 476 EXPECT_CALL(*item, IsDangerous()) |
477 .WillOnce(Return(false)); | 477 .WillOnce(Return(false)); |
478 EXPECT_CALL(*item, IsPartialDownload()) | 478 EXPECT_CALL(*item, IsPartialDownload()) |
479 .WillOnce(Return(false)); | 479 .WillOnce(Return(false)); |
480 } | 480 } |
481 EXPECT_CALL(GetMockObserver(), ManagerGoingDown(download_manager_.get())) | 481 EXPECT_CALL(GetMockObserver(), ManagerGoingDown(download_manager_.get())) |
482 .WillOnce(Return()); | 482 .WillOnce(Return()); |
483 | 483 |
484 download_manager_->Shutdown(); | 484 download_manager_->Shutdown(); |
485 download_manager_ = NULL; | 485 download_manager_.reset(); |
486 message_loop_.RunUntilIdle(); | 486 message_loop_.RunUntilIdle(); |
487 ASSERT_EQ(NULL, mock_download_item_factory_.get()); | 487 ASSERT_EQ(NULL, mock_download_item_factory_.get()); |
488 ASSERT_EQ(NULL, mock_download_file_factory_.get()); | 488 ASSERT_EQ(NULL, mock_download_file_factory_.get()); |
489 message_loop_.RunUntilIdle(); | 489 message_loop_.RunUntilIdle(); |
490 mock_download_manager_delegate_.reset(); | 490 mock_download_manager_delegate_.reset(); |
491 mock_browser_context_.reset(); | 491 mock_browser_context_.reset(); |
492 } | 492 } |
493 | 493 |
494 // Returns download id. | 494 // Returns download id. |
495 MockDownloadItemImpl& AddItemToManager() { | 495 MockDownloadItemImpl& AddItemToManager() { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 | 549 |
550 void DetermineDownloadTarget(DownloadItemImpl* item) { | 550 void DetermineDownloadTarget(DownloadItemImpl* item) { |
551 download_manager_->DetermineDownloadTarget( | 551 download_manager_->DetermineDownloadTarget( |
552 item, base::Bind( | 552 item, base::Bind( |
553 &DownloadManagerTest::DownloadTargetDeterminedCallback, | 553 &DownloadManagerTest::DownloadTargetDeterminedCallback, |
554 base::Unretained(this))); | 554 base::Unretained(this))); |
555 } | 555 } |
556 | 556 |
557 protected: | 557 protected: |
558 // Key test variable; we'll keep it available to sub-classes. | 558 // Key test variable; we'll keep it available to sub-classes. |
559 scoped_refptr<DownloadManagerImpl> download_manager_; | 559 scoped_ptr<DownloadManagerImpl> download_manager_; |
560 base::WeakPtr<MockDownloadFileFactory> mock_download_file_factory_; | 560 base::WeakPtr<MockDownloadFileFactory> mock_download_file_factory_; |
561 | 561 |
562 // Target detetermined callback. | 562 // Target detetermined callback. |
563 bool callback_called_; | 563 bool callback_called_; |
564 base::FilePath target_path_; | 564 base::FilePath target_path_; |
565 DownloadItem::TargetDisposition target_disposition_; | 565 DownloadItem::TargetDisposition target_disposition_; |
566 DownloadDangerType danger_type_; | 566 DownloadDangerType danger_type_; |
567 base::FilePath intermediate_path_; | 567 base::FilePath intermediate_path_; |
568 | 568 |
569 private: | 569 private: |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 .WillOnce(Return()); | 681 .WillOnce(Return()); |
682 EXPECT_CALL(GetMockDownloadItem(3), Remove()) | 682 EXPECT_CALL(GetMockDownloadItem(3), Remove()) |
683 .Times(0); | 683 .Times(0); |
684 | 684 |
685 download_manager_->RemoveAllDownloads(); | 685 download_manager_->RemoveAllDownloads(); |
686 // Because we're mocking the download item, the Remove call doesn't | 686 // Because we're mocking the download item, the Remove call doesn't |
687 // result in them being removed from the DownloadManager list. | 687 // result in them being removed from the DownloadManager list. |
688 } | 688 } |
689 | 689 |
690 } // namespace content | 690 } // namespace content |
OLD | NEW |