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

Side by Side Diff: chrome/browser/extensions/extension_icon_image_unittest.cc

Issue 16295003: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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/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.h" 8 #include "base/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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 TEST_F(ExtensionIconImageTest, Basic) { 212 TEST_F(ExtensionIconImageTest, Basic) {
213 scoped_ptr<Profile> profile(new TestingProfile()); 213 scoped_ptr<Profile> profile(new TestingProfile());
214 scoped_refptr<Extension> extension(CreateExtension( 214 scoped_refptr<Extension> extension(CreateExtension(
215 "extension_icon_image", Manifest::INVALID_LOCATION)); 215 "extension_icon_image", Manifest::INVALID_LOCATION));
216 ASSERT_TRUE(extension.get() != NULL); 216 ASSERT_TRUE(extension.get() != NULL);
217 217
218 gfx::ImageSkia default_icon = GetDefaultIcon(); 218 gfx::ImageSkia default_icon = GetDefaultIcon();
219 219
220 // Load images we expect to find as representations in icon_image, so we 220 // Load images we expect to find as representations in icon_image, so we
221 // can later use them to validate icon_image. 221 // can later use them to validate icon_image.
222 SkBitmap bitmap_16 = 222 SkBitmap bitmap_16 = GetTestBitmap(extension.get(), "16.png", 16);
223 GetTestBitmap(extension, "16.png", 16);
224 ASSERT_FALSE(bitmap_16.empty()); 223 ASSERT_FALSE(bitmap_16.empty());
225 224
226 // There is no image of size 32 defined in the extension manifest, so we 225 // There is no image of size 32 defined in the extension manifest, so we
227 // should expect manifest image of size 48 resized to size 32. 226 // should expect manifest image of size 48 resized to size 32.
228 SkBitmap bitmap_48_resized_to_32 = 227 SkBitmap bitmap_48_resized_to_32 =
229 GetTestBitmap(extension, "48.png", 32); 228 GetTestBitmap(extension.get(), "48.png", 32);
230 ASSERT_FALSE(bitmap_48_resized_to_32.empty()); 229 ASSERT_FALSE(bitmap_48_resized_to_32.empty());
231 230
232 IconImage image(profile.get(), 231 IconImage image(profile.get(),
233 extension, 232 extension.get(),
234 extensions::IconsInfo::GetIcons(extension), 233 extensions::IconsInfo::GetIcons(extension.get()),
235 16, 234 16,
236 default_icon, this); 235 default_icon,
236 this);
237 237
238 // No representations in |image_| yet. 238 // No representations in |image_| yet.
239 gfx::ImageSkia::ImageSkiaReps image_reps = image.image_skia().image_reps(); 239 gfx::ImageSkia::ImageSkiaReps image_reps = image.image_skia().image_reps();
240 ASSERT_EQ(0u, image_reps.size()); 240 ASSERT_EQ(0u, image_reps.size());
241 241
242 // Gets representation for a scale factor. 242 // Gets representation for a scale factor.
243 gfx::ImageSkiaRep representation = 243 gfx::ImageSkiaRep representation =
244 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); 244 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
245 245
246 // Before the image representation is loaded, image should contain blank 246 // Before the image representation is loaded, image should contain blank
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 TEST_F(ExtensionIconImageTest, FallbackToSmallerWhenNoBigger) { 283 TEST_F(ExtensionIconImageTest, FallbackToSmallerWhenNoBigger) {
284 scoped_ptr<Profile> profile(new TestingProfile()); 284 scoped_ptr<Profile> profile(new TestingProfile());
285 scoped_refptr<Extension> extension(CreateExtension( 285 scoped_refptr<Extension> extension(CreateExtension(
286 "extension_icon_image", Manifest::INVALID_LOCATION)); 286 "extension_icon_image", Manifest::INVALID_LOCATION));
287 ASSERT_TRUE(extension.get() != NULL); 287 ASSERT_TRUE(extension.get() != NULL);
288 288
289 gfx::ImageSkia default_icon = GetDefaultIcon(); 289 gfx::ImageSkia default_icon = GetDefaultIcon();
290 290
291 // Load images we expect to find as representations in icon_image, so we 291 // Load images we expect to find as representations in icon_image, so we
292 // can later use them to validate icon_image. 292 // can later use them to validate icon_image.
293 SkBitmap bitmap_48 = 293 SkBitmap bitmap_48 = GetTestBitmap(extension.get(), "48.png", 48);
294 GetTestBitmap(extension, "48.png", 48);
295 ASSERT_FALSE(bitmap_48.empty()); 294 ASSERT_FALSE(bitmap_48.empty());
296 295
297 IconImage image(profile.get(), 296 IconImage image(profile.get(),
298 extension, 297 extension.get(),
299 extensions::IconsInfo::GetIcons(extension), 298 extensions::IconsInfo::GetIcons(extension.get()),
300 32, 299 32,
301 default_icon, this); 300 default_icon,
301 this);
302 302
303 gfx::ImageSkiaRep representation = 303 gfx::ImageSkiaRep representation =
304 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P); 304 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
305 305
306 WaitForImageLoad(); 306 WaitForImageLoad();
307 EXPECT_EQ(1, ImageLoadedCount()); 307 EXPECT_EQ(1, ImageLoadedCount());
308 ASSERT_EQ(1u, image.image_skia().image_reps().size()); 308 ASSERT_EQ(1u, image.image_skia().image_reps().size());
309 309
310 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P); 310 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
311 311
(...skipping 11 matching lines...) Expand all
323 TEST_F(ExtensionIconImageTest, FallbackToSmaller) { 323 TEST_F(ExtensionIconImageTest, FallbackToSmaller) {
324 scoped_ptr<Profile> profile(new TestingProfile()); 324 scoped_ptr<Profile> profile(new TestingProfile());
325 scoped_refptr<Extension> extension(CreateExtension( 325 scoped_refptr<Extension> extension(CreateExtension(
326 "extension_icon_image", Manifest::INVALID_LOCATION)); 326 "extension_icon_image", Manifest::INVALID_LOCATION));
327 ASSERT_TRUE(extension.get() != NULL); 327 ASSERT_TRUE(extension.get() != NULL);
328 328
329 gfx::ImageSkia default_icon = GetDefaultIcon(); 329 gfx::ImageSkia default_icon = GetDefaultIcon();
330 330
331 // Load images we expect to find as representations in icon_image, so we 331 // Load images we expect to find as representations in icon_image, so we
332 // can later use them to validate icon_image. 332 // can later use them to validate icon_image.
333 SkBitmap bitmap_16 = 333 SkBitmap bitmap_16 = GetTestBitmap(extension.get(), "16.png", 16);
334 GetTestBitmap(extension, "16.png", 16);
335 ASSERT_FALSE(bitmap_16.empty()); 334 ASSERT_FALSE(bitmap_16.empty());
336 335
337 IconImage image(profile.get(), 336 IconImage image(profile.get(),
338 extension, 337 extension.get(),
339 extensions::IconsInfo::GetIcons(extension), 338 extensions::IconsInfo::GetIcons(extension.get()),
340 17, 339 17,
341 default_icon, this); 340 default_icon,
341 this);
342 342
343 gfx::ImageSkiaRep representation = 343 gfx::ImageSkiaRep representation =
344 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); 344 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
345 345
346 WaitForImageLoad(); 346 WaitForImageLoad();
347 EXPECT_EQ(1, ImageLoadedCount()); 347 EXPECT_EQ(1, ImageLoadedCount());
348 ASSERT_EQ(1u, image.image_skia().image_reps().size()); 348 ASSERT_EQ(1u, image.image_skia().image_reps().size());
349 349
350 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); 350 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
351 351
352 // We should have loaded smaller (resized) resource. 352 // We should have loaded smaller (resized) resource.
353 EXPECT_EQ(ui::SCALE_FACTOR_100P, representation.scale_factor()); 353 EXPECT_EQ(ui::SCALE_FACTOR_100P, representation.scale_factor());
354 EXPECT_EQ(17, representation.pixel_width()); 354 EXPECT_EQ(17, representation.pixel_width());
355 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), 355 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(),
356 EnsureBitmapSize(bitmap_16, 17))); 356 EnsureBitmapSize(bitmap_16, 17)));
357 } 357 }
358 358
359 // If resource set is empty, |GetRepresentation| should synchronously return 359 // If resource set is empty, |GetRepresentation| should synchronously return
360 // default icon, without notifying observer of image change. 360 // default icon, without notifying observer of image change.
361 TEST_F(ExtensionIconImageTest, NoResources) { 361 TEST_F(ExtensionIconImageTest, NoResources) {
362 scoped_ptr<Profile> profile(new TestingProfile()); 362 scoped_ptr<Profile> profile(new TestingProfile());
363 scoped_refptr<Extension> extension(CreateExtension( 363 scoped_refptr<Extension> extension(CreateExtension(
364 "extension_icon_image", Manifest::INVALID_LOCATION)); 364 "extension_icon_image", Manifest::INVALID_LOCATION));
365 ASSERT_TRUE(extension.get() != NULL); 365 ASSERT_TRUE(extension.get() != NULL);
366 366
367 ExtensionIconSet empty_icon_set; 367 ExtensionIconSet empty_icon_set;
368 gfx::ImageSkia default_icon = GetDefaultIcon(); 368 gfx::ImageSkia default_icon = GetDefaultIcon();
369 369
370 const int kRequestedSize = 24; 370 const int kRequestedSize = 24;
371 IconImage image(profile.get(), extension, empty_icon_set, kRequestedSize, 371 IconImage image(profile.get(),
372 default_icon, this); 372 extension.get(),
373 empty_icon_set,
374 kRequestedSize,
375 default_icon,
376 this);
373 377
374 gfx::ImageSkiaRep representation = 378 gfx::ImageSkiaRep representation =
375 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); 379 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
376 EXPECT_TRUE(gfx::BitmapsAreEqual( 380 EXPECT_TRUE(gfx::BitmapsAreEqual(
377 representation.sk_bitmap(), 381 representation.sk_bitmap(),
378 EnsureBitmapSize( 382 EnsureBitmapSize(
379 default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(), 383 default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap(),
380 kRequestedSize))); 384 kRequestedSize)));
381 385
382 EXPECT_EQ(0, ImageLoadedCount()); 386 EXPECT_EQ(0, ImageLoadedCount());
(...skipping 16 matching lines...) Expand all
399 scoped_refptr<Extension> extension(CreateExtension( 403 scoped_refptr<Extension> extension(CreateExtension(
400 "extension_icon_image", Manifest::INVALID_LOCATION)); 404 "extension_icon_image", Manifest::INVALID_LOCATION));
401 ASSERT_TRUE(extension.get() != NULL); 405 ASSERT_TRUE(extension.get() != NULL);
402 406
403 const int kInvalidIconSize = 24; 407 const int kInvalidIconSize = 24;
404 ExtensionIconSet invalid_icon_set; 408 ExtensionIconSet invalid_icon_set;
405 invalid_icon_set.Add(kInvalidIconSize, "invalid.png"); 409 invalid_icon_set.Add(kInvalidIconSize, "invalid.png");
406 410
407 gfx::ImageSkia default_icon = GetDefaultIcon(); 411 gfx::ImageSkia default_icon = GetDefaultIcon();
408 412
409 IconImage image(profile.get(), extension, invalid_icon_set, kInvalidIconSize, 413 IconImage image(profile.get(),
410 default_icon, this); 414 extension.get(),
415 invalid_icon_set,
416 kInvalidIconSize,
417 default_icon,
418 this);
411 419
412 gfx::ImageSkiaRep representation = 420 gfx::ImageSkiaRep representation =
413 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); 421 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
414 EXPECT_TRUE(gfx::BitmapsAreEqual( 422 EXPECT_TRUE(gfx::BitmapsAreEqual(
415 representation.sk_bitmap(), 423 representation.sk_bitmap(),
416 CreateBlankBitmapForScale(kInvalidIconSize, ui::SCALE_FACTOR_100P))); 424 CreateBlankBitmapForScale(kInvalidIconSize, ui::SCALE_FACTOR_100P)));
417 425
418 WaitForImageLoad(); 426 WaitForImageLoad();
419 EXPECT_EQ(1, ImageLoadedCount()); 427 EXPECT_EQ(1, ImageLoadedCount());
420 // We should have default icon representation now. 428 // We should have default icon representation now.
(...skipping 15 matching lines...) Expand all
436 "extension_icon_image", Manifest::INVALID_LOCATION)); 444 "extension_icon_image", Manifest::INVALID_LOCATION));
437 ASSERT_TRUE(extension.get() != NULL); 445 ASSERT_TRUE(extension.get() != NULL);
438 446
439 gfx::ImageSkia default_icon = GetDefaultIcon(); 447 gfx::ImageSkia default_icon = GetDefaultIcon();
440 gfx::ImageSkia lazy_default_icon(new MockImageSkiaSource(default_icon), 448 gfx::ImageSkia lazy_default_icon(new MockImageSkiaSource(default_icon),
441 default_icon.size()); 449 default_icon.size());
442 450
443 ExtensionIconSet empty_icon_set; 451 ExtensionIconSet empty_icon_set;
444 452
445 const int kRequestedSize = 128; 453 const int kRequestedSize = 128;
446 IconImage image(profile.get(), extension, empty_icon_set, kRequestedSize, 454 IconImage image(profile.get(),
447 lazy_default_icon, this); 455 extension.get(),
456 empty_icon_set,
457 kRequestedSize,
458 lazy_default_icon,
459 this);
448 460
449 ASSERT_FALSE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P)); 461 ASSERT_FALSE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P));
450 462
451 gfx::ImageSkiaRep representation = 463 gfx::ImageSkiaRep representation =
452 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); 464 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
453 465
454 // The resouce set is empty, so we should get the result right away. 466 // The resouce set is empty, so we should get the result right away.
455 EXPECT_TRUE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P)); 467 EXPECT_TRUE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P));
456 EXPECT_TRUE(gfx::BitmapsAreEqual( 468 EXPECT_TRUE(gfx::BitmapsAreEqual(
457 representation.sk_bitmap(), 469 representation.sk_bitmap(),
(...skipping 14 matching lines...) Expand all
472 ASSERT_TRUE(extension.get() != NULL); 484 ASSERT_TRUE(extension.get() != NULL);
473 485
474 gfx::ImageSkia default_icon = GetDefaultIcon(); 486 gfx::ImageSkia default_icon = GetDefaultIcon();
475 gfx::ImageSkia lazy_default_icon(new MockImageSkiaSource(default_icon), 487 gfx::ImageSkia lazy_default_icon(new MockImageSkiaSource(default_icon),
476 default_icon.size()); 488 default_icon.size());
477 489
478 const int kInvalidIconSize = 24; 490 const int kInvalidIconSize = 24;
479 ExtensionIconSet invalid_icon_set; 491 ExtensionIconSet invalid_icon_set;
480 invalid_icon_set.Add(kInvalidIconSize, "invalid.png"); 492 invalid_icon_set.Add(kInvalidIconSize, "invalid.png");
481 493
482 IconImage image(profile.get(), extension, invalid_icon_set, kInvalidIconSize, 494 IconImage image(profile.get(),
483 lazy_default_icon, this); 495 extension.get(),
496 invalid_icon_set,
497 kInvalidIconSize,
498 lazy_default_icon,
499 this);
484 500
485 ASSERT_FALSE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P)); 501 ASSERT_FALSE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P));
486 502
487 gfx::ImageSkiaRep representation = 503 gfx::ImageSkiaRep representation =
488 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); 504 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
489 505
490 WaitForImageLoad(); 506 WaitForImageLoad();
491 EXPECT_EQ(1, ImageLoadedCount()); 507 EXPECT_EQ(1, ImageLoadedCount());
492 // We should have default icon representation now. 508 // We should have default icon representation now.
493 ASSERT_EQ(1u, image.image_skia().image_reps().size()); 509 ASSERT_EQ(1u, image.image_skia().image_reps().size());
(...skipping 15 matching lines...) Expand all
509 TEST_F(ExtensionIconImageTest, IconImageDestruction) { 525 TEST_F(ExtensionIconImageTest, IconImageDestruction) {
510 scoped_ptr<Profile> profile(new TestingProfile()); 526 scoped_ptr<Profile> profile(new TestingProfile());
511 scoped_refptr<Extension> extension(CreateExtension( 527 scoped_refptr<Extension> extension(CreateExtension(
512 "extension_icon_image", Manifest::INVALID_LOCATION)); 528 "extension_icon_image", Manifest::INVALID_LOCATION));
513 ASSERT_TRUE(extension.get() != NULL); 529 ASSERT_TRUE(extension.get() != NULL);
514 530
515 gfx::ImageSkia default_icon = GetDefaultIcon(); 531 gfx::ImageSkia default_icon = GetDefaultIcon();
516 532
517 // Load images we expect to find as representations in icon_image, so we 533 // Load images we expect to find as representations in icon_image, so we
518 // can later use them to validate icon_image. 534 // can later use them to validate icon_image.
519 SkBitmap bitmap_16 = 535 SkBitmap bitmap_16 = GetTestBitmap(extension.get(), "16.png", 16);
520 GetTestBitmap(extension, "16.png", 16);
521 ASSERT_FALSE(bitmap_16.empty()); 536 ASSERT_FALSE(bitmap_16.empty());
522 537
523 scoped_ptr<IconImage> image( 538 scoped_ptr<IconImage> image(
524 new IconImage(profile.get(), 539 new IconImage(profile.get(),
525 extension, 540 extension.get(),
526 extensions::IconsInfo::GetIcons(extension), 541 extensions::IconsInfo::GetIcons(extension.get()),
527 16, 542 16,
528 default_icon, this)); 543 default_icon,
544 this));
529 545
530 // Load an image representation. 546 // Load an image representation.
531 gfx::ImageSkiaRep representation = 547 gfx::ImageSkiaRep representation =
532 image->image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); 548 image->image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
533 549
534 WaitForImageLoad(); 550 WaitForImageLoad();
535 EXPECT_EQ(1, ImageLoadedCount()); 551 EXPECT_EQ(1, ImageLoadedCount());
536 ASSERT_EQ(1u, image->image_skia().image_reps().size()); 552 ASSERT_EQ(1u, image->image_skia().image_reps().size());
537 553
538 // Stash loaded image skia, and destroy |image|. 554 // Stash loaded image skia, and destroy |image|.
539 gfx::ImageSkia image_skia = image->image_skia(); 555 gfx::ImageSkia image_skia = image->image_skia();
540 image.reset(); 556 image.reset();
541 extension = NULL; 557 extension = NULL;
542 558
543 // Image skia should still be able to get previously loaded representation. 559 // Image skia should still be able to get previously loaded representation.
544 representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_100P); 560 representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_100P);
545 561
546 EXPECT_EQ(ui::SCALE_FACTOR_100P, representation.scale_factor()); 562 EXPECT_EQ(ui::SCALE_FACTOR_100P, representation.scale_factor());
547 EXPECT_EQ(16, representation.pixel_width()); 563 EXPECT_EQ(16, representation.pixel_width());
548 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16)); 564 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16));
549 565
550 // When requesting another representation, we should get blank image. 566 // When requesting another representation, we should get blank image.
551 representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_200P); 567 representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_200P);
552 568
553 EXPECT_TRUE(gfx::BitmapsAreEqual( 569 EXPECT_TRUE(gfx::BitmapsAreEqual(
554 representation.sk_bitmap(), 570 representation.sk_bitmap(),
555 CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_200P))); 571 CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_200P)));
556 } 572 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_function_dispatcher.cc ('k') | chrome/browser/extensions/extension_info_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698