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() {} |
| 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) { |
| 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 } |
OLD | NEW |