| OLD | NEW |
| 1 // Copyright (c) 2011 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 "ash/test/aura_shell_test_base.h" | 5 #include "ash/test/aura_shell_test_base.h" |
| 6 #include "ash/wm/image_grid.h" | 6 #include "ash/wm/image_grid.h" |
| 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/gfx/image/image.h" | 9 #include "ui/gfx/image/image.h" |
| 10 | 10 |
| 11 using ash::internal::ImageGrid; | 11 using ash::internal::ImageGrid; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 31 TEST_F(ImageGridTest, Basic) { | 31 TEST_F(ImageGridTest, Basic) { |
| 32 // Size of the images around the grid's border. | 32 // Size of the images around the grid's border. |
| 33 const int kBorder = 2; | 33 const int kBorder = 2; |
| 34 | 34 |
| 35 scoped_ptr<gfx::Image> image_1x1(CreateImage(gfx::Size(1, 1))); | 35 scoped_ptr<gfx::Image> image_1x1(CreateImage(gfx::Size(1, 1))); |
| 36 scoped_ptr<gfx::Image> image_1xB(CreateImage(gfx::Size(1, kBorder))); | 36 scoped_ptr<gfx::Image> image_1xB(CreateImage(gfx::Size(1, kBorder))); |
| 37 scoped_ptr<gfx::Image> image_Bx1(CreateImage(gfx::Size(kBorder, 1))); | 37 scoped_ptr<gfx::Image> image_Bx1(CreateImage(gfx::Size(kBorder, 1))); |
| 38 scoped_ptr<gfx::Image> image_BxB(CreateImage(gfx::Size(kBorder, kBorder))); | 38 scoped_ptr<gfx::Image> image_BxB(CreateImage(gfx::Size(kBorder, kBorder))); |
| 39 | 39 |
| 40 ImageGrid grid; | 40 ImageGrid grid; |
| 41 grid.Init(image_BxB.get(), image_1xB.get(), image_BxB.get(), | 41 grid.SetImages(image_BxB.get(), image_1xB.get(), image_BxB.get(), |
| 42 image_Bx1.get(), image_1x1.get(), image_Bx1.get(), | 42 image_Bx1.get(), image_1x1.get(), image_Bx1.get(), |
| 43 image_BxB.get(), image_1xB.get(), image_BxB.get()); | 43 image_BxB.get(), image_1xB.get(), image_BxB.get()); |
| 44 | 44 |
| 45 ImageGrid::TestAPI test_api(&grid); | 45 ImageGrid::TestAPI test_api(&grid); |
| 46 ASSERT_TRUE(test_api.top_left_layer() != NULL); | 46 ASSERT_TRUE(test_api.top_left_layer() != NULL); |
| 47 ASSERT_TRUE(test_api.top_layer() != NULL); | 47 ASSERT_TRUE(test_api.top_layer() != NULL); |
| 48 ASSERT_TRUE(test_api.top_right_layer() != NULL); | 48 ASSERT_TRUE(test_api.top_right_layer() != NULL); |
| 49 ASSERT_TRUE(test_api.left_layer() != NULL); | 49 ASSERT_TRUE(test_api.left_layer() != NULL); |
| 50 ASSERT_TRUE(test_api.center_layer() != NULL); | 50 ASSERT_TRUE(test_api.center_layer() != NULL); |
| 51 ASSERT_TRUE(test_api.right_layer() != NULL); | 51 ASSERT_TRUE(test_api.right_layer() != NULL); |
| 52 ASSERT_TRUE(test_api.bottom_left_layer() != NULL); | 52 ASSERT_TRUE(test_api.bottom_left_layer() != NULL); |
| 53 ASSERT_TRUE(test_api.bottom_layer() != NULL); | 53 ASSERT_TRUE(test_api.bottom_layer() != NULL); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 test_api.GetTransformedLayerBounds( | 117 test_api.GetTransformedLayerBounds( |
| 118 *test_api.bottom_right_layer()).ToString()); | 118 *test_api.bottom_right_layer()).ToString()); |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Check that we don't crash if only a single image is supplied. | 121 // Check that we don't crash if only a single image is supplied. |
| 122 TEST_F(ImageGridTest, SingleImage) { | 122 TEST_F(ImageGridTest, SingleImage) { |
| 123 const int kBorder = 1; | 123 const int kBorder = 1; |
| 124 scoped_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder))); | 124 scoped_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder))); |
| 125 | 125 |
| 126 ImageGrid grid; | 126 ImageGrid grid; |
| 127 grid.Init(NULL, image.get(), NULL, | 127 grid.SetImages(NULL, image.get(), NULL, |
| 128 NULL, NULL, NULL, | 128 NULL, NULL, NULL, |
| 129 NULL, NULL, NULL); | 129 NULL, NULL, NULL); |
| 130 | 130 |
| 131 ImageGrid::TestAPI test_api(&grid); | 131 ImageGrid::TestAPI test_api(&grid); |
| 132 EXPECT_TRUE(test_api.top_left_layer() == NULL); | 132 EXPECT_TRUE(test_api.top_left_layer() == NULL); |
| 133 ASSERT_TRUE(test_api.top_layer() != NULL); | 133 ASSERT_TRUE(test_api.top_layer() != NULL); |
| 134 EXPECT_TRUE(test_api.top_right_layer() == NULL); | 134 EXPECT_TRUE(test_api.top_right_layer() == NULL); |
| 135 EXPECT_TRUE(test_api.left_layer() == NULL); | 135 EXPECT_TRUE(test_api.left_layer() == NULL); |
| 136 EXPECT_TRUE(test_api.center_layer() == NULL); | 136 EXPECT_TRUE(test_api.center_layer() == NULL); |
| 137 EXPECT_TRUE(test_api.right_layer() == NULL); | 137 EXPECT_TRUE(test_api.right_layer() == NULL); |
| 138 EXPECT_TRUE(test_api.bottom_left_layer() == NULL); | 138 EXPECT_TRUE(test_api.bottom_left_layer() == NULL); |
| 139 EXPECT_TRUE(test_api.bottom_layer() == NULL); | 139 EXPECT_TRUE(test_api.bottom_layer() == NULL); |
| 140 EXPECT_TRUE(test_api.bottom_right_layer() == NULL); | 140 EXPECT_TRUE(test_api.bottom_right_layer() == NULL); |
| 141 | 141 |
| 142 const gfx::Size kSize(10, 10); | 142 const gfx::Size kSize(10, 10); |
| 143 grid.SetSize(kSize); | 143 grid.SetSize(kSize); |
| 144 | 144 |
| 145 // The top layer should be scaled horizontally across the entire width, but it | 145 // The top layer should be scaled horizontally across the entire width, but it |
| 146 // shouldn't be scaled vertically. | 146 // shouldn't be scaled vertically. |
| 147 EXPECT_EQ(gfx::Rect(0, 0, kSize.width(), kBorder).ToString(), | 147 EXPECT_EQ(gfx::Rect(0, 0, kSize.width(), kBorder).ToString(), |
| 148 test_api.GetTransformedLayerBounds( | 148 test_api.GetTransformedLayerBounds( |
| 149 *test_api.top_layer()).ToString()); | 149 *test_api.top_layer()).ToString()); |
| 150 } | 150 } |
| 151 | 151 |
| 152 // Check that we don't crash when we reset existing images to NULL and |
| 153 // reset NULL images to new ones. |
| 154 TEST_F(ImageGridTest, ResetImages) { |
| 155 const int kBorder = 1; |
| 156 scoped_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder))); |
| 157 |
| 158 ImageGrid grid; |
| 159 grid.SetImages(NULL, image.get(), NULL, |
| 160 NULL, NULL, NULL, |
| 161 NULL, NULL, NULL); |
| 162 |
| 163 // Only the top edge has a layer. |
| 164 ImageGrid::TestAPI test_api(&grid); |
| 165 ASSERT_TRUE(test_api.top_left_layer() == NULL); |
| 166 ASSERT_FALSE(test_api.top_layer() == NULL); |
| 167 ASSERT_TRUE(test_api.top_right_layer() == NULL); |
| 168 ASSERT_TRUE(test_api.left_layer() == NULL); |
| 169 ASSERT_TRUE(test_api.center_layer() == NULL); |
| 170 ASSERT_TRUE(test_api.right_layer() == NULL); |
| 171 ASSERT_TRUE(test_api.bottom_left_layer() == NULL); |
| 172 ASSERT_TRUE(test_api.bottom_layer() == NULL); |
| 173 ASSERT_TRUE(test_api.bottom_right_layer() == NULL); |
| 174 |
| 175 grid.SetImages(NULL, NULL, NULL, |
| 176 NULL, NULL, NULL, |
| 177 NULL, image.get(), NULL); |
| 178 |
| 179 // Now only the bottom edge has a layer. |
| 180 ASSERT_TRUE(test_api.top_left_layer() == NULL); |
| 181 ASSERT_TRUE(test_api.top_layer() == NULL); |
| 182 ASSERT_TRUE(test_api.top_right_layer() == NULL); |
| 183 ASSERT_TRUE(test_api.left_layer() == NULL); |
| 184 ASSERT_TRUE(test_api.center_layer() == NULL); |
| 185 ASSERT_TRUE(test_api.right_layer() == NULL); |
| 186 ASSERT_TRUE(test_api.bottom_left_layer() == NULL); |
| 187 ASSERT_FALSE(test_api.bottom_layer() == NULL); |
| 188 ASSERT_TRUE(test_api.bottom_right_layer() == NULL); |
| 189 } |
| 190 |
| 152 // Test that side (top, left, right, bottom) layers that are narrower than their | 191 // Test that side (top, left, right, bottom) layers that are narrower than their |
| 153 // adjacent corner layers stay pinned to the outside edges instead of getting | 192 // adjacent corner layers stay pinned to the outside edges instead of getting |
| 154 // moved inwards or scaled. This exercises the scenario used for shadows. | 193 // moved inwards or scaled. This exercises the scenario used for shadows. |
| 155 TEST_F(ImageGridTest, SmallerSides) { | 194 TEST_F(ImageGridTest, SmallerSides) { |
| 156 const int kCorner = 2; | 195 const int kCorner = 2; |
| 157 const int kEdge = 1; | 196 const int kEdge = 1; |
| 158 | 197 |
| 159 scoped_ptr<gfx::Image> top_left_image( | 198 scoped_ptr<gfx::Image> top_left_image( |
| 160 CreateImage(gfx::Size(kCorner, kCorner))); | 199 CreateImage(gfx::Size(kCorner, kCorner))); |
| 161 scoped_ptr<gfx::Image> top_image(CreateImage(gfx::Size(kEdge, kEdge))); | 200 scoped_ptr<gfx::Image> top_image(CreateImage(gfx::Size(kEdge, kEdge))); |
| 162 scoped_ptr<gfx::Image> top_right_image( | 201 scoped_ptr<gfx::Image> top_right_image( |
| 163 CreateImage(gfx::Size(kCorner, kCorner))); | 202 CreateImage(gfx::Size(kCorner, kCorner))); |
| 164 scoped_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge))); | 203 scoped_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge))); |
| 165 scoped_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge))); | 204 scoped_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge))); |
| 166 | 205 |
| 167 ImageGrid grid; | 206 ImageGrid grid; |
| 168 grid.Init(top_left_image.get(), top_image.get(), top_right_image.get(), | 207 grid.SetImages(top_left_image.get(), top_image.get(), top_right_image.get(), |
| 169 left_image.get(), NULL, right_image.get(), | 208 left_image.get(), NULL, right_image.get(), |
| 170 NULL, NULL, NULL); | 209 NULL, NULL, NULL); |
| 171 ImageGrid::TestAPI test_api(&grid); | 210 ImageGrid::TestAPI test_api(&grid); |
| 172 | 211 |
| 173 const gfx::Size kSize(20, 30); | 212 const gfx::Size kSize(20, 30); |
| 174 grid.SetSize(kSize); | 213 grid.SetSize(kSize); |
| 175 | 214 |
| 176 // The top layer should be flush with the top edge and stretched horizontally | 215 // The top layer should be flush with the top edge and stretched horizontally |
| 177 // between the two top corners. | 216 // between the two top corners. |
| 178 EXPECT_EQ(gfx::Rect( | 217 EXPECT_EQ(gfx::Rect( |
| 179 kCorner, 0, kSize.width() - 2 * kCorner, kEdge).ToString(), | 218 kCorner, 0, kSize.width() - 2 * kCorner, kEdge).ToString(), |
| 180 test_api.GetTransformedLayerBounds( | 219 test_api.GetTransformedLayerBounds( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 211 scoped_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge))); | 250 scoped_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge))); |
| 212 scoped_ptr<gfx::Image> center_image(CreateImage(gfx::Size(kCenter, kCenter))); | 251 scoped_ptr<gfx::Image> center_image(CreateImage(gfx::Size(kCenter, kCenter))); |
| 213 scoped_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge))); | 252 scoped_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge))); |
| 214 scoped_ptr<gfx::Image> bottom_left_image( | 253 scoped_ptr<gfx::Image> bottom_left_image( |
| 215 CreateImage(gfx::Size(kCorner, kCorner))); | 254 CreateImage(gfx::Size(kCorner, kCorner))); |
| 216 scoped_ptr<gfx::Image> bottom_image(CreateImage(gfx::Size(kEdge, kEdge))); | 255 scoped_ptr<gfx::Image> bottom_image(CreateImage(gfx::Size(kEdge, kEdge))); |
| 217 scoped_ptr<gfx::Image> bottom_right_image( | 256 scoped_ptr<gfx::Image> bottom_right_image( |
| 218 CreateImage(gfx::Size(kCorner, kCorner))); | 257 CreateImage(gfx::Size(kCorner, kCorner))); |
| 219 | 258 |
| 220 ImageGrid grid; | 259 ImageGrid grid; |
| 221 grid.Init( | 260 grid.SetImages( |
| 222 top_left_image.get(), top_image.get(), top_right_image.get(), | 261 top_left_image.get(), top_image.get(), top_right_image.get(), |
| 223 left_image.get(), center_image.get(), right_image.get(), | 262 left_image.get(), center_image.get(), right_image.get(), |
| 224 bottom_left_image.get(), bottom_image.get(), bottom_right_image.get()); | 263 bottom_left_image.get(), bottom_image.get(), bottom_right_image.get()); |
| 225 ImageGrid::TestAPI test_api(&grid); | 264 ImageGrid::TestAPI test_api(&grid); |
| 226 | 265 |
| 227 // Set a size that's smaller than the combined (unscaled) corner images. | 266 // Set a size that's smaller than the combined (unscaled) corner images. |
| 228 const gfx::Size kSmallSize(kCorner + kCorner - 3, kCorner + kCorner - 5); | 267 const gfx::Size kSmallSize(kCorner + kCorner - 3, kCorner + kCorner - 5); |
| 229 grid.SetSize(kSmallSize); | 268 grid.SetSize(kSmallSize); |
| 230 | 269 |
| 231 // The scalable images around the sides and in the center should be hidden. | 270 // The scalable images around the sides and in the center should be hidden. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 302 |
| 264 // We shouldn't be clipping the corner images anymore. | 303 // We shouldn't be clipping the corner images anymore. |
| 265 EXPECT_TRUE(test_api.top_left_clip_rect().IsEmpty()); | 304 EXPECT_TRUE(test_api.top_left_clip_rect().IsEmpty()); |
| 266 EXPECT_TRUE(test_api.top_right_clip_rect().IsEmpty()); | 305 EXPECT_TRUE(test_api.top_right_clip_rect().IsEmpty()); |
| 267 EXPECT_TRUE(test_api.bottom_left_clip_rect().IsEmpty()); | 306 EXPECT_TRUE(test_api.bottom_left_clip_rect().IsEmpty()); |
| 268 EXPECT_TRUE(test_api.bottom_right_clip_rect().IsEmpty()); | 307 EXPECT_TRUE(test_api.bottom_right_clip_rect().IsEmpty()); |
| 269 } | 308 } |
| 270 | 309 |
| 271 } // namespace test | 310 } // namespace test |
| 272 } // namespace ash | 311 } // namespace ash |
| OLD | NEW |