cc: Make VideoResourceUpdater use CopyToResource instead of SetPixels.
[chromium-blink-merge.git] / cc / layers / layer_impl_unittest.cc
blob0dbf356cdd09dc01e37c28ad8b72b7bb6efdde10
1 // Copyright 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.
5 #include "cc/layers/layer_impl.h"
7 #include "cc/layers/painted_scrollbar_layer_impl.h"
8 #include "cc/layers/solid_color_scrollbar_layer_impl.h"
9 #include "cc/output/filter_operation.h"
10 #include "cc/output/filter_operations.h"
11 #include "cc/test/fake_impl_proxy.h"
12 #include "cc/test/fake_layer_tree_host_impl.h"
13 #include "cc/test/fake_output_surface.h"
14 #include "cc/test/geometry_test_utils.h"
15 #include "cc/test/test_shared_bitmap_manager.h"
16 #include "cc/trees/layer_tree_impl.h"
17 #include "cc/trees/single_thread_proxy.h"
18 #include "cc/trees/tree_synchronizer.h"
19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
23 namespace cc {
24 namespace {
26 #define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(code_to_test) \
27 root->ResetAllChangeTrackingForSubtree(); \
28 code_to_test; \
29 EXPECT_TRUE(root->needs_push_properties()); \
30 EXPECT_FALSE(child->needs_push_properties()); \
31 EXPECT_FALSE(grand_child->needs_push_properties()); \
32 EXPECT_TRUE(root->LayerPropertyChanged()); \
33 EXPECT_TRUE(child->LayerPropertyChanged()); \
34 EXPECT_TRUE(grand_child->LayerPropertyChanged());
36 #define EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(code_to_test) \
37 root->ResetAllChangeTrackingForSubtree(); \
38 code_to_test; \
39 EXPECT_FALSE(root->needs_push_properties()); \
40 EXPECT_FALSE(child->needs_push_properties()); \
41 EXPECT_FALSE(grand_child->needs_push_properties()); \
42 EXPECT_FALSE(root->LayerPropertyChanged()); \
43 EXPECT_FALSE(child->LayerPropertyChanged()); \
44 EXPECT_FALSE(grand_child->LayerPropertyChanged());
46 #define EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE( \
47 code_to_test) \
48 root->ResetAllChangeTrackingForSubtree(); \
49 code_to_test; \
50 EXPECT_TRUE(root->needs_push_properties()); \
51 EXPECT_FALSE(child->needs_push_properties()); \
52 EXPECT_FALSE(grand_child->needs_push_properties()); \
53 EXPECT_FALSE(root->LayerPropertyChanged()); \
54 EXPECT_FALSE(child->LayerPropertyChanged()); \
55 EXPECT_FALSE(grand_child->LayerPropertyChanged());
57 #define EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(code_to_test) \
58 root->ResetAllChangeTrackingForSubtree(); \
59 code_to_test; \
60 EXPECT_TRUE(root->needs_push_properties()); \
61 EXPECT_FALSE(child->needs_push_properties()); \
62 EXPECT_FALSE(grand_child->needs_push_properties()); \
63 EXPECT_TRUE(root->LayerPropertyChanged()); \
64 EXPECT_FALSE(child->LayerPropertyChanged()); \
65 EXPECT_FALSE(grand_child->LayerPropertyChanged());
67 #define VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(code_to_test) \
68 root->ResetAllChangeTrackingForSubtree(); \
69 host_impl.ForcePrepareToDraw(); \
70 EXPECT_FALSE(host_impl.active_tree()->needs_update_draw_properties()); \
71 code_to_test; \
72 EXPECT_TRUE(host_impl.active_tree()->needs_update_draw_properties());
74 #define VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(code_to_test) \
75 root->ResetAllChangeTrackingForSubtree(); \
76 host_impl.ForcePrepareToDraw(); \
77 EXPECT_FALSE(host_impl.active_tree()->needs_update_draw_properties()); \
78 code_to_test; \
79 EXPECT_FALSE(host_impl.active_tree()->needs_update_draw_properties());
81 TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) {
83 // This test checks that layerPropertyChanged() has the correct behavior.
86 // The constructor on this will fake that we are on the correct thread.
87 // Create a simple LayerImpl tree:
88 FakeImplProxy proxy;
89 TestSharedBitmapManager shared_bitmap_manager;
90 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
91 EXPECT_TRUE(host_impl.InitializeRenderer(FakeOutputSurface::Create3d()));
92 scoped_ptr<LayerImpl> root_clip =
93 LayerImpl::Create(host_impl.active_tree(), 1);
94 scoped_ptr<LayerImpl> root_ptr =
95 LayerImpl::Create(host_impl.active_tree(), 2);
96 LayerImpl* root = root_ptr.get();
97 root_clip->AddChild(root_ptr.Pass());
98 scoped_ptr<LayerImpl> scroll_parent =
99 LayerImpl::Create(host_impl.active_tree(), 3);
100 LayerImpl* scroll_child = LayerImpl::Create(host_impl.active_tree(), 4).get();
101 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>();
102 scroll_children->insert(scroll_child);
103 scroll_children->insert(root);
104 root->SetHasRenderSurface(true);
106 scoped_ptr<LayerImpl> clip_parent =
107 LayerImpl::Create(host_impl.active_tree(), 5);
108 LayerImpl* clip_child = LayerImpl::Create(host_impl.active_tree(), 6).get();
109 std::set<LayerImpl*>* clip_children = new std::set<LayerImpl*>();
110 clip_children->insert(clip_child);
111 clip_children->insert(root);
113 root->AddChild(LayerImpl::Create(host_impl.active_tree(), 7));
114 LayerImpl* child = root->children()[0];
115 child->AddChild(LayerImpl::Create(host_impl.active_tree(), 8));
116 LayerImpl* grand_child = child->children()[0];
118 root->SetScrollClipLayer(root_clip->id());
120 // Adding children is an internal operation and should not mark layers as
121 // changed.
122 EXPECT_FALSE(root->LayerPropertyChanged());
123 EXPECT_FALSE(child->LayerPropertyChanged());
124 EXPECT_FALSE(grand_child->LayerPropertyChanged());
126 gfx::PointF arbitrary_point_f = gfx::PointF(0.125f, 0.25f);
127 gfx::Point3F arbitrary_point_3f = gfx::Point3F(0.125f, 0.25f, 0.f);
128 float arbitrary_number = 0.352f;
129 gfx::Size arbitrary_size = gfx::Size(111, 222);
130 gfx::Point arbitrary_point = gfx::Point(333, 444);
131 gfx::Vector2d arbitrary_vector2d = gfx::Vector2d(111, 222);
132 gfx::Rect arbitrary_rect = gfx::Rect(arbitrary_point, arbitrary_size);
133 gfx::RectF arbitrary_rect_f =
134 gfx::RectF(arbitrary_point_f, gfx::SizeF(1.234f, 5.678f));
135 SkColor arbitrary_color = SkColorSetRGB(10, 20, 30);
136 gfx::Transform arbitrary_transform;
137 arbitrary_transform.Scale3d(0.1f, 0.2f, 0.3f);
138 FilterOperations arbitrary_filters;
139 arbitrary_filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
140 SkXfermode::Mode arbitrary_blend_mode = SkXfermode::kMultiply_Mode;
142 // These properties are internal, and should not be considered "change" when
143 // they are used.
144 EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE(
145 root->SetUpdateRect(arbitrary_rect));
146 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->SetBounds(arbitrary_size));
148 // Changing these properties affects the entire subtree of layers.
149 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(
150 root->SetTransformOrigin(arbitrary_point_3f));
151 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetFilters(arbitrary_filters));
152 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetFilters(FilterOperations()));
153 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(
154 root->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 9)));
155 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetMasksToBounds(true));
156 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetContentsOpaque(true));
157 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(
158 root->SetReplicaLayer(LayerImpl::Create(host_impl.active_tree(), 10)));
159 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetPosition(arbitrary_point_f));
160 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetShouldFlattenTransform(false));
161 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->Set3dSortingContextId(1));
162 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(
163 root->SetDoubleSided(false)); // constructor initializes it to "true".
164 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->ScrollBy(arbitrary_vector2d));
165 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetScrollDelta(gfx::Vector2d()));
166 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->PushScrollOffsetFromMainThread(
167 gfx::ScrollOffset(arbitrary_vector2d)));
168 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetHideLayerAndSubtree(true));
169 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetOpacity(arbitrary_number));
170 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetBlendMode(arbitrary_blend_mode));
171 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetTransform(arbitrary_transform));
173 // Changing these properties only affects the layer itself.
174 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->SetContentBounds(arbitrary_size));
175 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(
176 root->SetContentsScale(arbitrary_number, arbitrary_number));
177 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->SetDrawsContent(true));
178 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(
179 root->SetBackgroundColor(arbitrary_color));
180 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(
181 root->SetBackgroundFilters(arbitrary_filters));
183 // Special case: check that SetBounds changes behavior depending on
184 // masksToBounds.
185 root->SetMasksToBounds(false);
186 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->SetBounds(gfx::Size(135, 246)));
187 root->SetMasksToBounds(true);
188 // Should be a different size than previous call, to ensure it marks tree
189 // changed.
190 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetBounds(arbitrary_size));
192 // Changing this property does not cause the layer to be marked as changed
193 // but does cause the layer to need to push properties.
194 EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE(
195 root->SetIsRootForIsolatedGroup(true));
197 // Changing these properties should cause the layer to need to push properties
198 EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE(
199 root->SetScrollParent(scroll_parent.get()));
200 EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE(
201 root->SetScrollChildren(scroll_children));
202 EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE(
203 root->SetClipParent(clip_parent.get()));
204 EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE(
205 root->SetClipChildren(clip_children));
206 EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE(
207 root->SetNumDescendantsThatDrawContent(10));
209 // After setting all these properties already, setting to the exact same
210 // values again should not cause any change.
211 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
212 root->SetTransformOrigin(arbitrary_point_3f));
213 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetMasksToBounds(true));
214 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
215 root->SetPosition(arbitrary_point_f));
216 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
217 root->SetShouldFlattenTransform(false));
218 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->Set3dSortingContextId(1));
219 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
220 root->SetTransform(arbitrary_transform));
221 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
222 root->SetDoubleSided(false)); // constructor initializes it to "true".
223 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
224 root->SetScrollDelta(gfx::Vector2d()));
225 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
226 root->PushScrollOffsetFromMainThread(
227 gfx::ScrollOffset(arbitrary_vector2d)));
228 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
229 root->SetContentBounds(arbitrary_size));
230 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
231 root->SetContentsScale(arbitrary_number, arbitrary_number));
232 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetContentsOpaque(true));
233 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetOpacity(arbitrary_number));
234 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
235 root->SetBlendMode(arbitrary_blend_mode));
236 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
237 root->SetIsRootForIsolatedGroup(true));
238 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetDrawsContent(true));
239 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetBounds(arbitrary_size));
240 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
241 root->SetScrollParent(scroll_parent.get()));
242 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
243 root->SetScrollChildren(scroll_children));
244 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
245 root->SetClipParent(clip_parent.get()));
246 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
247 root->SetClipChildren(clip_children));
250 TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) {
251 FakeImplProxy proxy;
252 TestSharedBitmapManager shared_bitmap_manager;
253 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
254 EXPECT_TRUE(host_impl.InitializeRenderer(FakeOutputSurface::Create3d()));
255 host_impl.active_tree()->SetRootLayer(
256 LayerImpl::Create(host_impl.active_tree(), 1));
257 LayerImpl* root = host_impl.active_tree()->root_layer();
258 root->SetHasRenderSurface(true);
259 scoped_ptr<LayerImpl> layer_ptr =
260 LayerImpl::Create(host_impl.active_tree(), 2);
261 LayerImpl* layer = layer_ptr.get();
262 root->AddChild(layer_ptr.Pass());
263 layer->SetScrollClipLayer(root->id());
264 DCHECK(host_impl.CanDraw());
266 gfx::PointF arbitrary_point_f = gfx::PointF(0.125f, 0.25f);
267 float arbitrary_number = 0.352f;
268 gfx::Size arbitrary_size = gfx::Size(111, 222);
269 gfx::Point arbitrary_point = gfx::Point(333, 444);
270 gfx::Vector2d arbitrary_vector2d = gfx::Vector2d(111, 222);
271 gfx::Size large_size = gfx::Size(1000, 1000);
272 gfx::Rect arbitrary_rect = gfx::Rect(arbitrary_point, arbitrary_size);
273 gfx::RectF arbitrary_rect_f =
274 gfx::RectF(arbitrary_point_f, gfx::SizeF(1.234f, 5.678f));
275 SkColor arbitrary_color = SkColorSetRGB(10, 20, 30);
276 gfx::Transform arbitrary_transform;
277 arbitrary_transform.Scale3d(0.1f, 0.2f, 0.3f);
278 FilterOperations arbitrary_filters;
279 arbitrary_filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
280 SkXfermode::Mode arbitrary_blend_mode = SkXfermode::kMultiply_Mode;
282 // Render surface functions.
283 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetHasRenderSurface(true));
284 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetHasRenderSurface(true));
285 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetHasRenderSurface(false));
286 // Create a render surface, because we must have a render surface if we have
287 // filters.
288 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetHasRenderSurface(true));
290 // Related filter functions.
291 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetFilters(arbitrary_filters));
292 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetFilters(arbitrary_filters));
293 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetFilters(FilterOperations()));
294 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetFilters(arbitrary_filters));
296 // Related scrolling functions.
297 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(large_size));
298 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(large_size));
299 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->ScrollBy(arbitrary_vector2d));
300 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->ScrollBy(gfx::Vector2d()));
301 layer->SetScrollDelta(gfx::Vector2d(0, 0));
302 host_impl.ForcePrepareToDraw();
303 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
304 layer->SetScrollDelta(arbitrary_vector2d));
305 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(
306 layer->SetScrollDelta(arbitrary_vector2d));
307 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->PushScrollOffsetFromMainThread(
308 gfx::ScrollOffset(arbitrary_vector2d)));
309 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->PushScrollOffsetFromMainThread(
310 gfx::ScrollOffset(arbitrary_vector2d)));
312 // Unrelated functions, always set to new values, always set needs update.
313 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
314 layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 4)));
315 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetMasksToBounds(true));
316 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetContentsOpaque(true));
317 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
318 layer->SetReplicaLayer(LayerImpl::Create(host_impl.active_tree(), 5)));
319 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetPosition(arbitrary_point_f));
320 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetShouldFlattenTransform(false));
321 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->Set3dSortingContextId(1));
323 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
324 layer->SetDoubleSided(false)); // constructor initializes it to "true".
325 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetContentBounds(arbitrary_size));
326 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
327 layer->SetContentsScale(arbitrary_number, arbitrary_number));
328 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetDrawsContent(true));
329 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
330 layer->SetBackgroundColor(arbitrary_color));
331 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
332 layer->SetBackgroundFilters(arbitrary_filters));
333 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetOpacity(arbitrary_number));
334 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
335 layer->SetBlendMode(arbitrary_blend_mode));
336 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetTransform(arbitrary_transform));
337 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(arbitrary_size));
339 // Unrelated functions, set to the same values, no needs update.
340 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(
341 layer->SetIsRootForIsolatedGroup(true));
342 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetFilters(arbitrary_filters));
343 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetMasksToBounds(true));
344 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetContentsOpaque(true));
345 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetPosition(arbitrary_point_f));
346 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->Set3dSortingContextId(1));
347 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(
348 layer->SetDoubleSided(false)); // constructor initializes it to "true".
349 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(
350 layer->SetContentBounds(arbitrary_size));
351 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(
352 layer->SetContentsScale(arbitrary_number, arbitrary_number));
353 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetDrawsContent(true));
354 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(
355 layer->SetBackgroundColor(arbitrary_color));
356 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(
357 layer->SetBackgroundFilters(arbitrary_filters));
358 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetOpacity(arbitrary_number));
359 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(
360 layer->SetBlendMode(arbitrary_blend_mode));
361 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(
362 layer->SetIsRootForIsolatedGroup(true));
363 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(
364 layer->SetTransform(arbitrary_transform));
365 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(arbitrary_size));
368 TEST(LayerImplTest, SafeOpaqueBackgroundColor) {
369 FakeImplProxy proxy;
370 TestSharedBitmapManager shared_bitmap_manager;
371 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
372 EXPECT_TRUE(host_impl.InitializeRenderer(FakeOutputSurface::Create3d()));
373 scoped_ptr<LayerImpl> layer = LayerImpl::Create(host_impl.active_tree(), 1);
375 for (int contents_opaque = 0; contents_opaque < 2; ++contents_opaque) {
376 for (int layer_opaque = 0; layer_opaque < 2; ++layer_opaque) {
377 for (int host_opaque = 0; host_opaque < 2; ++host_opaque) {
378 layer->SetContentsOpaque(!!contents_opaque);
379 layer->SetBackgroundColor(layer_opaque ? SK_ColorRED
380 : SK_ColorTRANSPARENT);
381 host_impl.active_tree()->set_background_color(
382 host_opaque ? SK_ColorRED : SK_ColorTRANSPARENT);
384 SkColor safe_color = layer->SafeOpaqueBackgroundColor();
385 if (contents_opaque) {
386 EXPECT_EQ(SkColorGetA(safe_color), 255u)
387 << "Flags: " << contents_opaque << ", " << layer_opaque << ", "
388 << host_opaque << "\n";
389 } else {
390 EXPECT_NE(SkColorGetA(safe_color), 255u)
391 << "Flags: " << contents_opaque << ", " << layer_opaque << ", "
392 << host_opaque << "\n";
399 TEST(LayerImplTest, TransformInvertibility) {
400 FakeImplProxy proxy;
401 TestSharedBitmapManager shared_bitmap_manager;
402 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
404 scoped_ptr<LayerImpl> layer = LayerImpl::Create(host_impl.active_tree(), 1);
405 EXPECT_TRUE(layer->transform().IsInvertible());
406 EXPECT_TRUE(layer->transform_is_invertible());
408 gfx::Transform transform;
409 transform.Scale3d(
410 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
411 layer->SetTransform(transform);
412 EXPECT_FALSE(layer->transform().IsInvertible());
413 EXPECT_FALSE(layer->transform_is_invertible());
415 transform.MakeIdentity();
416 transform.ApplyPerspectiveDepth(SkDoubleToMScalar(100.0));
417 transform.RotateAboutZAxis(75.0);
418 transform.RotateAboutXAxis(32.2);
419 transform.RotateAboutZAxis(-75.0);
420 transform.Translate3d(SkDoubleToMScalar(50.5),
421 SkDoubleToMScalar(42.42),
422 SkDoubleToMScalar(-100.25));
424 layer->SetTransform(transform);
425 EXPECT_TRUE(layer->transform().IsInvertible());
426 EXPECT_TRUE(layer->transform_is_invertible());
429 class LayerImplScrollTest : public testing::Test {
430 public:
431 LayerImplScrollTest()
432 : host_impl_(settings(), &proxy_, &shared_bitmap_manager_), root_id_(7) {
433 host_impl_.active_tree()->SetRootLayer(
434 LayerImpl::Create(host_impl_.active_tree(), root_id_));
435 host_impl_.active_tree()->root_layer()->AddChild(
436 LayerImpl::Create(host_impl_.active_tree(), root_id_ + 1));
437 layer()->SetScrollClipLayer(root_id_);
438 // Set the max scroll offset by noting that the root layer has bounds (1,1),
439 // thus whatever bounds are set for the layer will be the max scroll
440 // offset plus 1 in each direction.
441 host_impl_.active_tree()->root_layer()->SetBounds(gfx::Size(1, 1));
442 gfx::Vector2d max_scroll_offset(51, 81);
443 layer()->SetBounds(gfx::Size(max_scroll_offset.x(), max_scroll_offset.y()));
446 LayerImpl* layer() {
447 return host_impl_.active_tree()->root_layer()->children()[0];
450 LayerTreeHostImpl& host_impl() { return host_impl_; }
452 LayerTreeImpl* tree() { return host_impl_.active_tree(); }
454 LayerTreeSettings settings() {
455 LayerTreeSettings settings;
456 settings.use_pinch_virtual_viewport = true;
457 return settings;
460 private:
461 FakeImplProxy proxy_;
462 TestSharedBitmapManager shared_bitmap_manager_;
463 FakeLayerTreeHostImpl host_impl_;
464 int root_id_;
467 TEST_F(LayerImplScrollTest, ScrollByWithZeroOffset) {
468 // Test that LayerImpl::ScrollBy only affects ScrollDelta and total scroll
469 // offset is bounded by the range [0, max scroll offset].
471 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->CurrentScrollOffset());
472 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->BaseScrollOffset());
473 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta());
475 layer()->ScrollBy(gfx::Vector2dF(-100, 100));
476 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 80), layer()->CurrentScrollOffset());
478 EXPECT_VECTOR_EQ(layer()->ScrollDelta(), layer()->CurrentScrollOffset());
479 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->BaseScrollOffset());
481 layer()->ScrollBy(gfx::Vector2dF(100, -100));
482 EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 0), layer()->CurrentScrollOffset());
484 EXPECT_VECTOR_EQ(layer()->ScrollDelta(), layer()->CurrentScrollOffset());
485 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->BaseScrollOffset());
488 TEST_F(LayerImplScrollTest, ScrollByWithNonZeroOffset) {
489 gfx::ScrollOffset scroll_offset(10, 5);
490 layer()->PushScrollOffsetFromMainThread(scroll_offset);
492 EXPECT_VECTOR_EQ(scroll_offset, layer()->CurrentScrollOffset());
493 EXPECT_VECTOR_EQ(scroll_offset, layer()->BaseScrollOffset());
494 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta());
496 layer()->ScrollBy(gfx::Vector2dF(-100, 100));
497 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 80), layer()->CurrentScrollOffset());
499 EXPECT_VECTOR_EQ(
500 gfx::ScrollOffsetWithDelta(scroll_offset, layer()->ScrollDelta()),
501 layer()->CurrentScrollOffset());
502 EXPECT_VECTOR_EQ(scroll_offset, layer()->BaseScrollOffset());
504 layer()->ScrollBy(gfx::Vector2dF(100, -100));
505 EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 0), layer()->CurrentScrollOffset());
507 EXPECT_VECTOR_EQ(
508 gfx::ScrollOffsetWithDelta(scroll_offset, layer()->ScrollDelta()),
509 layer()->CurrentScrollOffset());
510 EXPECT_VECTOR_EQ(scroll_offset, layer()->BaseScrollOffset());
513 class ScrollDelegateIgnore : public LayerImpl::ScrollOffsetDelegate {
514 public:
515 void SetCurrentScrollOffset(const gfx::ScrollOffset& new_value) override {
516 last_attempted_set_offset_ = new_value;
518 gfx::ScrollOffset last_attempted_set_offset() const {
519 return last_attempted_set_offset_;
522 gfx::ScrollOffset GetCurrentScrollOffset() override {
523 return gfx::ScrollOffset(fixed_offset_);
525 bool IsExternalFlingActive() const override { return false; }
526 void Update() const override { }
528 void set_fixed_offset(const gfx::Vector2dF& fixed_offset) {
529 fixed_offset_ = fixed_offset;
532 private:
533 gfx::ScrollOffset last_attempted_set_offset_;
534 gfx::Vector2dF fixed_offset_;
537 TEST_F(LayerImplScrollTest, ScrollByWithIgnoringDelegate) {
538 gfx::ScrollOffset scroll_offset(10, 5);
539 layer()->PushScrollOffsetFromMainThread(scroll_offset);
541 EXPECT_VECTOR_EQ(scroll_offset, layer()->CurrentScrollOffset());
542 EXPECT_VECTOR_EQ(scroll_offset, layer()->BaseScrollOffset());
543 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta());
545 ScrollDelegateIgnore delegate;
546 gfx::Vector2dF fixed_offset(32, 12);
547 delegate.set_fixed_offset(fixed_offset);
548 layer()->SetScrollOffsetDelegate(&delegate);
549 layer()->RefreshFromScrollDelegate();
551 EXPECT_VECTOR_EQ(fixed_offset, layer()->CurrentScrollOffset());
552 EXPECT_VECTOR_EQ(scroll_offset, layer()->BaseScrollOffset());
554 layer()->ScrollBy(gfx::Vector2dF(-100, 100));
556 EXPECT_VECTOR_EQ(fixed_offset, layer()->CurrentScrollOffset());
557 EXPECT_VECTOR_EQ(scroll_offset, layer()->BaseScrollOffset());
559 layer()->SetScrollOffsetDelegate(nullptr);
561 EXPECT_VECTOR_EQ(fixed_offset, layer()->CurrentScrollOffset());
562 EXPECT_VECTOR_EQ(scroll_offset, layer()->BaseScrollOffset());
564 gfx::Vector2dF scroll_delta(1, 1);
565 layer()->ScrollBy(scroll_delta);
567 EXPECT_VECTOR_EQ(fixed_offset + scroll_delta, layer()->CurrentScrollOffset());
568 EXPECT_VECTOR_EQ(scroll_offset, layer()->BaseScrollOffset());
571 class ScrollDelegateAccept : public LayerImpl::ScrollOffsetDelegate {
572 public:
573 void SetCurrentScrollOffset(const gfx::ScrollOffset& new_value) override {
574 current_offset_ = new_value;
576 gfx::ScrollOffset GetCurrentScrollOffset() override {
577 return current_offset_;
579 bool IsExternalFlingActive() const override { return false; }
580 void Update() const override { }
582 private:
583 gfx::ScrollOffset current_offset_;
586 TEST_F(LayerImplScrollTest, ScrollByWithAcceptingDelegate) {
587 gfx::ScrollOffset scroll_offset(10, 5);
588 layer()->PushScrollOffsetFromMainThread(scroll_offset);
590 EXPECT_VECTOR_EQ(scroll_offset, layer()->CurrentScrollOffset());
591 EXPECT_VECTOR_EQ(scroll_offset, layer()->BaseScrollOffset());
592 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta());
594 ScrollDelegateAccept delegate;
595 layer()->SetScrollOffsetDelegate(&delegate);
597 EXPECT_VECTOR_EQ(scroll_offset, layer()->CurrentScrollOffset());
598 EXPECT_VECTOR_EQ(scroll_offset, layer()->BaseScrollOffset());
599 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta());
601 layer()->ScrollBy(gfx::Vector2dF(-100, 100));
603 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 80), layer()->CurrentScrollOffset());
604 EXPECT_VECTOR_EQ(scroll_offset, layer()->BaseScrollOffset());
606 layer()->SetScrollOffsetDelegate(nullptr);
608 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 80), layer()->CurrentScrollOffset());
609 EXPECT_VECTOR_EQ(scroll_offset, layer()->BaseScrollOffset());
611 gfx::Vector2dF scroll_delta(1, 1);
612 layer()->ScrollBy(scroll_delta);
614 EXPECT_VECTOR_EQ(gfx::Vector2dF(1, 80), layer()->CurrentScrollOffset());
615 EXPECT_VECTOR_EQ(scroll_offset, layer()->BaseScrollOffset());
618 TEST_F(LayerImplScrollTest, ApplySentScrollsNoDelegate) {
619 gfx::ScrollOffset scroll_offset(10, 5);
620 gfx::Vector2dF scroll_delta(20.5f, 8.5f);
621 gfx::Vector2d sent_scroll_delta(12, -3);
623 layer()->PushScrollOffsetFromMainThread(scroll_offset);
624 layer()->ScrollBy(sent_scroll_delta);
625 layer()->PullDeltaForMainThread();
626 layer()->SetCurrentScrollOffset(scroll_offset +
627 gfx::ScrollOffset(scroll_delta));
629 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, scroll_delta),
630 layer()->CurrentScrollOffset());
631 EXPECT_VECTOR_EQ(scroll_delta, layer()->ScrollDelta());
632 EXPECT_VECTOR_EQ(scroll_offset, layer()->BaseScrollOffset());
634 layer()->ApplySentScrollDeltasFromAbortedCommit();
636 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, scroll_delta),
637 layer()->CurrentScrollOffset());
638 EXPECT_VECTOR_EQ(scroll_delta - sent_scroll_delta, layer()->ScrollDelta());
639 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, sent_scroll_delta),
640 layer()->BaseScrollOffset());
643 TEST_F(LayerImplScrollTest, ApplySentScrollsWithIgnoringDelegate) {
644 gfx::ScrollOffset scroll_offset(10, 5);
645 gfx::Vector2d sent_scroll_delta(12, -3);
646 gfx::Vector2dF fixed_offset(32, 12);
648 layer()->PushScrollOffsetFromMainThread(scroll_offset);
649 layer()->ScrollBy(sent_scroll_delta);
650 layer()->PullDeltaForMainThread();
651 layer()->SetCurrentScrollOffset(scroll_offset);
652 ScrollDelegateIgnore delegate;
653 delegate.set_fixed_offset(fixed_offset);
654 layer()->SetScrollOffsetDelegate(&delegate);
655 layer()->RefreshFromScrollDelegate();
657 EXPECT_VECTOR_EQ(fixed_offset, layer()->CurrentScrollOffset());
658 EXPECT_VECTOR_EQ(scroll_offset, layer()->BaseScrollOffset());
660 layer()->ApplySentScrollDeltasFromAbortedCommit();
662 EXPECT_VECTOR_EQ(fixed_offset, delegate.last_attempted_set_offset());
664 EXPECT_VECTOR_EQ(fixed_offset, layer()->CurrentScrollOffset());
665 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, sent_scroll_delta),
666 layer()->BaseScrollOffset());
669 TEST_F(LayerImplScrollTest, ApplySentScrollsWithAcceptingDelegate) {
670 gfx::ScrollOffset scroll_offset(10, 5);
671 gfx::Vector2d sent_scroll_delta(12, -3);
672 gfx::Vector2dF scroll_delta(20.5f, 8.5f);
674 layer()->PushScrollOffsetFromMainThread(scroll_offset);
675 layer()->ScrollBy(sent_scroll_delta);
676 layer()->PullDeltaForMainThread();
677 ScrollDelegateAccept delegate;
678 layer()->SetScrollOffsetDelegate(&delegate);
679 layer()->SetCurrentScrollOffset(scroll_offset +
680 gfx::ScrollOffset(scroll_delta));
682 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, scroll_delta),
683 layer()->CurrentScrollOffset());
684 EXPECT_VECTOR_EQ(scroll_offset, layer()->BaseScrollOffset());
686 layer()->ApplySentScrollDeltasFromAbortedCommit();
688 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, scroll_delta),
689 layer()->CurrentScrollOffset());
690 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, sent_scroll_delta),
691 layer()->BaseScrollOffset());
694 TEST_F(LayerImplScrollTest, ScrollUserUnscrollableLayer) {
695 gfx::ScrollOffset scroll_offset(10, 5);
696 gfx::Vector2dF scroll_delta(20.5f, 8.5f);
698 layer()->set_user_scrollable_vertical(false);
699 layer()->PushScrollOffsetFromMainThread(scroll_offset);
700 gfx::Vector2dF unscrolled = layer()->ScrollBy(scroll_delta);
702 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 8.5f), unscrolled);
703 EXPECT_VECTOR_EQ(gfx::Vector2dF(30.5f, 5), layer()->CurrentScrollOffset());
706 TEST_F(LayerImplScrollTest, PushPropertiesToMirrorsCurrentScrollOffset) {
707 gfx::ScrollOffset scroll_offset(10, 5);
708 gfx::Vector2dF scroll_delta(12, 18);
710 host_impl().CreatePendingTree();
712 layer()->PushScrollOffsetFromMainThread(scroll_offset);
713 gfx::Vector2dF unscrolled = layer()->ScrollBy(scroll_delta);
715 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), unscrolled);
716 EXPECT_VECTOR_EQ(gfx::Vector2dF(22, 23), layer()->CurrentScrollOffset());
718 layer()->PullDeltaForMainThread();
720 scoped_ptr<LayerImpl> pending_layer = LayerImpl::Create(
721 host_impl().sync_tree(), layer()->id(), layer()->synced_scroll_offset());
722 pending_layer->PushScrollOffsetFromMainThread(layer()->CurrentScrollOffset());
724 pending_layer->PushPropertiesTo(layer());
726 EXPECT_VECTOR_EQ(gfx::Vector2dF(22, 23), layer()->CurrentScrollOffset());
727 EXPECT_VECTOR_EQ(layer()->CurrentScrollOffset(),
728 pending_layer->CurrentScrollOffset());
731 TEST_F(LayerImplScrollTest, SetNewScrollbarParameters) {
732 gfx::ScrollOffset scroll_offset(10, 5);
733 layer()->PushScrollOffsetFromMainThread(scroll_offset);
735 scoped_ptr<PaintedScrollbarLayerImpl> vertical_scrollbar(
736 PaintedScrollbarLayerImpl::Create(tree(), 100, VERTICAL));
737 vertical_scrollbar->SetScrollLayerAndClipLayerByIds(
738 layer()->id(), tree()->root_layer()->id());
740 int expected_vertical_maximum =
741 layer()->bounds().height() - tree()->root_layer()->bounds().height();
742 EXPECT_EQ(expected_vertical_maximum, vertical_scrollbar->maximum());
743 EXPECT_EQ(scroll_offset.y(), vertical_scrollbar->current_pos());
745 scoped_ptr<PaintedScrollbarLayerImpl> horizontal_scrollbar(
746 PaintedScrollbarLayerImpl::Create(tree(), 101, HORIZONTAL));
747 horizontal_scrollbar->SetScrollLayerAndClipLayerByIds(
748 layer()->id(), tree()->root_layer()->id());
750 int expected_horizontal_maximum =
751 layer()->bounds().width() - tree()->root_layer()->bounds().width();
752 EXPECT_EQ(expected_horizontal_maximum, horizontal_scrollbar->maximum());
753 EXPECT_EQ(scroll_offset.x(), horizontal_scrollbar->current_pos());
756 class LayerImplScrollbarSyncTest : public testing::Test {
757 public:
758 enum {
759 ROOT = 1,
760 IV_CLIP = 2,
761 PAGE = 3,
762 IV_SCROLL = 4,
763 SCROLLBAR = 5,
764 OLD_ROOT = 6,
765 OV_CLIP = 7,
766 OV_SCROLL = 8,
768 enum TreeID {
769 PENDING,
770 ACTIVE
773 LayerImplScrollbarSyncTest()
774 : host_impl_(settings(), &proxy_, &shared_bitmap_manager_) {
775 host_impl_.CreatePendingTree();
777 CreateLayers(host_impl_.pending_tree());
778 CreateLayers(host_impl_.active_tree());
781 void CreateLayers(LayerTreeImpl * tree) {
782 tree->SetRootLayer(LayerImpl::Create(tree, ROOT));
783 LayerImpl * root = tree->root_layer();
784 ASSERT_TRUE(root != nullptr);
786 int hierarchy[] = {IV_CLIP, PAGE, IV_SCROLL, OLD_ROOT, OV_CLIP, OV_SCROLL};
787 LayerImpl * parent = root;
788 for (int child_id : hierarchy) {
789 parent->AddChild(LayerImpl::Create(tree, child_id));
790 parent = tree->LayerById(child_id);
791 ASSERT_TRUE(parent != nullptr);
794 root->AddChild(
795 SolidColorScrollbarLayerImpl::Create(tree, SCROLLBAR, HORIZONTAL,
796 5, 5, false, true));
799 LayerImpl* layer(int id, TreeID tree_id) {
800 LayerTreeImpl* tree =
801 ((tree_id == PENDING) ?
802 host_impl_.pending_tree() : host_impl_.active_tree());
804 assert(tree);
805 return tree->LayerById(id);
808 bool LayerHasScrollbar(int id, TreeID tree_id) {
809 return layer(id, tree_id)->HasScrollbar(HORIZONTAL);
812 ScrollbarLayerImplBase* pending_scrollbar() {
813 LayerImpl* layer_impl = layer(SCROLLBAR, PENDING);
814 assert(layer_impl);
815 return layer_impl->ToScrollbarLayer();
818 LayerImpl* pending_root() {
819 LayerImpl * result = layer(ROOT, PENDING);
820 assert(result);
821 return result;
824 LayerImpl* active_root() {
825 LayerImpl * result = layer(ROOT, ACTIVE);
826 assert(result);
827 return result;
830 LayerTreeSettings settings() {
831 LayerTreeSettings settings;
832 settings.use_pinch_virtual_viewport = true;
833 return settings;
836 private:
837 FakeImplProxy proxy_;
838 TestSharedBitmapManager shared_bitmap_manager_;
839 FakeLayerTreeHostImpl host_impl_;
842 TEST_F(LayerImplScrollbarSyncTest, LayerImplBecomesScrollable) {
843 // In the beginning IV_SCROLL layer is not scrollable.
844 ASSERT_FALSE(layer(IV_SCROLL, PENDING)->scrollable());
846 // For pinch virtual viewport the clip layer is the inner viewport
847 // clip layer (IV_CLIP) and the scroll one is the outer viewport
848 // scroll layer (OV_SCROLL).
849 pending_scrollbar()->SetScrollLayerAndClipLayerByIds(OV_SCROLL, IV_CLIP);
851 ASSERT_TRUE(LayerHasScrollbar(OV_SCROLL, PENDING));
852 ASSERT_TRUE(LayerHasScrollbar(IV_CLIP, PENDING));
854 // Synchronize with the active tree.
855 TreeSynchronizer::PushProperties(pending_root(), active_root());
857 ASSERT_TRUE(LayerHasScrollbar(OV_SCROLL, ACTIVE));
858 ASSERT_TRUE(LayerHasScrollbar(IV_CLIP, ACTIVE));
860 // Make IV_SCROLL layer scrollable.
861 layer(IV_SCROLL, PENDING)->SetScrollClipLayer(IV_CLIP);
862 layer(IV_SCROLL, PENDING)->SetNeedsPushProperties();
863 ASSERT_TRUE(layer(IV_SCROLL, PENDING)->scrollable());
865 pending_scrollbar()->SetScrollLayerAndClipLayerByIds(OV_SCROLL, IV_CLIP);
867 // Now IV_CLIP layer should also receive the scrollbar.
868 ASSERT_TRUE(LayerHasScrollbar(OV_SCROLL, PENDING));
869 ASSERT_TRUE(LayerHasScrollbar(IV_CLIP, PENDING));
870 ASSERT_TRUE(LayerHasScrollbar(IV_SCROLL, PENDING));
872 // Synchronize with the active tree.
873 TreeSynchronizer::PushProperties(pending_root(), active_root());
875 ASSERT_TRUE(layer(IV_SCROLL, ACTIVE)->scrollable());
877 ASSERT_TRUE(LayerHasScrollbar(OV_SCROLL, ACTIVE));
878 ASSERT_TRUE(LayerHasScrollbar(IV_CLIP, ACTIVE));
879 ASSERT_TRUE(LayerHasScrollbar(IV_SCROLL, ACTIVE));
882 } // namespace
883 } // namespace cc