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

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

Issue 11786003: Move Icons out of Extension class (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_unref_browser_action
Patch Set: Latest master + Yoyo's requests Created 7 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "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"
11 #include "chrome/common/chrome_paths.h" 11 #include "chrome/common/chrome_paths.h"
12 #include "chrome/common/extensions/api/icons/icons_handler.h"
12 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/extension.h"
13 #include "chrome/common/extensions/extension_constants.h" 14 #include "chrome/common/extensions/extension_constants.h"
14 #include "content/public/test/test_browser_thread.h" 15 #include "content/public/test/test_browser_thread.h"
15 #include "grit/theme_resources.h" 16 #include "grit/theme_resources.h"
16 #include "skia/ext/image_operations.h" 17 #include "skia/ext/image_operations.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/gfx/image/image_skia_source.h" 20 #include "ui/gfx/image/image_skia_source.h"
20 #include "ui/gfx/skia_util.h" 21 #include "ui/gfx/skia_util.h"
21 22
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 SkBitmap bitmap_16 = 218 SkBitmap bitmap_16 =
218 GetTestBitmap(extension, "16.png", 16); 219 GetTestBitmap(extension, "16.png", 16);
219 ASSERT_FALSE(bitmap_16.empty()); 220 ASSERT_FALSE(bitmap_16.empty());
220 221
221 // There is no image of size 32 defined in the extension manifest, so we 222 // There is no image of size 32 defined in the extension manifest, so we
222 // should expect manifest image of size 48 resized to size 32. 223 // should expect manifest image of size 48 resized to size 32.
223 SkBitmap bitmap_48_resized_to_32 = 224 SkBitmap bitmap_48_resized_to_32 =
224 GetTestBitmap(extension, "48.png", 32); 225 GetTestBitmap(extension, "48.png", 32);
225 ASSERT_FALSE(bitmap_48_resized_to_32.empty()); 226 ASSERT_FALSE(bitmap_48_resized_to_32.empty());
226 227
227 IconImage image(extension, extension->icons(), 16, default_icon, this); 228 IconImage image(extension,
229 extensions::IconsInfo::GetIcons(extension),
230 16,
231 default_icon,
232 this);
228 233
229 // No representations in |image_| yet. 234 // No representations in |image_| yet.
230 gfx::ImageSkia::ImageSkiaReps image_reps = image.image_skia().image_reps(); 235 gfx::ImageSkia::ImageSkiaReps image_reps = image.image_skia().image_reps();
231 ASSERT_EQ(0u, image_reps.size()); 236 ASSERT_EQ(0u, image_reps.size());
232 237
233 // Gets representation for a scale factor. 238 // Gets representation for a scale factor.
234 gfx::ImageSkiaRep representation = 239 gfx::ImageSkiaRep representation =
235 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); 240 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
236 241
237 // Before the image representation is loaded, image should contain blank 242 // Before the image representation is loaded, image should contain blank
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 ASSERT_TRUE(extension.get() != NULL); 282 ASSERT_TRUE(extension.get() != NULL);
278 283
279 gfx::ImageSkia default_icon = GetDefaultIcon(); 284 gfx::ImageSkia default_icon = GetDefaultIcon();
280 285
281 // Load images we expect to find as representations in icon_image, so we 286 // Load images we expect to find as representations in icon_image, so we
282 // can later use them to validate icon_image. 287 // can later use them to validate icon_image.
283 SkBitmap bitmap_48 = 288 SkBitmap bitmap_48 =
284 GetTestBitmap(extension, "48.png", 48); 289 GetTestBitmap(extension, "48.png", 48);
285 ASSERT_FALSE(bitmap_48.empty()); 290 ASSERT_FALSE(bitmap_48.empty());
286 291
287 IconImage image(extension, extension->icons(), 32, default_icon, this); 292 IconImage image(extension,
293 extensions::IconsInfo::GetIcons(extension),
294 32,
295 default_icon,
296 this);
288 297
289 gfx::ImageSkiaRep representation = 298 gfx::ImageSkiaRep representation =
290 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P); 299 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
291 300
292 WaitForImageLoad(); 301 WaitForImageLoad();
293 EXPECT_EQ(1, ImageLoadedCount()); 302 EXPECT_EQ(1, ImageLoadedCount());
294 ASSERT_EQ(1u, image.image_skia().image_reps().size()); 303 ASSERT_EQ(1u, image.image_skia().image_reps().size());
295 304
296 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P); 305 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
297 306
(...skipping 14 matching lines...) Expand all
312 ASSERT_TRUE(extension.get() != NULL); 321 ASSERT_TRUE(extension.get() != NULL);
313 322
314 gfx::ImageSkia default_icon = GetDefaultIcon(); 323 gfx::ImageSkia default_icon = GetDefaultIcon();
315 324
316 // Load images we expect to find as representations in icon_image, so we 325 // Load images we expect to find as representations in icon_image, so we
317 // can later use them to validate icon_image. 326 // can later use them to validate icon_image.
318 SkBitmap bitmap_16 = 327 SkBitmap bitmap_16 =
319 GetTestBitmap(extension, "16.png", 16); 328 GetTestBitmap(extension, "16.png", 16);
320 ASSERT_FALSE(bitmap_16.empty()); 329 ASSERT_FALSE(bitmap_16.empty());
321 330
322 IconImage image(extension, extension->icons(), 17, default_icon, this); 331 IconImage image(extension,
332 extensions::IconsInfo::GetIcons(extension),
333 17,
334 default_icon,
335 this);
323 336
324 gfx::ImageSkiaRep representation = 337 gfx::ImageSkiaRep representation =
325 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); 338 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
326 339
327 WaitForImageLoad(); 340 WaitForImageLoad();
328 EXPECT_EQ(1, ImageLoadedCount()); 341 EXPECT_EQ(1, ImageLoadedCount());
329 ASSERT_EQ(1u, image.image_skia().image_reps().size()); 342 ASSERT_EQ(1u, image.image_skia().image_reps().size());
330 343
331 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); 344 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
332 345
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 499
487 gfx::ImageSkia default_icon = GetDefaultIcon(); 500 gfx::ImageSkia default_icon = GetDefaultIcon();
488 501
489 // Store the image in the cache. 502 // Store the image in the cache.
490 SkBitmap bitmap_16 = 503 SkBitmap bitmap_16 =
491 GetTestBitmap(extension, "16.png", 16); 504 GetTestBitmap(extension, "16.png", 16);
492 ASSERT_FALSE(bitmap_16.empty()); 505 ASSERT_FALSE(bitmap_16.empty());
493 extension->SetCachedImage(extension->GetResource("16.png"), bitmap_16, 506 extension->SetCachedImage(extension->GetResource("16.png"), bitmap_16,
494 gfx::Size(16, 16)); 507 gfx::Size(16, 16));
495 508
496 IconImage image(extension, extension->icons(), 16, default_icon, this); 509 IconImage image(extension,
510 extensions::IconsInfo::GetIcons(extension),
511 16,
512 default_icon,
513 this);
497 514
498 // No representations in |image_| yet. 515 // No representations in |image_| yet.
499 gfx::ImageSkia::ImageSkiaReps image_reps = image.image_skia().image_reps(); 516 gfx::ImageSkia::ImageSkiaReps image_reps = image.image_skia().image_reps();
500 ASSERT_EQ(0u, image_reps.size()); 517 ASSERT_EQ(0u, image_reps.size());
501 518
502 // Gets representation for a scale factor. 519 // Gets representation for a scale factor.
503 // Since the icon representation is precached, it should be returned right 520 // Since the icon representation is precached, it should be returned right
504 // away. Also, we should not receive any notifications. 521 // away. Also, we should not receive any notifications.
505 gfx::ImageSkiaRep representation = 522 gfx::ImageSkiaRep representation =
506 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); 523 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
(...skipping 13 matching lines...) Expand all
520 ASSERT_TRUE(extension.get() != NULL); 537 ASSERT_TRUE(extension.get() != NULL);
521 538
522 gfx::ImageSkia default_icon = GetDefaultIcon(); 539 gfx::ImageSkia default_icon = GetDefaultIcon();
523 540
524 // Load images we expect to find as representations in icon_image, so we 541 // Load images we expect to find as representations in icon_image, so we
525 // can later use them to validate icon_image. 542 // can later use them to validate icon_image.
526 SkBitmap bitmap_16 = 543 SkBitmap bitmap_16 =
527 GetTestBitmap(extension, "16.png", 16); 544 GetTestBitmap(extension, "16.png", 16);
528 ASSERT_FALSE(bitmap_16.empty()); 545 ASSERT_FALSE(bitmap_16.empty());
529 546
530 scoped_ptr<IconImage> image( 547 scoped_ptr<IconImage> image(new IconImage(
531 new IconImage(extension, extension->icons(), 16, default_icon, this)); 548 extension,
549 extensions::IconsInfo::GetIcons(extension),
550 16,
551 default_icon,
552 this));
532 553
533 // Load an image representation. 554 // Load an image representation.
534 gfx::ImageSkiaRep representation = 555 gfx::ImageSkiaRep representation =
535 image->image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); 556 image->image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
536 557
537 WaitForImageLoad(); 558 WaitForImageLoad();
538 EXPECT_EQ(1, ImageLoadedCount()); 559 EXPECT_EQ(1, ImageLoadedCount());
539 ASSERT_EQ(1u, image->image_skia().image_reps().size()); 560 ASSERT_EQ(1u, image->image_skia().image_reps().size());
540 561
541 // Stash loaded image skia, and destroy |image|. 562 // Stash loaded image skia, and destroy |image|.
542 gfx::ImageSkia image_skia = image->image_skia(); 563 gfx::ImageSkia image_skia = image->image_skia();
543 image.reset(); 564 image.reset();
544 extension = NULL; 565 extension = NULL;
545 566
546 // Image skia should still be able to get previously loaded representation. 567 // Image skia should still be able to get previously loaded representation.
547 representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_100P); 568 representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_100P);
548 569
549 EXPECT_EQ(ui::SCALE_FACTOR_100P, representation.scale_factor()); 570 EXPECT_EQ(ui::SCALE_FACTOR_100P, representation.scale_factor());
550 EXPECT_EQ(16, representation.pixel_width()); 571 EXPECT_EQ(16, representation.pixel_width());
551 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16)); 572 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16));
552 573
553 // When requesting another representation, we should get blank image. 574 // When requesting another representation, we should get blank image.
554 representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_200P); 575 representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_200P);
555 576
556 EXPECT_TRUE(gfx::BitmapsAreEqual( 577 EXPECT_TRUE(gfx::BitmapsAreEqual(
557 representation.sk_bitmap(), 578 representation.sk_bitmap(),
558 CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_200P))); 579 CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_200P)));
559 } 580 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698