OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "third_party/skia/include/core/SkBitmap.h" | 6 #include "third_party/skia/include/core/SkBitmap.h" |
7 #include "ui/aura_shell/image_grid.h" | 7 #include "ui/aura_shell/image_grid.h" |
8 #include "ui/aura_shell/test/aura_shell_test_base.h" | 8 #include "ui/aura_shell/test/aura_shell_test_base.h" |
9 #include "ui/gfx/image/image.h" | 9 #include "ui/gfx/image/image.h" |
10 | 10 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 const gfx::Size kSize(20, 30); | 173 const gfx::Size kSize(20, 30); |
174 grid.SetSize(kSize); | 174 grid.SetSize(kSize); |
175 | 175 |
176 // The top layer should be flush with the top edge and stretched horizontally | 176 // The top layer should be flush with the top edge and stretched horizontally |
177 // between the two top corners. | 177 // between the two top corners. |
178 EXPECT_EQ(gfx::Rect( | 178 EXPECT_EQ(gfx::Rect( |
179 kCorner, 0, kSize.width() - 2 * kCorner, kEdge).ToString(), | 179 kCorner, 0, kSize.width() - 2 * kCorner, kEdge).ToString(), |
180 test_api.GetTransformedLayerBounds( | 180 test_api.GetTransformedLayerBounds( |
181 *test_api.top_layer()).ToString()); | 181 *test_api.top_layer()).ToString()); |
182 | 182 |
183 | |
184 // The left layer should be flush with the left edge and stretched vertically | 183 // The left layer should be flush with the left edge and stretched vertically |
185 // between the top left corner and the bottom. | 184 // between the top left corner and the bottom. |
186 EXPECT_EQ(gfx::Rect( | 185 EXPECT_EQ(gfx::Rect( |
187 0, kCorner, kEdge, kSize.height() - kCorner).ToString(), | 186 0, kCorner, kEdge, kSize.height() - kCorner).ToString(), |
188 test_api.GetTransformedLayerBounds( | 187 test_api.GetTransformedLayerBounds( |
189 *test_api.left_layer()).ToString()); | 188 *test_api.left_layer()).ToString()); |
190 | 189 |
191 // The right layer should be flush with the right edge and stretched | 190 // The right layer should be flush with the right edge and stretched |
192 // vertically between the top right corner and the bottom. | 191 // vertically between the top right corner and the bottom. |
193 EXPECT_EQ(gfx::Rect( | 192 EXPECT_EQ(gfx::Rect( |
194 kSize.width() - kEdge, kCorner, | 193 kSize.width() - kEdge, kCorner, |
195 kEdge, kSize.height() - kCorner).ToString(), | 194 kEdge, kSize.height() - kCorner).ToString(), |
196 test_api.GetTransformedLayerBounds( | 195 test_api.GetTransformedLayerBounds( |
197 *test_api.right_layer()).ToString()); | 196 *test_api.right_layer()).ToString()); |
198 } | 197 } |
199 | 198 |
| 199 // Test that we hide or clip layers as needed when the grid is assigned a small |
| 200 // size. |
| 201 TEST_F(ImageGridTest, TooSmall) { |
| 202 const int kCorner = 5; |
| 203 const int kCenter = 3; |
| 204 const int kEdge = 3; |
| 205 |
| 206 scoped_ptr<gfx::Image> top_left_image( |
| 207 CreateImage(gfx::Size(kCorner, kCorner))); |
| 208 scoped_ptr<gfx::Image> top_image(CreateImage(gfx::Size(kEdge, kEdge))); |
| 209 scoped_ptr<gfx::Image> top_right_image( |
| 210 CreateImage(gfx::Size(kCorner, kCorner))); |
| 211 scoped_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge))); |
| 212 scoped_ptr<gfx::Image> center_image(CreateImage(gfx::Size(kCenter, kCenter))); |
| 213 scoped_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge))); |
| 214 scoped_ptr<gfx::Image> bottom_left_image( |
| 215 CreateImage(gfx::Size(kCorner, kCorner))); |
| 216 scoped_ptr<gfx::Image> bottom_image(CreateImage(gfx::Size(kEdge, kEdge))); |
| 217 scoped_ptr<gfx::Image> bottom_right_image( |
| 218 CreateImage(gfx::Size(kCorner, kCorner))); |
| 219 |
| 220 ImageGrid grid; |
| 221 grid.Init( |
| 222 top_left_image.get(), top_image.get(), top_right_image.get(), |
| 223 left_image.get(), center_image.get(), right_image.get(), |
| 224 bottom_left_image.get(), bottom_image.get(), bottom_right_image.get()); |
| 225 ImageGrid::TestAPI test_api(&grid); |
| 226 |
| 227 // Set a size that's smaller than the combined (unscaled) corner images. |
| 228 const gfx::Size kSmallSize(kCorner + kCorner - 3, kCorner + kCorner - 5); |
| 229 grid.SetSize(kSmallSize); |
| 230 |
| 231 // The scalable images around the sides and in the center should be hidden. |
| 232 EXPECT_FALSE(test_api.top_layer()->visible()); |
| 233 EXPECT_FALSE(test_api.bottom_layer()->visible()); |
| 234 EXPECT_FALSE(test_api.left_layer()->visible()); |
| 235 EXPECT_FALSE(test_api.right_layer()->visible()); |
| 236 EXPECT_FALSE(test_api.center_layer()->visible()); |
| 237 |
| 238 // The corner images' clip rects should sum to the expected size. |
| 239 EXPECT_EQ(kSmallSize.width(), |
| 240 test_api.GetTopLeftClipRect().width() + |
| 241 test_api.GetTopRightClipRect().width()); |
| 242 EXPECT_EQ(kSmallSize.width(), |
| 243 test_api.GetBottomLeftClipRect().width() + |
| 244 test_api.GetBottomRightClipRect().width()); |
| 245 EXPECT_EQ(kSmallSize.height(), |
| 246 test_api.GetTopLeftClipRect().height() + |
| 247 test_api.GetBottomLeftClipRect().height()); |
| 248 EXPECT_EQ(kSmallSize.height(), |
| 249 test_api.GetTopRightClipRect().height() + |
| 250 test_api.GetBottomRightClipRect().height()); |
| 251 |
| 252 // Resize the grid to be large enough to show all images. |
| 253 const gfx::Size kLargeSize(kCorner + kCorner + kCenter, |
| 254 kCorner + kCorner + kCenter); |
| 255 grid.SetSize(kLargeSize); |
| 256 |
| 257 // The scalable images should be visible now. |
| 258 EXPECT_TRUE(test_api.top_layer()->visible()); |
| 259 EXPECT_TRUE(test_api.bottom_layer()->visible()); |
| 260 EXPECT_TRUE(test_api.left_layer()->visible()); |
| 261 EXPECT_TRUE(test_api.right_layer()->visible()); |
| 262 EXPECT_TRUE(test_api.center_layer()->visible()); |
| 263 |
| 264 // We shouldn't be clipping the corner images anymore. |
| 265 EXPECT_TRUE(test_api.GetTopLeftClipRect().IsEmpty()); |
| 266 EXPECT_TRUE(test_api.GetTopRightClipRect().IsEmpty()); |
| 267 EXPECT_TRUE(test_api.GetBottomLeftClipRect().IsEmpty()); |
| 268 EXPECT_TRUE(test_api.GetBottomRightClipRect().IsEmpty()); |
| 269 } |
| 270 |
200 } // namespace test | 271 } // namespace test |
201 } // namespace aura_shell | 272 } // namespace aura_shell |
OLD | NEW |