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

Side by Side Diff: chrome/browser/tab_contents/thumbnail_generator_unittest.cc

Issue 7465041: GTTF: Use a fresh TestingBrowserProcess for each test, part #4 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/stringprintf.h" 6 #include "base/stringprintf.h"
7 #include "chrome/browser/history/top_sites.h" 7 #include "chrome/browser/history/top_sites.h"
8 #include "chrome/browser/tab_contents/thumbnail_generator.h" 8 #include "chrome/browser/tab_contents/thumbnail_generator.h"
9 #include "chrome/common/render_messages.h" 9 #include "chrome/common/render_messages.h"
10 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
11 #include "chrome/test/testing_browser_process_test.h"
11 #include "content/browser/renderer_host/backing_store_manager.h" 12 #include "content/browser/renderer_host/backing_store_manager.h"
12 #include "content/browser/renderer_host/backing_store_skia.h" 13 #include "content/browser/renderer_host/backing_store_skia.h"
13 #include "content/browser/renderer_host/mock_render_process_host.h" 14 #include "content/browser/renderer_host/mock_render_process_host.h"
14 #include "content/browser/renderer_host/test_render_view_host.h" 15 #include "content/browser/renderer_host/test_render_view_host.h"
15 #include "content/browser/tab_contents/render_view_host_manager.h" 16 #include "content/browser/tab_contents/render_view_host_manager.h"
16 #include "content/common/notification_service.h" 17 #include "content/common/notification_service.h"
17 #include "content/common/view_messages.h" 18 #include "content/common/view_messages.h"
18 #include "skia/ext/platform_canvas.h" 19 #include "skia/ext/platform_canvas.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 #include "third_party/skia/include/core/SkColorPriv.h" 21 #include "third_party/skia/include/core/SkColorPriv.h"
(...skipping 25 matching lines...) Expand all
46 47
47 BackingStore* AllocBackingStore(const gfx::Size& size) { 48 BackingStore* AllocBackingStore(const gfx::Size& size) {
48 return new BackingStoreSkia(rwh_, size); 49 return new BackingStoreSkia(rwh_, size);
49 } 50 }
50 51
51 private: 52 private:
52 RenderWidgetHost* rwh_; 53 RenderWidgetHost* rwh_;
53 DISALLOW_COPY_AND_ASSIGN(TestRenderWidgetHostViewWithBackingStoreSkia); 54 DISALLOW_COPY_AND_ASSIGN(TestRenderWidgetHostViewWithBackingStoreSkia);
54 }; 55 };
55 56
56 class ThumbnailGeneratorTest : public testing::Test { 57 class ThumbnailGeneratorTest : public TestingBrowserProcessTest {
57 public: 58 public:
58 ThumbnailGeneratorTest() { 59 ThumbnailGeneratorTest() {
59 profile_.reset(new TestingProfile()); 60 profile_.reset(new TestingProfile());
60 process_ = new MockRenderProcessHost(profile_.get()); 61 process_ = new MockRenderProcessHost(profile_.get());
61 widget_.reset(new RenderWidgetHost(process_, 1)); 62 widget_.reset(new RenderWidgetHost(process_, 1));
62 view_.reset(new TestRenderWidgetHostViewWithBackingStoreSkia( 63 view_.reset(new TestRenderWidgetHostViewWithBackingStoreSkia(
63 widget_.get())); 64 widget_.get()));
64 // Paiting will be skipped if there's no view. 65 // Paiting will be skipped if there's no view.
65 widget_->SetView(view_.get()); 66 widget_->SetView(view_.get());
66 67
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 ASSERT_FALSE(widget_->GetBackingStore(false)); 201 ASSERT_FALSE(widget_->GetBackingStore(false));
201 202
202 // The thumbnail generator should not be able to retrieve a thumbnail, 203 // The thumbnail generator should not be able to retrieve a thumbnail,
203 // as the backing store is now gone. 204 // as the backing store is now gone.
204 result = generator_.GetThumbnailForRenderer(widget_.get()); 205 result = generator_.GetThumbnailForRenderer(widget_.get());
205 ASSERT_TRUE(result.isNull()); 206 ASSERT_TRUE(result.isNull());
206 } 207 }
207 208
208 #endif // !defined(OS_MAC) 209 #endif // !defined(OS_MAC)
209 210
210 TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_Empty) { 211 typedef TestingBrowserProcessTest ThumbnailGeneratorSimpleTest;
212
213 TEST_F(ThumbnailGeneratorSimpleTest, CalculateBoringScore_Empty) {
211 SkBitmap bitmap; 214 SkBitmap bitmap;
212 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); 215 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap));
213 } 216 }
214 217
215 TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_SingleColor) { 218 TEST_F(ThumbnailGeneratorSimpleTest, CalculateBoringScore_SingleColor) {
216 const SkColor kBlack = SkColorSetRGB(0, 0, 0); 219 const SkColor kBlack = SkColorSetRGB(0, 0, 0);
217 const gfx::Size kSize(20, 10); 220 const gfx::Size kSize(20, 10);
218 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true); 221 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true);
219 // Fill all pixesl in black. 222 // Fill all pixesl in black.
220 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height()); 223 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height());
221 224
222 SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); 225 SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false);
223 // The thumbnail should deserve the highest boring score. 226 // The thumbnail should deserve the highest boring score.
224 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); 227 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap));
225 } 228 }
226 229
227 TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_TwoColors) { 230 TEST_F(ThumbnailGeneratorSimpleTest, CalculateBoringScore_TwoColors) {
228 const SkColor kBlack = SkColorSetRGB(0, 0, 0); 231 const SkColor kBlack = SkColorSetRGB(0, 0, 0);
229 const SkColor kWhite = SkColorSetRGB(0xFF, 0xFF, 0xFF); 232 const SkColor kWhite = SkColorSetRGB(0xFF, 0xFF, 0xFF);
230 const gfx::Size kSize(20, 10); 233 const gfx::Size kSize(20, 10);
231 234
232 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true); 235 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true);
233 // Fill all pixesl in black. 236 // Fill all pixesl in black.
234 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height()); 237 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height());
235 // Fill the left half pixels in white. 238 // Fill the left half pixels in white.
236 canvas.FillRectInt(kWhite, 0, 0, kSize.width() / 2, kSize.height()); 239 canvas.FillRectInt(kWhite, 0, 0, kSize.width() / 2, kSize.height());
237 240
238 SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); 241 SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false);
239 ASSERT_EQ(kSize.width(), bitmap.width()); 242 ASSERT_EQ(kSize.width(), bitmap.width());
240 ASSERT_EQ(kSize.height(), bitmap.height()); 243 ASSERT_EQ(kSize.height(), bitmap.height());
241 // The thumbnail should be less boring because two colors are used. 244 // The thumbnail should be less boring because two colors are used.
242 EXPECT_DOUBLE_EQ(0.5, ThumbnailGenerator::CalculateBoringScore(&bitmap)); 245 EXPECT_DOUBLE_EQ(0.5, ThumbnailGenerator::CalculateBoringScore(&bitmap));
243 } 246 }
244 247
245 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_TallerThanWide) { 248 TEST_F(ThumbnailGeneratorSimpleTest, GetClippedBitmap_TallerThanWide) {
246 // The input bitmap is vertically long. 249 // The input bitmap is vertically long.
247 gfx::CanvasSkia canvas(40, 90, true); 250 gfx::CanvasSkia canvas(40, 90, true);
248 const SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); 251 const SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false);
249 252
250 // The desired size is square. 253 // The desired size is square.
251 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; 254 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped;
252 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( 255 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap(
253 bitmap, 10, 10, &clip_result); 256 bitmap, 10, 10, &clip_result);
254 // The clipped bitmap should be square. 257 // The clipped bitmap should be square.
255 EXPECT_EQ(40, clipped_bitmap.width()); 258 EXPECT_EQ(40, clipped_bitmap.width());
256 EXPECT_EQ(40, clipped_bitmap.height()); 259 EXPECT_EQ(40, clipped_bitmap.height());
257 // The input was taller than wide. 260 // The input was taller than wide.
258 EXPECT_EQ(ThumbnailGenerator::kTallerThanWide, clip_result); 261 EXPECT_EQ(ThumbnailGenerator::kTallerThanWide, clip_result);
259 } 262 }
260 263
261 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_WiderThanTall) { 264 TEST_F(ThumbnailGeneratorSimpleTest, GetClippedBitmap_WiderThanTall) {
262 // The input bitmap is horizontally long. 265 // The input bitmap is horizontally long.
263 gfx::CanvasSkia canvas(90, 40, true); 266 gfx::CanvasSkia canvas(90, 40, true);
264 const SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); 267 const SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false);
265 268
266 // The desired size is square. 269 // The desired size is square.
267 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; 270 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped;
268 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( 271 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap(
269 bitmap, 10, 10, &clip_result); 272 bitmap, 10, 10, &clip_result);
270 // The clipped bitmap should be square. 273 // The clipped bitmap should be square.
271 EXPECT_EQ(40, clipped_bitmap.width()); 274 EXPECT_EQ(40, clipped_bitmap.width());
272 EXPECT_EQ(40, clipped_bitmap.height()); 275 EXPECT_EQ(40, clipped_bitmap.height());
273 // The input was wider than tall. 276 // The input was wider than tall.
274 EXPECT_EQ(ThumbnailGenerator::kWiderThanTall, clip_result); 277 EXPECT_EQ(ThumbnailGenerator::kWiderThanTall, clip_result);
275 } 278 }
276 279
277 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NotClipped) { 280 TEST_F(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NotClipped) {
278 // The input bitmap is square. 281 // The input bitmap is square.
279 gfx::CanvasSkia canvas(40, 40, true); 282 gfx::CanvasSkia canvas(40, 40, true);
280 const SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); 283 const SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false);
281 284
282 // The desired size is square. 285 // The desired size is square.
283 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; 286 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped;
284 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( 287 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap(
285 bitmap, 10, 10, &clip_result); 288 bitmap, 10, 10, &clip_result);
286 // The clipped bitmap should be square. 289 // The clipped bitmap should be square.
287 EXPECT_EQ(40, clipped_bitmap.width()); 290 EXPECT_EQ(40, clipped_bitmap.width());
288 EXPECT_EQ(40, clipped_bitmap.height()); 291 EXPECT_EQ(40, clipped_bitmap.height());
289 // There was no need to clip. 292 // There was no need to clip.
290 EXPECT_EQ(ThumbnailGenerator::kNotClipped, clip_result); 293 EXPECT_EQ(ThumbnailGenerator::kNotClipped, clip_result);
291 } 294 }
292 295
293 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NonSquareOutput) { 296 TEST_F(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NonSquareOutput) {
294 // The input bitmap is square. 297 // The input bitmap is square.
295 gfx::CanvasSkia canvas(40, 40, true); 298 gfx::CanvasSkia canvas(40, 40, true);
296 const SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); 299 const SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false);
297 300
298 // The desired size is horizontally long. 301 // The desired size is horizontally long.
299 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; 302 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped;
300 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( 303 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap(
301 bitmap, 20, 10, &clip_result); 304 bitmap, 20, 10, &clip_result);
302 // The clipped bitmap should have the same aspect ratio of the desired size. 305 // The clipped bitmap should have the same aspect ratio of the desired size.
303 EXPECT_EQ(40, clipped_bitmap.width()); 306 EXPECT_EQ(40, clipped_bitmap.width());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 void AddKnownURL(const GURL& url, const ThumbnailScore& score) { 339 void AddKnownURL(const GURL& url, const ThumbnailScore& score) {
337 known_url_map_[url.spec()] = score; 340 known_url_map_[url.spec()] = score;
338 } 341 }
339 342
340 private: 343 private:
341 virtual ~MockTopSites() {} 344 virtual ~MockTopSites() {}
342 size_t capacity_; 345 size_t capacity_;
343 std::map<std::string, ThumbnailScore> known_url_map_; 346 std::map<std::string, ThumbnailScore> known_url_map_;
344 }; 347 };
345 348
346 TEST(ThumbnailGeneratorSimpleTest, ShouldUpdateThumbnail) { 349 TEST_F(ThumbnailGeneratorSimpleTest, ShouldUpdateThumbnail) {
347 const GURL kGoodURL("http://www.google.com/"); 350 const GURL kGoodURL("http://www.google.com/");
348 const GURL kBadURL("chrome://newtab"); 351 const GURL kBadURL("chrome://newtab");
349 352
350 // Set up the profile. 353 // Set up the profile.
351 TestingProfile profile; 354 TestingProfile profile;
352 355
353 // Set up the top sites service. 356 // Set up the top sites service.
354 ScopedTempDir temp_dir; 357 ScopedTempDir temp_dir;
355 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 358 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
356 scoped_refptr<MockTopSites> top_sites(new MockTopSites(&profile)); 359 scoped_refptr<MockTopSites> top_sites(new MockTopSites(&profile));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 good_score.good_clipping = true; 399 good_score.good_clipping = true;
397 good_score.boring_score = 0.0; 400 good_score.boring_score = 0.0;
398 good_score.load_completed = true; 401 good_score.load_completed = true;
399 top_sites->AddKnownURL(kGoodURL, good_score); 402 top_sites->AddKnownURL(kGoodURL, good_score);
400 403
401 // Should be false, as the existing thumbnail is good enough (i.e. don't 404 // Should be false, as the existing thumbnail is good enough (i.e. don't
402 // need to replace the existing thumbnail which is new and good). 405 // need to replace the existing thumbnail which is new and good).
403 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( 406 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail(
404 &profile, top_sites.get(), kGoodURL)); 407 &profile, top_sites.get(), kGoodURL));
405 } 408 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_unittest.cc ('k') | chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698