Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5272)

Unified Diff: chrome/browser/download/download_item_model_unittest.cc

Issue 2219953004: Refactor download image-MIME-type-detection code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add more tests Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/download/download_item_model_unittest.cc
diff --git a/chrome/browser/download/download_item_model_unittest.cc b/chrome/browser/download/download_item_model_unittest.cc
index dfb07feff443ef48d4b1f11afa0a28ef4cd563c8..7325f00b07b25ae4eba581f975e7309a26d9b690 100644
--- a/chrome/browser/download/download_item_model_unittest.cc
+++ b/chrome/browser/download/download_item_model_unittest.cc
@@ -30,6 +30,7 @@ using safe_browsing::DownloadFileType;
using ::testing::Mock;
using ::testing::NiceMock;
using ::testing::Return;
+using ::testing::ReturnRef;
using ::testing::ReturnRefOfCopy;
using ::testing::SetArgPointee;
using ::testing::_;
@@ -382,6 +383,33 @@ TEST_F(DownloadItemModelTest, DangerLevel) {
EXPECT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE, model().GetDangerLevel());
}
+TEST_F(DownloadItemModelTest, HasSupportedImageMimeType) {
+ SetupDownloadItemDefaults();
+
+ // When the item has a supported image MIME type, true should be returned.
+ ON_CALL(item(), GetMimeType()).WillByDefault(Return("image/png"));
+ EXPECT_TRUE(model().HasSupportedImageMimeType());
+
+ // An unsupported MIME type should result in false being returned...
+ ON_CALL(item(), GetMimeType()).WillByDefault(Return("image/unsupported"));
+ EXPECT_FALSE(model().HasSupportedImageMimeType());
+
+ // ... unless the target path has a well-known image extension.
+ const base::FilePath kImagePath(FILE_PATH_LITERAL("/foo/image.png"));
+ ON_CALL(item(), GetTargetFilePath()).WillByDefault(ReturnRef(kImagePath));
+ EXPECT_TRUE(model().HasSupportedImageMimeType());
+
+ // .txt and missing extensions should also result in false being returned.
+ const base::FilePath kTextPath(FILE_PATH_LITERAL("/foo/image.txt"));
+ ON_CALL(item(), GetTargetFilePath()).WillByDefault(ReturnRef(kTextPath));
+ EXPECT_FALSE(model().HasSupportedImageMimeType());
+
+ const base::FilePath kNoExtensionPath(FILE_PATH_LITERAL("/foo/image."));
+ ON_CALL(item(), GetTargetFilePath())
+ .WillByDefault(ReturnRef(kNoExtensionPath));
+ EXPECT_FALSE(model().HasSupportedImageMimeType());
+}
+
TEST_F(DownloadItemModelTest, ShouldRemoveFromShelfWhenComplete) {
const struct TestCase {
DownloadItem::DownloadState state;
« no previous file with comments | « chrome/browser/download/download_item_model.cc ('k') | chrome/browser/download/notification/download_item_notification.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698