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

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
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 8008f78ad24465fcaff0f3865756910a107d92ad..24c9fe484be4ff447588d12aedc01654afe39922 100644
--- a/ui/gfx/image/image_skia_unittest.cc
+++ b/ui/gfx/image/image_skia_unittest.cc
@@ -52,6 +52,22 @@ class DynamicSource : public ImageSkiaSource {
DISALLOW_COPY_AND_ASSIGN(DynamicSource);
};
+class NullSource: public ImageSkiaSource {
+ public:
+ NullSource() {
+ }
+
+ ~NullSource() {
oshima 2012/07/17 16:43:21 virtual
+ }
+
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ return gfx::ImageSkiaRep();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NullSource);
+};
+
} // namespace;
typedef testing::Test ImageSkiaTest;
@@ -113,4 +129,48 @@ 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));
oshima 2012/07/17 16:43:21 will this fit single line?
+ // 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
+
} // namespace gfx

Powered by Google App Engine
This is Rietveld 408576698