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

Unified Diff: chrome/browser/extensions/extension_icon_image_unittest.cc

Issue 10861034: Supply default icon to extension icon image. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: .. Created 8 years, 3 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 | « chrome/browser/extensions/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: chrome/browser/extensions/extension_icon_image_unittest.cc
diff --git a/chrome/browser/extensions/extension_icon_image_unittest.cc b/chrome/browser/extensions/extension_icon_image_unittest.cc
index 5693396b02e9423ee648e9eed248cbd492134dac..cba8c93a62a0011dd7dd1e21c5686cd996d3fb6b 100644
--- a/chrome/browser/extensions/extension_icon_image_unittest.cc
+++ b/chrome/browser/extensions/extension_icon_image_unittest.cc
@@ -7,10 +7,16 @@
#include "base/json/json_file_value_serializer.h"
#include "base/message_loop.h"
#include "base/path_service.h"
+#include "chrome/browser/extensions/image_loading_tracker.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension.h"
+#include "chrome/common/extensions/extension_constants.h"
#include "content/public/test/test_browser_thread.h"
+#include "grit/theme_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/image/image_skia_source.h"
+#include "ui/gfx/skia_util.h"
using content::BrowserThread;
using extensions::Extension;
@@ -18,12 +24,95 @@ using extensions::IconImage;
namespace {
+SkBitmap CreateBlankBitmapForScale(int size_dip, ui::ScaleFactor scale_factor) {
+ SkBitmap bitmap;
+ const float scale = ui::GetScaleFactorScale(scale_factor);
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config,
+ static_cast<int>(size_dip * scale),
+ static_cast<int>(size_dip * scale));
+ bitmap.allocPixels();
+ bitmap.eraseColor(SkColorSetARGB(0, 0, 0, 0));
+ return bitmap;
+}
+
+// Used to test behaviour including images defined by an image skia source.
+// |GetImageForScale| simply returns image representation from the image given
+// in the ctor.
+class MockImageSkiaSource : public gfx::ImageSkiaSource {
+ public:
+ explicit MockImageSkiaSource(const gfx::ImageSkia& image)
+ : image_(image) {
+ }
+ virtual ~MockImageSkiaSource() {}
+
+ virtual gfx::ImageSkiaRep GetImageForScale(
+ ui::ScaleFactor scale_factor) OVERRIDE {
+ return image_.GetRepresentation(scale_factor);
+ }
+
+ private:
+ gfx::ImageSkia image_;
+};
+
+// Helper class for synchronously loading extension image resource.
+class TestImageLoader : public ImageLoadingTracker::Observer {
+ public:
+ explicit TestImageLoader(const Extension* extension)
+ : extension_(extension),
+ waiting_(false),
+ image_loaded_(false),
+ ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) {
+ }
+ virtual ~TestImageLoader() {}
+
+ // ImageLoadingTracker::Observer override.
+ virtual void OnImageLoaded(const gfx::Image& image,
+ const std::string& extension_id,
+ int index) OVERRIDE {
+ image_ = image;
+ image_loaded_ = true;
+ if (waiting_)
+ MessageLoop::current()->Quit();
+ }
+
+ SkBitmap LoadBitmap(const std::string& path,
+ int size,
+ ImageLoadingTracker::CacheParam cache_param) {
+ image_loaded_ = false;
+
+ tracker_.LoadImage(extension_,
+ extension_->GetResource(path),
+ gfx::Size(size, size),
+ cache_param);
+
+ // If |image_| still hasn't been loaded (i.e. it is being loaded
+ // asynchronously), wait for it.
+ if (!image_loaded_) {
+ waiting_ = true;
+ MessageLoop::current()->Run();
+ waiting_ = false;
+ }
+
+ EXPECT_TRUE(image_loaded_);
+
+ return image_.IsEmpty() ? SkBitmap() : *image_.ToSkBitmap();
+ }
+
+ private:
+ const Extension* extension_;
+ bool waiting_;
+ bool image_loaded_;
+ gfx::Image image_;
+ ImageLoadingTracker tracker_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestImageLoader);
+};
+
class ExtensionIconImageTest : public testing::Test,
public IconImage::Observer {
public:
ExtensionIconImageTest()
: image_loaded_count_(0),
- image_load_failure_count_(0),
quit_in_image_loaded_(false),
ui_thread_(BrowserThread::UI, &ui_loop_),
file_thread_(BrowserThread::FILE),
@@ -33,10 +122,6 @@ class ExtensionIconImageTest : public testing::Test,
virtual ~ExtensionIconImageTest() {}
void WaitForImageLoad() {
- // ExtensionIconImage may return synchronously, in which case there's
- // nothing to wait for.
- if (image_loaded_count_ > 0 || image_load_failure_count_ > 0)
- return;
quit_in_image_loaded_ = true;
MessageLoop::current()->Run();
quit_in_image_loaded_ = false;
@@ -48,12 +133,6 @@ class ExtensionIconImageTest : public testing::Test,
return result;
}
- int ImageLoadFailureCount() {
- int result = image_load_failure_count_;
- image_load_failure_count_ = 0;
- return result;
- }
-
scoped_refptr<Extension> CreateExtension(const char* name,
Extension::Location location) {
// Create and load an extension.
@@ -94,16 +173,23 @@ class ExtensionIconImageTest : public testing::Test,
MessageLoop::current()->Quit();
}
- virtual void OnIconImageLoadFailed(IconImage* image,
- ui::ScaleFactor scale_factor) OVERRIDE {
- image_load_failure_count_++;
- if (quit_in_image_loaded_)
- MessageLoop::current()->Quit();
+ gfx::ImageSkia GetDefaultIcon() {
+ return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ IDR_EXTENSIONS_FAVICON);
+ }
+
+ // Loads an image to be used in test from the extension.
+ // The image will be loaded from the relative path |path|.
+ SkBitmap GetTestBitmap(const Extension* extension,
+ const std::string& path,
+ int size,
+ ImageLoadingTracker::CacheParam cache_param) {
+ TestImageLoader image_loader(extension);
+ return image_loader.LoadBitmap(path, size, cache_param);
}
private:
int image_loaded_count_;
- int image_load_failure_count_;
bool quit_in_image_loaded_;
MessageLoop ui_loop_;
content::TestBrowserThread ui_thread_;
@@ -120,65 +206,63 @@ TEST_F(ExtensionIconImageTest, Basic) {
"extension_icon_image", Extension::INVALID));
ASSERT_TRUE(extension.get() != NULL);
- IconImage image(
- extension,
- extension->icons(),
- extension_misc::EXTENSION_ICON_BITTY,
- this);
+ gfx::ImageSkia default_icon = GetDefaultIcon();
+
+ // Load images we expect to find as representations in icon_image, so we
+ // can later use them to validate icon_image.
+ SkBitmap bitmap_16 =
+ GetTestBitmap(extension, "16.png", 16, ImageLoadingTracker::DONT_CACHE);
+ ASSERT_FALSE(bitmap_16.empty());
+
+ // There is no image of size 32 defined in the extension manifest, so we
+ // should expect manifest image of size 48 resized to size 32.
+ SkBitmap bitmap_48_resized_to_32 =
+ GetTestBitmap(extension, "48.png", 32, ImageLoadingTracker::DONT_CACHE);
+ ASSERT_FALSE(bitmap_48_resized_to_32.empty());
+
+ IconImage image(extension, extension->icons(), 16, default_icon, this);
// No representations in |image_| yet.
gfx::ImageSkia::ImageSkiaReps image_reps = image.image_skia().image_reps();
ASSERT_EQ(0u, image_reps.size());
// Gets representation for a scale factor.
- image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
- WaitForImageLoad();
- EXPECT_EQ(1, ImageLoadedCount());
- EXPECT_EQ(0, ImageLoadFailureCount());
+ gfx::ImageSkiaRep representation =
+ image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+
+ // Before the image representation is loaded, image should contain blank
+ // image representation.
+ EXPECT_TRUE(gfx::BitmapsAreEqual(
+ representation.sk_bitmap(),
+ CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_100P)));
- // Gets representation for an additional scale factor.
- image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
WaitForImageLoad();
EXPECT_EQ(1, ImageLoadedCount());
- EXPECT_EQ(0, ImageLoadFailureCount());
+ ASSERT_EQ(1u, image.image_skia().image_reps().size());
- gfx::ImageSkiaRep image_rep =
- image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
- EXPECT_EQ(extension_misc::EXTENSION_ICON_BITTY,
- image_rep.pixel_width());
+ representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
- image_rep = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
- EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALL,
- image_rep.pixel_width());
-}
+ // We should get the right representation now.
+ EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16));
+ EXPECT_EQ(16, representation.pixel_width());
-// If we can't load icon with the exact size, but a bigger resource is
-// available.
-TEST_F(ExtensionIconImageTest, FallbackToBigger) {
- scoped_refptr<Extension> extension(CreateExtension(
- "extension_icon_image", Extension::INVALID));
- ASSERT_TRUE(extension.get() != NULL);
-
- IconImage image(
- extension,
- extension->icons(),
- extension_misc::EXTENSION_ICON_BITTY,
- this);
+ // Gets representation for an additional scale factor.
+ representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
- // Get representation for 2x.
- image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
+ EXPECT_TRUE(gfx::BitmapsAreEqual(
+ representation.sk_bitmap(),
+ CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_200P)));
WaitForImageLoad();
EXPECT_EQ(1, ImageLoadedCount());
- EXPECT_EQ(0, ImageLoadFailureCount());
+ ASSERT_EQ(2u, image.image_skia().image_reps().size());
- gfx::ImageSkiaRep image_rep =
- image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
+ representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
- // We should have found a bigger resource and it should have been resized.
- EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor());
- EXPECT_EQ(2 * extension_misc::EXTENSION_ICON_BITTY,
- image_rep.pixel_width());
+ // Image should have been resized.
+ EXPECT_EQ(32, representation.pixel_width());
+ EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(),
+ bitmap_48_resized_to_32));
}
// There is no resource with either exact or bigger size, but there is a smaller
@@ -188,27 +272,30 @@ TEST_F(ExtensionIconImageTest, FallbackToSmallerWhenNoBigger) {
"extension_icon_image", Extension::INVALID));
ASSERT_TRUE(extension.get() != NULL);
- IconImage image(
- extension,
- extension->icons(),
- extension_misc::EXTENSION_ICON_SMALL,
- this);
+ gfx::ImageSkia default_icon = GetDefaultIcon();
- // Attempt to get representation for 2x.
- image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
+ // Load images we expect to find as representations in icon_image, so we
+ // can later use them to validate icon_image.
+ SkBitmap bitmap_48 =
+ GetTestBitmap(extension, "48.png", 48, ImageLoadingTracker::DONT_CACHE);
+ ASSERT_FALSE(bitmap_48.empty());
+
+ IconImage image(extension, extension->icons(), 32, default_icon, this);
+
+ gfx::ImageSkiaRep representation =
+ image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
WaitForImageLoad();
EXPECT_EQ(1, ImageLoadedCount());
- EXPECT_EQ(0, ImageLoadFailureCount());
+ ASSERT_EQ(1u, image.image_skia().image_reps().size());
- gfx::ImageSkiaRep image_rep =
- image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
+ representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
// We should have loaded the biggest smaller resource. In this case the
// loaded resource should not be resized.
- EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor());
- EXPECT_EQ(extension_misc::EXTENSION_ICON_MEDIUM,
- image_rep.pixel_width());
+ EXPECT_EQ(ui::SCALE_FACTOR_200P, representation.scale_factor());
+ EXPECT_EQ(48, representation.pixel_width());
+ EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_48));
}
// There is no resource with exact size, but there is a smaller and a bigger
@@ -219,46 +306,228 @@ TEST_F(ExtensionIconImageTest, FallbackToSmaller) {
"extension_icon_image", Extension::INVALID));
ASSERT_TRUE(extension.get() != NULL);
- IconImage image(
- extension,
- extension->icons(),
- 17,
- this);
+ gfx::ImageSkia default_icon = GetDefaultIcon();
- // Attempt to get representation for 1x.
- image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ // Load images we expect to find as representations in icon_image, so we
+ // can later use them to validate icon_image.
+ SkBitmap bitmap_16 =
+ GetTestBitmap(extension, "16.png", 16, ImageLoadingTracker::DONT_CACHE);
+ ASSERT_FALSE(bitmap_16.empty());
+
+ IconImage image(extension, extension->icons(), 17, default_icon, this);
+
+ gfx::ImageSkiaRep representation =
+ image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
WaitForImageLoad();
EXPECT_EQ(1, ImageLoadedCount());
- EXPECT_EQ(0, ImageLoadFailureCount());
+ ASSERT_EQ(1u, image.image_skia().image_reps().size());
- gfx::ImageSkiaRep image_rep =
- image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
// We should have loaded smaller (not resized) resource.
- EXPECT_EQ(ui::SCALE_FACTOR_100P, image_rep.scale_factor());
- EXPECT_EQ(extension_misc::EXTENSION_ICON_BITTY,
- image_rep.pixel_width());
+ EXPECT_EQ(ui::SCALE_FACTOR_100P, representation.scale_factor());
+ EXPECT_EQ(16, representation.pixel_width());
+ EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16));
}
-// If resource set is empty, failure should be reported.
+// If resource set is empty, |GetRepresentation| should synchronously return
+// default icon, without notifying observer of image change.
TEST_F(ExtensionIconImageTest, NoResources) {
scoped_refptr<Extension> extension(CreateExtension(
"extension_icon_image", Extension::INVALID));
ASSERT_TRUE(extension.get() != NULL);
ExtensionIconSet empty_icon_set;
+ gfx::ImageSkia default_icon = GetDefaultIcon();
+
+ IconImage image(extension, empty_icon_set, 24, default_icon, this);
+
+ gfx::ImageSkiaRep representation =
+ image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ EXPECT_TRUE(gfx::BitmapsAreEqual(
+ representation.sk_bitmap(),
+ default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap()));
+
+ EXPECT_EQ(0, ImageLoadedCount());
+ // We should have a default icon representation.
+ ASSERT_EQ(1u, image.image_skia().image_reps().size());
+
+ representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ EXPECT_TRUE(gfx::BitmapsAreEqual(
+ representation.sk_bitmap(),
+ default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap()));
+}
+
+// If resource set is invalid, image load should be done asynchronously and
+// the observer should be notified when it's done. |GetRepresentation| should
+// return the default icon representation once image load is done.
+TEST_F(ExtensionIconImageTest, InvalidResource) {
+ scoped_refptr<Extension> extension(CreateExtension(
+ "extension_icon_image", Extension::INVALID));
+ ASSERT_TRUE(extension.get() != NULL);
+
+ ExtensionIconSet invalid_icon_set;
+ invalid_icon_set.Add(24, "invalid.png");
+
+ gfx::ImageSkia default_icon = GetDefaultIcon();
+
+ IconImage image(extension, invalid_icon_set, 24, default_icon, this);
+
+ gfx::ImageSkiaRep representation =
+ image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ EXPECT_TRUE(gfx::BitmapsAreEqual(
+ representation.sk_bitmap(),
+ CreateBlankBitmapForScale(24, ui::SCALE_FACTOR_100P)));
+
+ WaitForImageLoad();
+ EXPECT_EQ(1, ImageLoadedCount());
+ // We should have default icon representation now.
+ ASSERT_EQ(1u, image.image_skia().image_reps().size());
+
+ representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ EXPECT_TRUE(gfx::BitmapsAreEqual(
+ representation.sk_bitmap(),
+ default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap()));
+}
+
+// Test that IconImage works with lazily (but synchronously) created default
+// icon when IconImage returns synchronously.
+TEST_F(ExtensionIconImageTest, LazyDefaultIcon) {
+ scoped_refptr<Extension> extension(CreateExtension(
+ "extension_icon_image", Extension::INVALID));
+ ASSERT_TRUE(extension.get() != NULL);
+
+ gfx::ImageSkia default_icon = GetDefaultIcon();
+ gfx::ImageSkia lazy_default_icon(new MockImageSkiaSource(default_icon),
+ default_icon.size());
+
+ ExtensionIconSet empty_icon_set;
+
+ IconImage image(extension, empty_icon_set, 128, lazy_default_icon, this);
- IconImage image(
- extension,
- empty_icon_set,
- extension_misc::EXTENSION_ICON_SMALLISH,
- this);
+ ASSERT_FALSE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P));
- // Attempt to get representation for 2x.
- image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
+ gfx::ImageSkiaRep representation =
+ image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+
+ // The resouce set is empty, so we should get the result right away.
+ EXPECT_TRUE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P));
+ EXPECT_TRUE(gfx::BitmapsAreEqual(
+ representation.sk_bitmap(),
+ default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap()));
+
+ // We should have a default icon representation.
+ ASSERT_EQ(1u, image.image_skia().image_reps().size());
+}
+
+// Test that IconImage works with lazily (but synchronously) created default
+// icon when IconImage returns asynchronously.
+TEST_F(ExtensionIconImageTest, LazyDefaultIcon_AsyncIconImage) {
+ scoped_refptr<Extension> extension(CreateExtension(
+ "extension_icon_image", Extension::INVALID));
+ ASSERT_TRUE(extension.get() != NULL);
+
+ gfx::ImageSkia default_icon = GetDefaultIcon();
+ gfx::ImageSkia lazy_default_icon(new MockImageSkiaSource(default_icon),
+ default_icon.size());
+
+ ExtensionIconSet invalid_icon_set;
+ invalid_icon_set.Add(24, "invalid.png");
+
+ IconImage image(extension, invalid_icon_set, 24, lazy_default_icon, this);
+
+ ASSERT_FALSE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P));
+
+ gfx::ImageSkiaRep representation =
+ image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
WaitForImageLoad();
+ EXPECT_EQ(1, ImageLoadedCount());
+ // We should have default icon representation now.
+ ASSERT_EQ(1u, image.image_skia().image_reps().size());
+
+ EXPECT_TRUE(lazy_default_icon.HasRepresentation(ui::SCALE_FACTOR_100P));
+
+ representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ EXPECT_TRUE(gfx::BitmapsAreEqual(
+ representation.sk_bitmap(),
+ default_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap()));
+}
+
+TEST_F(ExtensionIconImageTest, LoadPrecachedImage) {
+ scoped_refptr<Extension> extension(CreateExtension(
+ "extension_icon_image", Extension::INVALID));
+ ASSERT_TRUE(extension.get() != NULL);
+
+ gfx::ImageSkia default_icon = GetDefaultIcon();
+
+ // Note the cache parameter.
+ SkBitmap bitmap_16 =
+ GetTestBitmap(extension, "16.png", 16, ImageLoadingTracker::CACHE);
+ ASSERT_FALSE(bitmap_16.empty());
+
+ IconImage image(extension, extension->icons(), 16, default_icon, this);
+
+ // No representations in |image_| yet.
+ gfx::ImageSkia::ImageSkiaReps image_reps = image.image_skia().image_reps();
+ ASSERT_EQ(0u, image_reps.size());
+
+ // Gets representation for a scale factor.
+ // Since the icon representation is precached, it should be returned right
+ // away. Also, we should not receive any notifications.
+ gfx::ImageSkiaRep representation =
+ image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+ EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16));
+
EXPECT_EQ(0, ImageLoadedCount());
- EXPECT_EQ(1, ImageLoadFailureCount());
+ ASSERT_EQ(1u, image.image_skia().image_reps().size());
+}
+
+// Tests behaviour of image created by IconImage after IconImage host goes
+// away. The image should still return loaded representations. If requested
+// representation was not loaded while IconImage host was around, transparent
+// representations should be returned.
+TEST_F(ExtensionIconImageTest, IconImageDestruction) {
+ scoped_refptr<Extension> extension(CreateExtension(
+ "extension_icon_image", Extension::INVALID));
+ ASSERT_TRUE(extension.get() != NULL);
+
+ gfx::ImageSkia default_icon = GetDefaultIcon();
+
+ // Load images we expect to find as representations in icon_image, so we
+ // can later use them to validate icon_image.
+ SkBitmap bitmap_16 =
+ GetTestBitmap(extension, "16.png", 16, ImageLoadingTracker::DONT_CACHE);
+ ASSERT_FALSE(bitmap_16.empty());
+
+ scoped_ptr<IconImage> image(
+ new IconImage(extension, extension->icons(), 16, default_icon, this));
+
+ // Load an image representation.
+ gfx::ImageSkiaRep representation =
+ image->image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
+
+ WaitForImageLoad();
+ EXPECT_EQ(1, ImageLoadedCount());
+ ASSERT_EQ(1u, image->image_skia().image_reps().size());
+
+ // Stash loaded image skia, and destroy |image|.
+ gfx::ImageSkia image_skia = image->image_skia();
+ image.reset();
+ extension = NULL;
+
+ // Image skia should still be able to get previously loaded representation.
+ representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_100P);
+
+ EXPECT_EQ(ui::SCALE_FACTOR_100P, representation.scale_factor());
+ EXPECT_EQ(16, representation.pixel_width());
+ EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16));
+
+ // When requesting another representation, we should get blank image.
+ representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_200P);
+
+ EXPECT_TRUE(gfx::BitmapsAreEqual(
+ representation.sk_bitmap(),
+ CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_200P)));
}
« no previous file with comments | « chrome/browser/extensions/extension_icon_image.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698