diff options
author | Ben Murdoch <benm@google.com> | 2013-07-17 14:55:54 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2013-07-17 14:55:54 +0100 |
commit | 7dbb3d5cf0c15f500944d211057644d6a2f37371 (patch) | |
tree | 701119ba0596f51b0ab466d6472b0f98211359c5 /content/browser/download/download_manager_impl_unittest.cc | |
parent | b2ecf4836a0eb284ddac7746b1f7ba613777a739 (diff) | |
download | chromium_org-7dbb3d5cf0c15f500944d211057644d6a2f37371.tar.gz |
Merge from Chromium at DEPS revision r212014
This commit was generated by merge_to_master.py.
Change-Id: Ie0f261e9682cd8abea1eea1e51beab83d5eea21a
Diffstat (limited to 'content/browser/download/download_manager_impl_unittest.cc')
-rw-r--r-- | content/browser/download/download_manager_impl_unittest.cc | 80 |
1 files changed, 39 insertions, 41 deletions
diff --git a/content/browser/download/download_manager_impl_unittest.cc b/content/browser/download/download_manager_impl_unittest.cc index 7817d3e915..cbba7a3e01 100644 --- a/content/browser/download/download_manager_impl_unittest.cc +++ b/content/browser/download/download_manager_impl_unittest.cc @@ -47,6 +47,11 @@ using ::testing::SetArgPointee; using ::testing::StrictMock; using ::testing::_; +ACTION_TEMPLATE(RunCallback, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_1_VALUE_PARAMS(p0)) { + return ::std::tr1::get<k>(args).Run(p0); +} namespace content { class ByteStreamReader; @@ -66,7 +71,7 @@ class MockDownloadItemImpl : public DownloadItemImpl { explicit MockDownloadItemImpl(DownloadItemImplDelegate* delegate) : DownloadItemImpl( delegate, - content::DownloadId(), + content::DownloadItem::kInvalidId, base::FilePath(), base::FilePath(), std::vector<GURL>(), @@ -135,8 +140,7 @@ class MockDownloadItemImpl : public DownloadItemImpl { MOCK_CONST_METHOD0(GetReceivedBytes, int64()); MOCK_CONST_METHOD0(GetHashState, const std::string&()); MOCK_CONST_METHOD0(GetHash, const std::string&()); - MOCK_CONST_METHOD0(GetId, int32()); - MOCK_CONST_METHOD0(GetGlobalId, DownloadId()); + MOCK_CONST_METHOD0(GetId, uint32()); MOCK_CONST_METHOD0(GetStartTime, base::Time()); MOCK_CONST_METHOD0(GetEndTime, base::Time()); MOCK_METHOD0(GetDownloadManager, DownloadManager*()); @@ -174,7 +178,7 @@ class MockDownloadManagerDelegate : public DownloadManagerDelegate { virtual ~MockDownloadManagerDelegate(); MOCK_METHOD0(Shutdown, void()); - MOCK_METHOD0(GetNextId, DownloadId()); + MOCK_METHOD1(GetNextId, void(const DownloadIdCallback&)); MOCK_METHOD2(DetermineDownloadTarget, bool(DownloadItem* item, const DownloadTargetCallback&)); @@ -220,7 +224,7 @@ class MockDownloadItemFactory // Overridden methods from DownloadItemFactory. virtual DownloadItemImpl* CreatePersistedItem( DownloadItemImplDelegate* delegate, - DownloadId download_id, + uint32 download_id, const base::FilePath& current_path, const base::FilePath& target_path, const std::vector<GURL>& url_chain, @@ -236,12 +240,12 @@ class MockDownloadItemFactory const net::BoundNetLog& bound_net_log) OVERRIDE; virtual DownloadItemImpl* CreateActiveItem( DownloadItemImplDelegate* delegate, - DownloadId download_id, + uint32 download_id, const DownloadCreateInfo& info, const net::BoundNetLog& bound_net_log) OVERRIDE; virtual DownloadItemImpl* CreateSavePageItem( DownloadItemImplDelegate* delegate, - DownloadId download_id, + uint32 download_id, const base::FilePath& path, const GURL& url, const std::string& mime_type, @@ -249,7 +253,7 @@ class MockDownloadItemFactory const net::BoundNetLog& bound_net_log) OVERRIDE; private: - std::map<int32, MockDownloadItemImpl*> items_; + std::map<uint32, MockDownloadItemImpl*> items_; DownloadItemImplDelegate item_delegate_; DISALLOW_COPY_AND_ASSIGN(MockDownloadItemFactory); @@ -269,7 +273,7 @@ MockDownloadItemImpl* MockDownloadItemFactory::PopItem() { if (items_.empty()) return NULL; - std::map<int32, MockDownloadItemImpl*>::iterator first_item + std::map<uint32, MockDownloadItemImpl*>::iterator first_item = items_.begin(); MockDownloadItemImpl* result = first_item->second; items_.erase(first_item); @@ -283,7 +287,7 @@ void MockDownloadItemFactory::RemoveItem(int id) { DownloadItemImpl* MockDownloadItemFactory::CreatePersistedItem( DownloadItemImplDelegate* delegate, - DownloadId download_id, + uint32 download_id, const base::FilePath& current_path, const base::FilePath& target_path, const std::vector<GURL>& url_chain, @@ -297,33 +301,27 @@ DownloadItemImpl* MockDownloadItemFactory::CreatePersistedItem( DownloadInterruptReason interrupt_reason, bool opened, const net::BoundNetLog& bound_net_log) { - int local_id = download_id.local(); - DCHECK(items_.find(local_id) == items_.end()); - + DCHECK(items_.find(download_id) == items_.end()); MockDownloadItemImpl* result = new StrictMock<MockDownloadItemImpl>(&item_delegate_); EXPECT_CALL(*result, GetId()) - .WillRepeatedly(Return(local_id)); - items_[local_id] = result; - + .WillRepeatedly(Return(download_id)); + items_[download_id] = result; return result; } DownloadItemImpl* MockDownloadItemFactory::CreateActiveItem( DownloadItemImplDelegate* delegate, - DownloadId download_id, + uint32 download_id, const DownloadCreateInfo& info, const net::BoundNetLog& bound_net_log) { - int local_id = download_id.local(); - DCHECK(items_.find(local_id) == items_.end()); + DCHECK(items_.find(download_id) == items_.end()); MockDownloadItemImpl* result = new StrictMock<MockDownloadItemImpl>(&item_delegate_); EXPECT_CALL(*result, GetId()) - .WillRepeatedly(Return(local_id)); - EXPECT_CALL(*result, GetGlobalId()) .WillRepeatedly(Return(download_id)); - items_[local_id] = result; + items_[download_id] = result; // Active items are created and then immediately are called to start // the download. @@ -334,20 +332,19 @@ DownloadItemImpl* MockDownloadItemFactory::CreateActiveItem( DownloadItemImpl* MockDownloadItemFactory::CreateSavePageItem( DownloadItemImplDelegate* delegate, - DownloadId download_id, + uint32 download_id, const base::FilePath& path, const GURL& url, const std::string& mime_type, scoped_ptr<DownloadRequestHandleInterface> request_handle, const net::BoundNetLog& bound_net_log) { - int local_id = download_id.local(); - DCHECK(items_.find(local_id) == items_.end()); + DCHECK(items_.find(download_id) == items_.end()); MockDownloadItemImpl* result = new StrictMock<MockDownloadItemImpl>(&item_delegate_); EXPECT_CALL(*result, GetId()) - .WillRepeatedly(Return(local_id)); - items_[local_id] = result; + .WillRepeatedly(Return(download_id)); + items_[download_id] = result; return result; } @@ -388,7 +385,7 @@ class MockBrowserContext : public BrowserContext { MockBrowserContext() {} ~MockBrowserContext() {} - MOCK_METHOD0(GetPath, base::FilePath()); + MOCK_CONST_METHOD0(GetPath, base::FilePath()); MOCK_CONST_METHOD0(IsOffTheRecord, bool()); MOCK_METHOD0(GetRequestContext, net::URLRequestContextGetter*()); MOCK_METHOD1(GetRequestContextForRenderProcess, @@ -400,12 +397,15 @@ class MockBrowserContext : public BrowserContext { MOCK_METHOD2(GetMediaRequestContextForStoragePartition, net::URLRequestContextGetter*( const base::FilePath& partition_path, bool in_memory)); + MOCK_METHOD4(RequestMIDISysExPermission, + void(int render_process_id, + int render_view_id, + const GURL& requesting_frame, + const MIDISysExPermissionCallback& callback)); MOCK_METHOD0(GetResourceContext, ResourceContext*()); MOCK_METHOD0(GetDownloadManagerDelegate, DownloadManagerDelegate*()); MOCK_METHOD0(GetGeolocationPermissionContext, GeolocationPermissionContext* ()); - MOCK_METHOD0(GetSpeechRecognitionPreferences, - SpeechRecognitionPreferences* ()); MOCK_METHOD0(GetSpecialStoragePolicy, quota::SpecialStoragePolicy*()); }; @@ -488,15 +488,12 @@ class DownloadManagerTest : public testing::Test { MockDownloadItemImpl& AddItemToManager() { DownloadCreateInfo info; - static const char* kDownloadIdDomain = "Test download id domain"; - // Args are ignored except for download id, so everything else can be // null. - int id = next_download_id_; + uint32 id = next_download_id_; ++next_download_id_; info.request_handle = DownloadRequestHandle(); - download_manager_->CreateActiveItem(DownloadId(kDownloadIdDomain, id), - info); + download_manager_->CreateActiveItem(id, info); DCHECK(mock_download_item_factory_->GetItem(id)); MockDownloadItemImpl& item(*mock_download_item_factory_->GetItem(id)); // Satisfy expectation. If the item is created in StartDownload(), @@ -567,7 +564,7 @@ class DownloadManagerTest : public testing::Test { scoped_ptr<MockDownloadManagerDelegate> mock_download_manager_delegate_; scoped_ptr<MockBrowserContext> mock_browser_context_; scoped_ptr<MockDownloadManagerObserver> observer_; - int next_download_id_; + uint32 next_download_id_; DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); }; @@ -576,15 +573,15 @@ class DownloadManagerTest : public testing::Test { TEST_F(DownloadManagerTest, StartDownload) { scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); scoped_ptr<ByteStreamReader> stream; - int32 local_id(5); // Random value + uint32 local_id(5); // Random value base::FilePath download_path(FILE_PATH_LITERAL("download/path")); EXPECT_FALSE(download_manager_->GetDownload(local_id)); EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) .WillOnce(Return()); - EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId()) - .WillOnce(Return(DownloadId(this, local_id))); + EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId(_)) + .WillOnce(RunCallback<0>(local_id)); // Doing nothing will set the default download directory to null. EXPECT_CALL(GetMockDownloadManagerDelegate(), GetSaveDir(_, _, _, _)); @@ -594,7 +591,8 @@ TEST_F(DownloadManagerTest, StartDownload) { MockCreateFile(Ref(*info->save_info.get()), _, _, _, true, stream.get(), _, _)); - download_manager_->StartDownload(info.Pass(), stream.Pass()); + download_manager_->StartDownload( + info.Pass(), stream.Pass(), DownloadUrlParameters::OnStartedCallback()); EXPECT_TRUE(download_manager_->GetDownload(local_id)); } @@ -638,7 +636,7 @@ TEST_F(DownloadManagerTest, DetermineDownloadTarget_False) { // Confirm the DownloadManagerImpl::RemoveAllDownloads() functionality TEST_F(DownloadManagerTest, RemoveAllDownloads) { base::Time now(base::Time::Now()); - for (int i = 0; i < 4; ++i) { + for (uint32 i = 0; i < 4; ++i) { MockDownloadItemImpl& item(AddItemToManager()); EXPECT_EQ(i, item.GetId()); EXPECT_CALL(item, GetStartTime()) |