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

Side by Side Diff: chrome/browser/manifest/manifest_icon_downloader_unittest.cc

Issue 2933743002: Move chrome/browser/manifest to content/browser. (Closed)
Patch Set: rebased Created 3 years, 6 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/manifest/manifest_icon_downloader.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "base/macros.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
13
14 class ManifestIconDownloaderTest : public testing::Test {
15 protected:
16 ManifestIconDownloaderTest() = default;
17 ~ManifestIconDownloaderTest() override = default;
18
19 int FindBitmap(const int ideal_icon_size_in_px,
20 const int minimum_icon_size_in_px,
21 const std::vector<SkBitmap>& bitmaps) {
22 return ManifestIconDownloader::FindClosestBitmapIndex(
23 ideal_icon_size_in_px, minimum_icon_size_in_px, bitmaps);
24 }
25
26 SkBitmap CreateDummyBitmap(int width, int height) {
27 SkBitmap bitmap;
28 bitmap.allocN32Pixels(width, height);
29 bitmap.setImmutable();
30 return bitmap;
31 }
32
33 DISALLOW_COPY_AND_ASSIGN(ManifestIconDownloaderTest);
34 };
35
36 TEST_F(ManifestIconDownloaderTest, NoIcons) {
37 ASSERT_EQ(-1, FindBitmap(0, 0, std::vector<SkBitmap>()));
38 }
39
40 TEST_F(ManifestIconDownloaderTest, ExactIsChosen) {
41 std::vector<SkBitmap> bitmaps;
42 bitmaps.push_back(CreateDummyBitmap(10, 10));
43
44 ASSERT_EQ(0, FindBitmap(10, 0, bitmaps));
45 }
46
47 TEST_F(ManifestIconDownloaderTest, BiggerIsChosen) {
48 std::vector<SkBitmap> bitmaps;
49 bitmaps.push_back(CreateDummyBitmap(20, 20));
50
51 ASSERT_EQ(0, FindBitmap(10, 0, bitmaps));
52 }
53
54 TEST_F(ManifestIconDownloaderTest, SmallerBelowMinimumIsIgnored) {
55 std::vector<SkBitmap> bitmaps;
56 bitmaps.push_back(CreateDummyBitmap(10, 10));
57
58 ASSERT_EQ(-1, FindBitmap(20, 15, bitmaps));
59 }
60
61 TEST_F(ManifestIconDownloaderTest, SmallerAboveMinimumIsChosen) {
62 std::vector<SkBitmap> bitmaps;
63 bitmaps.push_back(CreateDummyBitmap(15, 15));
64
65 ASSERT_EQ(0, FindBitmap(20, 15, bitmaps));
66 }
67
68 TEST_F(ManifestIconDownloaderTest, ExactIsPreferredOverBigger) {
69 std::vector<SkBitmap> bitmaps;
70 bitmaps.push_back(CreateDummyBitmap(20, 20));
71 bitmaps.push_back(CreateDummyBitmap(10, 10));
72
73 ASSERT_EQ(1, FindBitmap(10, 0, bitmaps));
74 }
75
76 TEST_F(ManifestIconDownloaderTest, ExactIsPreferredOverSmaller) {
77 std::vector<SkBitmap> bitmaps;
78 bitmaps.push_back(CreateDummyBitmap(20, 20));
79 bitmaps.push_back(CreateDummyBitmap(10, 10));
80
81 ASSERT_EQ(0, FindBitmap(20, 0, bitmaps));
82 }
83
84 TEST_F(ManifestIconDownloaderTest, BiggerIsPreferredOverCloserSmaller) {
85 std::vector<SkBitmap> bitmaps;
86 bitmaps.push_back(CreateDummyBitmap(20, 20));
87 bitmaps.push_back(CreateDummyBitmap(10, 10));
88
89 ASSERT_EQ(0, FindBitmap(11, 0, bitmaps));
90 }
91
92 TEST_F(ManifestIconDownloaderTest, ClosestToExactIsChosen) {
93 std::vector<SkBitmap> bitmaps;
94 bitmaps.push_back(CreateDummyBitmap(25, 25));
95 bitmaps.push_back(CreateDummyBitmap(20, 20));
96
97 ASSERT_EQ(1, FindBitmap(10, 0, bitmaps));
98 }
99
100 TEST_F(ManifestIconDownloaderTest, MixedReturnsBiggestClosest) {
101 std::vector<SkBitmap> bitmaps;
102 bitmaps.push_back(CreateDummyBitmap(10, 10));
103 bitmaps.push_back(CreateDummyBitmap(8, 8));
104 bitmaps.push_back(CreateDummyBitmap(6, 6));
105
106 ASSERT_EQ(0, FindBitmap(9, 0, bitmaps));
107 }
108
109 TEST_F(ManifestIconDownloaderTest, MixedCanReturnMiddle) {
110 std::vector<SkBitmap> bitmaps;
111 bitmaps.push_back(CreateDummyBitmap(10, 10));
112 bitmaps.push_back(CreateDummyBitmap(8, 8));
113 bitmaps.push_back(CreateDummyBitmap(6, 6));
114
115 ASSERT_EQ(1, FindBitmap(7, 0, bitmaps));
116 }
117
118 TEST_F(ManifestIconDownloaderTest, SquareIsPickedOverNonSquare) {
119 std::vector<SkBitmap> bitmaps;
120 bitmaps.push_back(CreateDummyBitmap(5, 5));
121 bitmaps.push_back(CreateDummyBitmap(10, 15));
122
123 ASSERT_EQ(0, FindBitmap(15, 5, bitmaps));
124 ASSERT_EQ(0, FindBitmap(10, 5, bitmaps));
125 }
126
127 TEST_F(ManifestIconDownloaderTest, MostSquareNonSquareIsPicked) {
128 std::vector<SkBitmap> bitmaps;
129 bitmaps.push_back(CreateDummyBitmap(25, 35));
130 bitmaps.push_back(CreateDummyBitmap(10, 11));
131
132 ASSERT_EQ(1, FindBitmap(25, 0, bitmaps));
133 ASSERT_EQ(1, FindBitmap(35, 0, bitmaps));
134 }
135
136 TEST_F(ManifestIconDownloaderTest, NonSquareBelowMinimumIsNotPicked) {
137 std::vector<SkBitmap> bitmaps;
138 bitmaps.push_back(CreateDummyBitmap(10, 15));
139 bitmaps.push_back(CreateDummyBitmap(15, 10));
140
141 ASSERT_EQ(-1, FindBitmap(15, 11, bitmaps));
142 }
OLDNEW
« no previous file with comments | « chrome/browser/manifest/manifest_icon_downloader.cc ('k') | chrome/browser/manifest/manifest_icon_selector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698