| OLD | NEW |
| 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_browser_process_test.h" | |
| 11 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
| 12 #include "content/browser/renderer_host/backing_store_manager.h" | 11 #include "content/browser/renderer_host/backing_store_manager.h" |
| 13 #include "content/browser/renderer_host/backing_store_skia.h" | 12 #include "content/browser/renderer_host/backing_store_skia.h" |
| 14 #include "content/browser/renderer_host/mock_render_process_host.h" | 13 #include "content/browser/renderer_host/mock_render_process_host.h" |
| 15 #include "content/browser/renderer_host/test_render_view_host.h" | 14 #include "content/browser/renderer_host/test_render_view_host.h" |
| 16 #include "content/browser/tab_contents/render_view_host_manager.h" | 15 #include "content/browser/tab_contents/render_view_host_manager.h" |
| 17 #include "content/common/notification_service.h" | 16 #include "content/common/notification_service.h" |
| 18 #include "content/common/view_messages.h" | 17 #include "content/common/view_messages.h" |
| 19 #include "skia/ext/platform_canvas.h" | 18 #include "skia/ext/platform_canvas.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 47 | 46 |
| 48 BackingStore* AllocBackingStore(const gfx::Size& size) { | 47 BackingStore* AllocBackingStore(const gfx::Size& size) { |
| 49 return new BackingStoreSkia(rwh_, size); | 48 return new BackingStoreSkia(rwh_, size); |
| 50 } | 49 } |
| 51 | 50 |
| 52 private: | 51 private: |
| 53 RenderWidgetHost* rwh_; | 52 RenderWidgetHost* rwh_; |
| 54 DISALLOW_COPY_AND_ASSIGN(TestRenderWidgetHostViewWithBackingStoreSkia); | 53 DISALLOW_COPY_AND_ASSIGN(TestRenderWidgetHostViewWithBackingStoreSkia); |
| 55 }; | 54 }; |
| 56 | 55 |
| 57 class ThumbnailGeneratorTest : public TestingBrowserProcessTest { | 56 class ThumbnailGeneratorTest : public testing::Test { |
| 58 public: | 57 public: |
| 59 ThumbnailGeneratorTest() { | 58 ThumbnailGeneratorTest() { |
| 60 profile_.reset(new TestingProfile()); | 59 profile_.reset(new TestingProfile()); |
| 61 process_ = new MockRenderProcessHost(profile_.get()); | 60 process_ = new MockRenderProcessHost(profile_.get()); |
| 62 widget_.reset(new RenderWidgetHost(process_, 1)); | 61 widget_.reset(new RenderWidgetHost(process_, 1)); |
| 63 view_.reset(new TestRenderWidgetHostViewWithBackingStoreSkia( | 62 view_.reset(new TestRenderWidgetHostViewWithBackingStoreSkia( |
| 64 widget_.get())); | 63 widget_.get())); |
| 65 // Paiting will be skipped if there's no view. | 64 // Paiting will be skipped if there's no view. |
| 66 widget_->SetView(view_.get()); | 65 widget_->SetView(view_.get()); |
| 67 | 66 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 ASSERT_FALSE(widget_->GetBackingStore(false)); | 200 ASSERT_FALSE(widget_->GetBackingStore(false)); |
| 202 | 201 |
| 203 // The thumbnail generator should not be able to retrieve a thumbnail, | 202 // The thumbnail generator should not be able to retrieve a thumbnail, |
| 204 // as the backing store is now gone. | 203 // as the backing store is now gone. |
| 205 result = generator_.GetThumbnailForRenderer(widget_.get()); | 204 result = generator_.GetThumbnailForRenderer(widget_.get()); |
| 206 ASSERT_TRUE(result.isNull()); | 205 ASSERT_TRUE(result.isNull()); |
| 207 } | 206 } |
| 208 | 207 |
| 209 #endif // !defined(OS_MAC) | 208 #endif // !defined(OS_MAC) |
| 210 | 209 |
| 211 typedef TestingBrowserProcessTest ThumbnailGeneratorSimpleTest; | 210 typedef testing::Test ThumbnailGeneratorSimpleTest; |
| 212 | 211 |
| 213 TEST_F(ThumbnailGeneratorSimpleTest, CalculateBoringScore_Empty) { | 212 TEST_F(ThumbnailGeneratorSimpleTest, CalculateBoringScore_Empty) { |
| 214 SkBitmap bitmap; | 213 SkBitmap bitmap; |
| 215 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); | 214 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); |
| 216 } | 215 } |
| 217 | 216 |
| 218 TEST_F(ThumbnailGeneratorSimpleTest, CalculateBoringScore_SingleColor) { | 217 TEST_F(ThumbnailGeneratorSimpleTest, CalculateBoringScore_SingleColor) { |
| 219 const SkColor kBlack = SkColorSetRGB(0, 0, 0); | 218 const SkColor kBlack = SkColorSetRGB(0, 0, 0); |
| 220 const gfx::Size kSize(20, 10); | 219 const gfx::Size kSize(20, 10); |
| 221 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true); | 220 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 good_score.good_clipping = true; | 398 good_score.good_clipping = true; |
| 400 good_score.boring_score = 0.0; | 399 good_score.boring_score = 0.0; |
| 401 good_score.load_completed = true; | 400 good_score.load_completed = true; |
| 402 top_sites->AddKnownURL(kGoodURL, good_score); | 401 top_sites->AddKnownURL(kGoodURL, good_score); |
| 403 | 402 |
| 404 // Should be false, as the existing thumbnail is good enough (i.e. don't | 403 // Should be false, as the existing thumbnail is good enough (i.e. don't |
| 405 // need to replace the existing thumbnail which is new and good). | 404 // need to replace the existing thumbnail which is new and good). |
| 406 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( | 405 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( |
| 407 &profile, top_sites.get(), kGoodURL)); | 406 &profile, top_sites.get(), kGoodURL)); |
| 408 } | 407 } |
| OLD | NEW |