Index: chrome/browser/download/download_ui_controller_unittest.cc |
diff --git a/chrome/browser/download/download_ui_controller_unittest.cc b/chrome/browser/download/download_ui_controller_unittest.cc |
index d3fc9cbf71c143e6c5423579a740f8b9e9cad312..31cf5e12b11ccacae86013d757a5532aaa24dfe1 100644 |
--- a/chrome/browser/download/download_ui_controller_unittest.cc |
+++ b/chrome/browser/download/download_ui_controller_unittest.cc |
@@ -2,6 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "base/bind.h" |
#include "base/files/file_path.h" |
#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_ptr.h" |
@@ -61,6 +62,8 @@ class DownloadUIControllerTest : public testing::Test { |
// delegate results in the DownloadItem* being stored in |received_item_|. |
scoped_ptr<DownloadUIController::Delegate> GetTestDelegate(); |
+ DownloadUIController::DownloadFilter NewDownloadPredicate(bool value); |
+ |
MockDownloadManager* manager() { return manager_.get(); } |
content::DownloadManager::Observer* manager_observer() { |
return manager_observer_; |
@@ -112,12 +115,21 @@ DownloadUIControllerTest::GetTestDelegate() { |
return delegate.Pass(); |
} |
-// Normal downloads that are constructed in the IN_PROGRESS state should be |
-// presented to the UI when GetTargetFilePath() returns a non-empty path. |
-// I.e. once the download target has been determined. |
+bool StaticDownloadItemPredicate(bool value, const content::DownloadItem*) { |
+ return value; |
+} |
+ |
+DownloadUIController::DownloadFilter |
+DownloadUIControllerTest::NewDownloadPredicate(bool value) { |
+ return base::Bind(&StaticDownloadItemPredicate, value); |
+} |
+ |
+// New downloads should be presented to the UI when GetTargetFilePath() returns |
+// a non-empty path. I.e. once the download target has been determined. |
TEST_F(DownloadUIControllerTest, DownloadUIController_NotifyBasic) { |
scoped_ptr<MockDownloadItem> item = GetMockDownload(); |
- DownloadUIController controller(manager(), GetTestDelegate()); |
+ DownloadUIController controller( |
+ manager(), NewDownloadPredicate(true), GetTestDelegate()); |
EXPECT_CALL(*item, GetTargetFilePath()) |
.WillOnce(ReturnRefOfCopy(base::FilePath())); |
EXPECT_CALL(*item, GetState()) |
@@ -139,12 +151,29 @@ TEST_F(DownloadUIControllerTest, DownloadUIController_NotifyBasic) { |
EXPECT_EQ(static_cast<content::DownloadItem*>(item.get()), received_item()); |
} |
+// A download that's created in an interrupted state should also be displayed if |
+// the new download filter flags it as a new download. |
+TEST_F(DownloadUIControllerTest, DownloadUIController_NotifyBasic_Interrupted) { |
+ scoped_ptr<MockDownloadItem> item = GetMockDownload(); |
+ DownloadUIController controller( |
+ manager(), NewDownloadPredicate(true), GetTestDelegate()); |
+ EXPECT_CALL(*item, GetTargetFilePath()) |
+ .WillOnce(ReturnRefOfCopy(base::FilePath(FILE_PATH_LITERAL("foo")))); |
+ EXPECT_CALL(*item, GetState()) |
+ .WillRepeatedly(Return(content::DownloadItem::INTERRUPTED)); |
+ |
+ ASSERT_TRUE(manager_observer()); |
+ manager_observer()->OnDownloadCreated(manager(), item.get()); |
+ EXPECT_EQ(static_cast<content::DownloadItem*>(item.get()), received_item()); |
+} |
+ |
// Downloads that have a target path on creation and are in the IN_PROGRESS |
// state should be displayed in the UI immediately without requiring an |
// additional OnDownloadUpdated() notification. |
TEST_F(DownloadUIControllerTest, DownloadUIController_NotifyReadyOnCreate) { |
scoped_ptr<MockDownloadItem> item = GetMockDownload(); |
- DownloadUIController controller(manager(), GetTestDelegate()); |
+ DownloadUIController controller( |
+ manager(), NewDownloadPredicate(true), GetTestDelegate()); |
EXPECT_CALL(*item, GetTargetFilePath()) |
.WillOnce(ReturnRefOfCopy(base::FilePath(FILE_PATH_LITERAL("foo")))); |
EXPECT_CALL(*item, GetState()) |
@@ -155,11 +184,13 @@ TEST_F(DownloadUIControllerTest, DownloadUIController_NotifyReadyOnCreate) { |
EXPECT_EQ(static_cast<content::DownloadItem*>(item.get()), received_item()); |
} |
-// History downloads (downloads that are not in IN_PROGRESS on create) should |
-// not be displayed on the shelf. |
+// Downloads that are flagged by the new download filter as not being a new |
+// download at the time OnDownloadCreated is called should not be displayed in |
+// the UI. |
TEST_F(DownloadUIControllerTest, DownloadUIController_NoNotifyHistory) { |
scoped_ptr<MockDownloadItem> item = GetMockDownload(); |
- DownloadUIController controller(manager(), GetTestDelegate()); |
+ DownloadUIController controller( |
+ manager(), NewDownloadPredicate(false), GetTestDelegate()); |
EXPECT_CALL(*item, GetState()) |
.WillRepeatedly(Return(content::DownloadItem::COMPLETE)); |