Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Side by Side Diff: content/browser/download/download_manager_impl_unittest.cc

Issue 15701007: BrowserContext should simply own DownloadManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 next_download_id_(0) { 437 next_download_id_(0) {
438 } 438 }
439 439
440 // We tear down everything in TearDown(). 440 // We tear down everything in TearDown().
441 virtual ~DownloadManagerTest() {} 441 virtual ~DownloadManagerTest() {}
442 442
443 // Create a MockDownloadItemFactory and MockDownloadManagerDelegate, 443 // Create a MockDownloadItemFactory and MockDownloadManagerDelegate,
444 // then create a DownloadManager that points 444 // then create a DownloadManager that points
445 // at all of those. 445 // at all of those.
446 virtual void SetUp() { 446 virtual void SetUp() {
447 DCHECK(!download_manager_.get()); 447 DCHECK(!download_manager_);
448 448
449 mock_download_item_factory_ = (new MockDownloadItemFactory())->AsWeakPtr(); 449 mock_download_item_factory_ = (new MockDownloadItemFactory())->AsWeakPtr();
450 mock_download_file_factory_ = (new MockDownloadFileFactory())->AsWeakPtr(); 450 mock_download_file_factory_ = (new MockDownloadFileFactory())->AsWeakPtr();
451 mock_download_manager_delegate_.reset( 451 mock_download_manager_delegate_.reset(
452 new StrictMock<MockDownloadManagerDelegate>); 452 new StrictMock<MockDownloadManagerDelegate>);
453 EXPECT_CALL(*mock_download_manager_delegate_.get(), Shutdown()) 453 EXPECT_CALL(*mock_download_manager_delegate_.get(), Shutdown())
454 .WillOnce(Return()); 454 .WillOnce(Return());
455 mock_browser_context_.reset(new StrictMock<MockBrowserContext>); 455 mock_browser_context_.reset(new StrictMock<MockBrowserContext>);
456 EXPECT_CALL(*mock_browser_context_.get(), IsOffTheRecord()) 456 EXPECT_CALL(*mock_browser_context_.get(), IsOffTheRecord())
457 .WillRepeatedly(Return(false)); 457 .WillRepeatedly(Return(false));
458 458
459 download_manager_ = new DownloadManagerImpl( 459 download_manager_.reset(new DownloadManagerImpl(
460 NULL, mock_browser_context_.get()); 460 NULL, mock_browser_context_.get()));
461 download_manager_->SetDownloadItemFactoryForTesting( 461 download_manager_->SetDownloadItemFactoryForTesting(
462 scoped_ptr<DownloadItemFactory>( 462 scoped_ptr<DownloadItemFactory>(
463 mock_download_item_factory_.get()).Pass()); 463 mock_download_item_factory_.get()).Pass());
464 download_manager_->SetDownloadFileFactoryForTesting( 464 download_manager_->SetDownloadFileFactoryForTesting(
465 scoped_ptr<DownloadFileFactory>( 465 scoped_ptr<DownloadFileFactory>(
466 mock_download_file_factory_.get()).Pass()); 466 mock_download_file_factory_.get()).Pass());
467 observer_.reset(new MockDownloadManagerObserver()); 467 observer_.reset(new MockDownloadManagerObserver());
468 download_manager_->AddObserver(observer_.get()); 468 download_manager_->AddObserver(observer_.get());
469 download_manager_->SetDelegate(mock_download_manager_delegate_.get()); 469 download_manager_->SetDelegate(mock_download_manager_delegate_.get());
470 } 470 }
471 471
472 virtual void TearDown() { 472 virtual void TearDown() {
473 while (MockDownloadItemImpl* 473 while (MockDownloadItemImpl*
474 item = mock_download_item_factory_->PopItem()) { 474 item = mock_download_item_factory_->PopItem()) {
475 EXPECT_CALL(*item, IsDangerous()) 475 EXPECT_CALL(*item, IsDangerous())
476 .WillOnce(Return(false)); 476 .WillOnce(Return(false));
477 EXPECT_CALL(*item, IsPartialDownload()) 477 EXPECT_CALL(*item, IsPartialDownload())
478 .WillOnce(Return(false)); 478 .WillOnce(Return(false));
479 } 479 }
480 EXPECT_CALL(GetMockObserver(), ManagerGoingDown(download_manager_.get())) 480 EXPECT_CALL(GetMockObserver(), ManagerGoingDown(download_manager_.get()))
481 .WillOnce(Return()); 481 .WillOnce(Return());
482 482
483 download_manager_->Shutdown(); 483 download_manager_->Shutdown();
484 download_manager_ = NULL; 484 download_manager_.reset();
485 message_loop_.RunUntilIdle(); 485 message_loop_.RunUntilIdle();
486 ASSERT_EQ(NULL, mock_download_item_factory_.get()); 486 ASSERT_EQ(NULL, mock_download_item_factory_.get());
487 ASSERT_EQ(NULL, mock_download_file_factory_.get()); 487 ASSERT_EQ(NULL, mock_download_file_factory_.get());
488 message_loop_.RunUntilIdle(); 488 message_loop_.RunUntilIdle();
489 mock_download_manager_delegate_.reset(); 489 mock_download_manager_delegate_.reset();
490 mock_browser_context_.reset(); 490 mock_browser_context_.reset();
491 } 491 }
492 492
493 // Returns download id. 493 // Returns download id.
494 MockDownloadItemImpl& AddItemToManager() { 494 MockDownloadItemImpl& AddItemToManager() {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(
552 &DownloadManagerTest::DownloadTargetDeterminedCallback, 552 &DownloadManagerTest::DownloadTargetDeterminedCallback,
553 base::Unretained(this))); 553 base::Unretained(this)));
554 } 554 }
555 555
556 protected: 556 protected:
557 // Key test variable; we'll keep it available to sub-classes. 557 // Key test variable; we'll keep it available to sub-classes.
558 scoped_refptr<DownloadManagerImpl> download_manager_; 558 scoped_ptr<DownloadManagerImpl> download_manager_;
559 base::WeakPtr<MockDownloadFileFactory> mock_download_file_factory_; 559 base::WeakPtr<MockDownloadFileFactory> mock_download_file_factory_;
560 560
561 // Target detetermined callback. 561 // Target detetermined callback.
562 bool callback_called_; 562 bool callback_called_;
563 base::FilePath target_path_; 563 base::FilePath target_path_;
564 DownloadItem::TargetDisposition target_disposition_; 564 DownloadItem::TargetDisposition target_disposition_;
565 DownloadDangerType danger_type_; 565 DownloadDangerType danger_type_;
566 base::FilePath intermediate_path_; 566 base::FilePath intermediate_path_;
567 567
568 private: 568 private:
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 .WillOnce(Return()); 680 .WillOnce(Return());
681 EXPECT_CALL(GetMockDownloadItem(3), Remove()) 681 EXPECT_CALL(GetMockDownloadItem(3), Remove())
682 .Times(0); 682 .Times(0);
683 683
684 download_manager_->RemoveAllDownloads(); 684 download_manager_->RemoveAllDownloads();
685 // Because we're mocking the download item, the Remove call doesn't 685 // Because we're mocking the download item, the Remove call doesn't
686 // result in them being removed from the DownloadManager list. 686 // result in them being removed from the DownloadManager list.
687 } 687 }
688 688
689 } // namespace content 689 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698