OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/extension_icon_image.h" | 5 #include "extensions/browser/extension_icon_image.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 // When requesting another representation, we should not crash and return some | 555 // When requesting another representation, we should not crash and return some |
556 // image of the size. It could be blank or a rescale from the existing 1.0f | 556 // image of the size. It could be blank or a rescale from the existing 1.0f |
557 // icon. | 557 // icon. |
558 representation = image_skia.GetRepresentation(2.0f); | 558 representation = image_skia.GetRepresentation(2.0f); |
559 | 559 |
560 EXPECT_EQ(16, representation.GetWidth()); | 560 EXPECT_EQ(16, representation.GetWidth()); |
561 EXPECT_EQ(16, representation.GetHeight()); | 561 EXPECT_EQ(16, representation.GetHeight()); |
562 EXPECT_EQ(2.0f, representation.scale()); | 562 EXPECT_EQ(2.0f, representation.scale()); |
563 } | 563 } |
564 | 564 |
| 565 // Test that new representations added to the image of an IconImage are cached |
| 566 // for future use. |
| 567 TEST_F(ExtensionIconImageTest, ImageCachesNewRepresentations) { |
| 568 // Load up an extension and create an icon image. |
| 569 scoped_refptr<Extension> extension( |
| 570 CreateExtension("extension_icon_image", Manifest::INVALID_LOCATION)); |
| 571 ASSERT_TRUE(extension.get() != NULL); |
| 572 gfx::ImageSkia default_icon = GetDefaultIcon(); |
| 573 scoped_ptr<IconImage> icon_image( |
| 574 new IconImage(browser_context(), |
| 575 extension.get(), |
| 576 IconsInfo::GetIcons(extension.get()), |
| 577 16, |
| 578 default_icon, |
| 579 this)); |
| 580 |
| 581 // Load an image representation. |
| 582 gfx::ImageSkiaRep representation = |
| 583 icon_image->image_skia().GetRepresentation(1.0f); |
| 584 WaitForImageLoad(); |
| 585 |
| 586 // Cache for later use. |
| 587 gfx::Image prior_image = icon_image->image(); |
| 588 |
| 589 // Now the fun part: access the image from the IconImage, and create a png |
| 590 // representation of it. |
| 591 gfx::Image image = icon_image->image(); |
| 592 scoped_refptr<base::RefCountedMemory> image_as_png = image.As1xPNGBytes(); |
| 593 |
| 594 // Access the image from the IconImage again, and get a png representation. |
| 595 // The two png representations should be exactly equal (the same object), |
| 596 // because image storage is shared, so when we created one from the first |
| 597 // image, all other images should also have that representation... |
| 598 gfx::Image image2 = icon_image->image(); |
| 599 EXPECT_EQ(image_as_png.get(), image2.As1xPNGBytes().get()); |
| 600 |
| 601 // ...even images that were copied before the representation was constructed. |
| 602 EXPECT_EQ(image_as_png.get(), prior_image.As1xPNGBytes().get()); |
| 603 } |
| 604 |
565 } // namespace extensions | 605 } // namespace extensions |
OLD | NEW |