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

Side by Side 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: fix windows compile, hopefully 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/download/download_item_model.h" 5 #include "chrome/browser/download/download_item_model.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <vector> 10 #include <vector>
(...skipping 12 matching lines...) Expand all
23 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
24 #include "ui/base/text/bytes_formatting.h" 24 #include "ui/base/text/bytes_formatting.h"
25 #include "ui/gfx/font_list.h" 25 #include "ui/gfx/font_list.h"
26 #include "ui/gfx/text_utils.h" 26 #include "ui/gfx/text_utils.h"
27 27
28 using content::DownloadItem; 28 using content::DownloadItem;
29 using safe_browsing::DownloadFileType; 29 using safe_browsing::DownloadFileType;
30 using ::testing::Mock; 30 using ::testing::Mock;
31 using ::testing::NiceMock; 31 using ::testing::NiceMock;
32 using ::testing::Return; 32 using ::testing::Return;
33 using ::testing::ReturnRef;
33 using ::testing::ReturnRefOfCopy; 34 using ::testing::ReturnRefOfCopy;
34 using ::testing::SetArgPointee; 35 using ::testing::SetArgPointee;
35 using ::testing::_; 36 using ::testing::_;
36 37
37 namespace { 38 namespace {
38 39
39 // Create a char array that has as many elements as there are download 40 // Create a char array that has as many elements as there are download
40 // interrupt reasons. We can then use that in a static_assert to make sure 41 // interrupt reasons. We can then use that in a static_assert to make sure
41 // that all the interrupt reason codes are accounted for. The reason codes are 42 // that all the interrupt reason codes are accounted for. The reason codes are
42 // unfortunately sparse, making this necessary. 43 // unfortunately sparse, making this necessary.
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 TEST_F(DownloadItemModelTest, DangerLevel) { 376 TEST_F(DownloadItemModelTest, DangerLevel) {
376 SetupDownloadItemDefaults(); 377 SetupDownloadItemDefaults();
377 378
378 // Default danger level is NOT_DANGEROUS. 379 // Default danger level is NOT_DANGEROUS.
379 EXPECT_EQ(DownloadFileType::NOT_DANGEROUS, model().GetDangerLevel()); 380 EXPECT_EQ(DownloadFileType::NOT_DANGEROUS, model().GetDangerLevel());
380 381
381 model().SetDangerLevel(DownloadFileType::ALLOW_ON_USER_GESTURE); 382 model().SetDangerLevel(DownloadFileType::ALLOW_ON_USER_GESTURE);
382 EXPECT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE, model().GetDangerLevel()); 383 EXPECT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE, model().GetDangerLevel());
383 } 384 }
384 385
386 TEST_F(DownloadItemModelTest, HasSupportedImageMimeType) {
387 SetupDownloadItemDefaults();
388
389 // When the item has a supported image MIME type, true should be returned.
390 ON_CALL(item(), GetMimeType()).WillByDefault(Return("image/png"));
391 EXPECT_TRUE(model().HasSupportedImageMimeType());
392
393 // An unsupported MIME type should result in false being returned...
394 ON_CALL(item(), GetMimeType()).WillByDefault(Return("image/unsupported"));
395 EXPECT_FALSE(model().HasSupportedImageMimeType());
396
397 // ... unless the target path has a well-known image extension.
398 const base::FilePath kTargetPath(FILE_PATH_LITERAL("/foo/image.png"));
399 ON_CALL(item(), GetTargetFilePath()).WillByDefault(ReturnRef(kTargetPath));
400 EXPECT_TRUE(model().HasSupportedImageMimeType());
svaldez 2016/08/08 15:07:52 Can you add a test for /foo/image.txt returning fa
Daniel Erat 2016/08/08 16:02:14 Done.
401 }
402
385 TEST_F(DownloadItemModelTest, ShouldRemoveFromShelfWhenComplete) { 403 TEST_F(DownloadItemModelTest, ShouldRemoveFromShelfWhenComplete) {
386 const struct TestCase { 404 const struct TestCase {
387 DownloadItem::DownloadState state; 405 DownloadItem::DownloadState state;
388 bool is_dangerous; // Expectation for IsDangerous(). 406 bool is_dangerous; // Expectation for IsDangerous().
389 bool is_auto_open; // Expectation for GetOpenWhenComplete(). 407 bool is_auto_open; // Expectation for GetOpenWhenComplete().
390 bool auto_opened; // Whether the download was successfully 408 bool auto_opened; // Whether the download was successfully
391 // auto-opened. Expecation for GetAutoOpened(). 409 // auto-opened. Expecation for GetAutoOpened().
392 bool expected_result; 410 bool expected_result;
393 } kTestCases[] = { 411 } kTestCases[] = {
394 // All the valid combinations of state, is_dangerous, is_auto_open and 412 // All the valid combinations of state, is_dangerous, is_auto_open and
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 EXPECT_CALL(item(), GetAutoOpened()) 447 EXPECT_CALL(item(), GetAutoOpened())
430 .WillRepeatedly(Return(test_case.auto_opened)); 448 .WillRepeatedly(Return(test_case.auto_opened));
431 449
432 EXPECT_EQ(test_case.expected_result, 450 EXPECT_EQ(test_case.expected_result,
433 model().ShouldRemoveFromShelfWhenComplete()) 451 model().ShouldRemoveFromShelfWhenComplete())
434 << "Test case: " << i; 452 << "Test case: " << i;
435 Mock::VerifyAndClearExpectations(&item()); 453 Mock::VerifyAndClearExpectations(&item());
436 Mock::VerifyAndClearExpectations(&model()); 454 Mock::VerifyAndClearExpectations(&model());
437 } 455 }
438 } 456 }
OLDNEW
« 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