Index: chrome/browser/manifest/manifest_icon_downloader_unittest.cc |
diff --git a/chrome/browser/manifest/manifest_icon_downloader_unittest.cc b/chrome/browser/manifest/manifest_icon_downloader_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4affb44ef93530657f5760ba558d5d7fdc3e462a |
--- /dev/null |
+++ b/chrome/browser/manifest/manifest_icon_downloader_unittest.cc |
@@ -0,0 +1,102 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/manifest/manifest_icon_downloader.h" |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+class ManifestIconDownloaderTest : public testing::Test { |
+ protected: |
+ ManifestIconDownloaderTest() = default; |
+ ~ManifestIconDownloaderTest() override = default; |
+ |
+ int FindBitmap(const int ideal_icon_size_in_px, |
+ const std::vector<SkBitmap>& bitmaps) { |
+ return ManifestIconDownloader::FindClosestBitmapIndex( |
+ ideal_icon_size_in_px, bitmaps); |
+ } |
+ |
+ SkBitmap CreateDummyBitmap(int width, int height) { |
+ SkBitmap bitmap; |
+ bitmap.allocN32Pixels(width, height); |
+ bitmap.setImmutable(); |
+ return bitmap; |
+ } |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ManifestIconDownloaderTest); |
+}; |
+ |
+TEST_F(ManifestIconDownloaderTest, NoIcons) { |
+ ASSERT_EQ(-1, FindBitmap(0, std::vector<SkBitmap>())); |
+} |
+ |
+TEST_F(ManifestIconDownloaderTest, ExactIsChosen) { |
+ std::vector<SkBitmap> vector { CreateDummyBitmap(10, 10) }; |
+ ASSERT_EQ(0, FindBitmap(10, vector)); |
+} |
+ |
+TEST_F(ManifestIconDownloaderTest, BiggerIsChosen) { |
+ std::vector<SkBitmap> vector { CreateDummyBitmap(20, 20) }; |
+ ASSERT_EQ(0, FindBitmap(10, vector)); |
+} |
+ |
+TEST_F(ManifestIconDownloaderTest, SmallerIsIgnored) { |
+ std::vector<SkBitmap> vector { CreateDummyBitmap(10, 10) }; |
+ ASSERT_EQ(-1, FindBitmap(20, vector)); |
+} |
+ |
+TEST_F(ManifestIconDownloaderTest, ExactIsPreferredOverBigger) { |
+ std::vector<SkBitmap> vector { |
+ CreateDummyBitmap(20, 20), CreateDummyBitmap(10, 10) |
+ }; |
+ ASSERT_EQ(1, FindBitmap(10, vector)); |
+} |
+ |
+TEST_F(ManifestIconDownloaderTest, ExactIsPreferredOverSmaller) { |
+ std::vector<SkBitmap> vector { |
+ CreateDummyBitmap(10, 10), CreateDummyBitmap(20, 20) |
+ }; |
+ ASSERT_EQ(1, FindBitmap(20, vector)); |
+} |
+ |
+TEST_F(ManifestIconDownloaderTest, ClosestToExactIsChosen) { |
+ std::vector<SkBitmap> vector { |
+ CreateDummyBitmap(20, 20), CreateDummyBitmap(25, 25) |
+ }; |
+ ASSERT_EQ(0, FindBitmap(10, vector)); |
+} |
+ |
+TEST_F(ManifestIconDownloaderTest, ClosestToExactIsChosenUnordered) { |
+ std::vector<SkBitmap> vector { |
+ CreateDummyBitmap(25, 25), CreateDummyBitmap(20, 20) |
+ }; |
+ ASSERT_EQ(1, FindBitmap(10, vector)); |
+} |
+ |
+TEST_F(ManifestIconDownloaderTest, MixedReturnsClosestAndBiggest) { |
+ std::vector<SkBitmap> vector { |
+ CreateDummyBitmap(10, 10), CreateDummyBitmap(8, 8), CreateDummyBitmap(6, 6) |
+ }; |
+ ASSERT_EQ(0, FindBitmap(9, vector)); |
+} |
+ |
+TEST_F(ManifestIconDownloaderTest, MixedCanReturnMiddle) { |
+ std::vector<SkBitmap> vector { |
+ CreateDummyBitmap(10, 10), CreateDummyBitmap(8, 8), CreateDummyBitmap(6, 6) |
+ }; |
+ ASSERT_EQ(1, FindBitmap(7, vector)); |
+} |
+ |
+TEST_F(ManifestIconDownloaderTest, NonSquareHeightIsIgnored) { |
+ std::vector<SkBitmap> vector { CreateDummyBitmap(15, 10) }; |
+ ASSERT_EQ(-1, FindBitmap(10, vector)); |
+} |
+ |
+TEST_F(ManifestIconDownloaderTest, NonSquareWidthIsIgnored) { |
+ std::vector<SkBitmap> vector { CreateDummyBitmap(15, 10) }; |
+ ASSERT_EQ(-1, FindBitmap(15, vector)); |
+} |