| OLD | NEW |
| 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/macros.h" | 5 #include "base/macros.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "chrome/browser/thumbnails/content_based_thumbnailing_algorithm.h" | 8 #include "chrome/browser/thumbnails/content_based_thumbnailing_algorithm.h" |
| 9 #include "chrome/browser/thumbnails/simple_thumbnail_crop.h" | 9 #include "chrome/browser/thumbnails/simple_thumbnail_crop.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 133 } |
| 134 | 134 |
| 135 TEST_F(ContentBasedThumbnailingAlgorithmTest, CreateRetargetedThumbnail) { | 135 TEST_F(ContentBasedThumbnailingAlgorithmTest, CreateRetargetedThumbnail) { |
| 136 // This tests the invocation of the main thumbnail-making apparatus. | 136 // This tests the invocation of the main thumbnail-making apparatus. |
| 137 // The actual content is not really of concern here, just check the plumbing. | 137 // The actual content is not really of concern here, just check the plumbing. |
| 138 const gfx::Size image_size(1200, 800); | 138 const gfx::Size image_size(1200, 800); |
| 139 gfx::Canvas canvas(image_size, 1.0f, true); | 139 gfx::Canvas canvas(image_size, 1.0f, true); |
| 140 | 140 |
| 141 // The image consists of vertical non-overlapping stripes 150 pixels wide. | 141 // The image consists of vertical non-overlapping stripes 150 pixels wide. |
| 142 canvas.FillRect(gfx::Rect(200, 200, 800, 400), SkColorSetRGB(255, 255, 255)); | 142 canvas.FillRect(gfx::Rect(200, 200, 800, 400), SkColorSetRGB(255, 255, 255)); |
| 143 SkBitmap source = canvas.ToBitmap(); | 143 SkBitmap source = canvas.GetBitmap(); |
| 144 | 144 |
| 145 ConsumerCallbackCatcher catcher; | 145 ConsumerCallbackCatcher catcher; |
| 146 const gfx::Size thumbnail_size(432, 284); | 146 const gfx::Size thumbnail_size(432, 284); |
| 147 scoped_refptr<ThumbnailingContext> context( | 147 scoped_refptr<ThumbnailingContext> context( |
| 148 ThumbnailingContext::CreateThumbnailingContextForTest()); | 148 ThumbnailingContext::CreateThumbnailingContextForTest()); |
| 149 context->requested_copy_size = image_size; | 149 context->requested_copy_size = image_size; |
| 150 context->clip_result = CLIP_RESULT_SOURCE_SAME_AS_TARGET; | 150 context->clip_result = CLIP_RESULT_SOURCE_SAME_AS_TARGET; |
| 151 | 151 |
| 152 base::MessageLoopForUI message_loop; | 152 base::MessageLoopForUI message_loop; |
| 153 content::TestBrowserThread ui_thread(content::BrowserThread::UI, | 153 content::TestBrowserThread ui_thread(content::BrowserThread::UI, |
| 154 &message_loop); | 154 &message_loop); |
| 155 ContentBasedThumbnailingAlgorithm::CreateRetargetedThumbnail( | 155 ContentBasedThumbnailingAlgorithm::CreateRetargetedThumbnail( |
| 156 source, | 156 source, |
| 157 thumbnail_size, | 157 thumbnail_size, |
| 158 context, | 158 context, |
| 159 base::Bind(&ConsumerCallbackCatcher::UiThreadCallback, | 159 base::Bind(&ConsumerCallbackCatcher::UiThreadCallback, |
| 160 base::Unretained(&catcher))); | 160 base::Unretained(&catcher))); |
| 161 base::RunLoop().RunUntilIdle(); | 161 base::RunLoop().RunUntilIdle(); |
| 162 ASSERT_TRUE(catcher.called_back()); | 162 ASSERT_TRUE(catcher.called_back()); |
| 163 EXPECT_TRUE(catcher.score().good_clipping); | 163 EXPECT_TRUE(catcher.score().good_clipping); |
| 164 EXPECT_FALSE(catcher.captured_bitmap().empty()); | 164 EXPECT_FALSE(catcher.captured_bitmap().empty()); |
| 165 EXPECT_LT(catcher.captured_bitmap().width(), source.width()); | 165 EXPECT_LT(catcher.captured_bitmap().width(), source.width()); |
| 166 EXPECT_LT(catcher.captured_bitmap().height(), source.height()); | 166 EXPECT_LT(catcher.captured_bitmap().height(), source.height()); |
| 167 } | 167 } |
| 168 | 168 |
| 169 } // namespace thumbnails | 169 } // namespace thumbnails |
| OLD | NEW |