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

Side by Side Diff: cc/quads/nine_patch_generator_unittest.cc

Issue 2591863003: Use nine-patch resource for drawing Aura overlay scrollbar thumb. (Closed)
Patch Set: Addressed sadrul@'s feedback Created 3 years, 9 months 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
OLDNEW
(Empty)
1 // Copyright 2017 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 "cc/quads/nine_patch_generator.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/gfx/geometry/rect.h"
9 #include "ui/gfx/geometry/size.h"
10
11 namespace cc {
12 namespace {
13
14 TEST(NinePatchGeneratorTest, SetLayoutReturnsChanged) {
15 NinePatchGenerator quad_generator;
16
17 EXPECT_TRUE(quad_generator.SetLayout(
18 gfx::Size(10, 10), gfx::Size(10, 10), gfx::Rect(1, 1, 8, 8),
19 gfx::Rect(1, 1, 2, 2), gfx::Rect(), true, false));
20
21 EXPECT_FALSE(quad_generator.SetLayout(
22 gfx::Size(10, 10), gfx::Size(10, 10), gfx::Rect(1, 1, 8, 8),
23 gfx::Rect(1, 1, 2, 2), gfx::Rect(), true, false));
24
25 EXPECT_TRUE(quad_generator.SetLayout(
26 gfx::Size(10, 10), gfx::Size(10, 10), gfx::Rect(1, 1, 8, 8),
27 gfx::Rect(1, 1, 2, 2), gfx::Rect(), false, false));
28
29 EXPECT_FALSE(quad_generator.SetLayout(
30 gfx::Size(10, 10), gfx::Size(10, 10), gfx::Rect(1, 1, 8, 8),
31 gfx::Rect(1, 1, 2, 2), gfx::Rect(), false, false));
32
33 EXPECT_TRUE(quad_generator.SetLayout(
34 gfx::Size(12, 10), gfx::Size(10, 10), gfx::Rect(1, 1, 8, 8),
35 gfx::Rect(1, 1, 2, 2), gfx::Rect(), false, false));
36 }
37
38 TEST(NinePatchGeneratorTest, BasicGenerate) {
39 NinePatchGenerator quad_generator;
40
41 quad_generator.SetLayout(gfx::Size(10, 10), gfx::Size(10, 10),
42 gfx::Rect(1, 1, 8, 8), gfx::Rect(1, 1, 2, 2),
43 gfx::Rect(), true, false);
44
45 std::vector<NinePatchGenerator::Patch> patches =
46 quad_generator.GeneratePatches();
47
48 ASSERT_EQ(9u, patches.size());
49
50 // Center.
51 EXPECT_EQ(gfx::RectF(1, 1, 8, 8), patches[8].image_rect);
52 EXPECT_EQ(gfx::RectF(1, 1, 8, 8), patches[8].output_rect);
53 EXPECT_EQ(gfx::RectF(0.1f, 0.1f, 0.8f, 0.8f),
54 patches[8].normalized_image_rect);
55
56 // Bottom.
57 EXPECT_EQ(gfx::RectF(1, 9, 8, 1), patches[7].image_rect);
58 EXPECT_EQ(gfx::RectF(1, 9, 8, 1), patches[7].output_rect);
59 EXPECT_EQ(gfx::RectF(0.1f, 0.9f, 0.8f, 0.1f),
60 patches[7].normalized_image_rect);
61
62 // Right.
63 EXPECT_EQ(gfx::RectF(9, 1, 1, 8), patches[6].image_rect);
64 EXPECT_EQ(gfx::RectF(9, 1, 1, 8), patches[6].output_rect);
65 EXPECT_EQ(gfx::RectF(0.9f, 0.1f, 0.1f, 0.8f),
66 patches[6].normalized_image_rect);
67
68 // Left.
69 EXPECT_EQ(gfx::RectF(0, 1, 1, 8), patches[5].image_rect);
70 EXPECT_EQ(gfx::RectF(0, 1, 1, 8), patches[5].output_rect);
71 EXPECT_EQ(gfx::RectF(0.f, 0.1f, 0.1f, 0.8f),
72 patches[5].normalized_image_rect);
73
74 // Top.
75 EXPECT_EQ(gfx::RectF(1, 0, 8, 1), patches[4].image_rect);
76 EXPECT_EQ(gfx::RectF(1, 0, 8, 1), patches[4].output_rect);
77 EXPECT_EQ(gfx::RectF(0.1f, 0.f, 0.8f, 0.1f),
78 patches[4].normalized_image_rect);
79
80 // Bottom-right
81 EXPECT_EQ(gfx::RectF(9, 9, 1, 1), patches[3].image_rect);
82 EXPECT_EQ(gfx::RectF(9, 9, 1, 1), patches[3].output_rect);
83 EXPECT_EQ(gfx::RectF(0.9f, 0.9f, 0.1f, 0.1f),
84 patches[3].normalized_image_rect);
85
86 // Bottom-left
87 EXPECT_EQ(gfx::RectF(0, 9, 1, 1), patches[2].image_rect);
88 EXPECT_EQ(gfx::RectF(0, 9, 1, 1), patches[2].output_rect);
89 EXPECT_EQ(gfx::RectF(0.f, 0.9f, 0.1f, 0.1f),
90 patches[2].normalized_image_rect);
91
92 // Top-right
93 EXPECT_EQ(gfx::RectF(9, 0, 1, 1), patches[1].image_rect);
94 EXPECT_EQ(gfx::RectF(9, 0, 1, 1), patches[1].output_rect);
95 EXPECT_EQ(gfx::RectF(0.9f, 0.f, 0.1f, 0.1f),
96 patches[1].normalized_image_rect);
97
98 // Top-left
99 EXPECT_EQ(gfx::RectF(0, 0, 1, 1), patches[0].image_rect);
100 EXPECT_EQ(gfx::RectF(0, 0, 1, 1), patches[0].output_rect);
101 EXPECT_EQ(gfx::RectF(0.f, 0.f, 0.1f, 0.1f), patches[0].normalized_image_rect);
102 }
103
104 TEST(NinePatchGeneratorTest, GenerateNonSymmetricAperture) {
105 NinePatchGenerator quad_generator;
106
107 quad_generator.SetLayout(gfx::Size(10, 10), gfx::Size(10, 10),
108 gfx::Rect(3, 5, 2, 2), gfx::Rect(2, 4, 4, 8),
109 gfx::Rect(), true, false);
110
111 std::vector<NinePatchGenerator::Patch> patches =
112 quad_generator.GeneratePatches();
113
114 ASSERT_EQ(9u, patches.size());
115
116 // Center.
117 EXPECT_EQ(gfx::RectF(3, 5, 2, 2), patches[8].image_rect);
118 EXPECT_EQ(gfx::RectF(2, 4, 6, 2), patches[8].output_rect);
119 EXPECT_EQ(gfx::RectF(0.3f, 0.5f, 0.2f, 0.2f),
120 patches[8].normalized_image_rect);
121
122 // Bottom.
123 EXPECT_EQ(gfx::RectF(3, 7, 2, 3), patches[7].image_rect);
124 EXPECT_EQ(gfx::RectF(2, 6, 6, 4), patches[7].output_rect);
125 EXPECT_EQ(gfx::RectF(0.3f, 0.7f, 0.2f, 0.3f),
126 patches[7].normalized_image_rect);
127
128 // Right.
129 EXPECT_EQ(gfx::RectF(5, 5, 5, 2), patches[6].image_rect);
130 EXPECT_EQ(gfx::RectF(8, 4, 2, 2), patches[6].output_rect);
131 EXPECT_EQ(gfx::RectF(0.5f, 0.5f, 0.5f, 0.2f),
132 patches[6].normalized_image_rect);
133
134 // Left.
135 EXPECT_EQ(gfx::RectF(0, 5, 3, 2), patches[5].image_rect);
136 EXPECT_EQ(gfx::RectF(0, 4, 2, 2), patches[5].output_rect);
137 EXPECT_EQ(gfx::RectF(0.f, 0.5f, 0.3f, 0.2f),
138 patches[5].normalized_image_rect);
139
140 // Top.
141 EXPECT_EQ(gfx::RectF(3, 0, 2, 5), patches[4].image_rect);
142 EXPECT_EQ(gfx::RectF(2, 0, 6, 4), patches[4].output_rect);
143 EXPECT_EQ(gfx::RectF(0.3f, 0.f, 0.2f, 0.5f),
144 patches[4].normalized_image_rect);
145
146 // Bottom-right
147 EXPECT_EQ(gfx::RectF(5, 7, 5, 3), patches[3].image_rect);
148 EXPECT_EQ(gfx::RectF(8, 6, 2, 4), patches[3].output_rect);
149 EXPECT_EQ(gfx::RectF(0.5f, 0.7f, 0.5f, 0.3f),
150 patches[3].normalized_image_rect);
151
152 // Bottom-left
153 EXPECT_EQ(gfx::RectF(0, 7, 3, 3), patches[2].image_rect);
154 EXPECT_EQ(gfx::RectF(0, 6, 2, 4), patches[2].output_rect);
155 EXPECT_EQ(gfx::RectF(0.f, 0.7f, 0.3f, 0.3f),
156 patches[2].normalized_image_rect);
157
158 // Top-right
159 EXPECT_EQ(gfx::RectF(5, 0, 5, 5), patches[1].image_rect);
160 EXPECT_EQ(gfx::RectF(8, 0, 2, 4), patches[1].output_rect);
161 EXPECT_EQ(gfx::RectF(0.5f, 0.f, 0.5f, 0.5f),
162 patches[1].normalized_image_rect);
163
164 // Top-left
165 EXPECT_EQ(gfx::RectF(0, 0, 3, 5), patches[0].image_rect);
166 EXPECT_EQ(gfx::RectF(0, 0, 2, 4), patches[0].output_rect);
167 EXPECT_EQ(gfx::RectF(0.f, 0.f, 0.3f, 0.5f), patches[0].normalized_image_rect);
168 }
169
170 TEST(NinePatchGeneratorTest, LargerLayerGenerate) {
171 NinePatchGenerator quad_generator;
172
173 quad_generator.SetLayout(gfx::Size(10, 10), gfx::Size(20, 15),
174 gfx::Rect(1, 1, 8, 8), gfx::Rect(1, 1, 2, 2),
175 gfx::Rect(), true, false);
176
177 std::vector<NinePatchGenerator::Patch> patches =
178 quad_generator.GeneratePatches();
179
180 ASSERT_EQ(9u, patches.size());
181
182 // Center.
183 EXPECT_EQ(gfx::RectF(1, 1, 8, 8), patches[8].image_rect);
184 EXPECT_EQ(gfx::RectF(1, 1, 18, 13), patches[8].output_rect);
185 EXPECT_EQ(gfx::RectF(0.1f, 0.1f, 0.8f, 0.8f),
186 patches[8].normalized_image_rect);
187
188 // Bottom.
189 EXPECT_EQ(gfx::RectF(1, 9, 8, 1), patches[7].image_rect);
190 EXPECT_EQ(gfx::RectF(1, 14, 18, 1), patches[7].output_rect);
191 EXPECT_EQ(gfx::RectF(0.1f, 0.9f, 0.8f, 0.1f),
192 patches[7].normalized_image_rect);
193
194 // Right.
195 EXPECT_EQ(gfx::RectF(9, 1, 1, 8), patches[6].image_rect);
196 EXPECT_EQ(gfx::RectF(19, 1, 1, 13), patches[6].output_rect);
197 EXPECT_EQ(gfx::RectF(0.9f, 0.1f, 0.1f, 0.8f),
198 patches[6].normalized_image_rect);
199
200 // Left.
201 EXPECT_EQ(gfx::RectF(0, 1, 1, 8), patches[5].image_rect);
202 EXPECT_EQ(gfx::RectF(0, 1, 1, 13), patches[5].output_rect);
203 EXPECT_EQ(gfx::RectF(0.f, 0.1f, 0.1f, 0.8f),
204 patches[5].normalized_image_rect);
205
206 // Top.
207 EXPECT_EQ(gfx::RectF(1, 0, 8, 1), patches[4].image_rect);
208 EXPECT_EQ(gfx::RectF(1, 0, 18, 1), patches[4].output_rect);
209 EXPECT_EQ(gfx::RectF(0.1f, 0.f, 0.8f, 0.1f),
210 patches[4].normalized_image_rect);
211
212 // Bottom-right
213 EXPECT_EQ(gfx::RectF(9, 9, 1, 1), patches[3].image_rect);
214 EXPECT_EQ(gfx::RectF(19, 14, 1, 1), patches[3].output_rect);
215 EXPECT_EQ(gfx::RectF(0.9f, 0.9f, 0.1f, 0.1f),
216 patches[3].normalized_image_rect);
217
218 // Bottom-left
219 EXPECT_EQ(gfx::RectF(0, 9, 1, 1), patches[2].image_rect);
220 EXPECT_EQ(gfx::RectF(0, 14, 1, 1), patches[2].output_rect);
221 EXPECT_EQ(gfx::RectF(0.f, 0.9f, 0.1f, 0.1f),
222 patches[2].normalized_image_rect);
223
224 // Top-right
225 EXPECT_EQ(gfx::RectF(9, 0, 1, 1), patches[1].image_rect);
226 EXPECT_EQ(gfx::RectF(19, 0, 1, 1), patches[1].output_rect);
227 EXPECT_EQ(gfx::RectF(0.9f, 0.f, 0.1f, 0.1f),
228 patches[1].normalized_image_rect);
229
230 // Top-left
231 EXPECT_EQ(gfx::RectF(0, 0, 1, 1), patches[0].image_rect);
232 EXPECT_EQ(gfx::RectF(0, 0, 1, 1), patches[0].output_rect);
233 EXPECT_EQ(gfx::RectF(0.f, 0.f, 0.1f, 0.1f), patches[0].normalized_image_rect);
234 }
235
236 } // namespace
237 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698