Add ICU message format support
[chromium-blink-merge.git] / cc / trees / occlusion_unittest.cc
blobbecc7a3889c95ea31cab060b7431bea751814a3f
1 // Copyright 2014 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.
5 #include "cc/trees/occlusion.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace cc {
10 namespace {
12 TEST(OcclusionTest, HasOcclusion) {
13 Occlusion empty;
14 EXPECT_FALSE(empty.HasOcclusion());
16 empty = Occlusion(
17 gfx::Transform(), SimpleEnclosedRegion(), SimpleEnclosedRegion());
18 EXPECT_FALSE(empty.HasOcclusion());
20 Occlusion outside_nonempty(
21 gfx::Transform(), SimpleEnclosedRegion(10, 10), SimpleEnclosedRegion());
22 EXPECT_TRUE(outside_nonempty.HasOcclusion());
24 Occlusion inside_nonempty(
25 gfx::Transform(), SimpleEnclosedRegion(), SimpleEnclosedRegion(10, 10));
26 EXPECT_TRUE(inside_nonempty.HasOcclusion());
28 Occlusion both_nonempty(gfx::Transform(),
29 SimpleEnclosedRegion(10, 10),
30 SimpleEnclosedRegion(10, 10));
31 EXPECT_TRUE(both_nonempty.HasOcclusion());
34 #define EXPECT_OCCLUSION(occlusion, rects, ...) \
35 { \
36 bool expected[] = {__VA_ARGS__}; \
37 ASSERT_EQ(arraysize(rects), arraysize(expected)); \
38 for (size_t i = 0; i < arraysize(rects); ++i) \
39 EXPECT_EQ(expected[i], occlusion.IsOccluded(rects[i])) \
40 << "Test failed for index " << i << "."; \
43 TEST(OcclusionTest, IsOccludedNoTransform) {
44 gfx::Rect rects[] = {gfx::Rect(10, 10),
45 gfx::Rect(10, 0, 10, 10),
46 gfx::Rect(0, 10, 10, 10),
47 gfx::Rect(10, 10, 10, 10)};
49 Occlusion no_occlusion;
50 EXPECT_OCCLUSION(no_occlusion, rects, false, false, false, false);
52 Occlusion all_occluded_outside(
53 gfx::Transform(), SimpleEnclosedRegion(20, 20), SimpleEnclosedRegion());
54 EXPECT_OCCLUSION(all_occluded_outside, rects, true, true, true, true);
56 Occlusion all_occluded_inside(
57 gfx::Transform(), SimpleEnclosedRegion(), SimpleEnclosedRegion(20, 20));
58 EXPECT_OCCLUSION(all_occluded_inside, rects, true, true, true, true);
60 Occlusion all_occluded_mixed(gfx::Transform(),
61 SimpleEnclosedRegion(10, 20),
62 SimpleEnclosedRegion(10, 0, 10, 20));
63 EXPECT_OCCLUSION(all_occluded_mixed, rects, true, true, true, true);
65 Occlusion some_occluded(gfx::Transform(),
66 SimpleEnclosedRegion(10, 10),
67 SimpleEnclosedRegion(10, 10, 10, 10));
68 EXPECT_OCCLUSION(some_occluded, rects, true, false, false, true);
71 TEST(OcclusionTest, IsOccludedScaled) {
72 gfx::Rect rects[] = {gfx::Rect(10, 10),
73 gfx::Rect(10, 0, 10, 10),
74 gfx::Rect(0, 10, 10, 10),
75 gfx::Rect(10, 10, 10, 10)};
77 gfx::Transform half_scale;
78 half_scale.Scale(0.5, 0.5);
80 gfx::Transform double_scale;
81 double_scale.Scale(2, 2);
83 Occlusion all_occluded_outside_half(
84 half_scale, SimpleEnclosedRegion(10, 10), SimpleEnclosedRegion());
85 Occlusion all_occluded_outside_double(
86 double_scale, SimpleEnclosedRegion(40, 40), SimpleEnclosedRegion());
87 EXPECT_OCCLUSION(all_occluded_outside_half, rects, true, true, true, true);
88 EXPECT_OCCLUSION(all_occluded_outside_double, rects, true, true, true, true);
90 Occlusion all_occluded_inside_half(
91 half_scale, SimpleEnclosedRegion(), SimpleEnclosedRegion(10, 10));
92 Occlusion all_occluded_inside_double(
93 double_scale, SimpleEnclosedRegion(), SimpleEnclosedRegion(40, 40));
94 EXPECT_OCCLUSION(all_occluded_inside_half, rects, true, true, true, true);
95 EXPECT_OCCLUSION(all_occluded_inside_double, rects, true, true, true, true);
97 Occlusion all_occluded_mixed_half(half_scale,
98 SimpleEnclosedRegion(5, 10),
99 SimpleEnclosedRegion(5, 0, 5, 10));
100 Occlusion all_occluded_mixed_double(double_scale,
101 SimpleEnclosedRegion(20, 40),
102 SimpleEnclosedRegion(20, 0, 20, 40));
103 EXPECT_OCCLUSION(all_occluded_mixed_half, rects, true, true, true, true);
104 EXPECT_OCCLUSION(all_occluded_mixed_double, rects, true, true, true, true);
106 Occlusion some_occluded_half(
107 half_scale, SimpleEnclosedRegion(5, 5), SimpleEnclosedRegion(5, 5, 5, 5));
108 Occlusion some_occluded_double(double_scale,
109 SimpleEnclosedRegion(20, 20),
110 SimpleEnclosedRegion(20, 20, 20, 20));
111 EXPECT_OCCLUSION(some_occluded_half, rects, true, false, false, true);
112 EXPECT_OCCLUSION(some_occluded_double, rects, true, false, false, true);
115 TEST(OcclusionTest, IsOccludedTranslated) {
116 gfx::Rect rects[] = {gfx::Rect(10, 10),
117 gfx::Rect(10, 0, 10, 10),
118 gfx::Rect(0, 10, 10, 10),
119 gfx::Rect(10, 10, 10, 10)};
121 gfx::Transform move_left;
122 move_left.Translate(-100, 0);
124 gfx::Transform move_down;
125 move_down.Translate(0, 100);
127 Occlusion all_occluded_outside_left(
128 move_left, SimpleEnclosedRegion(-100, 0, 20, 20), SimpleEnclosedRegion());
129 Occlusion all_occluded_outside_down(
130 move_down, SimpleEnclosedRegion(0, 100, 20, 20), SimpleEnclosedRegion());
131 EXPECT_OCCLUSION(all_occluded_outside_left, rects, true, true, true, true);
132 EXPECT_OCCLUSION(all_occluded_outside_down, rects, true, true, true, true);
134 Occlusion all_occluded_inside_left(
135 move_left, SimpleEnclosedRegion(), SimpleEnclosedRegion(-100, 0, 20, 20));
136 Occlusion all_occluded_inside_down(
137 move_down, SimpleEnclosedRegion(), SimpleEnclosedRegion(0, 100, 20, 20));
138 EXPECT_OCCLUSION(all_occluded_inside_left, rects, true, true, true, true);
139 EXPECT_OCCLUSION(all_occluded_inside_down, rects, true, true, true, true);
141 Occlusion all_occluded_mixed_left(move_left,
142 SimpleEnclosedRegion(-100, 0, 10, 20),
143 SimpleEnclosedRegion(-90, 0, 10, 20));
144 Occlusion all_occluded_mixed_down(move_down,
145 SimpleEnclosedRegion(0, 100, 10, 20),
146 SimpleEnclosedRegion(10, 100, 10, 20));
147 EXPECT_OCCLUSION(all_occluded_mixed_left, rects, true, true, true, true);
148 EXPECT_OCCLUSION(all_occluded_mixed_down, rects, true, true, true, true);
150 Occlusion some_occluded_left(move_left,
151 SimpleEnclosedRegion(-100, 0, 10, 10),
152 SimpleEnclosedRegion(-90, 10, 10, 10));
153 Occlusion some_occluded_down(move_down,
154 SimpleEnclosedRegion(0, 100, 10, 10),
155 SimpleEnclosedRegion(10, 110, 10, 10));
156 EXPECT_OCCLUSION(some_occluded_left, rects, true, false, false, true);
157 EXPECT_OCCLUSION(some_occluded_down, rects, true, false, false, true);
160 TEST(OcclusionTest, IsOccludedScaledAfterConstruction) {
161 gfx::Rect rects[] = {gfx::Rect(10, 10),
162 gfx::Rect(10, 0, 10, 10),
163 gfx::Rect(0, 10, 10, 10),
164 gfx::Rect(10, 10, 10, 10)};
166 gfx::Transform half_transform;
167 half_transform.Scale(0.5, 0.5);
169 gfx::Transform double_transform;
170 double_transform.Scale(2, 2);
172 Occlusion all_occluded_outside(
173 gfx::Transform(), SimpleEnclosedRegion(10, 10), SimpleEnclosedRegion());
174 Occlusion all_occluded_outside_half =
175 all_occluded_outside.GetOcclusionWithGivenDrawTransform(half_transform);
177 all_occluded_outside = Occlusion(
178 gfx::Transform(), SimpleEnclosedRegion(40, 40), SimpleEnclosedRegion());
179 Occlusion all_occluded_outside_double =
180 all_occluded_outside.GetOcclusionWithGivenDrawTransform(double_transform);
182 EXPECT_OCCLUSION(all_occluded_outside_half, rects, true, true, true, true);
183 EXPECT_OCCLUSION(all_occluded_outside_double, rects, true, true, true, true);
185 Occlusion some_occluded(gfx::Transform(),
186 SimpleEnclosedRegion(5, 5),
187 SimpleEnclosedRegion(5, 5, 5, 5));
188 Occlusion some_occluded_half =
189 some_occluded.GetOcclusionWithGivenDrawTransform(half_transform);
191 some_occluded = Occlusion(gfx::Transform(),
192 SimpleEnclosedRegion(20, 20),
193 SimpleEnclosedRegion(20, 20, 20, 20));
194 Occlusion some_occluded_double =
195 some_occluded.GetOcclusionWithGivenDrawTransform(double_transform);
197 EXPECT_OCCLUSION(some_occluded_half, rects, true, false, false, true);
198 EXPECT_OCCLUSION(some_occluded_double, rects, true, false, false, true);
201 TEST(OcclusionTest, GetUnoccludedContentRectNoTransform) {
202 Occlusion some_occluded(gfx::Transform(),
203 SimpleEnclosedRegion(10, 10),
204 SimpleEnclosedRegion(10, 10, 10, 10));
206 gfx::Rect full_query_result =
207 some_occluded.GetUnoccludedContentRect(gfx::Rect(20, 20));
208 EXPECT_EQ(gfx::Rect(20, 20), full_query_result);
210 gfx::Rect half_query_result =
211 some_occluded.GetUnoccludedContentRect(gfx::Rect(10, 0, 10, 20));
212 EXPECT_EQ(gfx::Rect(10, 0, 10, 10), half_query_result);
215 TEST(OcclusionTest, GetUnoccludedContentRectScaled) {
216 gfx::Transform half_scale;
217 half_scale.Scale(0.5, 0.5);
219 gfx::Transform double_scale;
220 double_scale.Scale(2, 2);
222 Occlusion some_occluded_half(
223 half_scale, SimpleEnclosedRegion(5, 5), SimpleEnclosedRegion(5, 5, 5, 5));
224 Occlusion some_occluded_double(double_scale,
225 SimpleEnclosedRegion(20, 20),
226 SimpleEnclosedRegion(20, 20, 20, 20));
227 gfx::Rect full_query_result_half =
228 some_occluded_half.GetUnoccludedContentRect(gfx::Rect(20, 20));
229 gfx::Rect full_query_result_double =
230 some_occluded_double.GetUnoccludedContentRect(gfx::Rect(20, 20));
231 EXPECT_EQ(gfx::Rect(20, 20), full_query_result_half);
232 EXPECT_EQ(gfx::Rect(20, 20), full_query_result_double);
234 gfx::Rect half_query_result_half =
235 some_occluded_half.GetUnoccludedContentRect(gfx::Rect(10, 0, 10, 20));
236 gfx::Rect half_query_result_double =
237 some_occluded_half.GetUnoccludedContentRect(gfx::Rect(10, 0, 10, 20));
238 EXPECT_EQ(gfx::Rect(10, 0, 10, 10), half_query_result_half);
239 EXPECT_EQ(gfx::Rect(10, 0, 10, 10), half_query_result_double);
242 TEST(OcclusionTest, GetUnoccludedContentRectTranslated) {
243 gfx::Transform move_left;
244 move_left.Translate(-100, 0);
246 gfx::Transform move_down;
247 move_down.Translate(0, 100);
249 Occlusion some_occluded_left(move_left,
250 SimpleEnclosedRegion(-100, 0, 10, 10),
251 SimpleEnclosedRegion(-90, 10, 10, 10));
252 Occlusion some_occluded_down(move_down,
253 SimpleEnclosedRegion(0, 100, 0, 10),
254 SimpleEnclosedRegion(10, 110, 10, 10));
256 gfx::Rect full_query_result_left =
257 some_occluded_left.GetUnoccludedContentRect(gfx::Rect(20, 20));
258 gfx::Rect full_query_result_down =
259 some_occluded_down.GetUnoccludedContentRect(gfx::Rect(20, 20));
260 EXPECT_EQ(gfx::Rect(20, 20), full_query_result_left);
261 EXPECT_EQ(gfx::Rect(20, 20), full_query_result_down);
263 gfx::Rect half_query_result_left =
264 some_occluded_left.GetUnoccludedContentRect(gfx::Rect(10, 0, 10, 20));
265 gfx::Rect half_query_result_down =
266 some_occluded_down.GetUnoccludedContentRect(gfx::Rect(10, 0, 10, 20));
267 EXPECT_EQ(gfx::Rect(10, 0, 10, 10), half_query_result_left);
268 EXPECT_EQ(gfx::Rect(10, 0, 10, 10), half_query_result_down);
271 } // namespace
272 } // namespace cc