Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: ash/wm/image_grid_unittest.cc

Issue 11359172: ui: Remove implicit flooring in skia rect conversion methods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make root window transform in tests produce an integer result Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/wm/image_grid.cc ('k') | cc/software_renderer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 ASSERT_TRUE(grid.center_layer() != NULL); 50 ASSERT_TRUE(grid.center_layer() != NULL);
51 ASSERT_TRUE(grid.right_layer() != NULL); 51 ASSERT_TRUE(grid.right_layer() != NULL);
52 ASSERT_TRUE(grid.bottom_left_layer() != NULL); 52 ASSERT_TRUE(grid.bottom_left_layer() != NULL);
53 ASSERT_TRUE(grid.bottom_layer() != NULL); 53 ASSERT_TRUE(grid.bottom_layer() != NULL);
54 ASSERT_TRUE(grid.bottom_right_layer() != NULL); 54 ASSERT_TRUE(grid.bottom_right_layer() != NULL);
55 55
56 const gfx::Size size(20, 30); 56 const gfx::Size size(20, 30);
57 grid.SetSize(size); 57 grid.SetSize(size);
58 58
59 // The top-left layer should be flush with the top-left corner and unscaled. 59 // The top-left layer should be flush with the top-left corner and unscaled.
60 EXPECT_EQ(gfx::Rect(0, 0, kBorder, kBorder).ToString(), 60 EXPECT_EQ(gfx::RectF(0, 0, kBorder, kBorder).ToString(),
61 test_api.GetTransformedLayerBounds( 61 test_api.GetTransformedLayerBounds(
62 *grid.top_left_layer()).ToString()); 62 *grid.top_left_layer()).ToString());
63 63
64 // The top layer should be flush with the top edge and stretched horizontally 64 // The top layer should be flush with the top edge and stretched horizontally
65 // between the two top corners. 65 // between the two top corners.
66 EXPECT_EQ(gfx::Rect( 66 EXPECT_EQ(gfx::RectF(
67 kBorder, 0, size.width() - 2 * kBorder, kBorder).ToString(), 67 kBorder, 0, size.width() - 2 * kBorder, kBorder).ToString(),
68 test_api.GetTransformedLayerBounds( 68 test_api.GetTransformedLayerBounds(
69 *grid.top_layer()).ToString()); 69 *grid.top_layer()).ToString());
70 70
71 // The top-right layer should be flush with the top-right corner and unscaled. 71 // The top-right layer should be flush with the top-right corner and unscaled.
72 EXPECT_EQ(gfx::Rect(size.width() - kBorder, 0, kBorder, kBorder).ToString(), 72 EXPECT_EQ(gfx::RectF(size.width() - kBorder, 0, kBorder, kBorder).ToString(),
73 test_api.GetTransformedLayerBounds( 73 test_api.GetTransformedLayerBounds(
74 *grid.top_right_layer()).ToString()); 74 *grid.top_right_layer()).ToString());
75 75
76 // The left layer should be flush with the left edge and stretched vertically 76 // The left layer should be flush with the left edge and stretched vertically
77 // between the two left corners. 77 // between the two left corners.
78 EXPECT_EQ(gfx::Rect( 78 EXPECT_EQ(gfx::RectF(
79 0, kBorder, kBorder, size.height() - 2 * kBorder).ToString(), 79 0, kBorder, kBorder, size.height() - 2 * kBorder).ToString(),
80 test_api.GetTransformedLayerBounds( 80 test_api.GetTransformedLayerBounds(
81 *grid.left_layer()).ToString()); 81 *grid.left_layer()).ToString());
82 82
83 // The center layer should fill the space in the middle of the grid. 83 // The center layer should fill the space in the middle of the grid.
84 EXPECT_EQ(gfx::Rect( 84 EXPECT_EQ(gfx::RectF(
85 kBorder, kBorder, size.width() - 2 * kBorder, 85 kBorder, kBorder, size.width() - 2 * kBorder,
86 size.height() - 2 * kBorder).ToString(), 86 size.height() - 2 * kBorder).ToString(),
87 test_api.GetTransformedLayerBounds( 87 test_api.GetTransformedLayerBounds(
88 *grid.center_layer()).ToString()); 88 *grid.center_layer()).ToString());
89 89
90 // The right layer should be flush with the right edge and stretched 90 // The right layer should be flush with the right edge and stretched
91 // vertically between the two right corners. 91 // vertically between the two right corners.
92 EXPECT_EQ(gfx::Rect( 92 EXPECT_EQ(gfx::RectF(
93 size.width() - kBorder, kBorder, 93 size.width() - kBorder, kBorder,
94 kBorder, size.height() - 2 * kBorder).ToString(), 94 kBorder, size.height() - 2 * kBorder).ToString(),
95 test_api.GetTransformedLayerBounds( 95 test_api.GetTransformedLayerBounds(
96 *grid.right_layer()).ToString()); 96 *grid.right_layer()).ToString());
97 97
98 // The bottom-left layer should be flush with the bottom-left corner and 98 // The bottom-left layer should be flush with the bottom-left corner and
99 // unscaled. 99 // unscaled.
100 EXPECT_EQ(gfx::Rect(0, size.height() - kBorder, kBorder, kBorder).ToString(), 100 EXPECT_EQ(gfx::RectF(0, size.height() - kBorder, kBorder, kBorder).ToString(),
101 test_api.GetTransformedLayerBounds( 101 test_api.GetTransformedLayerBounds(
102 *grid.bottom_left_layer()).ToString()); 102 *grid.bottom_left_layer()).ToString());
103 103
104 // The bottom layer should be flush with the bottom edge and stretched 104 // The bottom layer should be flush with the bottom edge and stretched
105 // horizontally between the two bottom corners. 105 // horizontally between the two bottom corners.
106 EXPECT_EQ(gfx::Rect( 106 EXPECT_EQ(gfx::RectF(
107 kBorder, size.height() - kBorder, 107 kBorder, size.height() - kBorder,
108 size.width() - 2 * kBorder, kBorder).ToString(), 108 size.width() - 2 * kBorder, kBorder).ToString(),
109 test_api.GetTransformedLayerBounds( 109 test_api.GetTransformedLayerBounds(
110 *grid.bottom_layer()).ToString()); 110 *grid.bottom_layer()).ToString());
111 111
112 // The bottom-right layer should be flush with the bottom-right corner and 112 // The bottom-right layer should be flush with the bottom-right corner and
113 // unscaled. 113 // unscaled.
114 EXPECT_EQ(gfx::Rect( 114 EXPECT_EQ(gfx::RectF(
115 size.width() - kBorder, size.height() - kBorder, 115 size.width() - kBorder, size.height() - kBorder,
116 kBorder, kBorder).ToString(), 116 kBorder, kBorder).ToString(),
117 test_api.GetTransformedLayerBounds( 117 test_api.GetTransformedLayerBounds(
118 *grid.bottom_right_layer()).ToString()); 118 *grid.bottom_right_layer()).ToString());
119 } 119 }
120 120
121 // Test that an ImageGrid's layers are transformed correctly when 121 // Test that an ImageGrid's layers are transformed correctly when
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.
(...skipping 10 matching lines...) Expand all
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::RectF(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)));
(...skipping 12 matching lines...) Expand all
168 EXPECT_TRUE(grid.right_layer() == NULL); 168 EXPECT_TRUE(grid.right_layer() == NULL);
169 EXPECT_TRUE(grid.bottom_left_layer() == NULL); 169 EXPECT_TRUE(grid.bottom_left_layer() == NULL);
170 EXPECT_TRUE(grid.bottom_layer() == NULL); 170 EXPECT_TRUE(grid.bottom_layer() == NULL);
171 EXPECT_TRUE(grid.bottom_right_layer() == NULL); 171 EXPECT_TRUE(grid.bottom_right_layer() == NULL);
172 172
173 const gfx::Size kSize(10, 10); 173 const gfx::Size kSize(10, 10);
174 grid.SetSize(kSize); 174 grid.SetSize(kSize);
175 175
176 // The top layer should be scaled horizontally across the entire width, but it 176 // The top layer should be scaled horizontally across the entire width, but it
177 // shouldn't be scaled vertically. 177 // shouldn't be scaled vertically.
178 EXPECT_EQ(gfx::Rect(0, 0, kSize.width(), kBorder).ToString(), 178 EXPECT_EQ(gfx::RectF(0, 0, kSize.width(), kBorder).ToString(),
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
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.
248 EXPECT_EQ(gfx::Rect( 248 EXPECT_EQ(gfx::RectF(
249 kCorner, 0, kSize.width() - 2 * kCorner, kEdge).ToString(), 249 kCorner, 0, kSize.width() - 2 * kCorner, kEdge).ToString(),
250 test_api.GetTransformedLayerBounds( 250 test_api.GetTransformedLayerBounds(
251 *grid.top_layer()).ToString()); 251 *grid.top_layer()).ToString());
252 252
253 // The left layer should be flush with the left edge and stretched vertically 253 // The left layer should be flush with the left edge and stretched vertically
254 // between the top left corner and the bottom. 254 // between the top left corner and the bottom.
255 EXPECT_EQ(gfx::Rect( 255 EXPECT_EQ(gfx::RectF(
256 0, kCorner, kEdge, kSize.height() - kCorner).ToString(), 256 0, kCorner, kEdge, kSize.height() - kCorner).ToString(),
257 test_api.GetTransformedLayerBounds( 257 test_api.GetTransformedLayerBounds(
258 *grid.left_layer()).ToString()); 258 *grid.left_layer()).ToString());
259 259
260 // The right layer should be flush with the right edge and stretched 260 // The right layer should be flush with the right edge and stretched
261 // vertically between the top right corner and the bottom. 261 // vertically between the top right corner and the bottom.
262 EXPECT_EQ(gfx::Rect( 262 EXPECT_EQ(gfx::RectF(
263 kSize.width() - kEdge, kCorner, 263 kSize.width() - kEdge, kCorner,
264 kEdge, kSize.height() - kCorner).ToString(), 264 kEdge, kSize.height() - kCorner).ToString(),
265 test_api.GetTransformedLayerBounds( 265 test_api.GetTransformedLayerBounds(
266 *grid.right_layer()).ToString()); 266 *grid.right_layer()).ToString());
267 } 267 }
268 268
269 // Test that we hide or clip layers as needed when the grid is assigned a small 269 // Test that we hide or clip layers as needed when the grid is assigned a small
270 // size. 270 // size.
271 TEST_F(ImageGridTest, TooSmall) { 271 TEST_F(ImageGridTest, TooSmall) {
272 const int kCorner = 5; 272 const int kCorner = 5;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « ash/wm/image_grid.cc ('k') | cc/software_renderer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698