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/wm/core/image_grid.h" | 5 #include "ui/wm/core/image_grid.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.h" |
9 #include "ui/aura/test/aura_test_base.h" | 9 #include "ui/aura/test/aura_test_base.h" |
10 #include "ui/gfx/image/image.h" | 10 #include "ui/gfx/image/image.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 } // namespace | 24 } // namespace |
25 | 25 |
26 typedef aura::test::AuraTestBase ImageGridTest; | 26 typedef aura::test::AuraTestBase ImageGridTest; |
27 | 27 |
28 // Test that an ImageGrid's layers are transformed correctly when SetSize() is | 28 // Test that an ImageGrid's layers are transformed correctly when SetSize() is |
29 // called. | 29 // called. |
30 TEST_F(ImageGridTest, Basic) { | 30 TEST_F(ImageGridTest, Basic) { |
31 // Size of the images around the grid's border. | 31 // Size of the images around the grid's border. |
32 const int kBorder = 2; | 32 const int kBorder = 2; |
33 | 33 |
34 scoped_ptr<gfx::Image> image_1x1(CreateImage(gfx::Size(1, 1))); | 34 std::unique_ptr<gfx::Image> image_1x1(CreateImage(gfx::Size(1, 1))); |
35 scoped_ptr<gfx::Image> image_1xB(CreateImage(gfx::Size(1, kBorder))); | 35 std::unique_ptr<gfx::Image> image_1xB(CreateImage(gfx::Size(1, kBorder))); |
36 scoped_ptr<gfx::Image> image_Bx1(CreateImage(gfx::Size(kBorder, 1))); | 36 std::unique_ptr<gfx::Image> image_Bx1(CreateImage(gfx::Size(kBorder, 1))); |
37 scoped_ptr<gfx::Image> image_BxB(CreateImage(gfx::Size(kBorder, kBorder))); | 37 std::unique_ptr<gfx::Image> image_BxB( |
| 38 CreateImage(gfx::Size(kBorder, kBorder))); |
38 | 39 |
39 ImageGrid grid; | 40 ImageGrid grid; |
40 grid.SetImages(image_BxB.get(), image_1xB.get(), image_BxB.get(), | 41 grid.SetImages(image_BxB.get(), image_1xB.get(), image_BxB.get(), |
41 image_Bx1.get(), image_1x1.get(), image_Bx1.get(), | 42 image_Bx1.get(), image_1x1.get(), image_Bx1.get(), |
42 image_BxB.get(), image_1xB.get(), image_BxB.get()); | 43 image_BxB.get(), image_1xB.get(), image_BxB.get()); |
43 | 44 |
44 ImageGrid::TestAPI test_api(&grid); | 45 ImageGrid::TestAPI test_api(&grid); |
45 ASSERT_TRUE(grid.top_left_layer() != NULL); | 46 ASSERT_TRUE(grid.top_left_layer() != NULL); |
46 ASSERT_TRUE(grid.top_layer() != NULL); | 47 ASSERT_TRUE(grid.top_layer() != NULL); |
47 ASSERT_TRUE(grid.top_right_layer() != NULL); | 48 ASSERT_TRUE(grid.top_right_layer() != NULL); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 test_api.GetTransformedLayerBounds( | 117 test_api.GetTransformedLayerBounds( |
117 *grid.bottom_right_layer()).ToString()); | 118 *grid.bottom_right_layer()).ToString()); |
118 } | 119 } |
119 | 120 |
120 // Test that an ImageGrid's layers are transformed correctly when | 121 // Test that an ImageGrid's layers are transformed correctly when |
121 // SetContentBounds() is called. | 122 // SetContentBounds() is called. |
122 TEST_F(ImageGridTest, SetContentBounds) { | 123 TEST_F(ImageGridTest, SetContentBounds) { |
123 // Size of the images around the grid's border. | 124 // Size of the images around the grid's border. |
124 const int kBorder = 2; | 125 const int kBorder = 2; |
125 | 126 |
126 scoped_ptr<gfx::Image> image_1x1(CreateImage(gfx::Size(1, 1))); | 127 std::unique_ptr<gfx::Image> image_1x1(CreateImage(gfx::Size(1, 1))); |
127 scoped_ptr<gfx::Image> image_1xB(CreateImage(gfx::Size(1, kBorder))); | 128 std::unique_ptr<gfx::Image> image_1xB(CreateImage(gfx::Size(1, kBorder))); |
128 scoped_ptr<gfx::Image> image_Bx1(CreateImage(gfx::Size(kBorder, 1))); | 129 std::unique_ptr<gfx::Image> image_Bx1(CreateImage(gfx::Size(kBorder, 1))); |
129 scoped_ptr<gfx::Image> image_BxB(CreateImage(gfx::Size(kBorder, kBorder))); | 130 std::unique_ptr<gfx::Image> image_BxB( |
| 131 CreateImage(gfx::Size(kBorder, kBorder))); |
130 | 132 |
131 ImageGrid grid; | 133 ImageGrid grid; |
132 grid.SetImages(image_BxB.get(), image_1xB.get(), image_BxB.get(), | 134 grid.SetImages(image_BxB.get(), image_1xB.get(), image_BxB.get(), |
133 image_Bx1.get(), image_1x1.get(), image_Bx1.get(), | 135 image_Bx1.get(), image_1x1.get(), image_Bx1.get(), |
134 image_BxB.get(), image_1xB.get(), image_BxB.get()); | 136 image_BxB.get(), image_1xB.get(), image_BxB.get()); |
135 | 137 |
136 ImageGrid::TestAPI test_api(&grid); | 138 ImageGrid::TestAPI test_api(&grid); |
137 | 139 |
138 const gfx::Point origin(5, 10); | 140 const gfx::Point origin(5, 10); |
139 const gfx::Size size(20, 30); | 141 const gfx::Size size(20, 30); |
140 grid.SetContentBounds(gfx::Rect(origin, size)); | 142 grid.SetContentBounds(gfx::Rect(origin, size)); |
141 | 143 |
142 // The master layer is positioned above the top-left corner of the content | 144 // The master layer is positioned above the top-left corner of the content |
143 // bounds and has height/width that contain the grid and bounds. | 145 // bounds and has height/width that contain the grid and bounds. |
144 EXPECT_EQ(gfx::RectF(origin.x() - kBorder, | 146 EXPECT_EQ(gfx::RectF(origin.x() - kBorder, |
145 origin.y() - kBorder, | 147 origin.y() - kBorder, |
146 size.width() + 2 * kBorder, | 148 size.width() + 2 * kBorder, |
147 size.height() + 2 * kBorder).ToString(), | 149 size.height() + 2 * kBorder).ToString(), |
148 test_api.GetTransformedLayerBounds(*grid.layer()).ToString()); | 150 test_api.GetTransformedLayerBounds(*grid.layer()).ToString()); |
149 } | 151 } |
150 | 152 |
151 // Check that we don't crash if only a single image is supplied. | 153 // Check that we don't crash if only a single image is supplied. |
152 TEST_F(ImageGridTest, SingleImage) { | 154 TEST_F(ImageGridTest, SingleImage) { |
153 const int kBorder = 1; | 155 const int kBorder = 1; |
154 scoped_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder))); | 156 std::unique_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder))); |
155 | 157 |
156 ImageGrid grid; | 158 ImageGrid grid; |
157 grid.SetImages(NULL, image.get(), NULL, | 159 grid.SetImages(NULL, image.get(), NULL, |
158 NULL, NULL, NULL, | 160 NULL, NULL, NULL, |
159 NULL, NULL, NULL); | 161 NULL, NULL, NULL); |
160 | 162 |
161 ImageGrid::TestAPI test_api(&grid); | 163 ImageGrid::TestAPI test_api(&grid); |
162 EXPECT_TRUE(grid.top_left_layer() == NULL); | 164 EXPECT_TRUE(grid.top_left_layer() == NULL); |
163 ASSERT_TRUE(grid.top_layer() != NULL); | 165 ASSERT_TRUE(grid.top_layer() != NULL); |
164 EXPECT_TRUE(grid.top_right_layer() == NULL); | 166 EXPECT_TRUE(grid.top_right_layer() == NULL); |
(...skipping 11 matching lines...) Expand all Loading... |
176 // shouldn't be scaled vertically. | 178 // shouldn't be scaled vertically. |
177 EXPECT_EQ(gfx::RectF(0, 0, kSize.width(), kBorder).ToString(), | 179 EXPECT_EQ(gfx::RectF(0, 0, kSize.width(), kBorder).ToString(), |
178 test_api.GetTransformedLayerBounds( | 180 test_api.GetTransformedLayerBounds( |
179 *grid.top_layer()).ToString()); | 181 *grid.top_layer()).ToString()); |
180 } | 182 } |
181 | 183 |
182 // Check that we don't crash when we reset existing images to NULL and | 184 // Check that we don't crash when we reset existing images to NULL and |
183 // reset NULL images to new ones. | 185 // reset NULL images to new ones. |
184 TEST_F(ImageGridTest, ResetImages) { | 186 TEST_F(ImageGridTest, ResetImages) { |
185 const int kBorder = 1; | 187 const int kBorder = 1; |
186 scoped_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder))); | 188 std::unique_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder))); |
187 | 189 |
188 ImageGrid grid; | 190 ImageGrid grid; |
189 grid.SetImages(NULL, image.get(), NULL, | 191 grid.SetImages(NULL, image.get(), NULL, |
190 NULL, NULL, NULL, | 192 NULL, NULL, NULL, |
191 NULL, NULL, NULL); | 193 NULL, NULL, NULL); |
192 | 194 |
193 // Only the top edge has a layer. | 195 // Only the top edge has a layer. |
194 ImageGrid::TestAPI test_api(&grid); | 196 ImageGrid::TestAPI test_api(&grid); |
195 ASSERT_TRUE(grid.top_left_layer() == NULL); | 197 ASSERT_TRUE(grid.top_left_layer() == NULL); |
196 ASSERT_FALSE(grid.top_layer() == NULL); | 198 ASSERT_FALSE(grid.top_layer() == NULL); |
(...skipping 21 matching lines...) Expand all Loading... |
218 ASSERT_TRUE(grid.bottom_right_layer() == NULL); | 220 ASSERT_TRUE(grid.bottom_right_layer() == NULL); |
219 } | 221 } |
220 | 222 |
221 // Test that side (top, left, right, bottom) layers that are narrower than their | 223 // Test that side (top, left, right, bottom) layers that are narrower than their |
222 // adjacent corner layers stay pinned to the outside edges instead of getting | 224 // adjacent corner layers stay pinned to the outside edges instead of getting |
223 // moved inwards or scaled. This exercises the scenario used for shadows. | 225 // moved inwards or scaled. This exercises the scenario used for shadows. |
224 TEST_F(ImageGridTest, SmallerSides) { | 226 TEST_F(ImageGridTest, SmallerSides) { |
225 const int kCorner = 2; | 227 const int kCorner = 2; |
226 const int kEdge = 1; | 228 const int kEdge = 1; |
227 | 229 |
228 scoped_ptr<gfx::Image> top_left_image( | 230 std::unique_ptr<gfx::Image> top_left_image( |
229 CreateImage(gfx::Size(kCorner, kCorner))); | 231 CreateImage(gfx::Size(kCorner, kCorner))); |
230 scoped_ptr<gfx::Image> top_image(CreateImage(gfx::Size(kEdge, kEdge))); | 232 std::unique_ptr<gfx::Image> top_image(CreateImage(gfx::Size(kEdge, kEdge))); |
231 scoped_ptr<gfx::Image> top_right_image( | 233 std::unique_ptr<gfx::Image> top_right_image( |
232 CreateImage(gfx::Size(kCorner, kCorner))); | 234 CreateImage(gfx::Size(kCorner, kCorner))); |
233 scoped_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge))); | 235 std::unique_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge))); |
234 scoped_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge))); | 236 std::unique_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge))); |
235 | 237 |
236 ImageGrid grid; | 238 ImageGrid grid; |
237 grid.SetImages(top_left_image.get(), top_image.get(), top_right_image.get(), | 239 grid.SetImages(top_left_image.get(), top_image.get(), top_right_image.get(), |
238 left_image.get(), NULL, right_image.get(), | 240 left_image.get(), NULL, right_image.get(), |
239 NULL, NULL, NULL); | 241 NULL, NULL, NULL); |
240 ImageGrid::TestAPI test_api(&grid); | 242 ImageGrid::TestAPI test_api(&grid); |
241 | 243 |
242 const gfx::Size kSize(20, 30); | 244 const gfx::Size kSize(20, 30); |
243 grid.SetSize(kSize); | 245 grid.SetSize(kSize); |
244 | 246 |
(...skipping 20 matching lines...) Expand all Loading... |
265 *grid.right_layer()).ToString()); | 267 *grid.right_layer()).ToString()); |
266 } | 268 } |
267 | 269 |
268 // Test that we hide or clip layers as needed when the grid is assigned a small | 270 // Test that we hide or clip layers as needed when the grid is assigned a small |
269 // size. | 271 // size. |
270 TEST_F(ImageGridTest, TooSmall) { | 272 TEST_F(ImageGridTest, TooSmall) { |
271 const int kCorner = 5; | 273 const int kCorner = 5; |
272 const int kCenter = 3; | 274 const int kCenter = 3; |
273 const int kEdge = 3; | 275 const int kEdge = 3; |
274 | 276 |
275 scoped_ptr<gfx::Image> top_left_image( | 277 std::unique_ptr<gfx::Image> top_left_image( |
276 CreateImage(gfx::Size(kCorner, kCorner))); | 278 CreateImage(gfx::Size(kCorner, kCorner))); |
277 scoped_ptr<gfx::Image> top_image(CreateImage(gfx::Size(kEdge, kEdge))); | 279 std::unique_ptr<gfx::Image> top_image(CreateImage(gfx::Size(kEdge, kEdge))); |
278 scoped_ptr<gfx::Image> top_right_image( | 280 std::unique_ptr<gfx::Image> top_right_image( |
279 CreateImage(gfx::Size(kCorner, kCorner))); | 281 CreateImage(gfx::Size(kCorner, kCorner))); |
280 scoped_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge))); | 282 std::unique_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge))); |
281 scoped_ptr<gfx::Image> center_image(CreateImage(gfx::Size(kCenter, kCenter))); | 283 std::unique_ptr<gfx::Image> center_image( |
282 scoped_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge))); | 284 CreateImage(gfx::Size(kCenter, kCenter))); |
283 scoped_ptr<gfx::Image> bottom_left_image( | 285 std::unique_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge))); |
| 286 std::unique_ptr<gfx::Image> bottom_left_image( |
284 CreateImage(gfx::Size(kCorner, kCorner))); | 287 CreateImage(gfx::Size(kCorner, kCorner))); |
285 scoped_ptr<gfx::Image> bottom_image(CreateImage(gfx::Size(kEdge, kEdge))); | 288 std::unique_ptr<gfx::Image> bottom_image( |
286 scoped_ptr<gfx::Image> bottom_right_image( | 289 CreateImage(gfx::Size(kEdge, kEdge))); |
| 290 std::unique_ptr<gfx::Image> bottom_right_image( |
287 CreateImage(gfx::Size(kCorner, kCorner))); | 291 CreateImage(gfx::Size(kCorner, kCorner))); |
288 | 292 |
289 ImageGrid grid; | 293 ImageGrid grid; |
290 grid.SetImages( | 294 grid.SetImages( |
291 top_left_image.get(), top_image.get(), top_right_image.get(), | 295 top_left_image.get(), top_image.get(), top_right_image.get(), |
292 left_image.get(), center_image.get(), right_image.get(), | 296 left_image.get(), center_image.get(), right_image.get(), |
293 bottom_left_image.get(), bottom_image.get(), bottom_right_image.get()); | 297 bottom_left_image.get(), bottom_image.get(), bottom_right_image.get()); |
294 ImageGrid::TestAPI test_api(&grid); | 298 ImageGrid::TestAPI test_api(&grid); |
295 | 299 |
296 // Set a size that's smaller than the combined (unscaled) corner images. | 300 // Set a size that's smaller than the combined (unscaled) corner images. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 EXPECT_TRUE(grid.center_layer()->visible()); | 335 EXPECT_TRUE(grid.center_layer()->visible()); |
332 | 336 |
333 // We shouldn't be clipping the corner images anymore. | 337 // We shouldn't be clipping the corner images anymore. |
334 EXPECT_TRUE(test_api.top_left_clip_rect().IsEmpty()); | 338 EXPECT_TRUE(test_api.top_left_clip_rect().IsEmpty()); |
335 EXPECT_TRUE(test_api.top_right_clip_rect().IsEmpty()); | 339 EXPECT_TRUE(test_api.top_right_clip_rect().IsEmpty()); |
336 EXPECT_TRUE(test_api.bottom_left_clip_rect().IsEmpty()); | 340 EXPECT_TRUE(test_api.bottom_left_clip_rect().IsEmpty()); |
337 EXPECT_TRUE(test_api.bottom_right_clip_rect().IsEmpty()); | 341 EXPECT_TRUE(test_api.bottom_right_clip_rect().IsEmpty()); |
338 } | 342 } |
339 | 343 |
340 } // namespace wm | 344 } // namespace wm |
OLD | NEW |