| 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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 | 563 |
| 564 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); | 564 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); |
| 565 }; | 565 }; |
| 566 | 566 |
| 567 // Confirm the appropriate invocations occur when you start a download. | 567 // Confirm the appropriate invocations occur when you start a download. |
| 568 TEST_F(DownloadManagerTest, StartDownload) { | 568 TEST_F(DownloadManagerTest, StartDownload) { |
| 569 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); | 569 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); |
| 570 scoped_ptr<content::ByteStreamReader> stream; | 570 scoped_ptr<content::ByteStreamReader> stream; |
| 571 int32 local_id(5); // Random value | 571 int32 local_id(5); // Random value |
| 572 | 572 |
| 573 EXPECT_FALSE(download_manager_->GetActiveDownloadItem(local_id)); | 573 EXPECT_FALSE(download_manager_->GetDownload(local_id)); |
| 574 | 574 |
| 575 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) | 575 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
| 576 .WillOnce(Return()); | 576 .WillOnce(Return()); |
| 577 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId()) | 577 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId()) |
| 578 .WillOnce(Return(content::DownloadId(this, local_id))); | 578 .WillOnce(Return(content::DownloadId(this, local_id))); |
| 579 EXPECT_CALL(GetMockDownloadManagerDelegate(), GenerateFileHash()) | 579 EXPECT_CALL(GetMockDownloadManagerDelegate(), GenerateFileHash()) |
| 580 .WillOnce(Return(true)); | 580 .WillOnce(Return(true)); |
| 581 EXPECT_CALL(GetMockDownloadFileManager(), MockCreateDownloadFile( | 581 EXPECT_CALL(GetMockDownloadFileManager(), MockCreateDownloadFile( |
| 582 info.get(), static_cast<content::ByteStreamReader*>(NULL), | 582 info.get(), static_cast<content::ByteStreamReader*>(NULL), |
| 583 download_manager_.get(), true, _, _)); | 583 download_manager_.get(), true, _, _)); |
| 584 | 584 |
| 585 download_manager_->StartDownload(info.Pass(), stream.Pass()); | 585 download_manager_->StartDownload(info.Pass(), stream.Pass()); |
| 586 EXPECT_TRUE(download_manager_->GetActiveDownloadItem(local_id)); | 586 EXPECT_TRUE(download_manager_->GetDownload(local_id)); |
| 587 } | 587 } |
| 588 | 588 |
| 589 // Do the results of an OnDownloadInterrupted get passed through properly | 589 // Do the results of an OnDownloadInterrupted get passed through properly |
| 590 // to the DownloadItem? | 590 // to the DownloadItem? |
| 591 TEST_F(DownloadManagerTest, OnDownloadInterrupted) { | 591 TEST_F(DownloadManagerTest, OnDownloadInterrupted) { |
| 592 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) | 592 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
| 593 .WillOnce(Return()); | 593 .WillOnce(Return()); |
| 594 // Put a mock we have a handle to on the download manager. | 594 // Put a mock we have a handle to on the download manager. |
| 595 MockDownloadItemImpl& item(AddItemToManager()); | 595 MockDownloadItemImpl& item(AddItemToManager()); |
| 596 int download_id = item.GetId(); | 596 int download_id = item.GetId(); |
| 597 | 597 |
| 598 content::DownloadInterruptReason reason( | 598 content::DownloadInterruptReason reason( |
| 599 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); | 599 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); |
| 600 | 600 |
| 601 EXPECT_CALL(item, Interrupt(reason)); | 601 EXPECT_CALL(item, Interrupt(reason)); |
| 602 download_manager_->OnDownloadInterrupted(download_id, reason); | 602 download_manager_->OnDownloadInterrupted(download_id, reason); |
| 603 EXPECT_EQ(&item, download_manager_->GetActiveDownloadItem(download_id)); | 603 EXPECT_EQ(&item, download_manager_->GetDownload(download_id)); |
| 604 } | 604 } |
| 605 | |
| 606 // Does DownloadStopped remove Download from appropriate queues? | |
| 607 // This test tests non-persisted downloads. | |
| 608 TEST_F(DownloadManagerTest, OnDownloadStopped_NonPersisted) { | |
| 609 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) | |
| 610 .WillOnce(Return()); | |
| 611 // Put a mock we have a handle to on the download manager. | |
| 612 MockDownloadItemImpl& item(AddItemToManager()); | |
| 613 | |
| 614 EXPECT_CALL(item, IsPersisted()) | |
| 615 .WillRepeatedly(Return(false)); | |
| 616 EXPECT_CALL(item, GetState()) | |
| 617 .WillRepeatedly(Return(DownloadItem::CANCELLED)); | |
| 618 EXPECT_CALL(item, GetDbHandle()) | |
| 619 .WillRepeatedly(Return(DownloadItem::kUninitializedHandle)); | |
| 620 | |
| 621 EXPECT_CALL(item, OffThreadCancel()); | |
| 622 DownloadStopped(&item); | |
| 623 // TODO(rdsmith): Confirm that the download item is no longer on the | |
| 624 // active list by calling download_manager_->GetActiveDownloadItem(id). | |
| 625 // Currently, the item is left on the active list for rendez-vous with | |
| 626 // the history system :-{. | |
| 627 } | |
| 628 | |
| 629 // Does DownloadStopped remove Download from appropriate queues? | |
| 630 // This test tests persisted downloads. | |
| 631 TEST_F(DownloadManagerTest, OnDownloadStopped_Persisted) { | |
| 632 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) | |
| 633 .WillOnce(Return()); | |
| 634 // Put a mock we have a handle to on the download manager. | |
| 635 MockDownloadItemImpl& item(AddItemToManager()); | |
| 636 int download_id = item.GetId(); | |
| 637 int64 db_handle = 0x7; | |
| 638 EXPECT_CALL(GetMockObserver(), ModelChanged(download_manager_.get())) | |
| 639 .WillOnce(Return()); | |
| 640 AddItemToHistory(item, db_handle); | |
| 641 | |
| 642 EXPECT_CALL(item, IsPersisted()) | |
| 643 .WillRepeatedly(Return(true)); | |
| 644 EXPECT_CALL(GetMockDownloadManagerDelegate(), | |
| 645 UpdateItemInPersistentStore(&item)); | |
| 646 EXPECT_CALL(item, GetState()) | |
| 647 .WillRepeatedly(Return(DownloadItem::CANCELLED)); | |
| 648 EXPECT_CALL(item, GetDbHandle()) | |
| 649 .WillRepeatedly(Return(db_handle)); | |
| 650 | |
| 651 EXPECT_CALL(item, OffThreadCancel()); | |
| 652 DownloadStopped(&item); | |
| 653 EXPECT_EQ(NULL, download_manager_->GetActiveDownloadItem(download_id)); | |
| 654 } | |
| OLD | NEW |