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

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

Issue 1261143004: Implement manifest icon downloader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address silly regressions due to switching between Android <-> Linux Created 5 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
(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 "testing/gtest/include/gtest/gtest.h"
11
12 class ManifestIconDownloaderTest : public testing::Test {
13 protected:
14 ManifestIconDownloaderTest() = default;
15 ~ManifestIconDownloaderTest() override = default;
16
17 int FindBitmap(const int ideal_icon_size_in_px,
18 const std::vector<SkBitmap>& bitmaps) {
19 return ManifestIconDownloader::FindClosestBitmapIndex(
20 ideal_icon_size_in_px, bitmaps);
21 }
22
23 SkBitmap CreateDummyBitmap(int width, int height) {
24 SkBitmap bitmap;
25 bitmap.allocN32Pixels(width, height);
26 bitmap.setImmutable();
27 return bitmap;
28 }
29
30 DISALLOW_COPY_AND_ASSIGN(ManifestIconDownloaderTest);
31 };
32
33 TEST_F(ManifestIconDownloaderTest, NoIcons) {
34 ASSERT_EQ(-1, FindBitmap(0, std::vector<SkBitmap>()));
35 }
36
37 TEST_F(ManifestIconDownloaderTest, ExactIsChosen) {
38 std::vector<SkBitmap> vector;
39 vector.push_back(CreateDummyBitmap(10, 10));
40
41 ASSERT_EQ(0, FindBitmap(10, vector));
42 }
43
44 TEST_F(ManifestIconDownloaderTest, BiggerIsChosen) {
45 std::vector<SkBitmap> vector;
46 vector.push_back(CreateDummyBitmap(20, 20));
47
48 ASSERT_EQ(0, FindBitmap(10, vector));
49 }
50
51 TEST_F(ManifestIconDownloaderTest, SmallerBelowIsIgnored) {
52 std::vector<SkBitmap> vector;
53 vector.push_back(CreateDummyBitmap(10, 10));
54
55 ASSERT_EQ(-1, FindBitmap(20, vector));
56 }
57
58 TEST_F(ManifestIconDownloaderTest, ExactIsPreferredOverBigger) {
59 std::vector<SkBitmap> vector;
60 vector.push_back(CreateDummyBitmap(20, 20));
61 vector.push_back(CreateDummyBitmap(10, 10));
62
63 ASSERT_EQ(1, FindBitmap(10, vector));
64 }
65
66 TEST_F(ManifestIconDownloaderTest, ExactIsPreferredOverSmaller) {
67 std::vector<SkBitmap> vector;
68 vector.push_back(CreateDummyBitmap(20, 20));
69 vector.push_back(CreateDummyBitmap(10, 10));
70
71 ASSERT_EQ(0, FindBitmap(20, vector));
72 }
73
74 TEST_F(ManifestIconDownloaderTest, BiggerIsPreferredOverCloserSmaller) {
75 std::vector<SkBitmap> vector;
76 vector.push_back(CreateDummyBitmap(20, 20));
77 vector.push_back(CreateDummyBitmap(10, 10));
78
79 ASSERT_EQ(0, FindBitmap(11, vector));
80 }
81
82 TEST_F(ManifestIconDownloaderTest, ClosestToExactIsChosen) {
83 std::vector<SkBitmap> vector;
84 vector.push_back(CreateDummyBitmap(25, 25));
85 vector.push_back(CreateDummyBitmap(20, 20));
86
87 ASSERT_EQ(1, FindBitmap(10, vector));
88 }
89
90 TEST_F(ManifestIconDownloaderTest, ClosestToExactIsChosenUnordered) {
gone 2015/08/19 22:21:08 how is this test different from ClosestToExactIsCh
Lalit Maganti 2015/08/20 16:48:00 It's not anymore because of the sorting restrictio
91 std::vector<SkBitmap> vector;
92 vector.push_back(CreateDummyBitmap(25, 25));
93 vector.push_back(CreateDummyBitmap(20, 20));
94
95 ASSERT_EQ(1, FindBitmap(10, vector));
96 }
97
98 TEST_F(ManifestIconDownloaderTest, MixedReturnsBiggestClosest) {
99 std::vector<SkBitmap> vector;
100 vector.push_back(CreateDummyBitmap(10, 10));
101 vector.push_back(CreateDummyBitmap(8, 8));
102 vector.push_back(CreateDummyBitmap(6, 6));
103
104 ASSERT_EQ(0, FindBitmap(9, vector));
105 }
106
107 TEST_F(ManifestIconDownloaderTest, MixedCanReturnMiddle) {
108 std::vector<SkBitmap> vector;
109 vector.push_back(CreateDummyBitmap(10, 10));
110 vector.push_back(CreateDummyBitmap(8, 8));
111 vector.push_back(CreateDummyBitmap(6, 6));
112
113 ASSERT_EQ(1, FindBitmap(7, vector));
114 }
115
116 TEST_F(ManifestIconDownloaderTest, NonSquareHeightIsIgnored) {
117 std::vector<SkBitmap> vector;
118 vector.push_back(CreateDummyBitmap(15, 10));
119
120 ASSERT_EQ(-1, FindBitmap(10, vector));
121 }
122
123 TEST_F(ManifestIconDownloaderTest, NonSquareWidthIsIgnored) {
124 std::vector<SkBitmap> vector;
125 vector.push_back(CreateDummyBitmap(15, 10));
126
127 ASSERT_EQ(-1, FindBitmap(15, vector));
128 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698