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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/stl_util.h" | 6 #include "base/stl_util.h" |
7 #include "base/threading/thread.h" | 7 #include "base/threading/thread.h" |
8 #include "content/browser/download/byte_stream.h" | 8 #include "content/browser/download/byte_stream.h" |
9 #include "content/browser/download/download_create_info.h" | 9 #include "content/browser/download/download_create_info.h" |
10 #include "content/browser/download/download_file_manager.h" | 10 #include "content/browser/download/download_file_manager.h" |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 AllOf(item, | 544 AllOf(item, |
545 Property(&DownloadItem::GetFullPath, final_path), | 545 Property(&DownloadItem::GetFullPath, final_path), |
546 Property(&DownloadItem::GetTargetFilePath, | 546 Property(&DownloadItem::GetTargetFilePath, |
547 final_path)))); | 547 final_path)))); |
548 item->OnDownloadCompleting(file_manager.get()); | 548 item->OnDownloadCompleting(file_manager.get()); |
549 RunAllPendingInMessageLoops(); | 549 RunAllPendingInMessageLoops(); |
550 ::testing::Mock::VerifyAndClearExpectations(file_manager.get()); | 550 ::testing::Mock::VerifyAndClearExpectations(file_manager.get()); |
551 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); | 551 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); |
552 } | 552 } |
553 | 553 |
| 554 TEST_F(DownloadItemTest, Interrupted) { |
| 555 DownloadItem* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); |
| 556 |
| 557 int64 size = 1022; |
| 558 const std::string hash_state("Live beef"); |
| 559 const content::DownloadInterruptReason reason( |
| 560 content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED); |
| 561 |
| 562 // Confirm interrupt sets state properly. |
| 563 item->Interrupted(size, hash_state, reason); |
| 564 EXPECT_EQ(size, item->GetReceivedBytes()); |
| 565 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); |
| 566 EXPECT_EQ(hash_state, item->GetHashState()); |
| 567 EXPECT_EQ(reason, item->GetLastReason()); |
| 568 |
| 569 // Cancel should result in no change. |
| 570 item->Cancel(true); |
| 571 EXPECT_EQ(size, item->GetReceivedBytes()); |
| 572 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); |
| 573 EXPECT_EQ(hash_state, item->GetHashState()); |
| 574 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED, |
| 575 item->GetLastReason()); |
| 576 } |
| 577 |
| 578 TEST_F(DownloadItemTest, Canceled) { |
| 579 DownloadItem* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); |
| 580 |
| 581 // Confirm cancel sets state properly. |
| 582 EXPECT_CALL(*mock_delegate(), DownloadCancelled(item)); |
| 583 item->Cancel(true); |
| 584 EXPECT_EQ(DownloadItem::CANCELLED, item->GetState()); |
| 585 } |
| 586 |
| 587 TEST_F(DownloadItemTest, FileRemoved) { |
| 588 DownloadItem* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); |
| 589 |
| 590 EXPECT_EQ(false, item->GetFileExternallyRemoved()); |
| 591 item->OnDownloadedFileRemoved(); |
| 592 EXPECT_EQ(true, item->GetFileExternallyRemoved()); |
| 593 } |
| 594 |
554 TEST(MockDownloadItem, Compiles) { | 595 TEST(MockDownloadItem, Compiles) { |
555 MockDownloadItem mock_item; | 596 MockDownloadItem mock_item; |
556 } | 597 } |
OLD | NEW |