| 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 30 matching lines...) Expand all Loading... |
| 41 MOCK_METHOD1(ShouldOpenDownload, bool(DownloadItemImpl* download)); | 41 MOCK_METHOD1(ShouldOpenDownload, bool(DownloadItemImpl* download)); |
| 42 MOCK_METHOD1(CheckForFileRemoval, void(DownloadItemImpl* download)); | 42 MOCK_METHOD1(CheckForFileRemoval, void(DownloadItemImpl* download)); |
| 43 MOCK_METHOD1(MaybeCompleteDownload, void(DownloadItemImpl* download)); | 43 MOCK_METHOD1(MaybeCompleteDownload, void(DownloadItemImpl* download)); |
| 44 MOCK_CONST_METHOD0(GetBrowserContext, content::BrowserContext*()); | 44 MOCK_CONST_METHOD0(GetBrowserContext, content::BrowserContext*()); |
| 45 MOCK_METHOD1(DownloadStopped, void(DownloadItemImpl* download)); | 45 MOCK_METHOD1(DownloadStopped, void(DownloadItemImpl* download)); |
| 46 MOCK_METHOD1(DownloadCompleted, void(DownloadItemImpl* download)); | 46 MOCK_METHOD1(DownloadCompleted, void(DownloadItemImpl* download)); |
| 47 MOCK_METHOD1(DownloadOpened, void(DownloadItemImpl* download)); | 47 MOCK_METHOD1(DownloadOpened, void(DownloadItemImpl* download)); |
| 48 MOCK_METHOD1(DownloadRemoved, void(DownloadItemImpl* download)); | 48 MOCK_METHOD1(DownloadRemoved, void(DownloadItemImpl* download)); |
| 49 MOCK_METHOD1(DownloadRenamedToIntermediateName, | 49 MOCK_METHOD1(DownloadRenamedToIntermediateName, |
| 50 void(DownloadItemImpl* download)); | 50 void(DownloadItemImpl* download)); |
| 51 MOCK_METHOD1(DownloadRenamedToFinalName, void(DownloadItemImpl* download)); | |
| 52 MOCK_CONST_METHOD1(AssertStateConsistent, void(DownloadItemImpl* download)); | 51 MOCK_CONST_METHOD1(AssertStateConsistent, void(DownloadItemImpl* download)); |
| 53 virtual DownloadFileManager* GetDownloadFileManager() OVERRIDE { | 52 virtual DownloadFileManager* GetDownloadFileManager() OVERRIDE { |
| 54 return file_manager_; | 53 return file_manager_; |
| 55 } | 54 } |
| 56 private: | 55 private: |
| 57 DownloadFileManager* file_manager_; | 56 DownloadFileManager* file_manager_; |
| 58 }; | 57 }; |
| 59 | 58 |
| 60 class MockRequestHandle : public DownloadRequestHandleInterface { | 59 class MockRequestHandle : public DownloadRequestHandleInterface { |
| 61 public: | 60 public: |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 EXPECT_EQ(FILE_PATH_LITERAL("foo.bar"), | 440 EXPECT_EQ(FILE_PATH_LITERAL("foo.bar"), |
| 442 item->GetFileNameToReportUser().value()); | 441 item->GetFileNameToReportUser().value()); |
| 443 item->SetDisplayName(FilePath(FILE_PATH_LITERAL("new.name"))); | 442 item->SetDisplayName(FilePath(FILE_PATH_LITERAL("new.name"))); |
| 444 EXPECT_EQ(FILE_PATH_LITERAL("new.name"), | 443 EXPECT_EQ(FILE_PATH_LITERAL("new.name"), |
| 445 item->GetFileNameToReportUser().value()); | 444 item->GetFileNameToReportUser().value()); |
| 446 } | 445 } |
| 447 | 446 |
| 448 // Test that the delegate is invoked after the download file is renamed. | 447 // Test that the delegate is invoked after the download file is renamed. |
| 449 // Delegate::DownloadRenamedToIntermediateName() should be invoked when the | 448 // Delegate::DownloadRenamedToIntermediateName() should be invoked when the |
| 450 // download is renamed to the intermediate name. | 449 // download is renamed to the intermediate name. |
| 451 // Delegate::DownloadRenamedToFinalName() should be invoked after the final | |
| 452 // rename. | |
| 453 TEST_F(DownloadItemTest, CallbackAfterRename) { | 450 TEST_F(DownloadItemTest, CallbackAfterRename) { |
| 454 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); | 451 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); |
| 455 FilePath final_path(FilePath(kDummyPath).AppendASCII("foo.bar")); | 452 FilePath final_path(FilePath(kDummyPath).AppendASCII("foo.bar")); |
| 456 FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); | 453 FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); |
| 457 FilePath new_intermediate_path(final_path.InsertBeforeExtensionASCII("y")); | 454 FilePath new_intermediate_path(final_path.InsertBeforeExtensionASCII("y")); |
| 458 EXPECT_CALL(*mock_file_manager(), | 455 EXPECT_CALL(*mock_file_manager(), |
| 459 RenameDownloadFile(item->GetGlobalId(), | 456 RenameDownloadFile(item->GetGlobalId(), |
| 460 intermediate_path, false, _)) | 457 intermediate_path, false, _)) |
| 461 .WillOnce(ScheduleRenameCallback(new_intermediate_path)); | 458 .WillOnce(ScheduleRenameCallback(new_intermediate_path)); |
| 462 // DownloadItemImpl should invoke this callback on the delegate once the | 459 // DownloadItemImpl should invoke this callback on the delegate once the |
| (...skipping 14 matching lines...) Expand all Loading... |
| 477 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); | 474 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); |
| 478 | 475 |
| 479 item->OnAllDataSaved(10, ""); | 476 item->OnAllDataSaved(10, ""); |
| 480 EXPECT_CALL(*mock_file_manager(), | 477 EXPECT_CALL(*mock_file_manager(), |
| 481 RenameDownloadFile(item->GetGlobalId(), | 478 RenameDownloadFile(item->GetGlobalId(), |
| 482 final_path, true, _)) | 479 final_path, true, _)) |
| 483 .WillOnce(ScheduleRenameCallback(final_path)); | 480 .WillOnce(ScheduleRenameCallback(final_path)); |
| 484 EXPECT_CALL(*mock_file_manager(), | 481 EXPECT_CALL(*mock_file_manager(), |
| 485 CompleteDownload(item->GetGlobalId(), _)) | 482 CompleteDownload(item->GetGlobalId(), _)) |
| 486 .WillOnce(ScheduleCompleteCallback()); | 483 .WillOnce(ScheduleCompleteCallback()); |
| 487 // DownloadItemImpl should invoke this callback on the delegate after the | |
| 488 // final rename has completed. Also check that GetFullPath() and | |
| 489 // GetTargetFilePath() return the final path at the time of the call. | |
| 490 EXPECT_CALL(*mock_delegate(), | |
| 491 DownloadRenamedToFinalName( | |
| 492 AllOf(item, | |
| 493 Property(&DownloadItem::GetFullPath, final_path), | |
| 494 Property(&DownloadItem::GetTargetFilePath, | |
| 495 final_path)))); | |
| 496 EXPECT_CALL(*mock_delegate(), DownloadCompleted(item)); | 484 EXPECT_CALL(*mock_delegate(), DownloadCompleted(item)); |
| 497 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item)) | 485 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item)) |
| 498 .WillOnce(Return(true)); | 486 .WillOnce(Return(true)); |
| 499 item->OnDownloadCompleting(); | 487 item->OnDownloadCompleting(); |
| 500 RunAllPendingInMessageLoops(); | 488 RunAllPendingInMessageLoops(); |
| 501 ::testing::Mock::VerifyAndClearExpectations(mock_file_manager()); | 489 ::testing::Mock::VerifyAndClearExpectations(mock_file_manager()); |
| 502 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); | 490 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); |
| 503 } | 491 } |
| 504 | 492 |
| 505 TEST_F(DownloadItemTest, Interrupted) { | 493 TEST_F(DownloadItemTest, Interrupted) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 533 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); | 521 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); |
| 534 | 522 |
| 535 EXPECT_FALSE(item->GetFileExternallyRemoved()); | 523 EXPECT_FALSE(item->GetFileExternallyRemoved()); |
| 536 item->OnDownloadedFileRemoved(); | 524 item->OnDownloadedFileRemoved(); |
| 537 EXPECT_TRUE(item->GetFileExternallyRemoved()); | 525 EXPECT_TRUE(item->GetFileExternallyRemoved()); |
| 538 } | 526 } |
| 539 | 527 |
| 540 TEST(MockDownloadItem, Compiles) { | 528 TEST(MockDownloadItem, Compiles) { |
| 541 MockDownloadItem mock_item; | 529 MockDownloadItem mock_item; |
| 542 } | 530 } |
| OLD | NEW |