OLD | NEW |
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/extensions/extension_icon_image.h" | 5 #include "chrome/browser/extensions/extension_icon_image.h" |
6 | 6 |
7 #include "base/json/json_file_value_serializer.h" | 7 #include "base/json/json_file_value_serializer.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "chrome/browser/extensions/image_loader.h" | 10 #include "chrome/browser/extensions/image_loader.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 using content::BrowserThread; | 25 using content::BrowserThread; |
26 using extensions::Extension; | 26 using extensions::Extension; |
27 using extensions::IconImage; | 27 using extensions::IconImage; |
28 using extensions::Manifest; | 28 using extensions::Manifest; |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 SkBitmap CreateBlankBitmapForScale(int size_dip, ui::ScaleFactor scale_factor) { | 32 SkBitmap CreateBlankBitmapForScale(int size_dip, ui::ScaleFactor scale_factor) { |
33 SkBitmap bitmap; | 33 SkBitmap bitmap; |
34 const float scale = ui::GetScaleFactorScale(scale_factor); | 34 const float scale = ui::GetImageScale(scale_factor); |
35 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 35 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
36 static_cast<int>(size_dip * scale), | 36 static_cast<int>(size_dip * scale), |
37 static_cast<int>(size_dip * scale)); | 37 static_cast<int>(size_dip * scale)); |
38 bitmap.allocPixels(); | 38 bitmap.allocPixels(); |
39 bitmap.eraseColor(SkColorSetARGB(0, 0, 0, 0)); | 39 bitmap.eraseColor(SkColorSetARGB(0, 0, 0, 0)); |
40 return bitmap; | 40 return bitmap; |
41 } | 41 } |
42 | 42 |
43 SkBitmap EnsureBitmapSize(const SkBitmap& original, int size) { | 43 SkBitmap EnsureBitmapSize(const SkBitmap& original, int size) { |
44 if (original.width() == size && original.height() == size) | 44 if (original.width() == size && original.height() == size) |
45 return original; | 45 return original; |
46 | 46 |
47 SkBitmap resized = skia::ImageOperations::Resize( | 47 SkBitmap resized = skia::ImageOperations::Resize( |
48 original, skia::ImageOperations::RESIZE_LANCZOS3, size, size); | 48 original, skia::ImageOperations::RESIZE_LANCZOS3, size, size); |
49 return resized; | 49 return resized; |
50 } | 50 } |
51 | 51 |
52 // Used to test behavior including images defined by an image skia source. | 52 // Used to test behavior including images defined by an image skia source. |
53 // |GetImageForScale| simply returns image representation from the image given | 53 // |GetImageForScale| simply returns image representation from the image given |
54 // in the ctor. | 54 // in the ctor. |
55 class MockImageSkiaSource : public gfx::ImageSkiaSource { | 55 class MockImageSkiaSource : public gfx::ImageSkiaSource { |
56 public: | 56 public: |
57 explicit MockImageSkiaSource(const gfx::ImageSkia& image) | 57 explicit MockImageSkiaSource(const gfx::ImageSkia& image) |
58 : image_(image) { | 58 : image_(image) { |
59 } | 59 } |
60 virtual ~MockImageSkiaSource() {} | 60 virtual ~MockImageSkiaSource() {} |
61 | 61 |
62 virtual gfx::ImageSkiaRep GetImageForScale( | 62 virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
63 ui::ScaleFactor scale_factor) OVERRIDE { | 63 return image_.GetRepresentation(scale); |
64 return image_.GetRepresentation(scale_factor); | |
65 } | 64 } |
66 | 65 |
67 private: | 66 private: |
68 gfx::ImageSkia image_; | 67 gfx::ImageSkia image_; |
69 }; | 68 }; |
70 | 69 |
71 // Helper class for synchronously loading extension image resource. | 70 // Helper class for synchronously loading extension image resource. |
72 class TestImageLoader { | 71 class TestImageLoader { |
73 public: | 72 public: |
74 explicit TestImageLoader(const Extension* extension) | 73 explicit TestImageLoader(const Extension* extension) |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 content::TestBrowserThread ui_thread_; | 202 content::TestBrowserThread ui_thread_; |
204 content::TestBrowserThread file_thread_; | 203 content::TestBrowserThread file_thread_; |
205 content::TestBrowserThread io_thread_; | 204 content::TestBrowserThread io_thread_; |
206 | 205 |
207 DISALLOW_COPY_AND_ASSIGN(ExtensionIconImageTest); | 206 DISALLOW_COPY_AND_ASSIGN(ExtensionIconImageTest); |
208 }; | 207 }; |
209 | 208 |
210 } // namespace | 209 } // namespace |
211 | 210 |
212 TEST_F(ExtensionIconImageTest, Basic) { | 211 TEST_F(ExtensionIconImageTest, Basic) { |
| 212 std::vector<ui::ScaleFactor> supported_factors; |
| 213 supported_factors.push_back(ui::SCALE_FACTOR_100P); |
| 214 supported_factors.push_back(ui::SCALE_FACTOR_200P); |
| 215 ui::test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors); |
213 scoped_ptr<Profile> profile(new TestingProfile()); | 216 scoped_ptr<Profile> profile(new TestingProfile()); |
214 scoped_refptr<Extension> extension(CreateExtension( | 217 scoped_refptr<Extension> extension(CreateExtension( |
215 "extension_icon_image", Manifest::INVALID_LOCATION)); | 218 "extension_icon_image", Manifest::INVALID_LOCATION)); |
216 ASSERT_TRUE(extension.get() != NULL); | 219 ASSERT_TRUE(extension.get() != NULL); |
217 | 220 |
218 gfx::ImageSkia default_icon = GetDefaultIcon(); | 221 gfx::ImageSkia default_icon = GetDefaultIcon(); |
219 | 222 |
220 // Load images we expect to find as representations in icon_image, so we | 223 // Load images we expect to find as representations in icon_image, so we |
221 // can later use them to validate icon_image. | 224 // can later use them to validate icon_image. |
222 SkBitmap bitmap_16 = GetTestBitmap(extension.get(), "16.png", 16); | 225 SkBitmap bitmap_16 = GetTestBitmap(extension.get(), "16.png", 16); |
(...skipping 10 matching lines...) Expand all Loading... |
233 extensions::IconsInfo::GetIcons(extension.get()), | 236 extensions::IconsInfo::GetIcons(extension.get()), |
234 16, | 237 16, |
235 default_icon, | 238 default_icon, |
236 this); | 239 this); |
237 | 240 |
238 // No representations in |image_| yet. | 241 // No representations in |image_| yet. |
239 gfx::ImageSkia::ImageSkiaReps image_reps = image.image_skia().image_reps(); | 242 gfx::ImageSkia::ImageSkiaReps image_reps = image.image_skia().image_reps(); |
240 ASSERT_EQ(0u, image_reps.size()); | 243 ASSERT_EQ(0u, image_reps.size()); |
241 | 244 |
242 // Gets representation for a scale factor. | 245 // Gets representation for a scale factor. |
243 gfx::ImageSkiaRep representation = | 246 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f); |
244 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); | |
245 | 247 |
246 // Before the image representation is loaded, image should contain blank | 248 // Before the image representation is loaded, image should contain blank |
247 // image representation. | 249 // image representation. |
248 EXPECT_TRUE(gfx::BitmapsAreEqual( | 250 EXPECT_TRUE(gfx::BitmapsAreEqual( |
249 representation.sk_bitmap(), | 251 representation.sk_bitmap(), |
250 CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_100P))); | 252 CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_100P))); |
251 | 253 |
252 WaitForImageLoad(); | 254 WaitForImageLoad(); |
253 EXPECT_EQ(1, ImageLoadedCount()); | 255 EXPECT_EQ(1, ImageLoadedCount()); |
254 ASSERT_EQ(1u, image.image_skia().image_reps().size()); | 256 ASSERT_EQ(1u, image.image_skia().image_reps().size()); |
255 | 257 |
256 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); | 258 representation = image.image_skia().GetRepresentation(1.0f); |
257 | 259 |
258 // We should get the right representation now. | 260 // We should get the right representation now. |
259 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16)); | 261 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16)); |
260 EXPECT_EQ(16, representation.pixel_width()); | 262 EXPECT_EQ(16, representation.pixel_width()); |
261 | 263 |
262 // Gets representation for an additional scale factor. | 264 // Gets representation for an additional scale factor. |
263 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P); | 265 representation = image.image_skia().GetRepresentation(2.0f); |
264 | 266 |
265 EXPECT_TRUE(gfx::BitmapsAreEqual( | 267 EXPECT_TRUE(gfx::BitmapsAreEqual( |
266 representation.sk_bitmap(), | 268 representation.sk_bitmap(), |
267 CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_200P))); | 269 CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_200P))); |
268 | 270 |
269 WaitForImageLoad(); | 271 WaitForImageLoad(); |
270 EXPECT_EQ(1, ImageLoadedCount()); | 272 EXPECT_EQ(1, ImageLoadedCount()); |
271 ASSERT_EQ(2u, image.image_skia().image_reps().size()); | 273 ASSERT_EQ(2u, image.image_skia().image_reps().size()); |
272 | 274 |
273 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P); | 275 representation = image.image_skia().GetRepresentation(2.0f); |
274 | 276 |
275 // Image should have been resized. | 277 // Image should have been resized. |
276 EXPECT_EQ(32, representation.pixel_width()); | 278 EXPECT_EQ(32, representation.pixel_width()); |
277 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), | 279 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), |
278 bitmap_48_resized_to_32)); | 280 bitmap_48_resized_to_32)); |
279 } | 281 } |
280 | 282 |
281 // There is no resource with either exact or bigger size, but there is a smaller | 283 // There is no resource with either exact or bigger size, but there is a smaller |
282 // resource. | 284 // resource. |
283 TEST_F(ExtensionIconImageTest, FallbackToSmallerWhenNoBigger) { | 285 TEST_F(ExtensionIconImageTest, FallbackToSmallerWhenNoBigger) { |
| 286 std::vector<ui::ScaleFactor> supported_factors; |
| 287 supported_factors.push_back(ui::SCALE_FACTOR_100P); |
| 288 supported_factors.push_back(ui::SCALE_FACTOR_200P); |
| 289 ui::test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors); |
284 scoped_ptr<Profile> profile(new TestingProfile()); | 290 scoped_ptr<Profile> profile(new TestingProfile()); |
285 scoped_refptr<Extension> extension(CreateExtension( | 291 scoped_refptr<Extension> extension(CreateExtension( |
286 "extension_icon_image", Manifest::INVALID_LOCATION)); | 292 "extension_icon_image", Manifest::INVALID_LOCATION)); |
287 ASSERT_TRUE(extension.get() != NULL); | 293 ASSERT_TRUE(extension.get() != NULL); |
288 | 294 |
289 gfx::ImageSkia default_icon = GetDefaultIcon(); | 295 gfx::ImageSkia default_icon = GetDefaultIcon(); |
290 | 296 |
291 // Load images we expect to find as representations in icon_image, so we | 297 // Load images we expect to find as representations in icon_image, so we |
292 // can later use them to validate icon_image. | 298 // can later use them to validate icon_image. |
293 SkBitmap bitmap_48 = GetTestBitmap(extension.get(), "48.png", 48); | 299 SkBitmap bitmap_48 = GetTestBitmap(extension.get(), "48.png", 48); |
294 ASSERT_FALSE(bitmap_48.empty()); | 300 ASSERT_FALSE(bitmap_48.empty()); |
295 | 301 |
296 IconImage image(profile.get(), | 302 IconImage image(profile.get(), |
297 extension.get(), | 303 extension.get(), |
298 extensions::IconsInfo::GetIcons(extension.get()), | 304 extensions::IconsInfo::GetIcons(extension.get()), |
299 32, | 305 32, |
300 default_icon, | 306 default_icon, |
301 this); | 307 this); |
302 | 308 |
303 gfx::ImageSkiaRep representation = | 309 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(2.0f); |
304 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P); | |
305 | 310 |
306 WaitForImageLoad(); | 311 WaitForImageLoad(); |
307 EXPECT_EQ(1, ImageLoadedCount()); | 312 EXPECT_EQ(1, ImageLoadedCount()); |
308 ASSERT_EQ(1u, image.image_skia().image_reps().size()); | 313 ASSERT_EQ(1u, image.image_skia().image_reps().size()); |
309 | 314 |
310 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P); | 315 representation = image.image_skia().GetRepresentation(2.0f); |
311 | 316 |
312 // We should have loaded the biggest smaller resource resized to the actual | 317 // We should have loaded the biggest smaller resource resized to the actual |
313 // size. | 318 // size. |
314 EXPECT_EQ(ui::SCALE_FACTOR_200P, representation.scale_factor()); | 319 EXPECT_EQ(2.0f, representation.scale()); |
315 EXPECT_EQ(64, representation.pixel_width()); | 320 EXPECT_EQ(64, representation.pixel_width()); |
316 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), | 321 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), |
317 EnsureBitmapSize(bitmap_48, 64))); | 322 EnsureBitmapSize(bitmap_48, 64))); |
318 } | 323 } |
319 | 324 |
320 // There is no resource with exact size, but there is a smaller and a bigger | 325 // There is no resource with exact size, but there is a smaller and a bigger |
321 // one. Requested size is smaller than 32 though, so the smaller resource should | 326 // one. Requested size is smaller than 32 though, so the smaller resource should |
322 // be loaded. | 327 // be loaded. |
323 TEST_F(ExtensionIconImageTest, FallbackToSmaller) { | 328 TEST_F(ExtensionIconImageTest, FallbackToSmaller) { |
324 scoped_ptr<Profile> profile(new TestingProfile()); | 329 scoped_ptr<Profile> profile(new TestingProfile()); |
325 scoped_refptr<Extension> extension(CreateExtension( | 330 scoped_refptr<Extension> extension(CreateExtension( |
326 "extension_icon_image", Manifest::INVALID_LOCATION)); | 331 "extension_icon_image", Manifest::INVALID_LOCATION)); |
327 ASSERT_TRUE(extension.get() != NULL); | 332 ASSERT_TRUE(extension.get() != NULL); |
328 | 333 |
329 gfx::ImageSkia default_icon = GetDefaultIcon(); | 334 gfx::ImageSkia default_icon = GetDefaultIcon(); |
330 | 335 |
331 // Load images we expect to find as representations in icon_image, so we | 336 // Load images we expect to find as representations in icon_image, so we |
332 // can later use them to validate icon_image. | 337 // can later use them to validate icon_image. |
333 SkBitmap bitmap_16 = GetTestBitmap(extension.get(), "16.png", 16); | 338 SkBitmap bitmap_16 = GetTestBitmap(extension.get(), "16.png", 16); |
334 ASSERT_FALSE(bitmap_16.empty()); | 339 ASSERT_FALSE(bitmap_16.empty()); |
335 | 340 |
336 IconImage image(profile.get(), | 341 IconImage image(profile.get(), |
337 extension.get(), | 342 extension.get(), |
338 extensions::IconsInfo::GetIcons(extension.get()), | 343 extensions::IconsInfo::GetIcons(extension.get()), |
339 17, | 344 17, |
340 default_icon, | 345 default_icon, |
341 this); | 346 this); |
342 | 347 |
343 gfx::ImageSkiaRep representation = | 348 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f); |
344 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); | |
345 | 349 |
346 WaitForImageLoad(); | 350 WaitForImageLoad(); |
347 EXPECT_EQ(1, ImageLoadedCount()); | 351 EXPECT_EQ(1, ImageLoadedCount()); |
348 ASSERT_EQ(1u, image.image_skia().image_reps().size()); | 352 ASSERT_EQ(1u, image.image_skia().image_reps().size()); |
349 | 353 |
350 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); | 354 representation = image.image_skia().GetRepresentation(1.0f); |
351 | 355 |
352 // We should have loaded smaller (resized) resource. | 356 // We should have loaded smaller (resized) resource. |
353 EXPECT_EQ(ui::SCALE_FACTOR_100P, representation.scale_factor()); | 357 EXPECT_EQ(1.0f, representation.scale()); |
354 EXPECT_EQ(17, representation.pixel_width()); | 358 EXPECT_EQ(17, representation.pixel_width()); |
355 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), | 359 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), |
356 EnsureBitmapSize(bitmap_16, 17))); | 360 EnsureBitmapSize(bitmap_16, 17))); |
357 } | 361 } |
358 | 362 |
359 // If resource set is empty, |GetRepresentation| should synchronously return | 363 // If resource set is empty, |GetRepresentation| should synchronously return |
360 // default icon, without notifying observer of image change. | 364 // default icon, without notifying observer of image change. |
361 TEST_F(ExtensionIconImageTest, NoResources) { | 365 TEST_F(ExtensionIconImageTest, NoResources) { |
362 scoped_ptr<Profile> profile(new TestingProfile()); | 366 scoped_ptr<Profile> profile(new TestingProfile()); |
363 scoped_refptr<Extension> extension(CreateExtension( | 367 scoped_refptr<Extension> extension(CreateExtension( |
364 "extension_icon_image", Manifest::INVALID_LOCATION)); | 368 "extension_icon_image", Manifest::INVALID_LOCATION)); |
365 ASSERT_TRUE(extension.get() != NULL); | 369 ASSERT_TRUE(extension.get() != NULL); |
366 | 370 |
367 ExtensionIconSet empty_icon_set; | 371 ExtensionIconSet empty_icon_set; |
368 gfx::ImageSkia default_icon = GetDefaultIcon(); | 372 gfx::ImageSkia default_icon = GetDefaultIcon(); |
369 | 373 |
370 const int kRequestedSize = 24; | 374 const int kRequestedSize = 24; |
371 IconImage image(profile.get(), | 375 IconImage image(profile.get(), |
372 extension.get(), | 376 extension.get(), |
373 empty_icon_set, | 377 empty_icon_set, |
374 kRequestedSize, | 378 kRequestedSize, |
375 default_icon, | 379 default_icon, |
376 this); | 380 this); |
377 | 381 |
378 gfx::ImageSkiaRep representation = | 382 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f); |
379 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); | |
380 EXPECT_TRUE(gfx::BitmapsAreEqual( | 383 EXPECT_TRUE(gfx::BitmapsAreEqual( |
381 representation.sk_bitmap(), | 384 representation.sk_bitmap(), |
382 EnsureBitmapSize( | 385 EnsureBitmapSize( |
383 default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(), | 386 default_icon.GetRepresentation(1.0f).sk_bitmap(), |
384 kRequestedSize))); | 387 kRequestedSize))); |
385 | 388 |
386 EXPECT_EQ(0, ImageLoadedCount()); | 389 EXPECT_EQ(0, ImageLoadedCount()); |
387 // We should have a default icon representation. | 390 // We should have a default icon representation. |
388 ASSERT_EQ(1u, image.image_skia().image_reps().size()); | 391 ASSERT_EQ(1u, image.image_skia().image_reps().size()); |
389 | 392 |
390 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); | 393 representation = image.image_skia().GetRepresentation(1.0f); |
391 EXPECT_TRUE(gfx::BitmapsAreEqual( | 394 EXPECT_TRUE(gfx::BitmapsAreEqual( |
392 representation.sk_bitmap(), | 395 representation.sk_bitmap(), |
393 EnsureBitmapSize( | 396 EnsureBitmapSize( |
394 default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(), | 397 default_icon.GetRepresentation(1.0f).sk_bitmap(), |
395 kRequestedSize))); | 398 kRequestedSize))); |
396 } | 399 } |
397 | 400 |
398 // If resource set is invalid, image load should be done asynchronously and | 401 // If resource set is invalid, image load should be done asynchronously and |
399 // the observer should be notified when it's done. |GetRepresentation| should | 402 // the observer should be notified when it's done. |GetRepresentation| should |
400 // return the default icon representation once image load is done. | 403 // return the default icon representation once image load is done. |
401 TEST_F(ExtensionIconImageTest, InvalidResource) { | 404 TEST_F(ExtensionIconImageTest, InvalidResource) { |
402 scoped_ptr<Profile> profile(new TestingProfile()); | 405 scoped_ptr<Profile> profile(new TestingProfile()); |
403 scoped_refptr<Extension> extension(CreateExtension( | 406 scoped_refptr<Extension> extension(CreateExtension( |
404 "extension_icon_image", Manifest::INVALID_LOCATION)); | 407 "extension_icon_image", Manifest::INVALID_LOCATION)); |
405 ASSERT_TRUE(extension.get() != NULL); | 408 ASSERT_TRUE(extension.get() != NULL); |
406 | 409 |
407 const int kInvalidIconSize = 24; | 410 const int kInvalidIconSize = 24; |
408 ExtensionIconSet invalid_icon_set; | 411 ExtensionIconSet invalid_icon_set; |
409 invalid_icon_set.Add(kInvalidIconSize, "invalid.png"); | 412 invalid_icon_set.Add(kInvalidIconSize, "invalid.png"); |
410 | 413 |
411 gfx::ImageSkia default_icon = GetDefaultIcon(); | 414 gfx::ImageSkia default_icon = GetDefaultIcon(); |
412 | 415 |
413 IconImage image(profile.get(), | 416 IconImage image(profile.get(), |
414 extension.get(), | 417 extension.get(), |
415 invalid_icon_set, | 418 invalid_icon_set, |
416 kInvalidIconSize, | 419 kInvalidIconSize, |
417 default_icon, | 420 default_icon, |
418 this); | 421 this); |
419 | 422 |
420 gfx::ImageSkiaRep representation = | 423 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f); |
421 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); | |
422 EXPECT_TRUE(gfx::BitmapsAreEqual( | 424 EXPECT_TRUE(gfx::BitmapsAreEqual( |
423 representation.sk_bitmap(), | 425 representation.sk_bitmap(), |
424 CreateBlankBitmapForScale(kInvalidIconSize, ui::SCALE_FACTOR_100P))); | 426 CreateBlankBitmapForScale(kInvalidIconSize, ui::SCALE_FACTOR_100P))); |
425 | 427 |
426 WaitForImageLoad(); | 428 WaitForImageLoad(); |
427 EXPECT_EQ(1, ImageLoadedCount()); | 429 EXPECT_EQ(1, ImageLoadedCount()); |
428 // We should have default icon representation now. | 430 // We should have default icon representation now. |
429 ASSERT_EQ(1u, image.image_skia().image_reps().size()); | 431 ASSERT_EQ(1u, image.image_skia().image_reps().size()); |
430 | 432 |
431 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); | 433 representation = image.image_skia().GetRepresentation(1.0f); |
432 EXPECT_TRUE(gfx::BitmapsAreEqual( | 434 EXPECT_TRUE(gfx::BitmapsAreEqual( |
433 representation.sk_bitmap(), | 435 representation.sk_bitmap(), |
434 EnsureBitmapSize( | 436 EnsureBitmapSize( |
435 default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(), | 437 default_icon.GetRepresentation(1.0f).sk_bitmap(), |
436 kInvalidIconSize))); | 438 kInvalidIconSize))); |
437 } | 439 } |
438 | 440 |
439 // Test that IconImage works with lazily (but synchronously) created default | 441 // Test that IconImage works with lazily (but synchronously) created default |
440 // icon when IconImage returns synchronously. | 442 // icon when IconImage returns synchronously. |
441 TEST_F(ExtensionIconImageTest, LazyDefaultIcon) { | 443 TEST_F(ExtensionIconImageTest, LazyDefaultIcon) { |
442 scoped_ptr<Profile> profile(new TestingProfile()); | 444 scoped_ptr<Profile> profile(new TestingProfile()); |
443 scoped_refptr<Extension> extension(CreateExtension( | 445 scoped_refptr<Extension> extension(CreateExtension( |
444 "extension_icon_image", Manifest::INVALID_LOCATION)); | 446 "extension_icon_image", Manifest::INVALID_LOCATION)); |
445 ASSERT_TRUE(extension.get() != NULL); | 447 ASSERT_TRUE(extension.get() != NULL); |
446 | 448 |
447 gfx::ImageSkia default_icon = GetDefaultIcon(); | 449 gfx::ImageSkia default_icon = GetDefaultIcon(); |
448 gfx::ImageSkia lazy_default_icon(new MockImageSkiaSource(default_icon), | 450 gfx::ImageSkia lazy_default_icon(new MockImageSkiaSource(default_icon), |
449 default_icon.size()); | 451 default_icon.size()); |
450 | 452 |
451 ExtensionIconSet empty_icon_set; | 453 ExtensionIconSet empty_icon_set; |
452 | 454 |
453 const int kRequestedSize = 128; | 455 const int kRequestedSize = 128; |
454 IconImage image(profile.get(), | 456 IconImage image(profile.get(), |
455 extension.get(), | 457 extension.get(), |
456 empty_icon_set, | 458 empty_icon_set, |
457 kRequestedSize, | 459 kRequestedSize, |
458 lazy_default_icon, | 460 lazy_default_icon, |
459 this); | 461 this); |
460 | 462 |
461 ASSERT_FALSE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P)); | 463 ASSERT_FALSE(lazy_default_icon.HasRepresentation(1.0f)); |
462 | 464 |
463 gfx::ImageSkiaRep representation = | 465 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f); |
464 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); | |
465 | 466 |
466 // The resouce set is empty, so we should get the result right away. | 467 // The resouce set is empty, so we should get the result right away. |
467 EXPECT_TRUE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P)); | 468 EXPECT_TRUE(lazy_default_icon.HasRepresentation(1.0f)); |
468 EXPECT_TRUE(gfx::BitmapsAreEqual( | 469 EXPECT_TRUE(gfx::BitmapsAreEqual( |
469 representation.sk_bitmap(), | 470 representation.sk_bitmap(), |
470 EnsureBitmapSize( | 471 EnsureBitmapSize( |
471 default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(), | 472 default_icon.GetRepresentation(1.0f).sk_bitmap(), |
472 kRequestedSize))); | 473 kRequestedSize))); |
473 | 474 |
474 // We should have a default icon representation. | 475 // We should have a default icon representation. |
475 ASSERT_EQ(1u, image.image_skia().image_reps().size()); | 476 ASSERT_EQ(1u, image.image_skia().image_reps().size()); |
476 } | 477 } |
477 | 478 |
478 // Test that IconImage works with lazily (but synchronously) created default | 479 // Test that IconImage works with lazily (but synchronously) created default |
479 // icon when IconImage returns asynchronously. | 480 // icon when IconImage returns asynchronously. |
480 TEST_F(ExtensionIconImageTest, LazyDefaultIcon_AsyncIconImage) { | 481 TEST_F(ExtensionIconImageTest, LazyDefaultIcon_AsyncIconImage) { |
481 scoped_ptr<Profile> profile(new TestingProfile()); | 482 scoped_ptr<Profile> profile(new TestingProfile()); |
482 scoped_refptr<Extension> extension(CreateExtension( | 483 scoped_refptr<Extension> extension(CreateExtension( |
483 "extension_icon_image", Manifest::INVALID_LOCATION)); | 484 "extension_icon_image", Manifest::INVALID_LOCATION)); |
484 ASSERT_TRUE(extension.get() != NULL); | 485 ASSERT_TRUE(extension.get() != NULL); |
485 | 486 |
486 gfx::ImageSkia default_icon = GetDefaultIcon(); | 487 gfx::ImageSkia default_icon = GetDefaultIcon(); |
487 gfx::ImageSkia lazy_default_icon(new MockImageSkiaSource(default_icon), | 488 gfx::ImageSkia lazy_default_icon(new MockImageSkiaSource(default_icon), |
488 default_icon.size()); | 489 default_icon.size()); |
489 | 490 |
490 const int kInvalidIconSize = 24; | 491 const int kInvalidIconSize = 24; |
491 ExtensionIconSet invalid_icon_set; | 492 ExtensionIconSet invalid_icon_set; |
492 invalid_icon_set.Add(kInvalidIconSize, "invalid.png"); | 493 invalid_icon_set.Add(kInvalidIconSize, "invalid.png"); |
493 | 494 |
494 IconImage image(profile.get(), | 495 IconImage image(profile.get(), |
495 extension.get(), | 496 extension.get(), |
496 invalid_icon_set, | 497 invalid_icon_set, |
497 kInvalidIconSize, | 498 kInvalidIconSize, |
498 lazy_default_icon, | 499 lazy_default_icon, |
499 this); | 500 this); |
500 | 501 |
501 ASSERT_FALSE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P)); | 502 ASSERT_FALSE(lazy_default_icon.HasRepresentation(1.0f)); |
502 | 503 |
503 gfx::ImageSkiaRep representation = | 504 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f); |
504 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); | |
505 | 505 |
506 WaitForImageLoad(); | 506 WaitForImageLoad(); |
507 EXPECT_EQ(1, ImageLoadedCount()); | 507 EXPECT_EQ(1, ImageLoadedCount()); |
508 // We should have default icon representation now. | 508 // We should have default icon representation now. |
509 ASSERT_EQ(1u, image.image_skia().image_reps().size()); | 509 ASSERT_EQ(1u, image.image_skia().image_reps().size()); |
510 | 510 |
511 EXPECT_TRUE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P)); | 511 EXPECT_TRUE(lazy_default_icon.HasRepresentation(1.0f)); |
512 | 512 |
513 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); | 513 representation = image.image_skia().GetRepresentation(1.0f); |
514 EXPECT_TRUE(gfx::BitmapsAreEqual( | 514 EXPECT_TRUE(gfx::BitmapsAreEqual( |
515 representation.sk_bitmap(), | 515 representation.sk_bitmap(), |
516 EnsureBitmapSize( | 516 EnsureBitmapSize( |
517 default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(), | 517 default_icon.GetRepresentation(1.0f).sk_bitmap(), |
518 kInvalidIconSize))); | 518 kInvalidIconSize))); |
519 } | 519 } |
520 | 520 |
521 // Tests behavior of image created by IconImage after IconImage host goes | 521 // Tests behavior of image created by IconImage after IconImage host goes |
522 // away. The image should still return loaded representations. If requested | 522 // away. The image should still return loaded representations. If requested |
523 // representation was not loaded while IconImage host was around, transparent | 523 // representation was not loaded while IconImage host was around, transparent |
524 // representations should be returned. | 524 // representations should be returned. |
525 TEST_F(ExtensionIconImageTest, IconImageDestruction) { | 525 TEST_F(ExtensionIconImageTest, IconImageDestruction) { |
526 scoped_ptr<Profile> profile(new TestingProfile()); | 526 scoped_ptr<Profile> profile(new TestingProfile()); |
527 scoped_refptr<Extension> extension(CreateExtension( | 527 scoped_refptr<Extension> extension(CreateExtension( |
(...skipping 10 matching lines...) Expand all Loading... |
538 scoped_ptr<IconImage> image( | 538 scoped_ptr<IconImage> image( |
539 new IconImage(profile.get(), | 539 new IconImage(profile.get(), |
540 extension.get(), | 540 extension.get(), |
541 extensions::IconsInfo::GetIcons(extension.get()), | 541 extensions::IconsInfo::GetIcons(extension.get()), |
542 16, | 542 16, |
543 default_icon, | 543 default_icon, |
544 this)); | 544 this)); |
545 | 545 |
546 // Load an image representation. | 546 // Load an image representation. |
547 gfx::ImageSkiaRep representation = | 547 gfx::ImageSkiaRep representation = |
548 image->image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); | 548 image->image_skia().GetRepresentation(1.0f); |
549 | 549 |
550 WaitForImageLoad(); | 550 WaitForImageLoad(); |
551 EXPECT_EQ(1, ImageLoadedCount()); | 551 EXPECT_EQ(1, ImageLoadedCount()); |
552 ASSERT_EQ(1u, image->image_skia().image_reps().size()); | 552 ASSERT_EQ(1u, image->image_skia().image_reps().size()); |
553 | 553 |
554 // Stash loaded image skia, and destroy |image|. | 554 // Stash loaded image skia, and destroy |image|. |
555 gfx::ImageSkia image_skia = image->image_skia(); | 555 gfx::ImageSkia image_skia = image->image_skia(); |
556 image.reset(); | 556 image.reset(); |
557 extension = NULL; | 557 extension = NULL; |
558 | 558 |
559 // Image skia should still be able to get previously loaded representation. | 559 // Image skia should still be able to get previously loaded representation. |
560 representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_100P); | 560 representation = image_skia.GetRepresentation(1.0f); |
561 | 561 |
562 EXPECT_EQ(ui::SCALE_FACTOR_100P, representation.scale_factor()); | 562 EXPECT_EQ(1.0f, representation.scale()); |
563 EXPECT_EQ(16, representation.pixel_width()); | 563 EXPECT_EQ(16, representation.pixel_width()); |
564 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16)); | 564 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16)); |
565 | 565 |
566 // When requesting another representation, we should get blank image. | 566 // When requesting another representation, we should get blank image. |
567 representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_200P); | 567 representation = image_skia.GetRepresentation(2.0f); |
568 | 568 |
569 EXPECT_TRUE(gfx::BitmapsAreEqual( | 569 EXPECT_TRUE(gfx::BitmapsAreEqual( |
570 representation.sk_bitmap(), | 570 representation.sk_bitmap(), |
571 CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_200P))); | 571 CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_200P))); |
572 } | 572 } |
OLD | NEW |