Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: content/browser/download/download_item_impl_unittest.cc

Issue 2439533002: Download Feedback Service should upload all eligible downloads (Closed)
Patch Set: make windows bots happy Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1521 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 DOWNLOAD_INTERRUPT_REASON_NONE, base::FilePath(kDummyTargetPath))); 1532 DOWNLOAD_INTERRUPT_REASON_NONE, base::FilePath(kDummyTargetPath)));
1533 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) 1533 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _))
1534 .WillOnce(Return(true)); 1534 .WillOnce(Return(true));
1535 EXPECT_CALL(*download_file, FullPath()) 1535 EXPECT_CALL(*download_file, FullPath())
1536 .WillOnce(ReturnRefOfCopy(base::FilePath())); 1536 .WillOnce(ReturnRefOfCopy(base::FilePath()));
1537 EXPECT_CALL(*download_file, Detach()); 1537 EXPECT_CALL(*download_file, Detach());
1538 RunAllPendingInMessageLoops(); 1538 RunAllPendingInMessageLoops();
1539 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); 1539 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState());
1540 } 1540 }
1541 1541
1542 TEST_F(DownloadItemTest, StealDangerousDownload) { 1542 TEST_F(DownloadItemTest, StealDangerousDownloadAndDiscard) {
1543 DownloadItemImpl* item = CreateDownloadItem(); 1543 DownloadItemImpl* item = CreateDownloadItem();
1544 MockDownloadFile* download_file = 1544 MockDownloadFile* download_file =
1545 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); 1545 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE);
1546 ASSERT_TRUE(item->IsDangerous()); 1546 ASSERT_TRUE(item->IsDangerous());
1547 base::FilePath full_path(FILE_PATH_LITERAL("foo.txt")); 1547 base::FilePath full_path(FILE_PATH_LITERAL("foo.txt"));
1548 base::FilePath returned_path; 1548 base::FilePath returned_path;
1549 1549
1550 EXPECT_CALL(*download_file, FullPath()).WillOnce(ReturnRefOfCopy(full_path)); 1550 EXPECT_CALL(*download_file, FullPath()).WillOnce(ReturnRefOfCopy(full_path));
1551 EXPECT_CALL(*download_file, Detach()); 1551 EXPECT_CALL(*download_file, Detach());
1552 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_)); 1552 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_));
1553 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this); 1553 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this);
1554 item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>());
1554 item->StealDangerousDownload( 1555 item->StealDangerousDownload(
1556 true, // delete_file_after_feedback
1555 base::Bind(&DownloadItemTest::OnDownloadFileAcquired, 1557 base::Bind(&DownloadItemTest::OnDownloadFileAcquired,
1556 weak_ptr_factory.GetWeakPtr(), 1558 weak_ptr_factory.GetWeakPtr(),
1557 base::Unretained(&returned_path))); 1559 base::Unretained(&returned_path)));
1558 RunAllPendingInMessageLoops(); 1560 RunAllPendingInMessageLoops();
1559 EXPECT_EQ(full_path, returned_path); 1561 EXPECT_EQ(full_path, returned_path);
1560 } 1562 }
1561 1563
1564 TEST_F(DownloadItemTest, StealDangerousDownloadAndKeep) {
1565 DownloadItemImpl* item = CreateDownloadItem();
1566 MockDownloadFile* download_file =
1567 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE);
1568 ASSERT_TRUE(item->IsDangerous());
1569 base::FilePath full_path(FILE_PATH_LITERAL("foo.txt"));
1570 base::FilePath returned_path;
1571 EXPECT_CALL(*download_file, FullPath()).WillOnce(ReturnRefOfCopy(full_path));
1572 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this);
1573 item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>());
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
1562 TEST_F(DownloadItemTest, StealInterruptedDangerousDownload) { 1584 TEST_F(DownloadItemTest, StealInterruptedDangerousDownload) {
1563 base::FilePath returned_path; 1585 base::FilePath returned_path;
1564 DownloadItemImpl* item = CreateDownloadItem(); 1586 DownloadItemImpl* item = CreateDownloadItem();
1565 MockDownloadFile* download_file = 1587 MockDownloadFile* download_file =
1566 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); 1588 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE);
1567 base::FilePath full_path = item->GetFullPath(); 1589 base::FilePath full_path = item->GetFullPath();
1568 EXPECT_FALSE(full_path.empty()); 1590 EXPECT_FALSE(full_path.empty());
1569 EXPECT_CALL(*download_file, FullPath()).WillOnce(ReturnRefOfCopy(full_path)); 1591 EXPECT_CALL(*download_file, FullPath()).WillOnce(ReturnRefOfCopy(full_path));
1570 EXPECT_CALL(*download_file, Detach()); 1592 EXPECT_CALL(*download_file, Detach());
1571 item->DestinationObserverAsWeakPtr()->DestinationError( 1593 item->DestinationObserverAsWeakPtr()->DestinationError(
1572 DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, 0, 1594 DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, 0,
1573 std::unique_ptr<crypto::SecureHash>()); 1595 std::unique_ptr<crypto::SecureHash>());
1574 ASSERT_TRUE(item->IsDangerous()); 1596 ASSERT_TRUE(item->IsDangerous());
1575 1597
1576 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_)); 1598 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_));
1577 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this); 1599 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this);
1600 item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>());
1578 item->StealDangerousDownload( 1601 item->StealDangerousDownload(
1579 base::Bind(&DownloadItemTest::OnDownloadFileAcquired, 1602 true, base::Bind(&DownloadItemTest::OnDownloadFileAcquired,
1580 weak_ptr_factory.GetWeakPtr(), 1603 weak_ptr_factory.GetWeakPtr(),
1581 base::Unretained(&returned_path))); 1604 base::Unretained(&returned_path)));
1582 RunAllPendingInMessageLoops(); 1605 RunAllPendingInMessageLoops();
1583 EXPECT_EQ(full_path, returned_path); 1606 EXPECT_EQ(full_path, returned_path);
1584 } 1607 }
1585 1608
1586 TEST_F(DownloadItemTest, StealInterruptedNonResumableDangerousDownload) { 1609 TEST_F(DownloadItemTest, StealInterruptedNonResumableDangerousDownload) {
1587 base::FilePath returned_path; 1610 base::FilePath returned_path;
1588 DownloadItemImpl* item = CreateDownloadItem(); 1611 DownloadItemImpl* item = CreateDownloadItem();
1589 MockDownloadFile* download_file = 1612 MockDownloadFile* download_file =
1590 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); 1613 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE);
1591 EXPECT_CALL(*download_file, Cancel()); 1614 EXPECT_CALL(*download_file, Cancel());
1592 item->DestinationObserverAsWeakPtr()->DestinationError( 1615 item->DestinationObserverAsWeakPtr()->DestinationError(
1593 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, 0, 1616 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, 0,
1594 std::unique_ptr<crypto::SecureHash>()); 1617 std::unique_ptr<crypto::SecureHash>());
1595 ASSERT_TRUE(item->IsDangerous()); 1618 ASSERT_TRUE(item->IsDangerous());
1596 1619
1597 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_)); 1620 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_));
1598 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this); 1621 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this);
1622 item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>());
1599 item->StealDangerousDownload( 1623 item->StealDangerousDownload(
1600 base::Bind(&DownloadItemTest::OnDownloadFileAcquired, 1624 true, base::Bind(&DownloadItemTest::OnDownloadFileAcquired,
1601 weak_ptr_factory.GetWeakPtr(), 1625 weak_ptr_factory.GetWeakPtr(),
1602 base::Unretained(&returned_path))); 1626 base::Unretained(&returned_path)));
1603 RunAllPendingInMessageLoops(); 1627 RunAllPendingInMessageLoops();
1604 EXPECT_TRUE(returned_path.empty()); 1628 EXPECT_TRUE(returned_path.empty());
1605 } 1629 }
1606 1630
1607 namespace { 1631 namespace {
1608 1632
1609 // The DownloadItemDestinationUpdateRaceTest fixture (defined below) is used to 1633 // The DownloadItemDestinationUpdateRaceTest fixture (defined below) is used to
1610 // test for race conditions between download destination events received via the 1634 // test for race conditions between download destination events received via the
1611 // DownloadDestinationObserver interface, and the target determination logic. 1635 // DownloadDestinationObserver interface, and the target determination logic.
1612 // 1636 //
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
2024 2048
2025 item_->Cancel(true); 2049 item_->Cancel(true);
2026 RunAllPendingInMessageLoops(); 2050 RunAllPendingInMessageLoops();
2027 } 2051 }
2028 2052
2029 TEST(MockDownloadItem, Compiles) { 2053 TEST(MockDownloadItem, Compiles) {
2030 MockDownloadItem mock_item; 2054 MockDownloadItem mock_item;
2031 } 2055 }
2032 2056
2033 } // namespace content 2057 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl.cc ('k') | content/browser/download/download_manager_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698