| 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "content/public/browser/download_item.h" | 30 #include "content/public/browser/download_item.h" |
| 31 #include "content/public/browser/download_manager_delegate.h" | 31 #include "content/public/browser/download_manager_delegate.h" |
| 32 #include "content/public/test/mock_download_item.h" | 32 #include "content/public/test/mock_download_item.h" |
| 33 #include "content/public/test/test_browser_context.h" | 33 #include "content/public/test/test_browser_context.h" |
| 34 #include "content/public/test/test_browser_thread.h" | 34 #include "content/public/test/test_browser_thread.h" |
| 35 #include "net/base/net_util.h" | 35 #include "net/base/net_util.h" |
| 36 #include "testing/gmock/include/gmock/gmock.h" | 36 #include "testing/gmock/include/gmock/gmock.h" |
| 37 #include "testing/gmock_mutant.h" | 37 #include "testing/gmock_mutant.h" |
| 38 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 39 | 39 |
| 40 using ::testing::AllOf; |
| 40 using ::testing::DoAll; | 41 using ::testing::DoAll; |
| 42 using ::testing::Eq; |
| 43 using ::testing::Field; |
| 44 using ::testing::Pointee; |
| 41 using ::testing::Ref; | 45 using ::testing::Ref; |
| 42 using ::testing::Return; | 46 using ::testing::Return; |
| 43 using ::testing::ReturnRef; | 47 using ::testing::ReturnRef; |
| 44 using ::testing::SetArgPointee; | 48 using ::testing::SetArgPointee; |
| 45 using ::testing::StrictMock; | 49 using ::testing::StrictMock; |
| 46 using ::testing::_; | 50 using ::testing::_; |
| 47 using content::DownloadInterruptReason; | 51 using content::DownloadInterruptReason; |
| 48 using content::DownloadItem; | 52 using content::DownloadItem; |
| 49 using content::DownloadManager; | 53 using content::DownloadManager; |
| 50 using content::WebContents; | 54 using content::WebContents; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 DownloadItem*, const base::Closure&)); | 178 DownloadItem*, const base::Closure&)); |
| 175 MOCK_METHOD1(ShouldOpenDownload, bool(DownloadItem*)); | 179 MOCK_METHOD1(ShouldOpenDownload, bool(DownloadItem*)); |
| 176 MOCK_METHOD0(GenerateFileHash, bool()); | 180 MOCK_METHOD0(GenerateFileHash, bool()); |
| 177 MOCK_METHOD1(AddItemToPersistentStore, void(DownloadItem*)); | 181 MOCK_METHOD1(AddItemToPersistentStore, void(DownloadItem*)); |
| 178 MOCK_METHOD1(UpdateItemInPersistentStore, void(DownloadItem*)); | 182 MOCK_METHOD1(UpdateItemInPersistentStore, void(DownloadItem*)); |
| 179 MOCK_METHOD2(UpdatePathForItemInPersistentStore, | 183 MOCK_METHOD2(UpdatePathForItemInPersistentStore, |
| 180 void(DownloadItem*, const FilePath&)); | 184 void(DownloadItem*, const FilePath&)); |
| 181 MOCK_METHOD1(RemoveItemFromPersistentStore, void(DownloadItem*)); | 185 MOCK_METHOD1(RemoveItemFromPersistentStore, void(DownloadItem*)); |
| 182 MOCK_METHOD2(RemoveItemsFromPersistentStoreBetween, void( | 186 MOCK_METHOD2(RemoveItemsFromPersistentStoreBetween, void( |
| 183 base::Time remove_begin, base::Time remove_end)); | 187 base::Time remove_begin, base::Time remove_end)); |
| 184 MOCK_METHOD4(GetSaveDir, void(WebContents*, FilePath*, FilePath*, bool*)); | 188 MOCK_METHOD4(GetSaveDir, void(content::BrowserContext*, |
| 189 FilePath*, FilePath*, bool*)); |
| 185 MOCK_METHOD5(ChooseSavePath, void( | 190 MOCK_METHOD5(ChooseSavePath, void( |
| 186 WebContents*, const FilePath&, const FilePath::StringType&, | 191 WebContents*, const FilePath&, const FilePath::StringType&, |
| 187 bool, const content::SavePackagePathPickedCallback&)); | 192 bool, const content::SavePackagePathPickedCallback&)); |
| 188 }; | 193 }; |
| 189 | 194 |
| 190 MockDownloadManagerDelegate::MockDownloadManagerDelegate() {} | 195 MockDownloadManagerDelegate::MockDownloadManagerDelegate() {} |
| 191 | 196 |
| 192 MockDownloadManagerDelegate::~MockDownloadManagerDelegate() {} | 197 MockDownloadManagerDelegate::~MockDownloadManagerDelegate() {} |
| 193 | 198 |
| 194 class MockDownloadFileManager : public DownloadFileManager { | 199 class MockDownloadFileManager : public DownloadFileManager { |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 int next_download_id_; | 568 int next_download_id_; |
| 564 | 569 |
| 565 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); | 570 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); |
| 566 }; | 571 }; |
| 567 | 572 |
| 568 // Confirm the appropriate invocations occur when you start a download. | 573 // Confirm the appropriate invocations occur when you start a download. |
| 569 TEST_F(DownloadManagerTest, StartDownload) { | 574 TEST_F(DownloadManagerTest, StartDownload) { |
| 570 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); | 575 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); |
| 571 scoped_ptr<content::ByteStreamReader> stream; | 576 scoped_ptr<content::ByteStreamReader> stream; |
| 572 int32 local_id(5); // Random value | 577 int32 local_id(5); // Random value |
| 578 FilePath download_path(FILE_PATH_LITERAL("download/path")); |
| 573 | 579 |
| 574 EXPECT_FALSE(download_manager_->GetActiveDownloadItem(local_id)); | 580 EXPECT_FALSE(download_manager_->GetActiveDownloadItem(local_id)); |
| 575 | 581 |
| 576 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) | 582 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
| 577 .WillOnce(Return()); | 583 .WillOnce(Return()); |
| 578 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId()) | 584 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId()) |
| 579 .WillOnce(Return(content::DownloadId(this, local_id))); | 585 .WillOnce(Return(content::DownloadId(this, local_id))); |
| 580 EXPECT_CALL(GetMockDownloadManagerDelegate(), GenerateFileHash()) | 586 EXPECT_CALL(GetMockDownloadManagerDelegate(), GenerateFileHash()) |
| 581 .WillOnce(Return(true)); | 587 .WillOnce(Return(true)); |
| 588 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetSaveDir(_,_,_,_)) |
| 589 .WillOnce(SetArgPointee<2>(download_path)); |
| 590 // The CreateDownloadFile call should specify a DownloadCreateInfo that |
| 591 // includes the result of the GetSaveDir() call. |
| 582 EXPECT_CALL(GetMockDownloadFileManager(), MockCreateDownloadFile( | 592 EXPECT_CALL(GetMockDownloadFileManager(), MockCreateDownloadFile( |
| 583 info.get(), static_cast<content::ByteStreamReader*>(NULL), | 593 AllOf(Eq(info.get()), |
| 594 Pointee(Field(&DownloadCreateInfo::default_download_directory, |
| 595 download_path))), |
| 596 static_cast<content::ByteStreamReader*>(NULL), |
| 584 download_manager_.get(), true, _, _)); | 597 download_manager_.get(), true, _, _)); |
| 585 | 598 |
| 586 download_manager_->StartDownload(info.Pass(), stream.Pass()); | 599 download_manager_->StartDownload(info.Pass(), stream.Pass()); |
| 587 EXPECT_TRUE(download_manager_->GetActiveDownloadItem(local_id)); | 600 EXPECT_TRUE(download_manager_->GetActiveDownloadItem(local_id)); |
| 588 } | 601 } |
| 589 | 602 |
| 590 // Do the results of an OnDownloadInterrupted get passed through properly | 603 // Do the results of an OnDownloadInterrupted get passed through properly |
| 591 // to the DownloadItem? | 604 // to the DownloadItem? |
| 592 TEST_F(DownloadManagerTest, OnDownloadInterrupted) { | 605 TEST_F(DownloadManagerTest, OnDownloadInterrupted) { |
| 593 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) | 606 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 UpdateItemInPersistentStore(&item)); | 659 UpdateItemInPersistentStore(&item)); |
| 647 EXPECT_CALL(item, GetState()) | 660 EXPECT_CALL(item, GetState()) |
| 648 .WillRepeatedly(Return(DownloadItem::CANCELLED)); | 661 .WillRepeatedly(Return(DownloadItem::CANCELLED)); |
| 649 EXPECT_CALL(item, GetDbHandle()) | 662 EXPECT_CALL(item, GetDbHandle()) |
| 650 .WillRepeatedly(Return(db_handle)); | 663 .WillRepeatedly(Return(db_handle)); |
| 651 | 664 |
| 652 EXPECT_CALL(item, OffThreadCancel()); | 665 EXPECT_CALL(item, OffThreadCancel()); |
| 653 DownloadStopped(&item); | 666 DownloadStopped(&item); |
| 654 EXPECT_EQ(NULL, download_manager_->GetActiveDownloadItem(download_id)); | 667 EXPECT_EQ(NULL, download_manager_->GetActiveDownloadItem(download_id)); |
| 655 } | 668 } |
| OLD | NEW |