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

Unified Diff: ui/gfx/image/image_skia_unittest.cc

Issue 10780010: Introduces ImageSkia::GetRepresentations() for Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 | « ui/gfx/image/image_skia.cc ('k') | ui/gfx/image/image_skia_util_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/image/image_skia_unittest.cc
diff --git a/ui/gfx/image/image_skia_unittest.cc b/ui/gfx/image/image_skia_unittest.cc
index dbc484a802fe658426ceedcfeed908812f3ea523..9d5dc809dc1168268ce1d8b85ef509b9ac793179 100644
--- a/ui/gfx/image/image_skia_unittest.cc
+++ b/ui/gfx/image/image_skia_unittest.cc
@@ -19,6 +19,9 @@ class FixedSource : public ImageSkiaSource {
public:
FixedSource(const ImageSkiaRep& image) : image_(image) {}
+ virtual ~FixedSource() {
+ }
+
virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
return image_;
}
@@ -33,6 +36,9 @@ class DynamicSource : public ImageSkiaSource {
public:
DynamicSource(const gfx::Size& size) : size_(size) {}
+ virtual ~DynamicSource() {
+ }
+
virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
return gfx::ImageSkiaRep(size_, scale_factor);
}
@@ -43,6 +49,22 @@ class DynamicSource : public ImageSkiaSource {
DISALLOW_COPY_AND_ASSIGN(DynamicSource);
};
+class NullSource: public ImageSkiaSource {
+ public:
+ NullSource() {
+ }
+
+ virtual ~NullSource() {
+ }
+
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ return gfx::ImageSkiaRep();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NullSource);
+};
+
} // namespace;
typedef testing::Test ImageSkiaTest;
@@ -104,6 +126,49 @@ TEST(ImageSkiaTest, DynamicSource) {
EXPECT_EQ(2U, image_skia.image_reps().size());
}
+#if defined(OS_MACOSX)
+
+// Tests that GetRepresentations returns all of the representations in the
+// image when there are multiple representations for a scale factor.
+// This currently is the case with ImageLoadingTracker::LoadImages, to
+// load the application shortcut icon on Mac in particular.
+TEST(ImageSkiaTest, GetRepresentationsManyRepsPerScaleFactor) {
+ const int kSmallIcon1x = 16;
+ const int kSmallIcon2x = 32;
+ const int kLargeIcon1x = 32;
+
+ ImageSkia image(new NullSource(), gfx::Size(kSmallIcon1x, kSmallIcon1x));
+ // Simulate a source which loads images on a delay. Upon
+ // GetImageForScaleFactor, it immediately returns null and starts loading
+ // image reps slowly.
+ image.GetRepresentation(ui::SCALE_FACTOR_100P);
+ image.GetRepresentation(ui::SCALE_FACTOR_200P);
+
+ // After a lengthy amount of simulated time, finally loaded image reps.
+ image.AddRepresentation(ImageSkiaRep(
+ gfx::Size(kSmallIcon1x, kSmallIcon1x), ui::SCALE_FACTOR_100P));
+ image.AddRepresentation(ImageSkiaRep(
+ gfx::Size(kSmallIcon2x, kSmallIcon2x), ui::SCALE_FACTOR_200P));
+ image.AddRepresentation(ImageSkiaRep(
+ gfx::Size(kLargeIcon1x, kLargeIcon1x), ui::SCALE_FACTOR_100P));
+
+ std::vector<ImageSkiaRep> image_reps = image.GetRepresentations();
+ EXPECT_EQ(3u, image_reps.size());
+
+ int num_1x = 0;
+ int num_2x = 0;
+ for (size_t i = 0; i < image_reps.size(); ++i) {
+ if (image_reps[i].scale_factor() == ui::SCALE_FACTOR_100P)
+ num_1x++;
+ else if (image_reps[i].scale_factor() == ui::SCALE_FACTOR_200P)
+ num_2x++;
+ }
+ EXPECT_EQ(2, num_1x);
+ EXPECT_EQ(1, num_2x);
+}
+
+#endif // OS_MACOSX
+
TEST(ImageSkiaTest, GetBitmap) {
ImageSkia image_skia(new DynamicSource(Size(100, 200)), Size(100, 200));
const SkBitmap* bitmap = image_skia.bitmap();
« no previous file with comments | « ui/gfx/image/image_skia.cc ('k') | ui/gfx/image/image_skia_util_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698