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

Side by Side Diff: chrome/browser/thumbnails/content_based_thumbnailing_algorithm_unittest.cc

Issue 1443723002: Revert of Fix NTP thumbnail generation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "chrome/browser/thumbnails/content_based_thumbnailing_algorithm.h" 6 #include "chrome/browser/thumbnails/content_based_thumbnailing_algorithm.h"
7 #include "chrome/browser/thumbnails/simple_thumbnail_crop.h" 7 #include "chrome/browser/thumbnails/simple_thumbnail_crop.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/test/test_browser_thread.h" 9 #include "content/public/test/test_browser_thread.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/skia/include/core/SkBitmap.h" 11 #include "third_party/skia/include/core/SkBitmap.h"
12 #include "ui/gfx/canvas.h" 12 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/scrollbar_size.h" 13 #include "ui/gfx/scrollbar_size.h"
14 14
15 namespace thumbnails { 15 namespace thumbnails {
16 16
17 typedef testing::Test ContentBasedThumbnailingAlgorithmTest; 17 typedef testing::Test ContentBasedThumbnailingAlgorithmTest;
18 18
19 class ConsumerCallbackCatcher { 19 class ConsumerCallbackCatcher {
20 public: 20 public:
21 ConsumerCallbackCatcher() 21 ConsumerCallbackCatcher()
22 : called_back_(false), clip_result_(CLIP_RESULT_UNPROCESSED) { 22 : called_back_(false), clip_result_(CLIP_RESULT_UNPROCESSED) {
23 } 23 }
24 24
25 void UiThreadCallback(const ThumbnailingContext& context, 25 void UiThreadCallback(const ThumbnailingContext& context,
26 const SkBitmap& bitmap) { 26 const SkBitmap& bitmap) {
27 called_back_ = true; 27 called_back_ = true;
28 captured_bitmap_ = bitmap; 28 captured_bitmap_ = bitmap;
29 clip_result_ = context.clip_result(); 29 clip_result_ = context.clip_result;
30 score_ = context.score(); 30 score_ = context.score;
31 } 31 }
32 32
33 bool called_back() const { 33 bool called_back() const {
34 return called_back_; 34 return called_back_;
35 } 35 }
36 36
37 const SkBitmap& captured_bitmap() const { 37 const SkBitmap& captured_bitmap() const {
38 return captured_bitmap_; 38 return captured_bitmap_;
39 } 39 }
40 40
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 SimpleThumbnailCrop::GetCopySizeForThumbnail( 93 SimpleThumbnailCrop::GetCopySizeForThumbnail(
94 ui::SCALE_FACTOR_100P, thumbnail_size).ToString()); 94 ui::SCALE_FACTOR_100P, thumbnail_size).ToString());
95 EXPECT_EQ(gfx::Point(0, 0).ToString(), clipping_rect.origin().ToString()); 95 EXPECT_EQ(gfx::Point(0, 0).ToString(), clipping_rect.origin().ToString());
96 } 96 }
97 97
98 TEST_F(ContentBasedThumbnailingAlgorithmTest, PrepareSourceBitmap) { 98 TEST_F(ContentBasedThumbnailingAlgorithmTest, PrepareSourceBitmap) {
99 const gfx::Size thumbnail_size(312, 165); 99 const gfx::Size thumbnail_size(312, 165);
100 const gfx::Size copy_size(400, 200); 100 const gfx::Size copy_size(400, 200);
101 scoped_refptr<ThumbnailingContext> context( 101 scoped_refptr<ThumbnailingContext> context(
102 ThumbnailingContext::CreateThumbnailingContextForTest()); 102 ThumbnailingContext::CreateThumbnailingContextForTest());
103 context->set_requested_copy_size(copy_size); 103 context->requested_copy_size = copy_size;
104 104
105 // This calls for exercising two distinct paths: with prior clipping and 105 // This calls for exercising two distinct paths: with prior clipping and
106 // without. 106 // without.
107 SkBitmap source; 107 SkBitmap source;
108 source.allocN32Pixels(800, 600); 108 source.allocN32Pixels(800, 600);
109 source.eraseARGB(255, 50, 150, 200); 109 source.eraseARGB(255, 50, 150, 200);
110 SkBitmap result = ContentBasedThumbnailingAlgorithm::PrepareSourceBitmap( 110 SkBitmap result = ContentBasedThumbnailingAlgorithm::PrepareSourceBitmap(
111 source, thumbnail_size, context.get()); 111 source, thumbnail_size, context.get());
112 EXPECT_EQ(CLIP_RESULT_SOURCE_SAME_AS_TARGET, context->clip_result()); 112 EXPECT_EQ(CLIP_RESULT_SOURCE_SAME_AS_TARGET, context->clip_result);
113 EXPECT_GE(result.width(), copy_size.width()); 113 EXPECT_GE(result.width(), copy_size.width());
114 EXPECT_GE(result.height(), copy_size.height()); 114 EXPECT_GE(result.height(), copy_size.height());
115 EXPECT_LT(result.width(), source.width()); 115 EXPECT_LT(result.width(), source.width());
116 EXPECT_LT(result.height(), source.height()); 116 EXPECT_LT(result.height(), source.height());
117 // The check below is a bit of a side effect: since the image was clipped 117 // The check below is a bit of a side effect: since the image was clipped
118 // by scrollbar_size, it cannot be shrunk and thus what we get below is 118 // by scrollbar_size, it cannot be shrunk and thus what we get below is
119 // true. 119 // true.
120 EXPECT_NEAR(result.width(), source.width(), gfx::scrollbar_size()); 120 EXPECT_NEAR(result.width(), source.width(), gfx::scrollbar_size());
121 EXPECT_NEAR(result.height(), source.height(), gfx::scrollbar_size()); 121 EXPECT_NEAR(result.height(), source.height(), gfx::scrollbar_size());
122 122
123 result = ContentBasedThumbnailingAlgorithm::PrepareSourceBitmap( 123 result = ContentBasedThumbnailingAlgorithm::PrepareSourceBitmap(
124 source, thumbnail_size, context.get()); 124 source, thumbnail_size, context.get());
125 EXPECT_EQ(CLIP_RESULT_SOURCE_SAME_AS_TARGET, context->clip_result()); 125 EXPECT_EQ(CLIP_RESULT_SOURCE_SAME_AS_TARGET, context->clip_result);
126 EXPECT_GE(result.width(), copy_size.width()); 126 EXPECT_GE(result.width(), copy_size.width());
127 EXPECT_GE(result.height(), copy_size.height()); 127 EXPECT_GE(result.height(), copy_size.height());
128 EXPECT_LT(result.width(), source.width()); 128 EXPECT_LT(result.width(), source.width());
129 EXPECT_LT(result.height(), source.height()); 129 EXPECT_LT(result.height(), source.height());
130 } 130 }
131 131
132 TEST_F(ContentBasedThumbnailingAlgorithmTest, CreateRetargetedThumbnail) { 132 TEST_F(ContentBasedThumbnailingAlgorithmTest, CreateRetargetedThumbnail) {
133 // This tests the invocation of the main thumbnail-making apparatus. 133 // This tests the invocation of the main thumbnail-making apparatus.
134 // The actual content is not really of concern here, just check the plumbing. 134 // The actual content is not really of concern here, just check the plumbing.
135 const gfx::Size image_size(1200, 800); 135 const gfx::Size image_size(1200, 800);
136 gfx::Canvas canvas(image_size, 1.0f, true); 136 gfx::Canvas canvas(image_size, 1.0f, true);
137 137
138 // The image consists of vertical non-overlapping stripes 150 pixels wide. 138 // The image consists of vertical non-overlapping stripes 150 pixels wide.
139 canvas.FillRect(gfx::Rect(200, 200, 800, 400), SkColorSetRGB(255, 255, 255)); 139 canvas.FillRect(gfx::Rect(200, 200, 800, 400), SkColorSetRGB(255, 255, 255));
140 SkBitmap source = skia::ReadPixels(canvas.sk_canvas()); 140 SkBitmap source = skia::ReadPixels(canvas.sk_canvas());
141 141
142 ConsumerCallbackCatcher catcher; 142 ConsumerCallbackCatcher catcher;
143 const gfx::Size thumbnail_size(432, 284); 143 const gfx::Size thumbnail_size(432, 284);
144 scoped_refptr<ThumbnailingContext> context( 144 scoped_refptr<ThumbnailingContext> context(
145 ThumbnailingContext::CreateThumbnailingContextForTest()); 145 ThumbnailingContext::CreateThumbnailingContextForTest());
146 context->set_requested_copy_size(image_size); 146 context->requested_copy_size = image_size;
147 context->set_clip_result(CLIP_RESULT_SOURCE_SAME_AS_TARGET); 147 context->clip_result = CLIP_RESULT_SOURCE_SAME_AS_TARGET;
148 148
149 base::MessageLoopForUI message_loop; 149 base::MessageLoopForUI message_loop;
150 content::TestBrowserThread ui_thread(content::BrowserThread::UI, 150 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
151 &message_loop); 151 &message_loop);
152 ContentBasedThumbnailingAlgorithm::CreateRetargetedThumbnail( 152 ContentBasedThumbnailingAlgorithm::CreateRetargetedThumbnail(
153 source, 153 source,
154 thumbnail_size, 154 thumbnail_size,
155 context, 155 context,
156 base::Bind(&ConsumerCallbackCatcher::UiThreadCallback, 156 base::Bind(&ConsumerCallbackCatcher::UiThreadCallback,
157 base::Unretained(&catcher))); 157 base::Unretained(&catcher)));
158 message_loop.RunUntilIdle(); 158 message_loop.RunUntilIdle();
159 ASSERT_TRUE(catcher.called_back()); 159 ASSERT_TRUE(catcher.called_back());
160 EXPECT_TRUE(catcher.score().good_clipping); 160 EXPECT_TRUE(catcher.score().good_clipping);
161 EXPECT_FALSE(catcher.captured_bitmap().empty()); 161 EXPECT_FALSE(catcher.captured_bitmap().empty());
162 EXPECT_LT(catcher.captured_bitmap().width(), source.width()); 162 EXPECT_LT(catcher.captured_bitmap().width(), source.width());
163 EXPECT_LT(catcher.captured_bitmap().height(), source.height()); 163 EXPECT_LT(catcher.captured_bitmap().height(), source.height());
164 } 164 }
165 165
166 } // namespace thumbnails 166 } // namespace thumbnails
OLDNEW
« no previous file with comments | « chrome/browser/thumbnails/content_based_thumbnailing_algorithm.cc ('k') | chrome/browser/thumbnails/simple_thumbnail_crop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698