OLD | NEW |
(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 int minimum_icon_size_in_px, |
| 19 const std::vector<SkBitmap>& bitmaps) { |
| 20 return ManifestIconDownloader::FindClosestBitmapIndex( |
| 21 ideal_icon_size_in_px, minimum_icon_size_in_px, bitmaps); |
| 22 } |
| 23 |
| 24 SkBitmap CreateDummyBitmap(int width, int height) { |
| 25 SkBitmap bitmap; |
| 26 bitmap.allocN32Pixels(width, height); |
| 27 bitmap.setImmutable(); |
| 28 return bitmap; |
| 29 } |
| 30 |
| 31 DISALLOW_COPY_AND_ASSIGN(ManifestIconDownloaderTest); |
| 32 }; |
| 33 |
| 34 TEST_F(ManifestIconDownloaderTest, NoIcons) { |
| 35 ASSERT_EQ(-1, FindBitmap(0, 0, std::vector<SkBitmap>())); |
| 36 } |
| 37 |
| 38 TEST_F(ManifestIconDownloaderTest, ExactIsChosen) { |
| 39 std::vector<SkBitmap> bitmaps; |
| 40 bitmaps.push_back(CreateDummyBitmap(10, 10)); |
| 41 |
| 42 ASSERT_EQ(0, FindBitmap(10, 0, bitmaps)); |
| 43 } |
| 44 |
| 45 TEST_F(ManifestIconDownloaderTest, BiggerIsChosen) { |
| 46 std::vector<SkBitmap> bitmaps; |
| 47 bitmaps.push_back(CreateDummyBitmap(20, 20)); |
| 48 |
| 49 ASSERT_EQ(0, FindBitmap(10, 0, bitmaps)); |
| 50 } |
| 51 |
| 52 TEST_F(ManifestIconDownloaderTest, SmallerBelowMinimumIsIgnored) { |
| 53 std::vector<SkBitmap> bitmaps; |
| 54 bitmaps.push_back(CreateDummyBitmap(10, 10)); |
| 55 |
| 56 ASSERT_EQ(-1, FindBitmap(20, 15, bitmaps)); |
| 57 } |
| 58 |
| 59 TEST_F(ManifestIconDownloaderTest, SmallerAboveMinimumIsChosen) { |
| 60 std::vector<SkBitmap> bitmaps; |
| 61 bitmaps.push_back(CreateDummyBitmap(15, 15)); |
| 62 |
| 63 ASSERT_EQ(0, FindBitmap(20, 15, bitmaps)); |
| 64 } |
| 65 |
| 66 TEST_F(ManifestIconDownloaderTest, ExactIsPreferredOverBigger) { |
| 67 std::vector<SkBitmap> bitmaps; |
| 68 bitmaps.push_back(CreateDummyBitmap(20, 20)); |
| 69 bitmaps.push_back(CreateDummyBitmap(10, 10)); |
| 70 |
| 71 ASSERT_EQ(1, FindBitmap(10, 0, bitmaps)); |
| 72 } |
| 73 |
| 74 TEST_F(ManifestIconDownloaderTest, ExactIsPreferredOverSmaller) { |
| 75 std::vector<SkBitmap> bitmaps; |
| 76 bitmaps.push_back(CreateDummyBitmap(20, 20)); |
| 77 bitmaps.push_back(CreateDummyBitmap(10, 10)); |
| 78 |
| 79 ASSERT_EQ(0, FindBitmap(20, 0, bitmaps)); |
| 80 } |
| 81 |
| 82 TEST_F(ManifestIconDownloaderTest, BiggerIsPreferredOverCloserSmaller) { |
| 83 std::vector<SkBitmap> bitmaps; |
| 84 bitmaps.push_back(CreateDummyBitmap(20, 20)); |
| 85 bitmaps.push_back(CreateDummyBitmap(10, 10)); |
| 86 |
| 87 ASSERT_EQ(0, FindBitmap(11, 0, bitmaps)); |
| 88 } |
| 89 |
| 90 TEST_F(ManifestIconDownloaderTest, ClosestToExactIsChosen) { |
| 91 std::vector<SkBitmap> bitmaps; |
| 92 bitmaps.push_back(CreateDummyBitmap(25, 25)); |
| 93 bitmaps.push_back(CreateDummyBitmap(20, 20)); |
| 94 |
| 95 ASSERT_EQ(1, FindBitmap(10, 0, bitmaps)); |
| 96 } |
| 97 |
| 98 TEST_F(ManifestIconDownloaderTest, MixedReturnsBiggestClosest) { |
| 99 std::vector<SkBitmap> bitmaps; |
| 100 bitmaps.push_back(CreateDummyBitmap(10, 10)); |
| 101 bitmaps.push_back(CreateDummyBitmap(8, 8)); |
| 102 bitmaps.push_back(CreateDummyBitmap(6, 6)); |
| 103 |
| 104 ASSERT_EQ(0, FindBitmap(9, 0, bitmaps)); |
| 105 } |
| 106 |
| 107 TEST_F(ManifestIconDownloaderTest, MixedCanReturnMiddle) { |
| 108 std::vector<SkBitmap> bitmaps; |
| 109 bitmaps.push_back(CreateDummyBitmap(10, 10)); |
| 110 bitmaps.push_back(CreateDummyBitmap(8, 8)); |
| 111 bitmaps.push_back(CreateDummyBitmap(6, 6)); |
| 112 |
| 113 ASSERT_EQ(1, FindBitmap(7, 0, bitmaps)); |
| 114 } |
| 115 |
| 116 TEST_F(ManifestIconDownloaderTest, NonSquareIsIgnored) { |
| 117 std::vector<SkBitmap> bitmaps; |
| 118 bitmaps.push_back(CreateDummyBitmap(15, 10)); |
| 119 bitmaps.push_back(CreateDummyBitmap(10, 15)); |
| 120 |
| 121 ASSERT_EQ(-1, FindBitmap(15, 0, bitmaps)); |
| 122 ASSERT_EQ(-1, FindBitmap(10, 0, bitmaps)); |
| 123 } |
OLD | NEW |