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

Side by Side Diff: ui/aura_shell/image_grid_unittest.cc

Issue 8555025: aura: Draw drop shadows under browsers and menus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor changes Created 9 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 | « ui/aura_shell/image_grid.cc ('k') | ui/aura_shell/shadow.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "third_party/skia/include/core/SkBitmap.h"
7 #include "ui/aura_shell/image_grid.h"
8 #include "ui/aura_shell/test/aura_shell_test_base.h"
9 #include "ui/gfx/image/image.h"
10
11 using aura_shell::internal::ImageGrid;
12
13 namespace aura_shell {
14 namespace test {
15
16 namespace {
17
18 // Creates a gfx::Image with the requested dimensions.
19 gfx::Image* CreateImage(const gfx::Size& size) {
20 SkBitmap* bitmap = new SkBitmap();
21 bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height());
22 return new gfx::Image(bitmap);
23 }
24
25 } // namespace
26
27 typedef aura_shell::test::AuraShellTestBase ImageGridTest;
28
29 // Test that an ImageGrid's layers are transformed correctly when SetSize() is
30 // called.
31 TEST_F(ImageGridTest, Basic) {
32 // Size of the images around the grid's border.
33 const int kBorder = 2;
34
35 scoped_ptr<gfx::Image> image_1x1(CreateImage(gfx::Size(1, 1)));
36 scoped_ptr<gfx::Image> image_1xB(CreateImage(gfx::Size(1, kBorder)));
37 scoped_ptr<gfx::Image> image_Bx1(CreateImage(gfx::Size(kBorder, 1)));
38 scoped_ptr<gfx::Image> image_BxB(CreateImage(gfx::Size(kBorder, kBorder)));
39
40 ImageGrid grid;
41 grid.Init(image_BxB.get(), image_1xB.get(), image_BxB.get(),
42 image_Bx1.get(), image_1x1.get(), image_Bx1.get(),
43 image_BxB.get(), image_1xB.get(), image_BxB.get());
44
45 ImageGrid::TestAPI test_api(&grid);
46 ASSERT_TRUE(test_api.top_left_layer() != NULL);
47 ASSERT_TRUE(test_api.top_layer() != NULL);
48 ASSERT_TRUE(test_api.top_right_layer() != NULL);
49 ASSERT_TRUE(test_api.left_layer() != NULL);
50 ASSERT_TRUE(test_api.center_layer() != NULL);
51 ASSERT_TRUE(test_api.right_layer() != NULL);
52 ASSERT_TRUE(test_api.bottom_left_layer() != NULL);
53 ASSERT_TRUE(test_api.bottom_layer() != NULL);
54 ASSERT_TRUE(test_api.bottom_right_layer() != NULL);
55
56 const gfx::Size size(20, 30);
57 grid.SetSize(size);
58
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(),
61 test_api.GetTransformedLayerBounds(
62 *test_api.top_left_layer()).ToString());
63
64 // The top layer should be flush with the top edge and stretched horizontally
65 // between the two top corners.
66 EXPECT_EQ(gfx::Rect(
67 kBorder, 0, size.width() - 2 * kBorder, kBorder).ToString(),
68 test_api.GetTransformedLayerBounds(
69 *test_api.top_layer()).ToString());
70
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(),
73 test_api.GetTransformedLayerBounds(
74 *test_api.top_right_layer()).ToString());
75
76 // The left layer should be flush with the left edge and stretched vertically
77 // between the two left corners.
78 EXPECT_EQ(gfx::Rect(
79 0, kBorder, kBorder, size.height() - 2 * kBorder).ToString(),
80 test_api.GetTransformedLayerBounds(
81 *test_api.left_layer()).ToString());
82
83 // The center layer should fill the space in the middle of the grid.
84 EXPECT_EQ(gfx::Rect(
85 kBorder, kBorder, size.width() - 2 * kBorder,
86 size.height() - 2 * kBorder).ToString(),
87 test_api.GetTransformedLayerBounds(
88 *test_api.center_layer()).ToString());
89
90 // The right layer should be flush with the right edge and stretched
91 // vertically between the two right corners.
92 EXPECT_EQ(gfx::Rect(
93 size.width() - kBorder, kBorder,
94 kBorder, size.height() - 2 * kBorder).ToString(),
95 test_api.GetTransformedLayerBounds(
96 *test_api.right_layer()).ToString());
97
98 // The bottom-left layer should be flush with the bottom-left corner and
99 // unscaled.
100 EXPECT_EQ(gfx::Rect(0, size.height() - kBorder, kBorder, kBorder).ToString(),
101 test_api.GetTransformedLayerBounds(
102 *test_api.bottom_left_layer()).ToString());
103
104 // The bottom layer should be flush with the bottom edge and stretched
105 // horizontally between the two bottom corners.
106 EXPECT_EQ(gfx::Rect(
107 kBorder, size.height() - kBorder,
108 size.width() - 2 * kBorder, kBorder).ToString(),
109 test_api.GetTransformedLayerBounds(
110 *test_api.bottom_layer()).ToString());
111
112 // The bottom-right layer should be flush with the bottom-right corner and
113 // unscaled.
114 EXPECT_EQ(gfx::Rect(
115 size.width() - kBorder, size.height() - kBorder,
116 kBorder, kBorder).ToString(),
117 test_api.GetTransformedLayerBounds(
118 *test_api.bottom_right_layer()).ToString());
119 }
120
121 // Check that we don't crash if only a single image is supplied.
122 TEST_F(ImageGridTest, SingleImage) {
123 const int kBorder = 1;
124 scoped_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder)));
125
126 ImageGrid grid;
127 grid.Init(NULL, image.get(), NULL,
128 NULL, NULL, NULL,
129 NULL, NULL, NULL);
130
131 ImageGrid::TestAPI test_api(&grid);
132 EXPECT_TRUE(test_api.top_left_layer() == NULL);
133 ASSERT_TRUE(test_api.top_layer() != NULL);
134 EXPECT_TRUE(test_api.top_right_layer() == NULL);
135 EXPECT_TRUE(test_api.left_layer() == NULL);
136 EXPECT_TRUE(test_api.center_layer() == NULL);
137 EXPECT_TRUE(test_api.right_layer() == NULL);
138 EXPECT_TRUE(test_api.bottom_left_layer() == NULL);
139 EXPECT_TRUE(test_api.bottom_layer() == NULL);
140 EXPECT_TRUE(test_api.bottom_right_layer() == NULL);
141
142 const gfx::Size kSize(10, 10);
143 grid.SetSize(kSize);
144
145 // The top layer should be scaled horizontally across the entire width, but it
146 // shouldn't be scaled vertically.
147 EXPECT_EQ(gfx::Rect(0, 0, kSize.width(), kBorder).ToString(),
148 test_api.GetTransformedLayerBounds(
149 *test_api.top_layer()).ToString());
150 }
151
152 // 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
154 // moved inwards or scaled. This exercises the scenario used for shadows.
155 TEST_F(ImageGridTest, SmallerSides) {
156 const int kCorner = 2;
157 const int kEdge = 1;
158
159 scoped_ptr<gfx::Image> top_left_image(
160 CreateImage(gfx::Size(kCorner, kCorner)));
161 scoped_ptr<gfx::Image> top_image(CreateImage(gfx::Size(kEdge, kEdge)));
162 scoped_ptr<gfx::Image> top_right_image(
163 CreateImage(gfx::Size(kCorner, kCorner)));
164 scoped_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge)));
165 scoped_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge)));
166
167 ImageGrid grid;
168 grid.Init(top_left_image.get(), top_image.get(), top_right_image.get(),
169 left_image.get(), NULL, right_image.get(),
170 NULL, NULL, NULL);
171 ImageGrid::TestAPI test_api(&grid);
172
173 const gfx::Size kSize(20, 30);
174 grid.SetSize(kSize);
175
176 // The top layer should be flush with the top edge and stretched horizontally
177 // between the two top corners.
178 EXPECT_EQ(gfx::Rect(
179 kCorner, 0, kSize.width() - 2 * kCorner, kEdge).ToString(),
180 test_api.GetTransformedLayerBounds(
181 *test_api.top_layer()).ToString());
182
183
184 // The left layer should be flush with the left edge and stretched vertically
185 // between the top left corner and the bottom.
186 EXPECT_EQ(gfx::Rect(
187 0, kCorner, kEdge, kSize.height() - kCorner).ToString(),
188 test_api.GetTransformedLayerBounds(
189 *test_api.left_layer()).ToString());
190
191 // The right layer should be flush with the right edge and stretched
192 // vertically between the top right corner and the bottom.
193 EXPECT_EQ(gfx::Rect(
194 kSize.width() - kEdge, kCorner,
195 kEdge, kSize.height() - kCorner).ToString(),
196 test_api.GetTransformedLayerBounds(
197 *test_api.right_layer()).ToString());
198 }
199
200 } // namespace test
201 } // namespace aura_shell
OLDNEW
« no previous file with comments | « ui/aura_shell/image_grid.cc ('k') | ui/aura_shell/shadow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698