| 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 "content/browser/download/download_item_impl.h" | 5 #include "content/browser/download/download_item_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <deque> | 9 #include <deque> |
| 10 #include <iterator> | 10 #include <iterator> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <queue> | 13 #include <queue> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> |
| 15 | 16 |
| 16 #include "base/callback.h" | 17 #include "base/callback.h" |
| 17 #include "base/callback_helpers.h" | 18 #include "base/callback_helpers.h" |
| 18 #include "base/feature_list.h" | 19 #include "base/feature_list.h" |
| 19 #include "base/files/file_util.h" | 20 #include "base/files/file_util.h" |
| 20 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
| 21 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
| 22 #include "base/run_loop.h" | 23 #include "base/run_loop.h" |
| 23 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
| 24 #include "content/browser/byte_stream.h" | 25 #include "content/browser/byte_stream.h" |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 | 517 |
| 517 TEST_F(DownloadItemTest, NotificationAfterOnContentCheckCompleted) { | 518 TEST_F(DownloadItemTest, NotificationAfterOnContentCheckCompleted) { |
| 518 // Setting to NOT_DANGEROUS does not trigger a notification. | 519 // Setting to NOT_DANGEROUS does not trigger a notification. |
| 519 DownloadItemImpl* safe_item = CreateDownloadItem(); | 520 DownloadItemImpl* safe_item = CreateDownloadItem(); |
| 520 MockDownloadFile* download_file = | 521 MockDownloadFile* download_file = |
| 521 DoIntermediateRename(safe_item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); | 522 DoIntermediateRename(safe_item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
| 522 TestDownloadItemObserver safe_observer(safe_item); | 523 TestDownloadItemObserver safe_observer(safe_item); |
| 523 | 524 |
| 524 safe_item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>()); | 525 safe_item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>()); |
| 525 EXPECT_TRUE(safe_observer.CheckAndResetDownloadUpdated()); | 526 EXPECT_TRUE(safe_observer.CheckAndResetDownloadUpdated()); |
| 526 safe_item->OnContentCheckCompleted(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); | 527 safe_item->OnContentCheckCompleted(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 528 DOWNLOAD_INTERRUPT_REASON_NONE); |
| 527 EXPECT_TRUE(safe_observer.CheckAndResetDownloadUpdated()); | 529 EXPECT_TRUE(safe_observer.CheckAndResetDownloadUpdated()); |
| 528 CleanupItem(safe_item, download_file, DownloadItem::IN_PROGRESS); | 530 CleanupItem(safe_item, download_file, DownloadItem::IN_PROGRESS); |
| 529 | 531 |
| 530 // Setting to unsafe url or unsafe file should trigger a notification. | 532 // Setting to unsafe url or unsafe file should trigger a notification. |
| 531 DownloadItemImpl* unsafeurl_item = CreateDownloadItem(); | 533 DownloadItemImpl* unsafeurl_item = CreateDownloadItem(); |
| 532 download_file = | 534 download_file = |
| 533 DoIntermediateRename(unsafeurl_item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); | 535 DoIntermediateRename(unsafeurl_item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
| 534 TestDownloadItemObserver unsafeurl_observer(unsafeurl_item); | 536 TestDownloadItemObserver unsafeurl_observer(unsafeurl_item); |
| 535 | 537 |
| 536 unsafeurl_item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>()); | 538 unsafeurl_item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>()); |
| 537 EXPECT_TRUE(unsafeurl_observer.CheckAndResetDownloadUpdated()); | 539 EXPECT_TRUE(unsafeurl_observer.CheckAndResetDownloadUpdated()); |
| 538 unsafeurl_item->OnContentCheckCompleted(DOWNLOAD_DANGER_TYPE_DANGEROUS_URL); | 540 unsafeurl_item->OnContentCheckCompleted(DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, |
| 541 DOWNLOAD_INTERRUPT_REASON_NONE); |
| 539 EXPECT_TRUE(unsafeurl_observer.CheckAndResetDownloadUpdated()); | 542 EXPECT_TRUE(unsafeurl_observer.CheckAndResetDownloadUpdated()); |
| 540 | 543 |
| 541 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(_, _)) | 544 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(_, _)) |
| 542 .WillOnce(Return(true)); | 545 .WillOnce(Return(true)); |
| 543 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _, _, _, _)); | 546 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _, _, _, _)); |
| 544 unsafeurl_item->ValidateDangerousDownload(); | 547 unsafeurl_item->ValidateDangerousDownload(); |
| 545 EXPECT_TRUE(unsafeurl_observer.CheckAndResetDownloadUpdated()); | 548 EXPECT_TRUE(unsafeurl_observer.CheckAndResetDownloadUpdated()); |
| 546 CleanupItem(unsafeurl_item, download_file, DownloadItem::IN_PROGRESS); | 549 CleanupItem(unsafeurl_item, download_file, DownloadItem::IN_PROGRESS); |
| 547 | 550 |
| 548 DownloadItemImpl* unsafefile_item = CreateDownloadItem(); | 551 DownloadItemImpl* unsafefile_item = CreateDownloadItem(); |
| 549 download_file = | 552 download_file = |
| 550 DoIntermediateRename(unsafefile_item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); | 553 DoIntermediateRename(unsafefile_item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
| 551 TestDownloadItemObserver unsafefile_observer(unsafefile_item); | 554 TestDownloadItemObserver unsafefile_observer(unsafefile_item); |
| 552 | 555 |
| 553 unsafefile_item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>()); | 556 unsafefile_item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>()); |
| 554 EXPECT_TRUE(unsafefile_observer.CheckAndResetDownloadUpdated()); | 557 EXPECT_TRUE(unsafefile_observer.CheckAndResetDownloadUpdated()); |
| 555 unsafefile_item->OnContentCheckCompleted(DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); | 558 unsafefile_item->OnContentCheckCompleted(DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
| 559 DOWNLOAD_INTERRUPT_REASON_NONE); |
| 556 EXPECT_TRUE(unsafefile_observer.CheckAndResetDownloadUpdated()); | 560 EXPECT_TRUE(unsafefile_observer.CheckAndResetDownloadUpdated()); |
| 557 | 561 |
| 558 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(_, _)) | 562 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(_, _)) |
| 559 .WillOnce(Return(true)); | 563 .WillOnce(Return(true)); |
| 560 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _, _, _, _)); | 564 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _, _, _, _)); |
| 561 unsafefile_item->ValidateDangerousDownload(); | 565 unsafefile_item->ValidateDangerousDownload(); |
| 562 EXPECT_TRUE(unsafefile_observer.CheckAndResetDownloadUpdated()); | 566 EXPECT_TRUE(unsafefile_observer.CheckAndResetDownloadUpdated()); |
| 563 CleanupItem(unsafefile_item, download_file, DownloadItem::IN_PROGRESS); | 567 CleanupItem(unsafefile_item, download_file, DownloadItem::IN_PROGRESS); |
| 564 } | 568 } |
| 565 | 569 |
| (...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1751 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) | 1755 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) |
| 1752 .WillOnce(DoAll(SaveArg<1>(&delegate_callback), | 1756 .WillOnce(DoAll(SaveArg<1>(&delegate_callback), |
| 1753 Return(false))) | 1757 Return(false))) |
| 1754 .WillOnce(Return(true)); | 1758 .WillOnce(Return(true)); |
| 1755 item->DestinationObserverAsWeakPtr()->DestinationCompleted( | 1759 item->DestinationObserverAsWeakPtr()->DestinationCompleted( |
| 1756 0, std::unique_ptr<crypto::SecureHash>()); | 1760 0, std::unique_ptr<crypto::SecureHash>()); |
| 1757 ASSERT_FALSE(delegate_callback.is_null()); | 1761 ASSERT_FALSE(delegate_callback.is_null()); |
| 1758 copy_delegate_callback = delegate_callback; | 1762 copy_delegate_callback = delegate_callback; |
| 1759 delegate_callback.Reset(); | 1763 delegate_callback.Reset(); |
| 1760 EXPECT_FALSE(item->IsDangerous()); | 1764 EXPECT_FALSE(item->IsDangerous()); |
| 1761 item->OnContentCheckCompleted( | 1765 item->OnContentCheckCompleted(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
| 1762 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); | 1766 DOWNLOAD_INTERRUPT_REASON_NONE); |
| 1763 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); | 1767 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
| 1764 copy_delegate_callback.Run(); | 1768 copy_delegate_callback.Run(); |
| 1765 ASSERT_TRUE(delegate_callback.is_null()); | 1769 ASSERT_TRUE(delegate_callback.is_null()); |
| 1766 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); | 1770 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
| 1767 EXPECT_TRUE(item->IsDangerous()); | 1771 EXPECT_TRUE(item->IsDangerous()); |
| 1768 | 1772 |
| 1769 // Make sure the download doesn't complete until we've validated it. | 1773 // Make sure the download doesn't complete until we've validated it. |
| 1770 EXPECT_CALL(*download_file, | 1774 EXPECT_CALL(*download_file, |
| 1771 RenameAndAnnotate(base::FilePath(kDummyTargetPath), _, _, _, _)) | 1775 RenameAndAnnotate(base::FilePath(kDummyTargetPath), _, _, _, _)) |
| 1772 .WillOnce(ScheduleRenameAndAnnotateCallback( | 1776 .WillOnce(ScheduleRenameAndAnnotateCallback( |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2347 | 2351 |
| 2348 item_->Cancel(true); | 2352 item_->Cancel(true); |
| 2349 RunAllPendingInMessageLoops(); | 2353 RunAllPendingInMessageLoops(); |
| 2350 } | 2354 } |
| 2351 | 2355 |
| 2352 TEST(MockDownloadItem, Compiles) { | 2356 TEST(MockDownloadItem, Compiles) { |
| 2353 MockDownloadItem mock_item; | 2357 MockDownloadItem mock_item; |
| 2354 } | 2358 } |
| 2355 | 2359 |
| 2356 } // namespace content | 2360 } // namespace content |
| OLD | NEW |