| 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 "ash/test/ash_test_base.h" | 5 #include "ash/test/ash_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 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // called. | 30 // called. |
| 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(NULL); | 40 ImageGrid grid; |
| 41 grid.SetImages(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(grid.top_left_layer() != NULL); | 46 ASSERT_TRUE(grid.top_left_layer() != NULL); |
| 47 ASSERT_TRUE(grid.top_layer() != NULL); | 47 ASSERT_TRUE(grid.top_layer() != NULL); |
| 48 ASSERT_TRUE(grid.top_right_layer() != NULL); | 48 ASSERT_TRUE(grid.top_right_layer() != NULL); |
| 49 ASSERT_TRUE(grid.left_layer() != NULL); | 49 ASSERT_TRUE(grid.left_layer() != NULL); |
| 50 ASSERT_TRUE(grid.center_layer() != NULL); | 50 ASSERT_TRUE(grid.center_layer() != NULL); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // SetContentBounds() is called. | 122 // SetContentBounds() is called. |
| 123 TEST_F(ImageGridTest, SetContentBounds) { | 123 TEST_F(ImageGridTest, SetContentBounds) { |
| 124 // Size of the images around the grid's border. | 124 // Size of the images around the grid's border. |
| 125 const int kBorder = 2; | 125 const int kBorder = 2; |
| 126 | 126 |
| 127 scoped_ptr<gfx::Image> image_1x1(CreateImage(gfx::Size(1, 1))); | 127 scoped_ptr<gfx::Image> image_1x1(CreateImage(gfx::Size(1, 1))); |
| 128 scoped_ptr<gfx::Image> image_1xB(CreateImage(gfx::Size(1, kBorder))); | 128 scoped_ptr<gfx::Image> image_1xB(CreateImage(gfx::Size(1, kBorder))); |
| 129 scoped_ptr<gfx::Image> image_Bx1(CreateImage(gfx::Size(kBorder, 1))); | 129 scoped_ptr<gfx::Image> image_Bx1(CreateImage(gfx::Size(kBorder, 1))); |
| 130 scoped_ptr<gfx::Image> image_BxB(CreateImage(gfx::Size(kBorder, kBorder))); | 130 scoped_ptr<gfx::Image> image_BxB(CreateImage(gfx::Size(kBorder, kBorder))); |
| 131 | 131 |
| 132 ImageGrid grid(NULL); | 132 ImageGrid grid; |
| 133 grid.SetImages(image_BxB.get(), image_1xB.get(), image_BxB.get(), | 133 grid.SetImages(image_BxB.get(), image_1xB.get(), image_BxB.get(), |
| 134 image_Bx1.get(), image_1x1.get(), image_Bx1.get(), | 134 image_Bx1.get(), image_1x1.get(), image_Bx1.get(), |
| 135 image_BxB.get(), image_1xB.get(), image_BxB.get()); | 135 image_BxB.get(), image_1xB.get(), image_BxB.get()); |
| 136 | 136 |
| 137 ImageGrid::TestAPI test_api(&grid); | 137 ImageGrid::TestAPI test_api(&grid); |
| 138 | 138 |
| 139 const gfx::Point origin(5, 10); | 139 const gfx::Point origin(5, 10); |
| 140 const gfx::Size size(20, 30); | 140 const gfx::Size size(20, 30); |
| 141 grid.SetContentBounds(gfx::Rect(origin, size)); | 141 grid.SetContentBounds(gfx::Rect(origin, size)); |
| 142 | 142 |
| 143 // The master layer is positioned above the top-left corner of the content | 143 // The master layer is positioned above the top-left corner of the content |
| 144 // bounds and has height/width that contain the grid and bounds. | 144 // bounds and has height/width that contain the grid and bounds. |
| 145 EXPECT_EQ(gfx::Rect(origin.x() - kBorder, | 145 EXPECT_EQ(gfx::Rect(origin.x() - kBorder, |
| 146 origin.y() - kBorder, | 146 origin.y() - kBorder, |
| 147 size.width() + 2 * kBorder, | 147 size.width() + 2 * kBorder, |
| 148 size.height() + 2 * kBorder).ToString(), | 148 size.height() + 2 * kBorder).ToString(), |
| 149 test_api.GetTransformedLayerBounds(*grid.layer()).ToString()); | 149 test_api.GetTransformedLayerBounds(*grid.layer()).ToString()); |
| 150 } | 150 } |
| 151 | 151 |
| 152 // Check that we don't crash if only a single image is supplied. | 152 // Check that we don't crash if only a single image is supplied. |
| 153 TEST_F(ImageGridTest, SingleImage) { | 153 TEST_F(ImageGridTest, SingleImage) { |
| 154 const int kBorder = 1; | 154 const int kBorder = 1; |
| 155 scoped_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder))); | 155 scoped_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder))); |
| 156 | 156 |
| 157 ImageGrid grid(NULL); | 157 ImageGrid grid; |
| 158 grid.SetImages(NULL, image.get(), NULL, | 158 grid.SetImages(NULL, image.get(), NULL, |
| 159 NULL, NULL, NULL, | 159 NULL, NULL, NULL, |
| 160 NULL, NULL, NULL); | 160 NULL, NULL, NULL); |
| 161 | 161 |
| 162 ImageGrid::TestAPI test_api(&grid); | 162 ImageGrid::TestAPI test_api(&grid); |
| 163 EXPECT_TRUE(grid.top_left_layer() == NULL); | 163 EXPECT_TRUE(grid.top_left_layer() == NULL); |
| 164 ASSERT_TRUE(grid.top_layer() != NULL); | 164 ASSERT_TRUE(grid.top_layer() != NULL); |
| 165 EXPECT_TRUE(grid.top_right_layer() == NULL); | 165 EXPECT_TRUE(grid.top_right_layer() == NULL); |
| 166 EXPECT_TRUE(grid.left_layer() == NULL); | 166 EXPECT_TRUE(grid.left_layer() == NULL); |
| 167 EXPECT_TRUE(grid.center_layer() == NULL); | 167 EXPECT_TRUE(grid.center_layer() == NULL); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 179 test_api.GetTransformedLayerBounds( | 179 test_api.GetTransformedLayerBounds( |
| 180 *grid.top_layer()).ToString()); | 180 *grid.top_layer()).ToString()); |
| 181 } | 181 } |
| 182 | 182 |
| 183 // Check that we don't crash when we reset existing images to NULL and | 183 // Check that we don't crash when we reset existing images to NULL and |
| 184 // reset NULL images to new ones. | 184 // reset NULL images to new ones. |
| 185 TEST_F(ImageGridTest, ResetImages) { | 185 TEST_F(ImageGridTest, ResetImages) { |
| 186 const int kBorder = 1; | 186 const int kBorder = 1; |
| 187 scoped_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder))); | 187 scoped_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder))); |
| 188 | 188 |
| 189 ImageGrid grid(NULL); | 189 ImageGrid grid; |
| 190 grid.SetImages(NULL, image.get(), NULL, | 190 grid.SetImages(NULL, image.get(), NULL, |
| 191 NULL, NULL, NULL, | 191 NULL, NULL, NULL, |
| 192 NULL, NULL, NULL); | 192 NULL, NULL, NULL); |
| 193 | 193 |
| 194 // Only the top edge has a layer. | 194 // Only the top edge has a layer. |
| 195 ImageGrid::TestAPI test_api(&grid); | 195 ImageGrid::TestAPI test_api(&grid); |
| 196 ASSERT_TRUE(grid.top_left_layer() == NULL); | 196 ASSERT_TRUE(grid.top_left_layer() == NULL); |
| 197 ASSERT_FALSE(grid.top_layer() == NULL); | 197 ASSERT_FALSE(grid.top_layer() == NULL); |
| 198 ASSERT_TRUE(grid.top_right_layer() == NULL); | 198 ASSERT_TRUE(grid.top_right_layer() == NULL); |
| 199 ASSERT_TRUE(grid.left_layer() == NULL); | 199 ASSERT_TRUE(grid.left_layer() == NULL); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 227 const int kEdge = 1; | 227 const int kEdge = 1; |
| 228 | 228 |
| 229 scoped_ptr<gfx::Image> top_left_image( | 229 scoped_ptr<gfx::Image> top_left_image( |
| 230 CreateImage(gfx::Size(kCorner, kCorner))); | 230 CreateImage(gfx::Size(kCorner, kCorner))); |
| 231 scoped_ptr<gfx::Image> top_image(CreateImage(gfx::Size(kEdge, kEdge))); | 231 scoped_ptr<gfx::Image> top_image(CreateImage(gfx::Size(kEdge, kEdge))); |
| 232 scoped_ptr<gfx::Image> top_right_image( | 232 scoped_ptr<gfx::Image> top_right_image( |
| 233 CreateImage(gfx::Size(kCorner, kCorner))); | 233 CreateImage(gfx::Size(kCorner, kCorner))); |
| 234 scoped_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge))); | 234 scoped_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge))); |
| 235 scoped_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge))); | 235 scoped_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge))); |
| 236 | 236 |
| 237 ImageGrid grid(NULL); | 237 ImageGrid grid; |
| 238 grid.SetImages(top_left_image.get(), top_image.get(), top_right_image.get(), | 238 grid.SetImages(top_left_image.get(), top_image.get(), top_right_image.get(), |
| 239 left_image.get(), NULL, right_image.get(), | 239 left_image.get(), NULL, right_image.get(), |
| 240 NULL, NULL, NULL); | 240 NULL, NULL, NULL); |
| 241 ImageGrid::TestAPI test_api(&grid); | 241 ImageGrid::TestAPI test_api(&grid); |
| 242 | 242 |
| 243 const gfx::Size kSize(20, 30); | 243 const gfx::Size kSize(20, 30); |
| 244 grid.SetSize(kSize); | 244 grid.SetSize(kSize); |
| 245 | 245 |
| 246 // The top layer should be flush with the top edge and stretched horizontally | 246 // The top layer should be flush with the top edge and stretched horizontally |
| 247 // between the two top corners. | 247 // between the two top corners. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 CreateImage(gfx::Size(kCorner, kCorner))); | 280 CreateImage(gfx::Size(kCorner, kCorner))); |
| 281 scoped_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge))); | 281 scoped_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge))); |
| 282 scoped_ptr<gfx::Image> center_image(CreateImage(gfx::Size(kCenter, kCenter))); | 282 scoped_ptr<gfx::Image> center_image(CreateImage(gfx::Size(kCenter, kCenter))); |
| 283 scoped_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge))); | 283 scoped_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge))); |
| 284 scoped_ptr<gfx::Image> bottom_left_image( | 284 scoped_ptr<gfx::Image> bottom_left_image( |
| 285 CreateImage(gfx::Size(kCorner, kCorner))); | 285 CreateImage(gfx::Size(kCorner, kCorner))); |
| 286 scoped_ptr<gfx::Image> bottom_image(CreateImage(gfx::Size(kEdge, kEdge))); | 286 scoped_ptr<gfx::Image> bottom_image(CreateImage(gfx::Size(kEdge, kEdge))); |
| 287 scoped_ptr<gfx::Image> bottom_right_image( | 287 scoped_ptr<gfx::Image> bottom_right_image( |
| 288 CreateImage(gfx::Size(kCorner, kCorner))); | 288 CreateImage(gfx::Size(kCorner, kCorner))); |
| 289 | 289 |
| 290 ImageGrid grid(NULL); | 290 ImageGrid grid; |
| 291 grid.SetImages( | 291 grid.SetImages( |
| 292 top_left_image.get(), top_image.get(), top_right_image.get(), | 292 top_left_image.get(), top_image.get(), top_right_image.get(), |
| 293 left_image.get(), center_image.get(), right_image.get(), | 293 left_image.get(), center_image.get(), right_image.get(), |
| 294 bottom_left_image.get(), bottom_image.get(), bottom_right_image.get()); | 294 bottom_left_image.get(), bottom_image.get(), bottom_right_image.get()); |
| 295 ImageGrid::TestAPI test_api(&grid); | 295 ImageGrid::TestAPI test_api(&grid); |
| 296 | 296 |
| 297 // Set a size that's smaller than the combined (unscaled) corner images. | 297 // Set a size that's smaller than the combined (unscaled) corner images. |
| 298 const gfx::Size kSmallSize(kCorner + kCorner - 3, kCorner + kCorner - 5); | 298 const gfx::Size kSmallSize(kCorner + kCorner - 3, kCorner + kCorner - 5); |
| 299 grid.SetSize(kSmallSize); | 299 grid.SetSize(kSmallSize); |
| 300 | 300 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 333 |
| 334 // We shouldn't be clipping the corner images anymore. | 334 // We shouldn't be clipping the corner images anymore. |
| 335 EXPECT_TRUE(test_api.top_left_clip_rect().IsEmpty()); | 335 EXPECT_TRUE(test_api.top_left_clip_rect().IsEmpty()); |
| 336 EXPECT_TRUE(test_api.top_right_clip_rect().IsEmpty()); | 336 EXPECT_TRUE(test_api.top_right_clip_rect().IsEmpty()); |
| 337 EXPECT_TRUE(test_api.bottom_left_clip_rect().IsEmpty()); | 337 EXPECT_TRUE(test_api.bottom_left_clip_rect().IsEmpty()); |
| 338 EXPECT_TRUE(test_api.bottom_right_clip_rect().IsEmpty()); | 338 EXPECT_TRUE(test_api.bottom_right_clip_rect().IsEmpty()); |
| 339 } | 339 } |
| 340 | 340 |
| 341 } // namespace test | 341 } // namespace test |
| 342 } // namespace ash | 342 } // namespace ash |
| OLD | NEW |