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

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

Issue 24175004: Remove dependency on ui::ScaleFactor from ui/gfx (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix new usage of scale in FastShowPickler Created 7 years, 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/thumbnails/content_analysis.h" 5 #include "chrome/browser/thumbnails/content_analysis.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <cstdlib> 9 #include <cstdlib>
10 #include <functional> 10 #include <functional>
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 72
73 } // namespace 73 } // namespace
74 74
75 namespace thumbnailing_utils { 75 namespace thumbnailing_utils {
76 76
77 class ThumbnailContentAnalysisTest : public testing::Test { 77 class ThumbnailContentAnalysisTest : public testing::Test {
78 }; 78 };
79 79
80 TEST_F(ThumbnailContentAnalysisTest, ApplyGradientMagnitudeOnImpulse) { 80 TEST_F(ThumbnailContentAnalysisTest, ApplyGradientMagnitudeOnImpulse) {
81 gfx::Canvas canvas(gfx::Size(800, 600), ui::SCALE_FACTOR_100P, true); 81 gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true);
82 82
83 // The image consists of vertical non-overlapping stripes 100 pixels wide. 83 // The image consists of vertical non-overlapping stripes 100 pixels wide.
84 canvas.FillRect(gfx::Rect(0, 0, 800, 600), SkColorSetARGB(0, 10, 10, 10)); 84 canvas.FillRect(gfx::Rect(0, 0, 800, 600), SkColorSetARGB(0, 10, 10, 10));
85 canvas.FillRect(gfx::Rect(400, 300, 1, 1), SkColorSetRGB(255, 255, 255)); 85 canvas.FillRect(gfx::Rect(400, 300, 1, 1), SkColorSetRGB(255, 255, 255));
86 86
87 SkBitmap source = 87 SkBitmap source =
88 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); 88 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false);
89 89
90 SkBitmap reduced_color; 90 SkBitmap reduced_color;
91 reduced_color.setConfig( 91 reduced_color.setConfig(
(...skipping 30 matching lines...) Expand all
122 } 122 }
123 123
124 // http://crbug.com/234336 124 // http://crbug.com/234336
125 #if defined(OS_MACOSX) 125 #if defined(OS_MACOSX)
126 #define MAYBE_ApplyGradientMagnitudeOnFrame \ 126 #define MAYBE_ApplyGradientMagnitudeOnFrame \
127 DISABLED_ApplyGradientMagnitudeOnFrame 127 DISABLED_ApplyGradientMagnitudeOnFrame
128 #else 128 #else
129 #define MAYBE_ApplyGradientMagnitudeOnFrame ApplyGradientMagnitudeOnFrame 129 #define MAYBE_ApplyGradientMagnitudeOnFrame ApplyGradientMagnitudeOnFrame
130 #endif 130 #endif
131 TEST_F(ThumbnailContentAnalysisTest, MAYBE_ApplyGradientMagnitudeOnFrame) { 131 TEST_F(ThumbnailContentAnalysisTest, MAYBE_ApplyGradientMagnitudeOnFrame) {
132 gfx::Canvas canvas(gfx::Size(800, 600), ui::SCALE_FACTOR_100P, true); 132 gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true);
133 133
134 // The image consists of a single white block in the centre. 134 // The image consists of a single white block in the centre.
135 gfx::Rect draw_rect(300, 200, 200, 200); 135 gfx::Rect draw_rect(300, 200, 200, 200);
136 canvas.FillRect(gfx::Rect(0, 0, 800, 600), SkColorSetARGB(0, 0, 0, 0)); 136 canvas.FillRect(gfx::Rect(0, 0, 800, 600), SkColorSetARGB(0, 0, 0, 0));
137 canvas.DrawRect(draw_rect, SkColorSetRGB(255, 255, 255)); 137 canvas.DrawRect(draw_rect, SkColorSetRGB(255, 255, 255));
138 138
139 SkBitmap source = 139 SkBitmap source =
140 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); 140 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false);
141 141
142 SkBitmap reduced_color; 142 SkBitmap reduced_color;
(...skipping 18 matching lines...) Expand all
161 draw_rect.width() - 2 * tail_length, 161 draw_rect.width() - 2 * tail_length,
162 draw_rect.height() - 2 * tail_length); 162 draw_rect.height() - 2 * tail_length);
163 unsigned long data_sum = ImagePixelSum(reduced_color, outer_rect); 163 unsigned long data_sum = ImagePixelSum(reduced_color, outer_rect);
164 unsigned long all_sum = ImagePixelSum(reduced_color, gfx::Rect(800, 600)); 164 unsigned long all_sum = ImagePixelSum(reduced_color, gfx::Rect(800, 600));
165 EXPECT_GT(data_sum, 0U); 165 EXPECT_GT(data_sum, 0U);
166 EXPECT_EQ(data_sum, all_sum); 166 EXPECT_EQ(data_sum, all_sum);
167 EXPECT_EQ(ImagePixelSum(reduced_color, inner_rect), 0U); 167 EXPECT_EQ(ImagePixelSum(reduced_color, inner_rect), 0U);
168 } 168 }
169 169
170 TEST_F(ThumbnailContentAnalysisTest, ExtractImageProfileInformation) { 170 TEST_F(ThumbnailContentAnalysisTest, ExtractImageProfileInformation) {
171 gfx::Canvas canvas(gfx::Size(800, 600), ui::SCALE_FACTOR_100P, true); 171 gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true);
172 172
173 // The image consists of a white frame drawn in the centre. 173 // The image consists of a white frame drawn in the centre.
174 gfx::Rect draw_rect(100, 100, 200, 100); 174 gfx::Rect draw_rect(100, 100, 200, 100);
175 gfx::Rect image_rect(0, 0, 800, 600); 175 gfx::Rect image_rect(0, 0, 800, 600);
176 canvas.FillRect(image_rect, SkColorSetARGB(0, 0, 0, 0)); 176 canvas.FillRect(image_rect, SkColorSetARGB(0, 0, 0, 0));
177 canvas.DrawRect(draw_rect, SkColorSetRGB(255, 255, 255)); 177 canvas.DrawRect(draw_rect, SkColorSetRGB(255, 255, 255));
178 178
179 SkBitmap source = 179 SkBitmap source =
180 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); 180 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false);
181 SkBitmap reduced_color; 181 SkBitmap reduced_color;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // http://crbug.com/234336 233 // http://crbug.com/234336
234 #if defined(OS_MACOSX) 234 #if defined(OS_MACOSX)
235 #define MAYBE_ExtractImageProfileInformationWithClosing \ 235 #define MAYBE_ExtractImageProfileInformationWithClosing \
236 DISABLED_ExtractImageProfileInformationWithClosing 236 DISABLED_ExtractImageProfileInformationWithClosing
237 #else 237 #else
238 #define MAYBE_ExtractImageProfileInformationWithClosing \ 238 #define MAYBE_ExtractImageProfileInformationWithClosing \
239 ExtractImageProfileInformationWithClosing 239 ExtractImageProfileInformationWithClosing
240 #endif 240 #endif
241 TEST_F(ThumbnailContentAnalysisTest, 241 TEST_F(ThumbnailContentAnalysisTest,
242 MAYBE_ExtractImageProfileInformationWithClosing) { 242 MAYBE_ExtractImageProfileInformationWithClosing) {
243 gfx::Canvas canvas(gfx::Size(800, 600), ui::SCALE_FACTOR_100P, true); 243 gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true);
244 244
245 // The image consists of a two white frames drawn side by side, with a 245 // The image consists of a two white frames drawn side by side, with a
246 // single-pixel vertical gap in between. 246 // single-pixel vertical gap in between.
247 gfx::Rect image_rect(0, 0, 800, 600); 247 gfx::Rect image_rect(0, 0, 800, 600);
248 canvas.FillRect(image_rect, SkColorSetARGB(0, 0, 0, 0)); 248 canvas.FillRect(image_rect, SkColorSetARGB(0, 0, 0, 0));
249 canvas.DrawRect(gfx::Rect(300, 250, 99, 100), SkColorSetRGB(255, 255, 255)); 249 canvas.DrawRect(gfx::Rect(300, 250, 99, 100), SkColorSetRGB(255, 255, 255));
250 canvas.DrawRect(gfx::Rect(401, 250, 99, 100), SkColorSetRGB(255, 255, 255)); 250 canvas.DrawRect(gfx::Rect(401, 250, 99, 100), SkColorSetRGB(255, 255, 255));
251 251
252 SkBitmap source = 252 SkBitmap source =
253 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); 253 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false);
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 columns_guide.begin(), columns_guide.end(), true); 568 columns_guide.begin(), columns_guide.end(), true);
569 float expected_aspect = 569 float expected_aspect =
570 static_cast<float>(target_size.width()) / target_size.height(); 570 static_cast<float>(target_size.width()) / target_size.height();
571 float actual_aspect = static_cast<float>(column_count) / row_count; 571 float actual_aspect = static_cast<float>(column_count) / row_count;
572 EXPECT_GE(1.05f, expected_aspect / actual_aspect); 572 EXPECT_GE(1.05f, expected_aspect / actual_aspect);
573 EXPECT_GE(1.05f, actual_aspect / expected_aspect); 573 EXPECT_GE(1.05f, actual_aspect / expected_aspect);
574 } 574 }
575 575
576 TEST_F(ThumbnailContentAnalysisTest, ComputeDecimatedImage) { 576 TEST_F(ThumbnailContentAnalysisTest, ComputeDecimatedImage) {
577 gfx::Size image_size(1600, 1200); 577 gfx::Size image_size(1600, 1200);
578 gfx::Canvas canvas(image_size, ui::SCALE_FACTOR_100P, true); 578 gfx::Canvas canvas(image_size, 1.0f, true);
579 579
580 // Make some content we will later want to keep. 580 // Make some content we will later want to keep.
581 canvas.FillRect(gfx::Rect(100, 200, 100, 100), SkColorSetARGB(0, 125, 0, 0)); 581 canvas.FillRect(gfx::Rect(100, 200, 100, 100), SkColorSetARGB(0, 125, 0, 0));
582 canvas.FillRect(gfx::Rect(300, 200, 100, 100), SkColorSetARGB(0, 0, 200, 0)); 582 canvas.FillRect(gfx::Rect(300, 200, 100, 100), SkColorSetARGB(0, 0, 200, 0));
583 canvas.FillRect(gfx::Rect(500, 200, 100, 100), SkColorSetARGB(0, 0, 0, 225)); 583 canvas.FillRect(gfx::Rect(500, 200, 100, 100), SkColorSetARGB(0, 0, 0, 225));
584 canvas.FillRect(gfx::Rect(100, 400, 600, 100), 584 canvas.FillRect(gfx::Rect(100, 400, 600, 100),
585 SkColorSetARGB(0, 125, 200, 225)); 585 SkColorSetARGB(0, 125, 200, 225));
586 586
587 std::vector<bool> rows(image_size.height(), false); 587 std::vector<bool> rows(image_size.height(), false);
588 std::fill_n(rows.begin() + 200, 100, true); 588 std::fill_n(rows.begin() + 200, 100, true);
(...skipping 29 matching lines...) Expand all
618 gfx::Point(200, 0))); 618 gfx::Point(200, 0)));
619 ASSERT_TRUE(CompareImageFragments(source, 619 ASSERT_TRUE(CompareImageFragments(source,
620 result, 620 result,
621 gfx::Size(100, 100), 621 gfx::Size(100, 100),
622 gfx::Point(100, 400), 622 gfx::Point(100, 400),
623 gfx::Point(0, 0))); 623 gfx::Point(0, 0)));
624 } 624 }
625 625
626 TEST_F(ThumbnailContentAnalysisTest, CreateRetargetedThumbnailImage) { 626 TEST_F(ThumbnailContentAnalysisTest, CreateRetargetedThumbnailImage) {
627 gfx::Size image_size(1200, 1300); 627 gfx::Size image_size(1200, 1300);
628 gfx::Canvas canvas(image_size, ui::SCALE_FACTOR_100P, true); 628 gfx::Canvas canvas(image_size, 1.0f, true);
629 629
630 // The following will create a 'fake image' consisting of color blocks placed 630 // The following will create a 'fake image' consisting of color blocks placed
631 // on a neutral background. The entire layout is supposed to mimic a 631 // on a neutral background. The entire layout is supposed to mimic a
632 // screenshot of a web page. 632 // screenshot of a web page.
633 // The tested function is supposed to locate the interesing areas in the 633 // The tested function is supposed to locate the interesing areas in the
634 // middle. 634 // middle.
635 const int margin_horizontal = 60; 635 const int margin_horizontal = 60;
636 const int margin_vertical = 20; 636 const int margin_vertical = 20;
637 canvas.FillRect(gfx::Rect(image_size), SkColorSetRGB(200, 210, 210)); 637 canvas.FillRect(gfx::Rect(image_size), SkColorSetRGB(200, 210, 210));
638 const gfx::Rect header_rect(margin_horizontal, 638 const gfx::Rect header_rect(margin_horizontal,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 721
722 int histogram[256] = {}; 722 int histogram[256] = {};
723 color_utils::BuildLumaHistogram(result, histogram); 723 color_utils::BuildLumaHistogram(result, histogram);
724 int non_zero_color_count = std::count_if( 724 int non_zero_color_count = std::count_if(
725 histogram, histogram + 256, std::bind2nd(std::greater<int>(), 0)); 725 histogram, histogram + 256, std::bind2nd(std::greater<int>(), 0));
726 EXPECT_GT(non_zero_color_count, 4); 726 EXPECT_GT(non_zero_color_count, 4);
727 727
728 } 728 }
729 729
730 } // namespace thumbnailing_utils 730 } // namespace thumbnailing_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698