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

Side by Side Diff: chrome/browser/extensions/api/extension_action/browser_action_apitest.cc

Issue 11017046: Use LANCZOS3 resize algorithm to generate missing image reps for extension action icons. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/extension_action/extension_actions_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(TOOLKIT_GTK) 7 #if defined(TOOLKIT_GTK)
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #endif 9 #endif
10 10
(...skipping 12 matching lines...) Expand all
23 #include "chrome/common/chrome_notification_types.h" 23 #include "chrome/common/chrome_notification_types.h"
24 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
25 #include "chrome/test/base/ui_test_utils.h" 25 #include "chrome/test/base/ui_test_utils.h"
26 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 #include "content/public/test/browser_test_utils.h" 28 #include "content/public/test/browser_test_utils.h"
29 #include "grit/theme_resources.h" 29 #include "grit/theme_resources.h"
30 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/gfx/rect.h" 31 #include "ui/gfx/rect.h"
32 #include "ui/gfx/size.h" 32 #include "ui/gfx/size.h"
33 #include "ui/gfx/size_conversions.h"
33 #include "ui/gfx/image/image_skia.h" 34 #include "ui/gfx/image/image_skia.h"
34 #include "ui/gfx/image/image_skia_operations.h" 35 #include "ui/gfx/image/image_skia_operations.h"
35 #include "ui/gfx/skia_util.h" 36 #include "ui/gfx/skia_util.h"
36 37
37 #if defined (OS_MACOSX) 38 #if defined (OS_MACOSX)
38 #include "ui/gfx/image/image_unittest_util.h" 39 #include "ui/gfx/image/image_unittest_util.h"
39 #endif 40 #endif
40 41
41 using content::WebContents; 42 using content::WebContents;
42 43
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // Tell the extension to update the icon using ImageData object. 163 // Tell the extension to update the icon using ImageData object.
163 GetBrowserActionsBar().Press(0); 164 GetBrowserActionsBar().Press(0);
164 ASSERT_TRUE(catcher.GetNextResult()); 165 ASSERT_TRUE(catcher.GetNextResult());
165 166
166 action_icon = icon_factory.GetIcon(0); 167 action_icon = icon_factory.GetIcon(0);
167 168
168 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 169 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
169 EXPECT_GT(action_icon_current_id, action_icon_last_id); 170 EXPECT_GT(action_icon_current_id, action_icon_last_id);
170 action_icon_last_id = action_icon_current_id; 171 action_icon_last_id = action_icon_current_id;
171 172
172 EXPECT_FALSE(
173 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
174
175 EXPECT_TRUE(ImagesAreEqualAtScale( 173 EXPECT_TRUE(ImagesAreEqualAtScale(
176 AddBackgroundForViews(*action_icon.ToImageSkia()), 174 AddBackgroundForViews(*action_icon.ToImageSkia()),
177 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 175 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
178 ui::SCALE_FACTOR_100P)); 176 ui::SCALE_FACTOR_100P));
179 177
180 // Tell the extension to update the icon using path. 178 // Tell the extension to update the icon using path.
181 GetBrowserActionsBar().Press(0); 179 GetBrowserActionsBar().Press(0);
182 ASSERT_TRUE(catcher.GetNextResult()); 180 ASSERT_TRUE(catcher.GetNextResult());
183 181
184 action_icon = icon_factory.GetIcon(0); 182 action_icon = icon_factory.GetIcon(0);
185 183
186 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 184 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
187 EXPECT_GT(action_icon_current_id, action_icon_last_id); 185 EXPECT_GT(action_icon_current_id, action_icon_last_id);
188 action_icon_last_id = action_icon_current_id; 186 action_icon_last_id = action_icon_current_id;
189 187
190 EXPECT_FALSE(
191 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
192
193 EXPECT_TRUE(ImagesAreEqualAtScale( 188 EXPECT_TRUE(ImagesAreEqualAtScale(
194 AddBackgroundForViews(*action_icon.ToImageSkia()), 189 AddBackgroundForViews(*action_icon.ToImageSkia()),
195 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 190 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
196 ui::SCALE_FACTOR_100P)); 191 ui::SCALE_FACTOR_100P));
197 192
198 // Tell the extension to update the icon using dictionary of ImageData 193 // Tell the extension to update the icon using dictionary of ImageData
199 // objects. 194 // objects.
200 GetBrowserActionsBar().Press(0); 195 GetBrowserActionsBar().Press(0);
201 ASSERT_TRUE(catcher.GetNextResult()); 196 ASSERT_TRUE(catcher.GetNextResult());
202 197
203 action_icon = icon_factory.GetIcon(0); 198 action_icon = icon_factory.GetIcon(0);
204 199
205 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 200 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
206 EXPECT_GT(action_icon_current_id, action_icon_last_id); 201 EXPECT_GT(action_icon_current_id, action_icon_last_id);
207 action_icon_last_id = action_icon_current_id; 202 action_icon_last_id = action_icon_current_id;
208 203
209 EXPECT_TRUE(
210 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
211
212 EXPECT_TRUE(ImagesAreEqualAtScale( 204 EXPECT_TRUE(ImagesAreEqualAtScale(
213 AddBackgroundForViews(*action_icon.ToImageSkia()), 205 AddBackgroundForViews(*action_icon.ToImageSkia()),
214 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 206 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
215 ui::SCALE_FACTOR_100P)); 207 ui::SCALE_FACTOR_100P));
216 208
217 // Tell the extension to update the icon using dictionary of paths. 209 // Tell the extension to update the icon using dictionary of paths.
218 GetBrowserActionsBar().Press(0); 210 GetBrowserActionsBar().Press(0);
219 ASSERT_TRUE(catcher.GetNextResult()); 211 ASSERT_TRUE(catcher.GetNextResult());
220 212
221 action_icon = icon_factory.GetIcon(0); 213 action_icon = icon_factory.GetIcon(0);
222 214
223 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 215 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
224 EXPECT_GT(action_icon_current_id, action_icon_last_id); 216 EXPECT_GT(action_icon_current_id, action_icon_last_id);
225 action_icon_last_id = action_icon_current_id; 217 action_icon_last_id = action_icon_current_id;
226 218
227 EXPECT_TRUE(
228 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
229
230 EXPECT_TRUE(ImagesAreEqualAtScale( 219 EXPECT_TRUE(ImagesAreEqualAtScale(
231 AddBackgroundForViews(*action_icon.ToImageSkia()), 220 AddBackgroundForViews(*action_icon.ToImageSkia()),
232 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 221 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
233 ui::SCALE_FACTOR_100P)); 222 ui::SCALE_FACTOR_100P));
234 223
235 // Tell the extension to update the icon using dictionary of ImageData 224 // Tell the extension to update the icon using dictionary of ImageData
236 // objects, but setting only size 19. 225 // objects, but setting only size 19.
237 GetBrowserActionsBar().Press(0); 226 GetBrowserActionsBar().Press(0);
238 ASSERT_TRUE(catcher.GetNextResult()); 227 ASSERT_TRUE(catcher.GetNextResult());
239 228
240 action_icon = icon_factory.GetIcon(0); 229 action_icon = icon_factory.GetIcon(0);
241 230
242 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 231 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
243 EXPECT_GT(action_icon_current_id, action_icon_last_id); 232 EXPECT_GT(action_icon_current_id, action_icon_last_id);
244 action_icon_last_id = action_icon_current_id; 233 action_icon_last_id = action_icon_current_id;
245 234
246 EXPECT_FALSE(
247 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
248
249 EXPECT_TRUE(ImagesAreEqualAtScale( 235 EXPECT_TRUE(ImagesAreEqualAtScale(
250 AddBackgroundForViews(*action_icon.ToImageSkia()), 236 AddBackgroundForViews(*action_icon.ToImageSkia()),
251 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 237 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
252 ui::SCALE_FACTOR_100P)); 238 ui::SCALE_FACTOR_100P));
253 239
240 const float scale = ui::GetScaleFactorScale(ui::SCALE_FACTOR_200P);
241 const gfx::Size scaled_up_pixel_size = gfx::ToFlooredSize(
242 action_icon.ToImageSkia()->size().Scale(scale));
243
244 SkBitmap action_icon_scaled_up = skia::ImageOperations::Resize(
245 *action_icon.ToSkBitmap(), skia::ImageOperations::RESIZE_LANCZOS3,
246 scaled_up_pixel_size.width(), scaled_up_pixel_size.height());
247
248 const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia();
249 EXPECT_TRUE(gfx::BitmapsAreEqual(
250 action_icon_scaled_up,
251 action_icon_skia->GetRepresentation(ui::SCALE_FACTOR_200P).sk_bitmap()));
252
254 // Tell the extension to update the icon using dictionary of paths, but 253 // Tell the extension to update the icon using dictionary of paths, but
255 // setting only size 19. 254 // setting only size 19.
256 GetBrowserActionsBar().Press(0); 255 GetBrowserActionsBar().Press(0);
257 ASSERT_TRUE(catcher.GetNextResult()); 256 ASSERT_TRUE(catcher.GetNextResult());
258 257
259 action_icon = icon_factory.GetIcon(0); 258 action_icon = icon_factory.GetIcon(0);
260 259
261 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 260 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
262 EXPECT_GT(action_icon_current_id, action_icon_last_id); 261 EXPECT_GT(action_icon_current_id, action_icon_last_id);
263 action_icon_last_id = action_icon_current_id; 262 action_icon_last_id = action_icon_current_id;
264 263
265 EXPECT_FALSE(
266 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
267
268 EXPECT_TRUE(ImagesAreEqualAtScale( 264 EXPECT_TRUE(ImagesAreEqualAtScale(
269 AddBackgroundForViews(*action_icon.ToImageSkia()), 265 AddBackgroundForViews(*action_icon.ToImageSkia()),
270 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 266 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
271 ui::SCALE_FACTOR_100P)); 267 ui::SCALE_FACTOR_100P));
272 268
273 // Tell the extension to update the icon using dictionary of ImageData 269 // Tell the extension to update the icon using dictionary of ImageData
274 // objects, but setting only size 38. 270 // objects, but setting only size 38.
275 GetBrowserActionsBar().Press(0); 271 GetBrowserActionsBar().Press(0);
276 ASSERT_TRUE(catcher.GetNextResult()); 272 ASSERT_TRUE(catcher.GetNextResult());
277 273
278 action_icon = icon_factory.GetIcon(0); 274 action_icon = icon_factory.GetIcon(0);
279 275
280 const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia();
281
282 EXPECT_FALSE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_100P));
283 EXPECT_TRUE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_200P));
284
285 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 276 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
286 EXPECT_GT(action_icon_current_id, action_icon_last_id); 277 EXPECT_GT(action_icon_current_id, action_icon_last_id);
287 action_icon_last_id = action_icon_current_id; 278 action_icon_last_id = action_icon_current_id;
288 279
289 EXPECT_TRUE(gfx::BitmapsAreEqual( 280 EXPECT_TRUE(ImagesAreEqualAtScale(
290 *action_icon.ToSkBitmap(), 281 AddBackgroundForViews(*action_icon.ToImageSkia()),
291 action_icon_skia->GetRepresentation(ui::SCALE_FACTOR_200P).sk_bitmap())); 282 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
283 ui::SCALE_FACTOR_100P));
292 284
285 #if !defined(TOOLKIT_GTK)
293 EXPECT_TRUE(ImagesAreEqualAtScale( 286 EXPECT_TRUE(ImagesAreEqualAtScale(
294 AddBackgroundForViews(*action_icon_skia), 287 AddBackgroundForViews(*action_icon.ToImageSkia()),
295 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 288 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
296 ui::SCALE_FACTOR_200P)); 289 ui::SCALE_FACTOR_200P));
290 #endif
297 291
298 // Try setting icon with empty dictionary of ImageData objects. 292 // Try setting icon with empty dictionary of ImageData objects.
299 GetBrowserActionsBar().Press(0); 293 GetBrowserActionsBar().Press(0);
300 ASSERT_FALSE(catcher.GetNextResult()); 294 ASSERT_FALSE(catcher.GetNextResult());
301 EXPECT_EQ(kEmptyImageDataError, catcher.message()); 295 EXPECT_EQ(kEmptyImageDataError, catcher.message());
302 296
303 // Try setting icon with empty dictionary of path objects. 297 // Try setting icon with empty dictionary of path objects.
304 GetBrowserActionsBar().Press(0); 298 GetBrowserActionsBar().Press(0);
305 ASSERT_FALSE(catcher.GetNextResult()); 299 ASSERT_FALSE(catcher.GetNextResult());
306 EXPECT_EQ(kEmptyPathError, catcher.message()); 300 EXPECT_EQ(kEmptyPathError, catcher.message());
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 ASSERT_TRUE(catcher.GetNextResult()); 640 ASSERT_TRUE(catcher.GetNextResult());
647 641
648 // Test the getters for a specific tab. 642 // Test the getters for a specific tab.
649 ui_test_utils::NavigateToURL(browser(), 643 ui_test_utils::NavigateToURL(browser(),
650 GURL(extension->GetResourceURL("update2.html"))); 644 GURL(extension->GetResourceURL("update2.html")));
651 ASSERT_TRUE(catcher.GetNextResult()); 645 ASSERT_TRUE(catcher.GetNextResult());
652 } 646 }
653 647
654 } // namespace 648 } // namespace
655 } // namespace extensions 649 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/extension_action/extension_actions_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698