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

Unified Diff: extensions/browser/extension_icon_image_unittest.cc

Issue 882243002: [Extensions] Make extension actions use gfx::Image over gfx::ImageSkia. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Latest master Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/browser/extension_icon_image.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/extension_icon_image_unittest.cc
diff --git a/extensions/browser/extension_icon_image_unittest.cc b/extensions/browser/extension_icon_image_unittest.cc
index 9f89fc2c50aee9541f1c6f2c915f47f6e0c75a71..24d0ac2e4a4c46ad925cacb3dea48f3c95c1d283 100644
--- a/extensions/browser/extension_icon_image_unittest.cc
+++ b/extensions/browser/extension_icon_image_unittest.cc
@@ -562,4 +562,44 @@ TEST_F(ExtensionIconImageTest, IconImageDestruction) {
EXPECT_EQ(2.0f, representation.scale());
}
+// Test that new representations added to the image of an IconImage are cached
+// for future use.
+TEST_F(ExtensionIconImageTest, ImageCachesNewRepresentations) {
+ // Load up an extension and create an icon image.
+ scoped_refptr<Extension> extension(
+ CreateExtension("extension_icon_image", Manifest::INVALID_LOCATION));
+ ASSERT_TRUE(extension.get() != NULL);
+ gfx::ImageSkia default_icon = GetDefaultIcon();
+ scoped_ptr<IconImage> icon_image(
+ new IconImage(browser_context(),
+ extension.get(),
+ IconsInfo::GetIcons(extension.get()),
+ 16,
+ default_icon,
+ this));
+
+ // Load an image representation.
+ gfx::ImageSkiaRep representation =
+ icon_image->image_skia().GetRepresentation(1.0f);
+ WaitForImageLoad();
+
+ // Cache for later use.
+ gfx::Image prior_image = icon_image->image();
+
+ // Now the fun part: access the image from the IconImage, and create a png
+ // representation of it.
+ gfx::Image image = icon_image->image();
+ scoped_refptr<base::RefCountedMemory> image_as_png = image.As1xPNGBytes();
+
+ // Access the image from the IconImage again, and get a png representation.
+ // The two png representations should be exactly equal (the same object),
+ // because image storage is shared, so when we created one from the first
+ // image, all other images should also have that representation...
+ gfx::Image image2 = icon_image->image();
+ EXPECT_EQ(image_as_png.get(), image2.As1xPNGBytes().get());
+
+ // ...even images that were copied before the representation was constructed.
+ EXPECT_EQ(image_as_png.get(), prior_image.As1xPNGBytes().get());
+}
+
} // namespace extensions
« no previous file with comments | « extensions/browser/extension_icon_image.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698