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

Side by Side 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: fix the function name... 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/tab_contents/thumbnail_generator.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "app/surface/transport_dib.h" 5 #include "app/surface/transport_dib.h"
6 #include "base/basictypes.h" 6 #include "base/basictypes.h"
7 #include "chrome/browser/renderer_host/backing_store_manager.h" 7 #include "chrome/browser/renderer_host/backing_store_manager.h"
8 #include "chrome/browser/renderer_host/mock_render_process_host.h" 8 #include "chrome/browser/renderer_host/mock_render_process_host.h"
9 #include "chrome/browser/renderer_host/test/test_render_view_host.h" 9 #include "chrome/browser/renderer_host/test/test_render_view_host.h"
10 #include "chrome/browser/tab_contents/thumbnail_generator.h" 10 #include "chrome/browser/tab_contents/thumbnail_generator.h"
11 #include "chrome/common/notification_service.h" 11 #include "chrome/common/notification_service.h"
12 #include "chrome/common/render_messages.h" 12 #include "chrome/common/render_messages.h"
13 #include "chrome/test/testing_profile.h" 13 #include "chrome/test/testing_profile.h"
14 #include "gfx/canvas_skia.h"
14 #include "skia/ext/platform_canvas.h" 15 #include "skia/ext/platform_canvas.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/skia/include/core/SkColorPriv.h" 17 #include "third_party/skia/include/core/SkColorPriv.h"
17 18
18 static const int kBitmapWidth = 100; 19 static const int kBitmapWidth = 100;
19 static const int kBitmapHeight = 100; 20 static const int kBitmapHeight = 100;
20 21
21 // TODO(brettw) enable this when GetThumbnailForBackingStore is implemented 22 // TODO(brettw) enable this when GetThumbnailForBackingStore is implemented
22 // for other platforms in thumbnail_generator.cc 23 // for other platforms in thumbnail_generator.cc
23 // #if defined(OS_WIN) 24 // #if defined(OS_WIN)
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // Running the message loop will process the timer, which should expire the 172 // Running the message loop will process the timer, which should expire the
172 // cached thumbnail. Asking again should give us a new one computed from the 173 // cached thumbnail. Asking again should give us a new one computed from the
173 // backing store. 174 // backing store.
174 message_loop_.RunAllPending(); 175 message_loop_.RunAllPending();
175 result = generator_.GetThumbnailForRenderer(&widget_); 176 result = generator_.GetThumbnailForRenderer(&widget_);
176 ASSERT_FALSE(result.isNull()); 177 ASSERT_FALSE(result.isNull());
177 EXPECT_EQ(TRANSPORT_WHITE, ClassifyFirstPixel(result)); 178 EXPECT_EQ(TRANSPORT_WHITE, ClassifyFirstPixel(result));
178 } 179 }
179 180
180 #endif 181 #endif
182
183 TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_Empty) {
184 SkBitmap bitmap;
185 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap));
186 }
187
188 TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_SingleColor) {
189 const SkColor kBlack = SkColorSetRGB(0, 0, 0);
190 const gfx::Size kSize(20, 10);
191 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true);
192 // Fill all pixesl in black.
193 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height());
194
195 SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false);
196 // The thumbnail should deserve the highest boring score.
197 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap));
198 }
199
200 TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_TwoColors) {
201 const SkColor kBlack = SkColorSetRGB(0, 0, 0);
202 const SkColor kWhite = SkColorSetRGB(0xFF, 0xFF, 0xFF);
203 const gfx::Size kSize(20, 10);
204
205 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true);
206 // Fill all pixesl in black.
207 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height());
208 // Fill the left half pixels in white.
209 canvas.FillRectInt(kWhite, 0, 0, kSize.width() / 2, kSize.height());
210
211 SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false);
212 ASSERT_EQ(kSize.width(), bitmap.width());
213 ASSERT_EQ(kSize.height(), bitmap.height());
214 // The thumbnail should be less boring because two colors are used.
215 EXPECT_DOUBLE_EQ(0.5, ThumbnailGenerator::CalculateBoringScore(&bitmap));
216 }
217
218 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_TallerThanWide) {
219 // The input bitmap is vertically long.
220 gfx::CanvasSkia canvas(40, 90, true);
221 const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false);
222
223 // The desired size is square.
224 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped;
225 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap(
226 bitmap, 10, 10, &clip_result);
227 // The clipped bitmap should be square.
228 EXPECT_EQ(40, clipped_bitmap.width());
229 EXPECT_EQ(40, clipped_bitmap.height());
230 // The input was taller than wide.
231 EXPECT_EQ(ThumbnailGenerator::kTallerThanWide, clip_result);
232 }
233
234 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_WiderThanTall) {
235 // The input bitmap is horizontally long.
236 gfx::CanvasSkia canvas(90, 40, true);
237 const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false);
238
239 // The desired size is square.
240 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped;
241 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap(
242 bitmap, 10, 10, &clip_result);
243 // The clipped bitmap should be square.
244 EXPECT_EQ(40, clipped_bitmap.width());
245 EXPECT_EQ(40, clipped_bitmap.height());
246 // The input was wider than tall.
247 EXPECT_EQ(ThumbnailGenerator::kWiderThanTall, clip_result);
248 }
249
250 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NotClipped) {
251 // The input bitmap is square.
252 gfx::CanvasSkia canvas(40, 40, true);
253 const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false);
254
255 // The desired size is square.
256 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped;
257 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap(
258 bitmap, 10, 10, &clip_result);
259 // The clipped bitmap should be square.
260 EXPECT_EQ(40, clipped_bitmap.width());
261 EXPECT_EQ(40, clipped_bitmap.height());
262 // There was no need to clip.
263 EXPECT_EQ(ThumbnailGenerator::kNotClipped, clip_result);
264 }
265
266 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NonSquareOutput) {
267 // The input bitmap is square.
268 gfx::CanvasSkia canvas(40, 40, true);
269 const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false);
270
271 // The desired size is horizontally long.
272 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped;
273 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap(
274 bitmap, 20, 10, &clip_result);
275 // The clipped bitmap should have the same aspect ratio of the desired size.
276 EXPECT_EQ(40, clipped_bitmap.width());
277 EXPECT_EQ(20, clipped_bitmap.height());
278 // The input was taller than wide.
279 EXPECT_EQ(ThumbnailGenerator::kTallerThanWide, clip_result);
280 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/thumbnail_generator.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698