OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/gfx/image/image_skia.h" | 5 #include "ui/gfx/image/image_skia.h" |
6 | 6 |
7 #include "third_party/skia/include/core/SkBitmap.h" | 7 #include "third_party/skia/include/core/SkBitmap.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/gfx/image/image_skia_rep.h" | 9 #include "ui/gfx/image/image_skia_rep.h" |
10 #include "ui/gfx/image/image_skia_source.h" | 10 #include "ui/gfx/image/image_skia_source.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | 45 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
46 return CreateImage(size_, scale_factor); | 46 return CreateImage(size_, scale_factor); |
47 } | 47 } |
48 | 48 |
49 private: | 49 private: |
50 gfx::Size size_; | 50 gfx::Size size_; |
51 | 51 |
52 DISALLOW_COPY_AND_ASSIGN(DynamicSource); | 52 DISALLOW_COPY_AND_ASSIGN(DynamicSource); |
53 }; | 53 }; |
54 | 54 |
55 class NullSource: public ImageSkiaSource { | |
56 public: | |
57 NullSource() { | |
58 } | |
59 | |
60 ~NullSource() { | |
oshima
2012/07/17 16:43:21
virtual
| |
61 } | |
62 | |
63 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | |
64 return gfx::ImageSkiaRep(); | |
65 } | |
66 | |
67 private: | |
68 DISALLOW_COPY_AND_ASSIGN(NullSource); | |
69 }; | |
70 | |
55 } // namespace; | 71 } // namespace; |
56 | 72 |
57 typedef testing::Test ImageSkiaTest; | 73 typedef testing::Test ImageSkiaTest; |
58 | 74 |
59 TEST(ImageSkiaTest, FixedSource) { | 75 TEST(ImageSkiaTest, FixedSource) { |
60 ImageSkiaRep image(CreateImage(Size(100, 200), ui::SCALE_FACTOR_100P)); | 76 ImageSkiaRep image(CreateImage(Size(100, 200), ui::SCALE_FACTOR_100P)); |
61 ImageSkia image_skia(new FixedSource(image), Size(100, 200)); | 77 ImageSkia image_skia(new FixedSource(image), Size(100, 200)); |
62 EXPECT_EQ(0U, image_skia.image_reps().size()); | 78 EXPECT_EQ(0U, image_skia.image_reps().size()); |
63 | 79 |
64 const ImageSkiaRep& result_100p = | 80 const ImageSkiaRep& result_100p = |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 EXPECT_EQ(2U, image_skia.image_reps().size()); | 122 EXPECT_EQ(2U, image_skia.image_reps().size()); |
107 | 123 |
108 // Get the representation again and make sure it doesn't | 124 // Get the representation again and make sure it doesn't |
109 // generate new image skia rep. | 125 // generate new image skia rep. |
110 image_skia.GetRepresentation(ui::SCALE_FACTOR_100P); | 126 image_skia.GetRepresentation(ui::SCALE_FACTOR_100P); |
111 EXPECT_EQ(2U, image_skia.image_reps().size()); | 127 EXPECT_EQ(2U, image_skia.image_reps().size()); |
112 image_skia.GetRepresentation(ui::SCALE_FACTOR_200P); | 128 image_skia.GetRepresentation(ui::SCALE_FACTOR_200P); |
113 EXPECT_EQ(2U, image_skia.image_reps().size()); | 129 EXPECT_EQ(2U, image_skia.image_reps().size()); |
114 } | 130 } |
115 | 131 |
132 #if defined(OS_MACOSX) | |
133 | |
134 // Tests that GetRepresentations returns all of the representations in the | |
135 // image when there are multiple representations for a scale factor. | |
136 // This currently is the case with ImageLoadingTracker::LoadImages, to | |
137 // load the application shortcut icon on Mac in particular. | |
138 TEST(ImageSkiaTest, GetRepresentationsManyRepsPerScaleFactor) { | |
139 const int kSmallIcon1x = 16; | |
140 const int kSmallIcon2x = 32; | |
141 const int kLargeIcon1x = 32; | |
142 | |
143 ImageSkia image(new NullSource(), | |
144 gfx::Size(kSmallIcon1x, kSmallIcon1x)); | |
oshima
2012/07/17 16:43:21
will this fit single line?
| |
145 // Simulate a source which loads images on a delay. Upon | |
146 // GetImageForScaleFactor, it immediately returns null and starts loading | |
147 // image reps slowly. | |
148 image.GetRepresentation(ui::SCALE_FACTOR_100P); | |
149 image.GetRepresentation(ui::SCALE_FACTOR_200P); | |
150 | |
151 // After a lengthy amount of simulated time, finally loaded image reps. | |
152 image.AddRepresentation(ImageSkiaRep( | |
153 gfx::Size(kSmallIcon1x, kSmallIcon1x), ui::SCALE_FACTOR_100P)); | |
154 image.AddRepresentation(ImageSkiaRep( | |
155 gfx::Size(kSmallIcon2x, kSmallIcon2x), ui::SCALE_FACTOR_200P)); | |
156 image.AddRepresentation(ImageSkiaRep( | |
157 gfx::Size(kLargeIcon1x, kLargeIcon1x), ui::SCALE_FACTOR_100P)); | |
158 | |
159 std::vector<ImageSkiaRep> image_reps = image.GetRepresentations(); | |
160 EXPECT_EQ(3u, image_reps.size()); | |
161 | |
162 int num_1x = 0; | |
163 int num_2x = 0; | |
164 for (size_t i = 0; i < image_reps.size(); ++i) { | |
165 if (image_reps[i].scale_factor() == ui::SCALE_FACTOR_100P) | |
166 num_1x++; | |
167 else if (image_reps[i].scale_factor() == ui::SCALE_FACTOR_200P) | |
168 num_2x++; | |
169 } | |
170 EXPECT_EQ(2, num_1x); | |
171 EXPECT_EQ(1, num_2x); | |
172 } | |
173 | |
174 #endif // OS_MACOSX | |
175 | |
116 } // namespace gfx | 176 } // namespace gfx |
OLD | NEW |