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

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

Powered by Google App Engine
This is Rietveld 408576698