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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 EXPECT_EQ(FILE_PATH_LITERAL("foo.bar"), | 439 EXPECT_EQ(FILE_PATH_LITERAL("foo.bar"), |
441 item->GetFileNameToReportUser().value()); | 440 item->GetFileNameToReportUser().value()); |
442 item->SetDisplayName(FilePath(FILE_PATH_LITERAL("new.name"))); | 441 item->SetDisplayName(FilePath(FILE_PATH_LITERAL("new.name"))); |
443 EXPECT_EQ(FILE_PATH_LITERAL("new.name"), | 442 EXPECT_EQ(FILE_PATH_LITERAL("new.name"), |
444 item->GetFileNameToReportUser().value()); | 443 item->GetFileNameToReportUser().value()); |
445 } | 444 } |
446 | 445 |
447 // Test that the delegate is invoked after the download file is renamed. | 446 // Test that the delegate is invoked after the download file is renamed. |
448 // Delegate::DownloadRenamedToIntermediateName() should be invoked when the | 447 // Delegate::DownloadRenamedToIntermediateName() should be invoked when the |
449 // download is renamed to the intermediate name. | 448 // download is renamed to the intermediate name. |
450 // Delegate::DownloadRenamedToFinalName() should be invoked after the final | |
451 // rename. | |
452 TEST_F(DownloadItemTest, CallbackAfterRename) { | 449 TEST_F(DownloadItemTest, CallbackAfterRename) { |
453 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); | 450 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); |
454 FilePath final_path(FilePath(kDummyPath).AppendASCII("foo.bar")); | 451 FilePath final_path(FilePath(kDummyPath).AppendASCII("foo.bar")); |
455 FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); | 452 FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); |
456 FilePath new_intermediate_path(final_path.InsertBeforeExtensionASCII("y")); | 453 FilePath new_intermediate_path(final_path.InsertBeforeExtensionASCII("y")); |
457 EXPECT_CALL(*mock_file_manager(), | 454 EXPECT_CALL(*mock_file_manager(), |
458 RenameDownloadFile(item->GetGlobalId(), | 455 RenameDownloadFile(item->GetGlobalId(), |
459 intermediate_path, false, _)) | 456 intermediate_path, false, _)) |
460 .WillOnce(ScheduleRenameCallback(new_intermediate_path)); | 457 .WillOnce(ScheduleRenameCallback(new_intermediate_path)); |
461 // DownloadItemImpl should invoke this callback on the delegate once the | 458 // DownloadItemImpl should invoke this callback on the delegate once the |
(...skipping 14 matching lines...) Expand all Loading... |
476 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); | 473 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); |
477 | 474 |
478 item->OnAllDataSaved(10, ""); | 475 item->OnAllDataSaved(10, ""); |
479 EXPECT_CALL(*mock_file_manager(), | 476 EXPECT_CALL(*mock_file_manager(), |
480 RenameDownloadFile(item->GetGlobalId(), | 477 RenameDownloadFile(item->GetGlobalId(), |
481 final_path, true, _)) | 478 final_path, true, _)) |
482 .WillOnce(ScheduleRenameCallback(final_path)); | 479 .WillOnce(ScheduleRenameCallback(final_path)); |
483 EXPECT_CALL(*mock_file_manager(), | 480 EXPECT_CALL(*mock_file_manager(), |
484 CompleteDownload(item->GetGlobalId(), _)) | 481 CompleteDownload(item->GetGlobalId(), _)) |
485 .WillOnce(ScheduleCompleteCallback()); | 482 .WillOnce(ScheduleCompleteCallback()); |
486 // DownloadItemImpl should invoke this callback on the delegate after the | |
487 // final rename has completed. Also check that GetFullPath() and | |
488 // GetTargetFilePath() return the final path at the time of the call. | |
489 EXPECT_CALL(*mock_delegate(), | |
490 DownloadRenamedToFinalName( | |
491 AllOf(item, | |
492 Property(&DownloadItem::GetFullPath, final_path), | |
493 Property(&DownloadItem::GetTargetFilePath, | |
494 final_path)))); | |
495 EXPECT_CALL(*mock_delegate(), DownloadCompleted(item)); | 483 EXPECT_CALL(*mock_delegate(), DownloadCompleted(item)); |
496 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item)) | 484 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item)) |
497 .WillOnce(Return(true)); | 485 .WillOnce(Return(true)); |
498 item->OnDownloadCompleting(); | 486 item->OnDownloadCompleting(); |
499 RunAllPendingInMessageLoops(); | 487 RunAllPendingInMessageLoops(); |
500 ::testing::Mock::VerifyAndClearExpectations(mock_file_manager()); | 488 ::testing::Mock::VerifyAndClearExpectations(mock_file_manager()); |
501 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); | 489 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); |
502 } | 490 } |
503 | 491 |
504 TEST_F(DownloadItemTest, Interrupted) { | 492 TEST_F(DownloadItemTest, Interrupted) { |
(...skipping 27 matching lines...) Expand all Loading... |
532 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); | 520 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); |
533 | 521 |
534 EXPECT_FALSE(item->GetFileExternallyRemoved()); | 522 EXPECT_FALSE(item->GetFileExternallyRemoved()); |
535 item->OnDownloadedFileRemoved(); | 523 item->OnDownloadedFileRemoved(); |
536 EXPECT_TRUE(item->GetFileExternallyRemoved()); | 524 EXPECT_TRUE(item->GetFileExternallyRemoved()); |
537 } | 525 } |
538 | 526 |
539 TEST(MockDownloadItem, Compiles) { | 527 TEST(MockDownloadItem, Compiles) { |
540 MockDownloadItem mock_item; | 528 MockDownloadItem mock_item; |
541 } | 529 } |
OLD | NEW |