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

Unified Diff: chrome/browser/tab_contents/thumbnail_generator_unittest.cc

Issue 6246007: Generate thumbnails in the browser process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move scroll offset into ViewHostMsg_UpdateRect_Params Created 9 years, 11 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/tab_contents/thumbnail_generator_unittest.cc
diff --git a/chrome/browser/tab_contents/thumbnail_generator_unittest.cc b/chrome/browser/tab_contents/thumbnail_generator_unittest.cc
index 787873c6a00a8eda24a741ac39b7c8b7c4669f1c..7c7f60185df41131651fbaf014d9dc73315a4fd5 100644
--- a/chrome/browser/tab_contents/thumbnail_generator_unittest.cc
+++ b/chrome/browser/tab_contents/thumbnail_generator_unittest.cc
@@ -11,6 +11,7 @@
#include "chrome/common/notification_service.h"
#include "chrome/common/render_messages.h"
#include "chrome/test/testing_profile.h"
+#include "gfx/canvas_skia.h"
#include "skia/ext/platform_canvas.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkColorPriv.h"
@@ -178,3 +179,102 @@ TEST_F(ThumbnailGeneratorTest, QuickShow) {
}
#endif
+
+TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_Empty) {
+ SkBitmap bitmap;
+ EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap));
+}
+
+TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_SingleColor) {
+ const SkColor kBlack = SkColorSetRGB(0, 0, 0);
+ const gfx::Size kSize(20, 10);
+ gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true);
+ // Fill all pixesl in black.
+ canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height());
+
+ SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false);
+ // The thumbnail should deserve the highest boring score.
+ EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap));
+}
+
+TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_TwoColors) {
+ const SkColor kBlack = SkColorSetRGB(0, 0, 0);
+ const SkColor kWhite = SkColorSetRGB(0xFF, 0xFF, 0xFF);
+ const gfx::Size kSize(20, 10);
+
+ gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true);
+ // Fill all pixesl in black.
+ canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height());
+ // Fill the left half pixels in white.
+ canvas.FillRectInt(kWhite, 0, 0, kSize.width() / 2, kSize.height());
+
+ SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false);
+ ASSERT_EQ(kSize.width(), bitmap.width());
+ ASSERT_EQ(kSize.height(), bitmap.height());
+ // The thumbnail should be less boring because two colors are used.
+ EXPECT_DOUBLE_EQ(0.5, ThumbnailGenerator::CalculateBoringScore(&bitmap));
+}
+
+TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_TallerThanWide) {
+ // The input bitmap is vertically long.
+ gfx::CanvasSkia canvas(40, 90, true);
+ const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false);
+
+ // The desired size is square.
+ ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped;
+ SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap(
+ bitmap, 10, 10, &clip_result);
+ // The clipped bitmap should be square.
+ EXPECT_EQ(40, clipped_bitmap.width());
+ EXPECT_EQ(40, clipped_bitmap.height());
+ // The input was taller than wide.
+ EXPECT_EQ(ThumbnailGenerator::kTallerThanWide, clip_result);
+}
+
+TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_WiderThanTall) {
+ // The input bitmap is horizontally long.
+ gfx::CanvasSkia canvas(90, 40, true);
+ const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false);
+
+ // The desired size is square.
+ ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped;
+ SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap(
+ bitmap, 10, 10, &clip_result);
+ // The clipped bitmap should be square.
+ EXPECT_EQ(40, clipped_bitmap.width());
+ EXPECT_EQ(40, clipped_bitmap.height());
+ // The input was wider than tall.
+ EXPECT_EQ(ThumbnailGenerator::kWiderThanTall, clip_result);
+}
+
+TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NotClipped) {
+ // The input bitmap is square.
+ gfx::CanvasSkia canvas(40, 40, true);
+ const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false);
+
+ // The desired size is square.
+ ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped;
+ SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap(
+ bitmap, 10, 10, &clip_result);
+ // The clipped bitmap should be square.
+ EXPECT_EQ(40, clipped_bitmap.width());
+ EXPECT_EQ(40, clipped_bitmap.height());
+ // There was no need to clip.
+ EXPECT_EQ(ThumbnailGenerator::kNotClipped, clip_result);
+}
+
+TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NonSquareOutput) {
+ // The input bitmap is square.
+ gfx::CanvasSkia canvas(40, 40, true);
+ const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false);
+
+ // The desired size is horizontally long.
+ ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped;
+ SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap(
+ bitmap, 20, 10, &clip_result);
+ // The clipped bitmap should have the same aspect ratio of the desired size.
+ EXPECT_EQ(40, clipped_bitmap.width());
+ EXPECT_EQ(20, clipped_bitmap.height());
+ // The input was taller than wide.
+ EXPECT_EQ(ThumbnailGenerator::kTallerThanWide, clip_result);
+}

Powered by Google App Engine
This is Rietveld 408576698