diff options
author | benjhayden@chromium.org <benjhayden@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-31 20:00:08 +0000 |
---|---|---|
committer | benjhayden@chromium.org <benjhayden@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-31 20:00:08 +0000 |
commit | 423939db27e73f8fe4dd5402a31856932e52cedb (patch) | |
tree | e671c21f50e007d86b6866324b4f93b7edf371cd /chrome/browser/download/download_shelf_unittest.cc | |
parent | b7f9bbd4e9c2d9835da8765471206f357efde2aa (diff) | |
download | chromium_src-423939db27e73f8fe4dd5402a31856932e52cedb.zip chromium_src-423939db27e73f8fe4dd5402a31856932e52cedb.tar.gz chromium_src-423939db27e73f8fe4dd5402a31856932e52cedb.tar.bz2 |
chrome.downloads.setShelfEnabled(boolean)
Reviewers:
meacer: basic idea and features
sail: profiles
sky: browser/ui/*
jam: automation/testing_automation_provider.cc
asanka: everything
Closes and Disables the shelf for every browser window associated with the Profile associated with the extension.
ExtensionDownloadsEventRouter manages a vector of Extensions that have disabled the shelf. When this vector is empty, the shelf is enabled. ExtensionDownloadsEventRouter listens for extension unload events so that the shelf will be re-enabled when the extension is disabled or uninstalled. DownloadShelf access this information through DownloadService, which owns ExtensionDownloadsEventRouter.
Extensions need to call setShelfEnabled(false) every time the browser is started. There is no persistence.
Requires permission "downloads.shelf" with no warning, as suggested by meacer.
Changed DownloadServiceFactory::GetForProfile to GetForBrowserContext so that DownloadShelf can use DownloadItem::GetBrowserContext().
R=asanka@chromium.org, asargent@chromium.org, jam@chromium.org, meacer@chromium.org, sky@chromium.org
Review URL: https://codereview.chromium.org/20474002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214810 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download/download_shelf_unittest.cc')
-rw-r--r-- | chrome/browser/download/download_shelf_unittest.cc | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/chrome/browser/download/download_shelf_unittest.cc b/chrome/browser/download/download_shelf_unittest.cc index 3a16773..c16701b 100644 --- a/chrome/browser/download/download_shelf_unittest.cc +++ b/chrome/browser/download/download_shelf_unittest.cc @@ -6,8 +6,14 @@ #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" #include "base/run_loop.h" +#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/download/download_item_model.h" +#include "chrome/browser/download/download_service.h" +#include "chrome/browser/download/download_service_factory.h" #include "chrome/browser/download/test_download_shelf.h" +#include "chrome/common/extensions/extension.h" +#include "chrome/test/base/testing_profile.h" +#include "content/public/browser/notification_service.h" #include "content/public/test/mock_download_item.h" #include "content/public/test/mock_download_manager.h" #include "content/public/test/test_browser_thread.h" @@ -22,6 +28,11 @@ using content::DownloadItem; namespace { +BrowserContextKeyedService* CreateDownloadService( + content::BrowserContext* context) { + return new DownloadService(Profile::FromBrowserContext(context)); +} + class DownloadShelfTest : public testing::Test { public: DownloadShelfTest(); @@ -36,6 +47,17 @@ class DownloadShelfTest : public testing::Test { TestDownloadShelf* shelf() { return &shelf_; } + Profile* profile() { return profile_.get(); } + + virtual void SetUp() OVERRIDE { + DownloadServiceFactory::GetInstance()->SetTestingFactory( + profile(), &CreateDownloadService); + } + + virtual void TearDown() OVERRIDE { + DownloadServiceFactory::GetInstance()->SetTestingFactory( + profile(), NULL); + } private: scoped_ptr<content::MockDownloadItem> GetInProgressMockDownload(); @@ -45,10 +67,12 @@ class DownloadShelfTest : public testing::Test { scoped_ptr<content::MockDownloadItem> download_item_; scoped_ptr<content::MockDownloadManager> download_manager_; TestDownloadShelf shelf_; + scoped_ptr<TestingProfile> profile_; }; DownloadShelfTest::DownloadShelfTest() - : ui_thread_(content::BrowserThread::UI, &message_loop_) { + : ui_thread_(content::BrowserThread::UI, &message_loop_), + profile_(new TestingProfile()) { download_item_.reset(new ::testing::NiceMock<content::MockDownloadItem>()); ON_CALL(*download_item_, GetAutoOpened()).WillByDefault(Return(false)); ON_CALL(*download_item_, GetMimeType()).WillByDefault(Return("text/plain")); @@ -62,11 +86,15 @@ DownloadShelfTest::DownloadShelfTest() ON_CALL(*download_item_, IsTemporary()).WillByDefault(Return(false)); ON_CALL(*download_item_, ShouldOpenFileBasedOnExtension()) .WillByDefault(Return(false)); + ON_CALL(*download_item_, GetBrowserContext()) + .WillByDefault(Return(profile())); download_manager_.reset( new ::testing::NiceMock<content::MockDownloadManager>()); ON_CALL(*download_manager_, GetDownload(_)) .WillByDefault(Return(download_item_.get())); + ON_CALL(*download_manager_, GetBrowserContext()) + .WillByDefault(Return(profile())); shelf_.set_download_manager(download_manager_.get()); } |