| 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_factory.h" | 10 #include "content/browser/download/download_file_factory.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // EXPECT_CALL(download_file, Rename(_,_,_)) | 76 // EXPECT_CALL(download_file, Rename(_,_,_)) |
| 77 // .WillOnce(ScheduleRenameCallback(new_path)); | 77 // .WillOnce(ScheduleRenameCallback(new_path)); |
| 78 ACTION_P(ScheduleRenameCallback, new_path) { | 78 ACTION_P(ScheduleRenameCallback, new_path) { |
| 79 BrowserThread::PostTask( | 79 BrowserThread::PostTask( |
| 80 BrowserThread::UI, FROM_HERE, | 80 BrowserThread::UI, FROM_HERE, |
| 81 base::Bind(arg2, content::DOWNLOAD_INTERRUPT_REASON_NONE, new_path)); | 81 base::Bind(arg2, content::DOWNLOAD_INTERRUPT_REASON_NONE, new_path)); |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Schedules a task to invoke the input closure on | 84 // Schedules a task to invoke the input closure on |
| 85 // the UI thread. Should only be used as the action for | 85 // the UI thread. Should only be used as the action for |
| 86 // MockDownloadFile::Detach/Cancel as follows: | 86 // MockDownloadFile::Detach as follows: |
| 87 // EXPECT_CALL(download_file, Detach(_)) | 87 // EXPECT_CALL(download_file, Detach(_)) |
| 88 // .WillOnce(ScheduleClosure())); | 88 // .WillOnce(ScheduleDetachCallback())); |
| 89 ACTION(ScheduleClosure) { | 89 ACTION(ScheduleDetachCallback) { |
| 90 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, arg0); | 90 BrowserThread::PostTask( |
| 91 } | 91 BrowserThread::UI, FROM_HERE, |
| 92 | 92 base::Bind(arg0, content::DOWNLOAD_INTERRUPT_REASON_NONE)); |
| 93 // Similarly for scheduling a completion callback. | |
| 94 ACTION(ScheduleCompleteCallback) { | |
| 95 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(arg1)); | |
| 96 } | 93 } |
| 97 | 94 |
| 98 } // namespace | 95 } // namespace |
| 99 | 96 |
| 100 class DownloadItemTest : public testing::Test { | 97 class DownloadItemTest : public testing::Test { |
| 101 public: | 98 public: |
| 102 class MockObserver : public DownloadItem::Observer { | 99 class MockObserver : public DownloadItem::Observer { |
| 103 public: | 100 public: |
| 104 explicit MockObserver(DownloadItem* item) | 101 explicit MockObserver(DownloadItem* item) |
| 105 : item_(item), | 102 : item_(item), |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 EXPECT_CALL(*mock_delegate(), | 507 EXPECT_CALL(*mock_delegate(), |
| 511 DownloadRenamedToFinalName( | 508 DownloadRenamedToFinalName( |
| 512 AllOf(item, | 509 AllOf(item, |
| 513 Property(&DownloadItem::GetFullPath, final_path), | 510 Property(&DownloadItem::GetFullPath, final_path), |
| 514 Property(&DownloadItem::GetTargetFilePath, | 511 Property(&DownloadItem::GetTargetFilePath, |
| 515 final_path)))); | 512 final_path)))); |
| 516 EXPECT_CALL(*mock_delegate(), DownloadCompleted(item)); | 513 EXPECT_CALL(*mock_delegate(), DownloadCompleted(item)); |
| 517 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item)) | 514 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item)) |
| 518 .WillOnce(Return(true)); | 515 .WillOnce(Return(true)); |
| 519 EXPECT_CALL(*download_file, Detach(_)) | 516 EXPECT_CALL(*download_file, Detach(_)) |
| 520 .WillOnce(ScheduleClosure()); | 517 .WillOnce(ScheduleDetachCallback()); |
| 521 item->SetIsPersisted(); | 518 item->SetIsPersisted(); |
| 522 item->MaybeCompleteDownload(); | 519 item->MaybeCompleteDownload(); |
| 523 RunAllPendingInMessageLoops(); | 520 RunAllPendingInMessageLoops(); |
| 524 ::testing::Mock::VerifyAndClearExpectations(download_file); | 521 ::testing::Mock::VerifyAndClearExpectations(download_file); |
| 525 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); | 522 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); |
| 526 } | 523 } |
| 527 | 524 |
| 528 TEST_F(DownloadItemTest, Interrupted) { | 525 TEST_F(DownloadItemTest, Interrupted) { |
| 529 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); | 526 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); |
| 530 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item, NULL); | 527 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item, NULL); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, item->GetState()); | 638 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, item->GetState()); |
| 642 EXPECT_TRUE(observer.CheckUpdated()); | 639 EXPECT_TRUE(observer.CheckUpdated()); |
| 643 EXPECT_EQ("livebeef", item->GetHash()); | 640 EXPECT_EQ("livebeef", item->GetHash()); |
| 644 EXPECT_EQ("", item->GetHashState()); | 641 EXPECT_EQ("", item->GetHashState()); |
| 645 EXPECT_TRUE(item->AllDataSaved()); | 642 EXPECT_TRUE(item->AllDataSaved()); |
| 646 } | 643 } |
| 647 | 644 |
| 648 TEST(MockDownloadItem, Compiles) { | 645 TEST(MockDownloadItem, Compiles) { |
| 649 MockDownloadItem mock_item; | 646 MockDownloadItem mock_item; |
| 650 } | 647 } |
| OLD | NEW |