Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / cc / trees / tree_synchronizer_unittest.cc
blob6cf75baf5292d126318b57f3dbeb5d74e6c49228
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/trees/tree_synchronizer.h"
7 #include <algorithm>
8 #include <set>
9 #include <vector>
11 #include "base/format_macros.h"
12 #include "base/strings/stringprintf.h"
13 #include "cc/animation/layer_animation_controller.h"
14 #include "cc/layers/layer.h"
15 #include "cc/layers/layer_impl.h"
16 #include "cc/test/animation_test_common.h"
17 #include "cc/test/fake_impl_proxy.h"
18 #include "cc/test/fake_layer_tree_host.h"
19 #include "cc/test/fake_rendering_stats_instrumentation.h"
20 #include "cc/test/test_shared_bitmap_manager.h"
21 #include "cc/trees/proxy.h"
22 #include "cc/trees/single_thread_proxy.h"
23 #include "testing/gtest/include/gtest/gtest.h"
25 namespace cc {
26 namespace {
28 class MockLayerImpl : public LayerImpl {
29 public:
30 static scoped_ptr<MockLayerImpl> Create(LayerTreeImpl* tree_impl,
31 int layer_id) {
32 return make_scoped_ptr(new MockLayerImpl(tree_impl, layer_id));
34 ~MockLayerImpl() override {
35 if (layer_impl_destruction_list_)
36 layer_impl_destruction_list_->push_back(id());
39 void SetLayerImplDestructionList(std::vector<int>* list) {
40 layer_impl_destruction_list_ = list;
43 private:
44 MockLayerImpl(LayerTreeImpl* tree_impl, int layer_id)
45 : LayerImpl(tree_impl, layer_id),
46 layer_impl_destruction_list_(NULL) {}
48 std::vector<int>* layer_impl_destruction_list_;
51 class MockLayer : public Layer {
52 public:
53 static scoped_refptr<MockLayer> Create(
54 const LayerSettings& settings,
55 std::vector<int>* layer_impl_destruction_list) {
56 return make_scoped_refptr(
57 new MockLayer(settings, layer_impl_destruction_list));
60 scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override {
61 return MockLayerImpl::Create(tree_impl, layer_id_);
64 void PushPropertiesTo(LayerImpl* layer_impl) override {
65 Layer::PushPropertiesTo(layer_impl);
67 MockLayerImpl* mock_layer_impl = static_cast<MockLayerImpl*>(layer_impl);
68 mock_layer_impl->SetLayerImplDestructionList(layer_impl_destruction_list_);
71 private:
72 explicit MockLayer(const LayerSettings& settings,
73 std::vector<int>* layer_impl_destruction_list)
74 : Layer(settings),
75 layer_impl_destruction_list_(layer_impl_destruction_list) {}
76 ~MockLayer() override {}
78 std::vector<int>* layer_impl_destruction_list_;
81 class FakeLayerAnimationController : public LayerAnimationController {
82 public:
83 static scoped_refptr<LayerAnimationController> Create() {
84 return static_cast<LayerAnimationController*>(
85 new FakeLayerAnimationController);
88 bool SynchronizedAnimations() const { return synchronized_animations_; }
90 private:
91 FakeLayerAnimationController()
92 : LayerAnimationController(1),
93 synchronized_animations_(false) {}
95 ~FakeLayerAnimationController() override {}
97 void PushAnimationUpdatesTo(
98 LayerAnimationController* controller_impl) override {
99 LayerAnimationController::PushAnimationUpdatesTo(controller_impl);
100 synchronized_animations_ = true;
103 bool synchronized_animations_;
106 void ExpectTreesAreIdentical(Layer* layer,
107 LayerImpl* layer_impl,
108 LayerTreeImpl* tree_impl) {
109 ASSERT_TRUE(layer);
110 ASSERT_TRUE(layer_impl);
112 EXPECT_EQ(layer->id(), layer_impl->id());
113 EXPECT_EQ(layer_impl->layer_tree_impl(), tree_impl);
115 EXPECT_EQ(layer->non_fast_scrollable_region(),
116 layer_impl->non_fast_scrollable_region());
118 ASSERT_EQ(!!layer->mask_layer(), !!layer_impl->mask_layer());
119 if (layer->mask_layer()) {
120 SCOPED_TRACE("mask_layer");
121 ExpectTreesAreIdentical(
122 layer->mask_layer(), layer_impl->mask_layer(), tree_impl);
125 ASSERT_EQ(!!layer->replica_layer(), !!layer_impl->replica_layer());
126 if (layer->replica_layer()) {
127 SCOPED_TRACE("replica_layer");
128 ExpectTreesAreIdentical(
129 layer->replica_layer(), layer_impl->replica_layer(), tree_impl);
132 const LayerList& layer_children = layer->children();
133 const OwnedLayerImplList& layer_impl_children = layer_impl->children();
135 ASSERT_EQ(layer_children.size(), layer_impl_children.size());
137 const std::set<Layer*>* layer_scroll_children = layer->scroll_children();
138 const std::set<LayerImpl*>* layer_impl_scroll_children =
139 layer_impl->scroll_children();
141 ASSERT_EQ(!!layer_scroll_children, !!layer_impl_scroll_children);
143 if (layer_scroll_children) {
144 ASSERT_EQ(
145 layer_scroll_children->size(),
146 layer_impl_scroll_children->size());
149 const Layer* layer_scroll_parent = layer->scroll_parent();
150 const LayerImpl* layer_impl_scroll_parent = layer_impl->scroll_parent();
152 ASSERT_EQ(!!layer_scroll_parent, !!layer_impl_scroll_parent);
154 if (layer_scroll_parent) {
155 ASSERT_EQ(layer_scroll_parent->id(), layer_impl_scroll_parent->id());
156 ASSERT_TRUE(layer_scroll_parent->scroll_children()->find(layer) !=
157 layer_scroll_parent->scroll_children()->end());
158 ASSERT_TRUE(layer_impl_scroll_parent->scroll_children()->find(layer_impl) !=
159 layer_impl_scroll_parent->scroll_children()->end());
162 const std::set<Layer*>* layer_clip_children = layer->clip_children();
163 const std::set<LayerImpl*>* layer_impl_clip_children =
164 layer_impl->clip_children();
166 ASSERT_EQ(!!layer_clip_children, !!layer_impl_clip_children);
168 if (layer_clip_children)
169 ASSERT_EQ(layer_clip_children->size(), layer_impl_clip_children->size());
171 const Layer* layer_clip_parent = layer->clip_parent();
172 const LayerImpl* layer_impl_clip_parent = layer_impl->clip_parent();
174 ASSERT_EQ(!!layer_clip_parent, !!layer_impl_clip_parent);
176 if (layer_clip_parent) {
177 const std::set<LayerImpl*>* clip_children_impl =
178 layer_impl_clip_parent->clip_children();
179 const std::set<Layer*>* clip_children =
180 layer_clip_parent->clip_children();
181 ASSERT_EQ(layer_clip_parent->id(), layer_impl_clip_parent->id());
182 ASSERT_TRUE(clip_children->find(layer) != clip_children->end());
183 ASSERT_TRUE(clip_children_impl->find(layer_impl) !=
184 clip_children_impl->end());
187 for (size_t i = 0; i < layer_children.size(); ++i) {
188 SCOPED_TRACE(base::StringPrintf("child layer %" PRIuS, i).c_str());
189 ExpectTreesAreIdentical(
190 layer_children[i].get(), layer_impl_children[i], tree_impl);
194 class TreeSynchronizerTest : public testing::Test {
195 public:
196 TreeSynchronizerTest()
197 : client_(FakeLayerTreeHostClient::DIRECT_3D),
198 host_(FakeLayerTreeHost::Create(&client_)) {}
200 protected:
201 FakeLayerTreeHostClient client_;
202 scoped_ptr<FakeLayerTreeHost> host_;
203 LayerSettings layer_settings_;
206 // Attempts to synchronizes a null tree. This should not crash, and should
207 // return a null tree.
208 TEST_F(TreeSynchronizerTest, SyncNullTree) {
209 scoped_ptr<LayerImpl> layer_impl_tree_root =
210 TreeSynchronizer::SynchronizeTrees(
211 static_cast<Layer*>(NULL), nullptr, host_->active_tree());
213 EXPECT_TRUE(!layer_impl_tree_root.get());
216 // Constructs a very simple tree and synchronizes it without trying to reuse any
217 // preexisting layers.
218 TEST_F(TreeSynchronizerTest, SyncSimpleTreeFromEmpty) {
219 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings_);
220 layer_tree_root->AddChild(Layer::Create(layer_settings_));
221 layer_tree_root->AddChild(Layer::Create(layer_settings_));
223 host_->SetRootLayer(layer_tree_root);
225 scoped_ptr<LayerImpl> layer_impl_tree_root =
226 TreeSynchronizer::SynchronizeTrees(
227 layer_tree_root.get(), nullptr, host_->active_tree());
229 ExpectTreesAreIdentical(layer_tree_root.get(),
230 layer_impl_tree_root.get(),
231 host_->active_tree());
234 // Constructs a very simple tree and synchronizes it attempting to reuse some
235 // layers
236 TEST_F(TreeSynchronizerTest, SyncSimpleTreeReusingLayers) {
237 std::vector<int> layer_impl_destruction_list;
239 scoped_refptr<Layer> layer_tree_root =
240 MockLayer::Create(layer_settings_, &layer_impl_destruction_list);
241 layer_tree_root->AddChild(
242 MockLayer::Create(layer_settings_, &layer_impl_destruction_list));
243 layer_tree_root->AddChild(
244 MockLayer::Create(layer_settings_, &layer_impl_destruction_list));
246 host_->SetRootLayer(layer_tree_root);
248 scoped_ptr<LayerImpl> layer_impl_tree_root =
249 TreeSynchronizer::SynchronizeTrees(
250 layer_tree_root.get(), nullptr, host_->active_tree());
251 ExpectTreesAreIdentical(layer_tree_root.get(),
252 layer_impl_tree_root.get(),
253 host_->active_tree());
255 // We have to push properties to pick up the destruction list pointer.
256 TreeSynchronizer::PushProperties(layer_tree_root.get(),
257 layer_impl_tree_root.get());
259 // Add a new layer to the Layer side
260 layer_tree_root->children()[0]->AddChild(
261 MockLayer::Create(layer_settings_, &layer_impl_destruction_list));
262 // Remove one.
263 layer_tree_root->children()[1]->RemoveFromParent();
264 int second_layer_impl_id = layer_impl_tree_root->children()[1]->id();
266 // Synchronize again. After the sync the trees should be equivalent and we
267 // should have created and destroyed one LayerImpl.
268 layer_impl_tree_root =
269 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
270 layer_impl_tree_root.Pass(),
271 host_->active_tree());
272 ExpectTreesAreIdentical(layer_tree_root.get(),
273 layer_impl_tree_root.get(),
274 host_->active_tree());
276 ASSERT_EQ(1u, layer_impl_destruction_list.size());
277 EXPECT_EQ(second_layer_impl_id, layer_impl_destruction_list[0]);
280 // Constructs a very simple tree and checks that a stacking-order change is
281 // tracked properly.
282 TEST_F(TreeSynchronizerTest, SyncSimpleTreeAndTrackStackingOrderChange) {
283 std::vector<int> layer_impl_destruction_list;
285 // Set up the tree and sync once. child2 needs to be synced here, too, even
286 // though we remove it to set up the intended scenario.
287 scoped_refptr<Layer> layer_tree_root =
288 MockLayer::Create(layer_settings_, &layer_impl_destruction_list);
289 scoped_refptr<Layer> child2 =
290 MockLayer::Create(layer_settings_, &layer_impl_destruction_list);
291 layer_tree_root->AddChild(
292 MockLayer::Create(layer_settings_, &layer_impl_destruction_list));
293 layer_tree_root->AddChild(child2);
295 host_->SetRootLayer(layer_tree_root);
297 scoped_ptr<LayerImpl> layer_impl_tree_root =
298 TreeSynchronizer::SynchronizeTrees(
299 layer_tree_root.get(), nullptr, host_->active_tree());
300 ExpectTreesAreIdentical(layer_tree_root.get(),
301 layer_impl_tree_root.get(),
302 host_->active_tree());
304 // We have to push properties to pick up the destruction list pointer.
305 TreeSynchronizer::PushProperties(layer_tree_root.get(),
306 layer_impl_tree_root.get());
308 layer_impl_tree_root->ResetAllChangeTrackingForSubtree();
310 // re-insert the layer and sync again.
311 child2->RemoveFromParent();
312 layer_tree_root->AddChild(child2);
313 layer_impl_tree_root =
314 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
315 layer_impl_tree_root.Pass(),
316 host_->active_tree());
317 ExpectTreesAreIdentical(layer_tree_root.get(),
318 layer_impl_tree_root.get(),
319 host_->active_tree());
321 TreeSynchronizer::PushProperties(layer_tree_root.get(),
322 layer_impl_tree_root.get());
324 // Check that the impl thread properly tracked the change.
325 EXPECT_FALSE(layer_impl_tree_root->LayerPropertyChanged());
326 EXPECT_FALSE(layer_impl_tree_root->children()[0]->LayerPropertyChanged());
327 EXPECT_TRUE(layer_impl_tree_root->children()[1]->LayerPropertyChanged());
330 TEST_F(TreeSynchronizerTest, SyncSimpleTreeAndProperties) {
331 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings_);
332 layer_tree_root->AddChild(Layer::Create(layer_settings_));
333 layer_tree_root->AddChild(Layer::Create(layer_settings_));
335 host_->SetRootLayer(layer_tree_root);
337 // Pick some random properties to set. The values are not important, we're
338 // just testing that at least some properties are making it through.
339 gfx::PointF root_position = gfx::PointF(2.3f, 7.4f);
340 layer_tree_root->SetPosition(root_position);
342 float first_child_opacity = 0.25f;
343 layer_tree_root->children()[0]->SetOpacity(first_child_opacity);
345 gfx::Size second_child_bounds = gfx::Size(25, 53);
346 layer_tree_root->children()[1]->SetBounds(second_child_bounds);
347 layer_tree_root->children()[1]->SavePaintProperties();
349 scoped_ptr<LayerImpl> layer_impl_tree_root =
350 TreeSynchronizer::SynchronizeTrees(
351 layer_tree_root.get(), nullptr, host_->active_tree());
352 ExpectTreesAreIdentical(layer_tree_root.get(),
353 layer_impl_tree_root.get(),
354 host_->active_tree());
356 TreeSynchronizer::PushProperties(layer_tree_root.get(),
357 layer_impl_tree_root.get());
359 // Check that the property values we set on the Layer tree are reflected in
360 // the LayerImpl tree.
361 gfx::PointF root_layer_impl_position = layer_impl_tree_root->position();
362 EXPECT_EQ(root_position.x(), root_layer_impl_position.x());
363 EXPECT_EQ(root_position.y(), root_layer_impl_position.y());
365 EXPECT_EQ(first_child_opacity,
366 layer_impl_tree_root->children()[0]->opacity());
368 gfx::Size second_layer_impl_child_bounds =
369 layer_impl_tree_root->children()[1]->bounds();
370 EXPECT_EQ(second_child_bounds.width(),
371 second_layer_impl_child_bounds.width());
372 EXPECT_EQ(second_child_bounds.height(),
373 second_layer_impl_child_bounds.height());
376 TEST_F(TreeSynchronizerTest, ReuseLayerImplsAfterStructuralChange) {
377 std::vector<int> layer_impl_destruction_list;
379 // Set up a tree with this sort of structure:
380 // root --- A --- B ---+--- C
381 // |
382 // +--- D
383 scoped_refptr<Layer> layer_tree_root =
384 MockLayer::Create(layer_settings_, &layer_impl_destruction_list);
385 layer_tree_root->AddChild(
386 MockLayer::Create(layer_settings_, &layer_impl_destruction_list));
388 scoped_refptr<Layer> layer_a = layer_tree_root->children()[0].get();
389 layer_a->AddChild(
390 MockLayer::Create(layer_settings_, &layer_impl_destruction_list));
392 scoped_refptr<Layer> layer_b = layer_a->children()[0].get();
393 layer_b->AddChild(
394 MockLayer::Create(layer_settings_, &layer_impl_destruction_list));
396 scoped_refptr<Layer> layer_c = layer_b->children()[0].get();
397 layer_b->AddChild(
398 MockLayer::Create(layer_settings_, &layer_impl_destruction_list));
399 scoped_refptr<Layer> layer_d = layer_b->children()[1].get();
401 host_->SetRootLayer(layer_tree_root);
403 scoped_ptr<LayerImpl> layer_impl_tree_root =
404 TreeSynchronizer::SynchronizeTrees(
405 layer_tree_root.get(), nullptr, host_->active_tree());
406 ExpectTreesAreIdentical(layer_tree_root.get(),
407 layer_impl_tree_root.get(),
408 host_->active_tree());
410 // We have to push properties to pick up the destruction list pointer.
411 TreeSynchronizer::PushProperties(layer_tree_root.get(),
412 layer_impl_tree_root.get());
414 // Now restructure the tree to look like this:
415 // root --- D ---+--- A
416 // |
417 // +--- C --- B
418 layer_tree_root->RemoveAllChildren();
419 layer_d->RemoveAllChildren();
420 layer_tree_root->AddChild(layer_d);
421 layer_a->RemoveAllChildren();
422 layer_d->AddChild(layer_a);
423 layer_c->RemoveAllChildren();
424 layer_d->AddChild(layer_c);
425 layer_b->RemoveAllChildren();
426 layer_c->AddChild(layer_b);
428 // After another synchronize our trees should match and we should not have
429 // destroyed any LayerImpls
430 layer_impl_tree_root =
431 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
432 layer_impl_tree_root.Pass(),
433 host_->active_tree());
434 ExpectTreesAreIdentical(layer_tree_root.get(),
435 layer_impl_tree_root.get(),
436 host_->active_tree());
438 EXPECT_EQ(0u, layer_impl_destruction_list.size());
441 // Constructs a very simple tree, synchronizes it, then synchronizes to a
442 // totally new tree. All layers from the old tree should be deleted.
443 TEST_F(TreeSynchronizerTest, SyncSimpleTreeThenDestroy) {
444 std::vector<int> layer_impl_destruction_list;
446 scoped_refptr<Layer> old_layer_tree_root =
447 MockLayer::Create(layer_settings_, &layer_impl_destruction_list);
448 old_layer_tree_root->AddChild(
449 MockLayer::Create(layer_settings_, &layer_impl_destruction_list));
450 old_layer_tree_root->AddChild(
451 MockLayer::Create(layer_settings_, &layer_impl_destruction_list));
453 host_->SetRootLayer(old_layer_tree_root);
455 int old_tree_root_layer_id = old_layer_tree_root->id();
456 int old_tree_first_child_layer_id = old_layer_tree_root->children()[0]->id();
457 int old_tree_second_child_layer_id = old_layer_tree_root->children()[1]->id();
459 scoped_ptr<LayerImpl> layer_impl_tree_root =
460 TreeSynchronizer::SynchronizeTrees(
461 old_layer_tree_root.get(), nullptr, host_->active_tree());
462 ExpectTreesAreIdentical(old_layer_tree_root.get(),
463 layer_impl_tree_root.get(),
464 host_->active_tree());
466 // We have to push properties to pick up the destruction list pointer.
467 TreeSynchronizer::PushProperties(old_layer_tree_root.get(),
468 layer_impl_tree_root.get());
470 // Remove all children on the Layer side.
471 old_layer_tree_root->RemoveAllChildren();
473 // Synchronize again. After the sync all LayerImpls from the old tree should
474 // be deleted.
475 scoped_refptr<Layer> new_layer_tree_root = Layer::Create(layer_settings_);
476 host_->SetRootLayer(new_layer_tree_root);
477 layer_impl_tree_root =
478 TreeSynchronizer::SynchronizeTrees(new_layer_tree_root.get(),
479 layer_impl_tree_root.Pass(),
480 host_->active_tree());
481 ExpectTreesAreIdentical(new_layer_tree_root.get(),
482 layer_impl_tree_root.get(),
483 host_->active_tree());
485 ASSERT_EQ(3u, layer_impl_destruction_list.size());
487 EXPECT_TRUE(std::find(layer_impl_destruction_list.begin(),
488 layer_impl_destruction_list.end(),
489 old_tree_root_layer_id) !=
490 layer_impl_destruction_list.end());
491 EXPECT_TRUE(std::find(layer_impl_destruction_list.begin(),
492 layer_impl_destruction_list.end(),
493 old_tree_first_child_layer_id) !=
494 layer_impl_destruction_list.end());
495 EXPECT_TRUE(std::find(layer_impl_destruction_list.begin(),
496 layer_impl_destruction_list.end(),
497 old_tree_second_child_layer_id) !=
498 layer_impl_destruction_list.end());
501 // Constructs+syncs a tree with mask, replica, and replica mask layers.
502 TEST_F(TreeSynchronizerTest, SyncMaskReplicaAndReplicaMaskLayers) {
503 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings_);
504 layer_tree_root->AddChild(Layer::Create(layer_settings_));
505 layer_tree_root->AddChild(Layer::Create(layer_settings_));
506 layer_tree_root->AddChild(Layer::Create(layer_settings_));
508 // First child gets a mask layer.
509 scoped_refptr<Layer> mask_layer = Layer::Create(layer_settings_);
510 layer_tree_root->children()[0]->SetMaskLayer(mask_layer.get());
512 // Second child gets a replica layer.
513 scoped_refptr<Layer> replica_layer = Layer::Create(layer_settings_);
514 layer_tree_root->children()[1]->SetReplicaLayer(replica_layer.get());
516 // Third child gets a replica layer with a mask layer.
517 scoped_refptr<Layer> replica_layer_with_mask = Layer::Create(layer_settings_);
518 scoped_refptr<Layer> replica_mask_layer = Layer::Create(layer_settings_);
519 replica_layer_with_mask->SetMaskLayer(replica_mask_layer.get());
520 layer_tree_root->children()[2]->
521 SetReplicaLayer(replica_layer_with_mask.get());
523 host_->SetRootLayer(layer_tree_root);
525 scoped_ptr<LayerImpl> layer_impl_tree_root =
526 TreeSynchronizer::SynchronizeTrees(
527 layer_tree_root.get(), nullptr, host_->active_tree());
529 ExpectTreesAreIdentical(layer_tree_root.get(),
530 layer_impl_tree_root.get(),
531 host_->active_tree());
533 // Remove the mask layer.
534 layer_tree_root->children()[0]->SetMaskLayer(NULL);
535 layer_impl_tree_root =
536 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
537 layer_impl_tree_root.Pass(),
538 host_->active_tree());
539 ExpectTreesAreIdentical(layer_tree_root.get(),
540 layer_impl_tree_root.get(),
541 host_->active_tree());
543 // Remove the replica layer.
544 layer_tree_root->children()[1]->SetReplicaLayer(NULL);
545 layer_impl_tree_root =
546 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
547 layer_impl_tree_root.Pass(),
548 host_->active_tree());
549 ExpectTreesAreIdentical(layer_tree_root.get(),
550 layer_impl_tree_root.get(),
551 host_->active_tree());
553 // Remove the replica mask.
554 replica_layer_with_mask->SetMaskLayer(NULL);
555 layer_impl_tree_root =
556 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
557 layer_impl_tree_root.Pass(),
558 host_->active_tree());
559 ExpectTreesAreIdentical(layer_tree_root.get(),
560 layer_impl_tree_root.get(),
561 host_->active_tree());
564 TEST_F(TreeSynchronizerTest, SynchronizeAnimations) {
565 LayerTreeSettings settings;
566 FakeProxy proxy;
567 DebugScopedSetImplThread impl(&proxy);
568 FakeRenderingStatsInstrumentation stats_instrumentation;
569 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
570 new TestSharedBitmapManager());
571 scoped_ptr<LayerTreeHostImpl> host_impl =
572 LayerTreeHostImpl::Create(settings, NULL, &proxy, &stats_instrumentation,
573 shared_bitmap_manager.get(), NULL, NULL, 0);
575 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings_);
576 host_->SetRootLayer(layer_tree_root);
578 layer_tree_root->SetLayerAnimationControllerForTest(
579 FakeLayerAnimationController::Create());
581 EXPECT_FALSE(static_cast<FakeLayerAnimationController*>(
582 layer_tree_root->layer_animation_controller())->SynchronizedAnimations());
584 scoped_ptr<LayerImpl> layer_impl_tree_root =
585 TreeSynchronizer::SynchronizeTrees(
586 layer_tree_root.get(), nullptr, host_->active_tree());
587 TreeSynchronizer::PushProperties(layer_tree_root.get(),
588 layer_impl_tree_root.get());
589 layer_impl_tree_root =
590 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
591 layer_impl_tree_root.Pass(),
592 host_->active_tree());
594 EXPECT_TRUE(static_cast<FakeLayerAnimationController*>(
595 layer_tree_root->layer_animation_controller())->SynchronizedAnimations());
598 TEST_F(TreeSynchronizerTest, SynchronizeScrollParent) {
599 LayerTreeSettings settings;
600 FakeProxy proxy;
601 DebugScopedSetImplThread impl(&proxy);
602 FakeRenderingStatsInstrumentation stats_instrumentation;
603 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
604 new TestSharedBitmapManager());
605 scoped_ptr<LayerTreeHostImpl> host_impl =
606 LayerTreeHostImpl::Create(settings, NULL, &proxy, &stats_instrumentation,
607 shared_bitmap_manager.get(), NULL, NULL, 0);
609 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings_);
610 scoped_refptr<Layer> scroll_parent = Layer::Create(layer_settings_);
611 layer_tree_root->AddChild(scroll_parent);
612 layer_tree_root->AddChild(Layer::Create(layer_settings_));
613 layer_tree_root->AddChild(Layer::Create(layer_settings_));
615 host_->SetRootLayer(layer_tree_root);
617 // First child is the second and third child's scroll parent.
618 layer_tree_root->children()[1]->SetScrollParent(scroll_parent.get());
619 layer_tree_root->children()[2]->SetScrollParent(scroll_parent.get());
621 scoped_ptr<LayerImpl> layer_impl_tree_root =
622 TreeSynchronizer::SynchronizeTrees(
623 layer_tree_root.get(), nullptr, host_impl->active_tree());
624 TreeSynchronizer::PushProperties(layer_tree_root.get(),
625 layer_impl_tree_root.get());
627 SCOPED_TRACE("case one");
628 ExpectTreesAreIdentical(layer_tree_root.get(),
629 layer_impl_tree_root.get(),
630 host_impl->active_tree());
633 // Remove the first scroll child.
634 layer_tree_root->children()[1]->RemoveFromParent();
635 layer_impl_tree_root =
636 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
637 layer_impl_tree_root.Pass(),
638 host_impl->active_tree());
639 TreeSynchronizer::PushProperties(layer_tree_root.get(),
640 layer_impl_tree_root.get());
642 SCOPED_TRACE("case two");
643 ExpectTreesAreIdentical(layer_tree_root.get(),
644 layer_impl_tree_root.get(),
645 host_impl->active_tree());
648 // Add an additional scroll layer.
649 scoped_refptr<Layer> additional_scroll_child = Layer::Create(layer_settings_);
650 layer_tree_root->AddChild(additional_scroll_child);
651 additional_scroll_child->SetScrollParent(scroll_parent.get());
652 layer_impl_tree_root =
653 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
654 layer_impl_tree_root.Pass(),
655 host_impl->active_tree());
656 TreeSynchronizer::PushProperties(layer_tree_root.get(),
657 layer_impl_tree_root.get());
659 SCOPED_TRACE("case three");
660 ExpectTreesAreIdentical(layer_tree_root.get(),
661 layer_impl_tree_root.get(),
662 host_impl->active_tree());
666 TEST_F(TreeSynchronizerTest, SynchronizeClipParent) {
667 LayerTreeSettings settings;
668 FakeProxy proxy;
669 DebugScopedSetImplThread impl(&proxy);
670 FakeRenderingStatsInstrumentation stats_instrumentation;
671 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
672 new TestSharedBitmapManager());
673 scoped_ptr<LayerTreeHostImpl> host_impl =
674 LayerTreeHostImpl::Create(settings, NULL, &proxy, &stats_instrumentation,
675 shared_bitmap_manager.get(), NULL, NULL, 0);
677 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings_);
678 scoped_refptr<Layer> clip_parent = Layer::Create(layer_settings_);
679 scoped_refptr<Layer> intervening = Layer::Create(layer_settings_);
680 scoped_refptr<Layer> clip_child1 = Layer::Create(layer_settings_);
681 scoped_refptr<Layer> clip_child2 = Layer::Create(layer_settings_);
682 layer_tree_root->AddChild(clip_parent);
683 clip_parent->AddChild(intervening);
684 intervening->AddChild(clip_child1);
685 intervening->AddChild(clip_child2);
687 host_->SetRootLayer(layer_tree_root);
689 // First child is the second and third child's scroll parent.
690 clip_child1->SetClipParent(clip_parent.get());
691 clip_child2->SetClipParent(clip_parent.get());
693 scoped_ptr<LayerImpl> layer_impl_tree_root =
694 TreeSynchronizer::SynchronizeTrees(
695 layer_tree_root.get(), nullptr, host_impl->active_tree());
696 TreeSynchronizer::PushProperties(layer_tree_root.get(),
697 layer_impl_tree_root.get());
698 ExpectTreesAreIdentical(layer_tree_root.get(),
699 layer_impl_tree_root.get(),
700 host_impl->active_tree());
702 // Remove the first clip child.
703 clip_child1->RemoveFromParent();
704 clip_child1 = NULL;
706 layer_impl_tree_root =
707 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
708 layer_impl_tree_root.Pass(),
709 host_impl->active_tree());
710 TreeSynchronizer::PushProperties(layer_tree_root.get(),
711 layer_impl_tree_root.get());
712 ExpectTreesAreIdentical(layer_tree_root.get(),
713 layer_impl_tree_root.get(),
714 host_impl->active_tree());
716 // Add an additional clip child.
717 scoped_refptr<Layer> additional_clip_child = Layer::Create(layer_settings_);
718 intervening->AddChild(additional_clip_child);
719 additional_clip_child->SetClipParent(clip_parent.get());
720 layer_impl_tree_root =
721 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
722 layer_impl_tree_root.Pass(),
723 host_impl->active_tree());
724 TreeSynchronizer::PushProperties(layer_tree_root.get(),
725 layer_impl_tree_root.get());
726 ExpectTreesAreIdentical(layer_tree_root.get(),
727 layer_impl_tree_root.get(),
728 host_impl->active_tree());
730 // Remove the nearest clipping ancestor.
731 clip_parent->RemoveFromParent();
732 clip_parent = NULL;
733 layer_impl_tree_root =
734 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
735 layer_impl_tree_root.Pass(),
736 host_impl->active_tree());
737 TreeSynchronizer::PushProperties(layer_tree_root.get(),
738 layer_impl_tree_root.get());
739 ExpectTreesAreIdentical(layer_tree_root.get(),
740 layer_impl_tree_root.get(),
741 host_impl->active_tree());
743 // The clip children should have been unhooked.
744 EXPECT_EQ(2u, intervening->children().size());
745 EXPECT_FALSE(clip_child2->clip_parent());
746 EXPECT_FALSE(additional_clip_child->clip_parent());
749 } // namespace
750 } // namespace cc