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

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 comments on previous review 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() {}
mlamouri (slow - plz ping) 2015/08/07 10:11:12 nit: = default;
Lalit Maganti 2015/08/07 13:04:30 Done.
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 CreateBitmap(int width, int height) {
mlamouri (slow - plz ping) 2015/08/07 10:11:12 nit: CreateDummyBitmap()
Lalit Maganti 2015/08/07 13:04:30 Done.
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 { CreateBitmap(10, 10) };
39 ASSERT_EQ(0, FindBitmap(10, vector));
40 }
41
42 TEST_F(ManifestIconDownloaderTest, BiggerIsChosen) {
43 std::vector<SkBitmap> vector { CreateBitmap(20, 20) };
44 ASSERT_EQ(0, FindBitmap(10, vector));
45 }
46
47 TEST_F(ManifestIconDownloaderTest, SmallerIsIgnored) {
48 std::vector<SkBitmap> vector { CreateBitmap(10, 10) };
49 ASSERT_EQ(-1, FindBitmap(20, vector));
50 }
51
52 TEST_F(ManifestIconDownloaderTest, ExactIsPreferredOverBigger) {
53 std::vector<SkBitmap> vector { CreateBitmap(20, 20), CreateBitmap(10, 10) };
54 ASSERT_EQ(1, FindBitmap(10, vector));
55 }
56
57 TEST_F(ManifestIconDownloaderTest, ExactIsPreferredOverSmaller) {
58 std::vector<SkBitmap> vector { CreateBitmap(10, 10), CreateBitmap(20, 20) };
59 ASSERT_EQ(1, FindBitmap(20, vector));
60 }
61
62 TEST_F(ManifestIconDownloaderTest, ClosestToExactIsChosen) {
63 std::vector<SkBitmap> vector { CreateBitmap(20, 20), CreateBitmap(25, 25) };
64 ASSERT_EQ(0, FindBitmap(10, vector));
65 }
66
67 TEST_F(ManifestIconDownloaderTest, ClosestToExactIsChosenUnordered) {
68 std::vector<SkBitmap> vector { CreateBitmap(25, 25), CreateBitmap(20, 20) };
69 ASSERT_EQ(1, FindBitmap(10, vector));
70 }
mlamouri (slow - plz ping) 2015/08/07 10:11:12 Could you test: - bitmap is 10x10, 8x8, 6x6 and id
Lalit Maganti 2015/08/07 13:04:30 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698