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

Unified 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 side-by-side diff with in-line comments
Download patch
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..600c9502b69c2b45145caf3c529c42d2a04cf7bc
--- /dev/null
+++ b/chrome/browser/manifest/manifest_icon_downloader_unittest.cc
@@ -0,0 +1,70 @@
+// 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() {}
mlamouri (slow - plz ping) 2015/08/07 10:11:12 nit: = default;
Lalit Maganti 2015/08/07 13:04:30 Done.
+ ~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 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.
+ 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 { CreateBitmap(10, 10) };
+ ASSERT_EQ(0, FindBitmap(10, vector));
+}
+
+TEST_F(ManifestIconDownloaderTest, BiggerIsChosen) {
+ std::vector<SkBitmap> vector { CreateBitmap(20, 20) };
+ ASSERT_EQ(0, FindBitmap(10, vector));
+}
+
+TEST_F(ManifestIconDownloaderTest, SmallerIsIgnored) {
+ std::vector<SkBitmap> vector { CreateBitmap(10, 10) };
+ ASSERT_EQ(-1, FindBitmap(20, vector));
+}
+
+TEST_F(ManifestIconDownloaderTest, ExactIsPreferredOverBigger) {
+ std::vector<SkBitmap> vector { CreateBitmap(20, 20), CreateBitmap(10, 10) };
+ ASSERT_EQ(1, FindBitmap(10, vector));
+}
+
+TEST_F(ManifestIconDownloaderTest, ExactIsPreferredOverSmaller) {
+ std::vector<SkBitmap> vector { CreateBitmap(10, 10), CreateBitmap(20, 20) };
+ ASSERT_EQ(1, FindBitmap(20, vector));
+}
+
+TEST_F(ManifestIconDownloaderTest, ClosestToExactIsChosen) {
+ std::vector<SkBitmap> vector { CreateBitmap(20, 20), CreateBitmap(25, 25) };
+ ASSERT_EQ(0, FindBitmap(10, vector));
+}
+
+TEST_F(ManifestIconDownloaderTest, ClosestToExactIsChosenUnordered) {
+ std::vector<SkBitmap> vector { CreateBitmap(25, 25), CreateBitmap(20, 20) };
+ ASSERT_EQ(1, FindBitmap(10, vector));
+}
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.

Powered by Google App Engine
This is Rietveld 408576698