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 <iterator> | 9 #include <iterator> |
10 #include <map> | 10 #include <map> |
(...skipping 1523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1534 DOWNLOAD_INTERRUPT_REASON_NONE, base::FilePath(kDummyTargetPath))); | 1534 DOWNLOAD_INTERRUPT_REASON_NONE, base::FilePath(kDummyTargetPath))); |
1535 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) | 1535 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) |
1536 .WillOnce(Return(true)); | 1536 .WillOnce(Return(true)); |
1537 EXPECT_CALL(*download_file, FullPath()) | 1537 EXPECT_CALL(*download_file, FullPath()) |
1538 .WillOnce(ReturnRefOfCopy(base::FilePath())); | 1538 .WillOnce(ReturnRefOfCopy(base::FilePath())); |
1539 EXPECT_CALL(*download_file, Detach()); | 1539 EXPECT_CALL(*download_file, Detach()); |
1540 RunAllPendingInMessageLoops(); | 1540 RunAllPendingInMessageLoops(); |
1541 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); | 1541 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); |
1542 } | 1542 } |
1543 | 1543 |
1544 TEST_F(DownloadItemTest, StealDangerousDownload) { | 1544 TEST_F(DownloadItemTest, StealDangerousDownloadAndDiscard) { |
1545 DownloadItemImpl* item = CreateDownloadItem(); | 1545 DownloadItemImpl* item = CreateDownloadItem(); |
1546 MockDownloadFile* download_file = | 1546 MockDownloadFile* download_file = |
1547 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); | 1547 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); |
1548 ASSERT_TRUE(item->IsDangerous()); | 1548 ASSERT_TRUE(item->IsDangerous()); |
1549 base::FilePath full_path(FILE_PATH_LITERAL("foo.txt")); | 1549 base::FilePath full_path(FILE_PATH_LITERAL("foo.txt")); |
1550 base::FilePath returned_path; | 1550 base::FilePath returned_path; |
1551 | 1551 |
1552 EXPECT_CALL(*download_file, FullPath()).WillOnce(ReturnRefOfCopy(full_path)); | 1552 EXPECT_CALL(*download_file, FullPath()).WillOnce(ReturnRefOfCopy(full_path)); |
1553 EXPECT_CALL(*download_file, Detach()); | 1553 EXPECT_CALL(*download_file, Detach()); |
1554 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_)); | 1554 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_)); |
1555 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this); | 1555 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this); |
1556 item->StealDangerousDownload( | 1556 item->StealDangerousDownload( |
| 1557 true, // delete_file_after_feedback |
1557 base::Bind(&DownloadItemTest::OnDownloadFileAcquired, | 1558 base::Bind(&DownloadItemTest::OnDownloadFileAcquired, |
1558 weak_ptr_factory.GetWeakPtr(), | 1559 weak_ptr_factory.GetWeakPtr(), |
1559 base::Unretained(&returned_path))); | 1560 base::Unretained(&returned_path))); |
1560 RunAllPendingInMessageLoops(); | 1561 RunAllPendingInMessageLoops(); |
1561 EXPECT_EQ(full_path, returned_path); | 1562 EXPECT_EQ(full_path, returned_path); |
1562 } | 1563 } |
1563 | 1564 |
| 1565 TEST_F(DownloadItemTest, StealDangerousDownloadAndKeep) { |
| 1566 DownloadItemImpl* item = CreateDownloadItem(); |
| 1567 MockDownloadFile* download_file = |
| 1568 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); |
| 1569 ASSERT_TRUE(item->IsDangerous()); |
| 1570 base::FilePath full_path(FILE_PATH_LITERAL("foo.txt")); |
| 1571 base::FilePath returned_path; |
| 1572 EXPECT_CALL(*download_file, FullPath()).WillOnce(ReturnRefOfCopy(full_path)); |
| 1573 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this); |
| 1574 item->StealDangerousDownload( |
| 1575 false, // delete_file_after_feedback |
| 1576 base::Bind(&DownloadItemTest::OnDownloadFileAcquired, |
| 1577 weak_ptr_factory.GetWeakPtr(), |
| 1578 base::Unretained(&returned_path))); |
| 1579 RunAllPendingInMessageLoops(); |
| 1580 EXPECT_NE(full_path, returned_path); |
| 1581 CleanupItem(item, download_file, DownloadItem::IN_PROGRESS); |
| 1582 } |
| 1583 |
1564 TEST_F(DownloadItemTest, StealInterruptedDangerousDownload) { | 1584 TEST_F(DownloadItemTest, StealInterruptedDangerousDownload) { |
1565 base::FilePath returned_path; | 1585 base::FilePath returned_path; |
1566 DownloadItemImpl* item = CreateDownloadItem(); | 1586 DownloadItemImpl* item = CreateDownloadItem(); |
1567 MockDownloadFile* download_file = | 1587 MockDownloadFile* download_file = |
1568 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); | 1588 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); |
1569 base::FilePath full_path = item->GetFullPath(); | 1589 base::FilePath full_path = item->GetFullPath(); |
1570 EXPECT_FALSE(full_path.empty()); | 1590 EXPECT_FALSE(full_path.empty()); |
1571 EXPECT_CALL(*download_file, FullPath()).WillOnce(ReturnRefOfCopy(full_path)); | 1591 EXPECT_CALL(*download_file, FullPath()).WillOnce(ReturnRefOfCopy(full_path)); |
1572 EXPECT_CALL(*download_file, Detach()); | 1592 EXPECT_CALL(*download_file, Detach()); |
1573 item->DestinationObserverAsWeakPtr()->DestinationError( | 1593 item->DestinationObserverAsWeakPtr()->DestinationError( |
1574 DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, 0, | 1594 DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, 0, |
1575 std::unique_ptr<crypto::SecureHash>()); | 1595 std::unique_ptr<crypto::SecureHash>()); |
1576 ASSERT_TRUE(item->IsDangerous()); | 1596 ASSERT_TRUE(item->IsDangerous()); |
1577 | 1597 |
1578 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_)); | 1598 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_)); |
1579 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this); | 1599 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this); |
1580 item->StealDangerousDownload( | 1600 item->StealDangerousDownload( |
1581 base::Bind(&DownloadItemTest::OnDownloadFileAcquired, | 1601 true, base::Bind(&DownloadItemTest::OnDownloadFileAcquired, |
1582 weak_ptr_factory.GetWeakPtr(), | 1602 weak_ptr_factory.GetWeakPtr(), |
1583 base::Unretained(&returned_path))); | 1603 base::Unretained(&returned_path))); |
1584 RunAllPendingInMessageLoops(); | 1604 RunAllPendingInMessageLoops(); |
1585 EXPECT_EQ(full_path, returned_path); | 1605 EXPECT_EQ(full_path, returned_path); |
1586 } | 1606 } |
1587 | 1607 |
1588 TEST_F(DownloadItemTest, StealInterruptedNonResumableDangerousDownload) { | 1608 TEST_F(DownloadItemTest, StealInterruptedNonResumableDangerousDownload) { |
1589 base::FilePath returned_path; | 1609 base::FilePath returned_path; |
1590 DownloadItemImpl* item = CreateDownloadItem(); | 1610 DownloadItemImpl* item = CreateDownloadItem(); |
1591 MockDownloadFile* download_file = | 1611 MockDownloadFile* download_file = |
1592 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); | 1612 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); |
1593 EXPECT_CALL(*download_file, Cancel()); | 1613 EXPECT_CALL(*download_file, Cancel()); |
1594 item->DestinationObserverAsWeakPtr()->DestinationError( | 1614 item->DestinationObserverAsWeakPtr()->DestinationError( |
1595 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, 0, | 1615 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, 0, |
1596 std::unique_ptr<crypto::SecureHash>()); | 1616 std::unique_ptr<crypto::SecureHash>()); |
1597 ASSERT_TRUE(item->IsDangerous()); | 1617 ASSERT_TRUE(item->IsDangerous()); |
1598 | 1618 |
1599 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_)); | 1619 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_)); |
1600 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this); | 1620 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this); |
1601 item->StealDangerousDownload( | 1621 item->StealDangerousDownload( |
1602 base::Bind(&DownloadItemTest::OnDownloadFileAcquired, | 1622 true, base::Bind(&DownloadItemTest::OnDownloadFileAcquired, |
1603 weak_ptr_factory.GetWeakPtr(), | 1623 weak_ptr_factory.GetWeakPtr(), |
1604 base::Unretained(&returned_path))); | 1624 base::Unretained(&returned_path))); |
1605 RunAllPendingInMessageLoops(); | 1625 RunAllPendingInMessageLoops(); |
1606 EXPECT_TRUE(returned_path.empty()); | 1626 EXPECT_TRUE(returned_path.empty()); |
1607 } | 1627 } |
1608 | 1628 |
1609 namespace { | 1629 namespace { |
1610 | 1630 |
1611 // The DownloadItemDestinationUpdateRaceTest fixture (defined below) is used to | 1631 // The DownloadItemDestinationUpdateRaceTest fixture (defined below) is used to |
1612 // test for race conditions between download destination events received via the | 1632 // test for race conditions between download destination events received via the |
1613 // DownloadDestinationObserver interface, and the target determination logic. | 1633 // DownloadDestinationObserver interface, and the target determination logic. |
1614 // | 1634 // |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2026 | 2046 |
2027 item_->Cancel(true); | 2047 item_->Cancel(true); |
2028 RunAllPendingInMessageLoops(); | 2048 RunAllPendingInMessageLoops(); |
2029 } | 2049 } |
2030 | 2050 |
2031 TEST(MockDownloadItem, Compiles) { | 2051 TEST(MockDownloadItem, Compiles) { |
2032 MockDownloadItem mock_item; | 2052 MockDownloadItem mock_item; |
2033 } | 2053 } |
2034 | 2054 |
2035 } // namespace content | 2055 } // namespace content |
OLD | NEW |