summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download/download_item_unittest.cc
diff options
context:
space:
mode:
authorkalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-06 02:07:08 +0000
committerkalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-06 02:07:08 +0000
commit53c873282889a6e98e520ce90775a1a76cf1c9ea (patch)
tree322b27aa50305b4ce067aa859c0e46cb0b36938b /chrome/browser/download/download_item_unittest.cc
parent543f890efb3af8bcc8e2d2e1e7e619f9c8c07979 (diff)
downloadchromium_src-53c873282889a6e98e520ce90775a1a76cf1c9ea.zip
chromium_src-53c873282889a6e98e520ce90775a1a76cf1c9ea.tar.gz
chromium_src-53c873282889a6e98e520ce90775a1a76cf1c9ea.tar.bz2
Revert 113007 - DownloadManager intereface refactoring to allow cleaner DownloadItem unit tests.
BUG=101214 Review URL: http://codereview.chromium.org/8697006 TBR=rdsmith@chromium.org Review URL: http://codereview.chromium.org/8817005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113084 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download/download_item_unittest.cc')
-rw-r--r--chrome/browser/download/download_item_unittest.cc66
1 files changed, 23 insertions, 43 deletions
diff --git a/chrome/browser/download/download_item_unittest.cc b/chrome/browser/download/download_item_unittest.cc
index 56500b8..ed30fdf 100644
--- a/chrome/browser/download/download_item_unittest.cc
+++ b/chrome/browser/download/download_item_unittest.cc
@@ -3,52 +3,25 @@
// found in the LICENSE file.
#include "base/message_loop.h"
-#include "base/stl_util.h"
#include "base/threading/thread.h"
#include "chrome/test/base/testing_profile.h"
#include "content/browser/download/download_create_info.h"
#include "content/browser/download/download_id.h"
#include "content/browser/download/download_id_factory.h"
-#include "content/browser/download/download_item_impl.h"
+#include "content/browser/download/download_item.h"
#include "content/browser/download/download_request_handle.h"
#include "content/browser/download/download_status_updater.h"
#include "content/browser/download/interrupt_reasons.h"
#include "content/browser/download/mock_download_item.h"
+#include "content/browser/download/mock_download_manager.h"
+#include "content/browser/download/mock_download_manager_delegate.h"
#include "content/test/test_browser_thread.h"
-#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using content::BrowserThread;
DownloadId::Domain kValidDownloadItemIdDomain = "valid DownloadId::Domain";
-namespace {
-class MockDelegate : public DownloadItemImpl::Delegate {
- public:
- MOCK_METHOD1(ShouldOpenFileBasedOnExtension, bool(const FilePath& path));
- MOCK_METHOD1(ShouldOpenDownload, bool(DownloadItem* download));
- MOCK_METHOD1(CheckForFileRemoval, void(DownloadItem* download));
- MOCK_METHOD1(MaybeCompleteDownload, void(DownloadItem* download));
- MOCK_CONST_METHOD0(BrowserContext, content::BrowserContext*());
- MOCK_METHOD1(DownloadCancelled, void(DownloadItem* download));
- MOCK_METHOD1(DownloadCompleted, void(DownloadItem* download));
- MOCK_METHOD1(DownloadOpened, void(DownloadItem* download));
- MOCK_METHOD1(DownloadRemoved, void(DownloadItem* download));
- MOCK_CONST_METHOD1(AssertStateConsistent, void(DownloadItem* download));
-};
-
-class MockRequestHandle : public DownloadRequestHandleInterface {
- public:
- MOCK_CONST_METHOD0(GetTabContents, TabContents*());
- MOCK_CONST_METHOD0(GetDownloadManager, DownloadManager*());
- MOCK_CONST_METHOD0(PauseRequest, void());
- MOCK_CONST_METHOD0(ResumeRequest, void());
- MOCK_CONST_METHOD0(CancelRequest, void());
- MOCK_CONST_METHOD0(DebugString, std::string());
-};
-
-}
-
class DownloadItemTest : public testing::Test {
public:
class MockObserver : public DownloadItem::Observer {
@@ -75,6 +48,7 @@ class DownloadItemTest : public testing::Test {
DownloadItemTest()
: id_factory_(new DownloadIdFactory(kValidDownloadItemIdDomain)),
+ profile_(new TestingProfile()),
ui_thread_(BrowserThread::UI, &loop_) {
}
@@ -82,16 +56,26 @@ class DownloadItemTest : public testing::Test {
}
virtual void SetUp() {
+ download_manager_delegate_.reset(new MockDownloadManagerDelegate());
+ download_manager_ = new MockDownloadManager(
+ download_manager_delegate_.get(),
+ id_factory_,
+ &download_status_updater_);
+ download_manager_->Init(profile_.get());
}
virtual void TearDown() {
+ download_manager_->Shutdown();
+ // When a DownloadManager's reference count drops to 0, it is not
+ // deleted immediately. Instead, a task is posted to the UI thread's
+ // message loop to delete it.
+ // So, drop the reference count to 0 and run the message loop once
+ // to ensure that all resources are cleaned up before the test exits.
+ download_manager_ = NULL;
+ profile_.reset(NULL);
ui_thread_.DeprecatedGetThreadObject()->message_loop()->RunAllPending();
- STLDeleteElements(&allocated_downloads_);
- allocated_downloads_.clear();
}
- // This class keeps ownership of the created download item; it will
- // be torn down at the end of the test.
DownloadItem* CreateDownloadItem(DownloadItem::DownloadState state) {
// Normally, the download system takes ownership of info, and is
// responsible for deleting it. In these unit tests, however, we
@@ -104,25 +88,21 @@ class DownloadItemTest : public testing::Test {
info_->url_chain.push_back(GURL());
info_->state = state;
- MockRequestHandle* request_handle =
- new testing::NiceMock<MockRequestHandle>;
- DownloadItem* download =
- new DownloadItemImpl(&delegate_, *(info_.get()),
- request_handle, false);
- allocated_downloads_.push_back(download);
- return download;
+ download_manager_->CreateDownloadItem(info_.get(), DownloadRequestHandle());
+ return download_manager_->GetActiveDownloadItem(info_->download_id.local());
}
protected:
DownloadStatusUpdater download_status_updater_;
+ scoped_ptr<MockDownloadManagerDelegate> download_manager_delegate_;
+ scoped_refptr<DownloadManager> download_manager_;
private:
scoped_refptr<DownloadIdFactory> id_factory_;
+ scoped_ptr<TestingProfile> profile_;
MessageLoopForUI loop_;
// UI thread.
content::TestBrowserThread ui_thread_;
- testing::NiceMock<MockDelegate> delegate_;
- std::vector<DownloadItem*> allocated_downloads_;
};
namespace {