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

Side by Side Diff: cc/layer_unittest.cc

Issue 12603013: Part 10 of cc/ directory shuffles: layers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « cc/layer_iterator_unittest.cc ('k') | cc/layers/append_quads_data.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 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 "cc/layer.h"
6
7 #include "cc/animation/keyframed_animation_curve.h"
8 #include "cc/base/math_util.h"
9 #include "cc/base/thread.h"
10 #include "cc/layer_impl.h"
11 #include "cc/resources/layer_painter.h"
12 #include "cc/test/animation_test_common.h"
13 #include "cc/test/fake_impl_proxy.h"
14 #include "cc/test/fake_layer_tree_host_client.h"
15 #include "cc/test/fake_layer_tree_host_impl.h"
16 #include "cc/test/geometry_test_utils.h"
17 #include "cc/trees/layer_tree_host.h"
18 #include "cc/trees/single_thread_proxy.h"
19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "ui/gfx/transform.h"
22
23 using ::testing::AnyNumber;
24 using ::testing::AtLeast;
25 using ::testing::Mock;
26 using ::testing::StrictMock;
27 using ::testing::_;
28
29 #define EXPECT_SET_NEEDS_COMMIT(expect, codeToTest) do { \
30 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times((expect)); \
31 codeToTest; \
32 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \
33 } while (0)
34
35 #define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, codeToTest) do { \
36 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((expect)); \
37 codeToTest; \
38 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \
39 } while (0)
40
41
42 namespace cc {
43 namespace {
44
45 class MockLayerImplTreeHost : public LayerTreeHost {
46 public:
47 MockLayerImplTreeHost()
48 : LayerTreeHost(&m_fakeClient, LayerTreeSettings())
49 {
50 Initialize(scoped_ptr<Thread>(NULL));
51 }
52
53 MOCK_METHOD0(SetNeedsCommit, void());
54 MOCK_METHOD0(SetNeedsFullTreeSync, void());
55
56 private:
57 FakeLayerImplTreeHostClient m_fakeClient;
58 };
59
60 class MockLayerPainter : public LayerPainter {
61 public:
62 virtual void Paint(SkCanvas* canvas, gfx::Rect content_rect, gfx::RectF* opa que) OVERRIDE { }
63 };
64
65
66 class LayerTest : public testing::Test {
67 public:
68 LayerTest()
69 : m_hostImpl(&m_proxy)
70 {
71 }
72
73 protected:
74 virtual void SetUp()
75 {
76 layer_tree_host_.reset(new StrictMock<MockLayerImplTreeHost>);
77 }
78
79 virtual void TearDown()
80 {
81 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
82 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber() );
83 parent_ = NULL;
84 m_child1 = NULL;
85 m_child2 = NULL;
86 m_child3 = NULL;
87 m_grandChild1 = NULL;
88 m_grandChild2 = NULL;
89 m_grandChild3 = NULL;
90
91 layer_tree_host_->SetRootLayer(NULL);
92 layer_tree_host_.reset();
93 }
94
95 void verifyTestTreeInitialState() const
96 {
97 ASSERT_EQ(3U, parent_->children().size());
98 EXPECT_EQ(m_child1, parent_->children()[0]);
99 EXPECT_EQ(m_child2, parent_->children()[1]);
100 EXPECT_EQ(m_child3, parent_->children()[2]);
101 EXPECT_EQ(parent_.get(), m_child1->parent());
102 EXPECT_EQ(parent_.get(), m_child2->parent());
103 EXPECT_EQ(parent_.get(), m_child3->parent());
104
105 ASSERT_EQ(2U, m_child1->children().size());
106 EXPECT_EQ(m_grandChild1, m_child1->children()[0]);
107 EXPECT_EQ(m_grandChild2, m_child1->children()[1]);
108 EXPECT_EQ(m_child1.get(), m_grandChild1->parent());
109 EXPECT_EQ(m_child1.get(), m_grandChild2->parent());
110
111 ASSERT_EQ(1U, m_child2->children().size());
112 EXPECT_EQ(m_grandChild3, m_child2->children()[0]);
113 EXPECT_EQ(m_child2.get(), m_grandChild3->parent());
114
115 ASSERT_EQ(0U, m_child3->children().size());
116 }
117
118 void createSimpleTestTree()
119 {
120 parent_ = Layer::Create();
121 m_child1 = Layer::Create();
122 m_child2 = Layer::Create();
123 m_child3 = Layer::Create();
124 m_grandChild1 = Layer::Create();
125 m_grandChild2 = Layer::Create();
126 m_grandChild3 = Layer::Create();
127
128 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber() );
129 layer_tree_host_->SetRootLayer(parent_);
130
131 parent_->AddChild(m_child1);
132 parent_->AddChild(m_child2);
133 parent_->AddChild(m_child3);
134 m_child1->AddChild(m_grandChild1);
135 m_child1->AddChild(m_grandChild2);
136 m_child2->AddChild(m_grandChild3);
137
138 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
139
140 verifyTestTreeInitialState();
141 }
142
143 FakeImplProxy m_proxy;
144 FakeLayerTreeHostImpl m_hostImpl;
145
146 scoped_ptr<StrictMock<MockLayerImplTreeHost> > layer_tree_host_;
147 scoped_refptr<Layer> parent_;
148 scoped_refptr<Layer> m_child1;
149 scoped_refptr<Layer> m_child2;
150 scoped_refptr<Layer> m_child3;
151 scoped_refptr<Layer> m_grandChild1;
152 scoped_refptr<Layer> m_grandChild2;
153 scoped_refptr<Layer> m_grandChild3;
154 };
155
156 TEST_F(LayerTest, basicCreateAndDestroy)
157 {
158 scoped_refptr<Layer> testLayer = Layer::Create();
159 ASSERT_TRUE(testLayer);
160
161 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0);
162 testLayer->SetLayerTreeHost(layer_tree_host_.get());
163 }
164
165 TEST_F(LayerTest, addAndRemoveChild)
166 {
167 scoped_refptr<Layer> parent = Layer::Create();
168 scoped_refptr<Layer> child = Layer::Create();
169
170 // Upon creation, layers should not have children or parent.
171 ASSERT_EQ(0U, parent->children().size());
172 EXPECT_FALSE(child->parent());
173
174 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent));
175 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->AddChild(child));
176
177 ASSERT_EQ(1U, parent->children().size());
178 EXPECT_EQ(child.get(), parent->children()[0]);
179 EXPECT_EQ(parent.get(), child->parent());
180 EXPECT_EQ(parent.get(), child->RootLayer());
181
182 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), child->RemoveFromParent());
183 }
184
185 TEST_F(LayerTest, addSameChildTwice)
186 {
187 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1));
188
189 scoped_refptr<Layer> parent = Layer::Create();
190 scoped_refptr<Layer> child = Layer::Create();
191
192 layer_tree_host_->SetRootLayer(parent);
193
194 ASSERT_EQ(0u, parent->children().size());
195
196 parent->AddChild(child);
197 ASSERT_EQ(1u, parent->children().size());
198 EXPECT_EQ(parent.get(), child->parent());
199
200 parent->AddChild(child);
201 ASSERT_EQ(1u, parent->children().size());
202 EXPECT_EQ(parent.get(), child->parent());
203 }
204
205 TEST_F(LayerTest, insertChild)
206 {
207 scoped_refptr<Layer> parent = Layer::Create();
208 scoped_refptr<Layer> child1 = Layer::Create();
209 scoped_refptr<Layer> child2 = Layer::Create();
210 scoped_refptr<Layer> child3 = Layer::Create();
211 scoped_refptr<Layer> child4 = Layer::Create();
212
213 parent->SetLayerTreeHost(layer_tree_host_.get());
214
215 ASSERT_EQ(0U, parent->children().size());
216
217 // Case 1: inserting to empty list.
218 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child3, 0));
219 ASSERT_EQ(1U, parent->children().size());
220 EXPECT_EQ(child3, parent->children()[0]);
221 EXPECT_EQ(parent.get(), child3->parent());
222
223 // Case 2: inserting to beginning of list
224 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0));
225 ASSERT_EQ(2U, parent->children().size());
226 EXPECT_EQ(child1, parent->children()[0]);
227 EXPECT_EQ(child3, parent->children()[1]);
228 EXPECT_EQ(parent.get(), child1->parent());
229
230 // Case 3: inserting to middle of list
231 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1));
232 ASSERT_EQ(3U, parent->children().size());
233 EXPECT_EQ(child1, parent->children()[0]);
234 EXPECT_EQ(child2, parent->children()[1]);
235 EXPECT_EQ(child3, parent->children()[2]);
236 EXPECT_EQ(parent.get(), child2->parent());
237
238 // Case 4: inserting to end of list
239 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child4, 3));
240
241 ASSERT_EQ(4U, parent->children().size());
242 EXPECT_EQ(child1, parent->children()[0]);
243 EXPECT_EQ(child2, parent->children()[1]);
244 EXPECT_EQ(child3, parent->children()[2]);
245 EXPECT_EQ(child4, parent->children()[3]);
246 EXPECT_EQ(parent.get(), child4->parent());
247
248 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1));
249 }
250
251 TEST_F(LayerTest, insertChildPastEndOfList)
252 {
253 scoped_refptr<Layer> parent = Layer::Create();
254 scoped_refptr<Layer> child1 = Layer::Create();
255 scoped_refptr<Layer> child2 = Layer::Create();
256
257 ASSERT_EQ(0U, parent->children().size());
258
259 // insert to an out-of-bounds index
260 parent->InsertChild(child1, 53);
261
262 ASSERT_EQ(1U, parent->children().size());
263 EXPECT_EQ(child1, parent->children()[0]);
264
265 // insert another child to out-of-bounds, when list is not already empty.
266 parent->InsertChild(child2, 2459);
267
268 ASSERT_EQ(2U, parent->children().size());
269 EXPECT_EQ(child1, parent->children()[0]);
270 EXPECT_EQ(child2, parent->children()[1]);
271 }
272
273 TEST_F(LayerTest, insertSameChildTwice)
274 {
275 scoped_refptr<Layer> parent = Layer::Create();
276 scoped_refptr<Layer> child1 = Layer::Create();
277 scoped_refptr<Layer> child2 = Layer::Create();
278
279 parent->SetLayerTreeHost(layer_tree_host_.get());
280
281 ASSERT_EQ(0U, parent->children().size());
282
283 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0));
284 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1));
285
286 ASSERT_EQ(2U, parent->children().size());
287 EXPECT_EQ(child1, parent->children()[0]);
288 EXPECT_EQ(child2, parent->children()[1]);
289
290 // Inserting the same child again should cause the child to be removed and r e-inserted at the new location.
291 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent->InsertChild(child1, 1));
292
293 // child1 should now be at the end of the list.
294 ASSERT_EQ(2U, parent->children().size());
295 EXPECT_EQ(child2, parent->children()[0]);
296 EXPECT_EQ(child1, parent->children()[1]);
297
298 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1));
299 }
300
301 TEST_F(LayerTest, replaceChildWithNewChild)
302 {
303 createSimpleTestTree();
304 scoped_refptr<Layer> child4 = Layer::Create();
305
306 EXPECT_FALSE(child4->parent());
307
308 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent_->ReplaceChild(m_child2.g et(), child4));
309 EXPECT_FALSE(parent_->NeedsDisplayForTesting());
310 EXPECT_FALSE(m_child1->NeedsDisplayForTesting());
311 EXPECT_FALSE(m_child2->NeedsDisplayForTesting());
312 EXPECT_FALSE(m_child3->NeedsDisplayForTesting());
313 EXPECT_FALSE(child4->NeedsDisplayForTesting());
314
315 ASSERT_EQ(static_cast<size_t>(3), parent_->children().size());
316 EXPECT_EQ(m_child1, parent_->children()[0]);
317 EXPECT_EQ(child4, parent_->children()[1]);
318 EXPECT_EQ(m_child3, parent_->children()[2]);
319 EXPECT_EQ(parent_.get(), child4->parent());
320
321 EXPECT_FALSE(m_child2->parent());
322 }
323
324 TEST_F(LayerTest, replaceChildWithNewChildAutomaticRasterScale)
325 {
326 createSimpleTestTree();
327 scoped_refptr<Layer> child4 = Layer::Create();
328 EXPECT_SET_NEEDS_COMMIT(1, m_child1->SetAutomaticallyComputeRasterScale(true ));
329 EXPECT_SET_NEEDS_COMMIT(1, m_child2->SetAutomaticallyComputeRasterScale(true ));
330 EXPECT_SET_NEEDS_COMMIT(1, m_child3->SetAutomaticallyComputeRasterScale(true ));
331
332 EXPECT_FALSE(child4->parent());
333
334 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent_->ReplaceChild(m_child2.g et(), child4));
335 EXPECT_FALSE(parent_->NeedsDisplayForTesting());
336 EXPECT_FALSE(m_child1->NeedsDisplayForTesting());
337 EXPECT_FALSE(m_child2->NeedsDisplayForTesting());
338 EXPECT_FALSE(m_child3->NeedsDisplayForTesting());
339 EXPECT_FALSE(child4->NeedsDisplayForTesting());
340
341 ASSERT_EQ(3U, parent_->children().size());
342 EXPECT_EQ(m_child1, parent_->children()[0]);
343 EXPECT_EQ(child4, parent_->children()[1]);
344 EXPECT_EQ(m_child3, parent_->children()[2]);
345 EXPECT_EQ(parent_.get(), child4->parent());
346
347 EXPECT_FALSE(m_child2->parent());
348 }
349
350 TEST_F(LayerTest, replaceChildWithNewChildThatHasOtherParent)
351 {
352 createSimpleTestTree();
353
354 // create another simple tree with testLayer and child4.
355 scoped_refptr<Layer> testLayer = Layer::Create();
356 scoped_refptr<Layer> child4 = Layer::Create();
357 testLayer->AddChild(child4);
358 ASSERT_EQ(1U, testLayer->children().size());
359 EXPECT_EQ(child4, testLayer->children()[0]);
360 EXPECT_EQ(testLayer.get(), child4->parent());
361
362 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent_->ReplaceChild(m_child2.g et(), child4));
363
364 ASSERT_EQ(3U, parent_->children().size());
365 EXPECT_EQ(m_child1, parent_->children()[0]);
366 EXPECT_EQ(child4, parent_->children()[1]);
367 EXPECT_EQ(m_child3, parent_->children()[2]);
368 EXPECT_EQ(parent_.get(), child4->parent());
369
370 // testLayer should no longer have child4,
371 // and child2 should no longer have a parent.
372 ASSERT_EQ(0U, testLayer->children().size());
373 EXPECT_FALSE(m_child2->parent());
374 }
375
376 TEST_F(LayerTest, replaceChildWithSameChild)
377 {
378 createSimpleTestTree();
379
380 // SetNeedsFullTreeSync / SetNeedsCommit should not be called because its th e same child
381 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0);
382 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(0);
383 parent_->ReplaceChild(m_child2.get(), m_child2);
384
385 verifyTestTreeInitialState();
386 }
387
388 TEST_F(LayerTest, removeAllChildren)
389 {
390 createSimpleTestTree();
391
392 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(3), parent_->RemoveAllChildren());
393
394 ASSERT_EQ(0U, parent_->children().size());
395 EXPECT_FALSE(m_child1->parent());
396 EXPECT_FALSE(m_child2->parent());
397 EXPECT_FALSE(m_child3->parent());
398 }
399
400 TEST_F(LayerTest, setChildren)
401 {
402 scoped_refptr<Layer> oldParent = Layer::Create();
403 scoped_refptr<Layer> newParent = Layer::Create();
404
405 scoped_refptr<Layer> child1 = Layer::Create();
406 scoped_refptr<Layer> child2 = Layer::Create();
407
408 std::vector<scoped_refptr<Layer> > newChildren;
409 newChildren.push_back(child1);
410 newChildren.push_back(child2);
411
412 // Set up and verify initial test conditions: child1 has a parent, child2 ha s no parent.
413 oldParent->AddChild(child1);
414 ASSERT_EQ(0U, newParent->children().size());
415 EXPECT_EQ(oldParent.get(), child1->parent());
416 EXPECT_FALSE(child2->parent());
417
418 newParent->SetLayerTreeHost(layer_tree_host_.get());
419
420 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), newParent->SetChildren(newChildr en));
421
422 ASSERT_EQ(2U, newParent->children().size());
423 EXPECT_EQ(newParent.get(), child1->parent());
424 EXPECT_EQ(newParent.get(), child2->parent());
425
426 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1));
427 }
428
429 TEST_F(LayerTest, getRootLayerAfterTreeManipulations)
430 {
431 createSimpleTestTree();
432
433 // For this test we don't care about SetNeedsFullTreeSync calls.
434 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber());
435
436 scoped_refptr<Layer> child4 = Layer::Create();
437
438 EXPECT_EQ(parent_.get(), parent_->RootLayer());
439 EXPECT_EQ(parent_.get(), m_child1->RootLayer());
440 EXPECT_EQ(parent_.get(), m_child2->RootLayer());
441 EXPECT_EQ(parent_.get(), m_child3->RootLayer());
442 EXPECT_EQ(child4.get(), child4->RootLayer());
443 EXPECT_EQ(parent_.get(), m_grandChild1->RootLayer());
444 EXPECT_EQ(parent_.get(), m_grandChild2->RootLayer());
445 EXPECT_EQ(parent_.get(), m_grandChild3->RootLayer());
446
447 m_child1->RemoveFromParent();
448
449 // child1 and its children, grandChild1 and grandChild2 are now on a separat e subtree.
450 EXPECT_EQ(parent_.get(), parent_->RootLayer());
451 EXPECT_EQ(m_child1.get(), m_child1->RootLayer());
452 EXPECT_EQ(parent_.get(), m_child2->RootLayer());
453 EXPECT_EQ(parent_.get(), m_child3->RootLayer());
454 EXPECT_EQ(child4.get(), child4->RootLayer());
455 EXPECT_EQ(m_child1.get(), m_grandChild1->RootLayer());
456 EXPECT_EQ(m_child1.get(), m_grandChild2->RootLayer());
457 EXPECT_EQ(parent_.get(), m_grandChild3->RootLayer());
458
459 m_grandChild3->AddChild(child4);
460
461 EXPECT_EQ(parent_.get(), parent_->RootLayer());
462 EXPECT_EQ(m_child1.get(), m_child1->RootLayer());
463 EXPECT_EQ(parent_.get(), m_child2->RootLayer());
464 EXPECT_EQ(parent_.get(), m_child3->RootLayer());
465 EXPECT_EQ(parent_.get(), child4->RootLayer());
466 EXPECT_EQ(m_child1.get(), m_grandChild1->RootLayer());
467 EXPECT_EQ(m_child1.get(), m_grandChild2->RootLayer());
468 EXPECT_EQ(parent_.get(), m_grandChild3->RootLayer());
469
470 m_child2->ReplaceChild(m_grandChild3.get(), m_child1);
471
472 // grandChild3 gets orphaned and the child1 subtree gets planted back into t he tree under child2.
473 EXPECT_EQ(parent_.get(), parent_->RootLayer());
474 EXPECT_EQ(parent_.get(), m_child1->RootLayer());
475 EXPECT_EQ(parent_.get(), m_child2->RootLayer());
476 EXPECT_EQ(parent_.get(), m_child3->RootLayer());
477 EXPECT_EQ(m_grandChild3.get(), child4->RootLayer());
478 EXPECT_EQ(parent_.get(), m_grandChild1->RootLayer());
479 EXPECT_EQ(parent_.get(), m_grandChild2->RootLayer());
480 EXPECT_EQ(m_grandChild3.get(), m_grandChild3->RootLayer());
481 }
482
483 TEST_F(LayerTest, checkSetNeedsDisplayCausesCorrectBehavior)
484 {
485 // The semantics for setNeedsDisplay which are tested here:
486 // 1. sets needsDisplay flag appropriately.
487 // 2. indirectly calls SetNeedsCommit, exactly once for each call to setNe edsDisplay.
488
489 scoped_refptr<Layer> testLayer = Layer::Create();
490 testLayer->SetLayerTreeHost(layer_tree_host_.get());
491 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetIsDrawable(true));
492
493 gfx::Size testBounds = gfx::Size(501, 508);
494
495 gfx::RectF dirty1 = gfx::RectF(10, 15, 1, 2);
496 gfx::RectF dirty2 = gfx::RectF(20, 25, 3, 4);
497 gfx::RectF emptyDirtyRect = gfx::RectF(40, 45, 0, 0);
498 gfx::RectF outOfBoundsDirtyRect = gfx::RectF(400, 405, 500, 502);
499
500 // Before anything, testLayer should not be dirty.
501 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
502
503 // This is just initialization, but SetNeedsCommit behavior is verified anyw ay to avoid warnings.
504 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetBounds(testBounds));
505 EXPECT_TRUE(testLayer->NeedsDisplayForTesting());
506
507 // The real test begins here.
508 testLayer->ResetNeedsDisplayForTesting();
509 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
510
511 // Case 1: Layer should accept dirty rects that go beyond its bounds.
512 testLayer->ResetNeedsDisplayForTesting();
513 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
514 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetNeedsDisplayRect(outOfBoundsDirtyRe ct));
515 EXPECT_TRUE(testLayer->NeedsDisplayForTesting());
516 testLayer->ResetNeedsDisplayForTesting();
517
518 // Case 2: SetNeedsDisplay() without the dirty rect arg.
519 testLayer->ResetNeedsDisplayForTesting();
520 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
521 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetNeedsDisplay());
522 EXPECT_TRUE(testLayer->NeedsDisplayForTesting());
523 testLayer->ResetNeedsDisplayForTesting();
524
525 // Case 3: SetNeedsDisplay() with a non-drawable layer
526 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetIsDrawable(false));
527 testLayer->ResetNeedsDisplayForTesting();
528 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
529 EXPECT_SET_NEEDS_COMMIT(0, testLayer->SetNeedsDisplayRect(dirty1));
530 EXPECT_TRUE(testLayer->NeedsDisplayForTesting());
531 }
532
533 TEST_F(LayerTest, checkPropertyChangeCausesCorrectBehavior)
534 {
535 scoped_refptr<Layer> testLayer = Layer::Create();
536 testLayer->SetLayerTreeHost(layer_tree_host_.get());
537 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetIsDrawable(true));
538
539 scoped_refptr<Layer> dummyLayer1 = Layer::Create(); // just a dummy layer fo r this test case.
540 scoped_refptr<Layer> dummyLayer2 = Layer::Create(); // just a dummy layer fo r this test case.
541
542 // sanity check of initial test condition
543 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
544
545 // Next, test properties that should call SetNeedsCommit (but not setNeedsDi splay)
546 // All properties need to be set to new values in order for SetNeedsCommit t o be called.
547 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetAnchorPoint(gfx::PointF(1.23f, 4.56 f)));
548 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetAnchorPointZ(0.7f));
549 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetBackgroundColor(SK_ColorLTGRAY));
550 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetMasksToBounds(true));
551 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetOpacity(0.5));
552 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetContentsOpaque(true));
553 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetPosition(gfx::PointF(4, 9)));
554 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetSublayerTransform(gfx::Transform(0. 0, 0.0, 0.0, 0.0, 0.0, 0.0)));
555 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetScrollable(true));
556 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetScrollOffset(gfx::Vector2d(10, 10)) );
557 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetShouldScrollOnMainThread(true));
558 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetNonFastScrollableRegion(gfx::Rect(1 , 1, 2, 2)));
559 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetHaveWheelEventHandlers(true));
560 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetTransform(gfx::Transform(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)));
561 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetDoubleSided(false));
562 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetDebugName("Test Layer"));
563 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetDrawCheckerboardForMissingTiles(!te stLayer->DrawCheckerboardForMissingTiles()));
564 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetForceRenderSurface(true));
565
566 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, testLayer->SetMaskLayer(dummyLayer1.get() ));
567 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, testLayer->SetReplicaLayer(dummyLayer2.ge t()));
568
569 // The above tests should not have caused a change to the needsDisplay flag.
570 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
571
572 // As layers are removed from the tree, they will cause a tree sync.
573 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((AnyNumber()));
574 }
575
576 TEST_F(LayerTest, setBoundsTriggersSetNeedsRedrawAfterGettingNonEmptyBounds)
577 {
578 scoped_refptr<Layer> testLayer = Layer::Create();
579 testLayer->SetLayerTreeHost(layer_tree_host_.get());
580 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetIsDrawable(true));
581
582 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
583 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetBounds(gfx::Size(0, 10)));
584 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
585 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetBounds(gfx::Size(10, 10)));
586 EXPECT_TRUE(testLayer->NeedsDisplayForTesting());
587
588 testLayer->ResetNeedsDisplayForTesting();
589 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
590
591 // Calling setBounds only invalidates on the first time.
592 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetBounds(gfx::Size(7, 10)));
593 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
594 }
595
596 TEST_F(LayerTest, verifyPushPropertiesAccumulatesUpdateRect)
597 {
598 scoped_refptr<Layer> testLayer = Layer::Create();
599 scoped_ptr<LayerImpl> implLayer = LayerImpl::Create(m_hostImpl.active_tree() , 1);
600
601 testLayer->SetNeedsDisplayRect(gfx::RectF(gfx::PointF(), gfx::SizeF(5, 5)));
602 testLayer->PushPropertiesTo(implLayer.get());
603 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(), gfx::SizeF(5, 5)), implLayer- >update_rect());
604
605 // The LayerImpl's updateRect should be accumulated here, since we did not d o anything to clear it.
606 testLayer->SetNeedsDisplayRect(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5, 5)));
607 testLayer->PushPropertiesTo(implLayer.get());
608 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(), gfx::SizeF(15, 15)), implLaye r->update_rect());
609
610 // If we do clear the LayerImpl side, then the next updateRect should be fre sh without accumulation.
611 implLayer->ResetAllChangeTrackingForSubtree();
612 testLayer->SetNeedsDisplayRect(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5, 5)));
613 testLayer->PushPropertiesTo(implLayer.get());
614 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5, 5)), impl Layer->update_rect());
615 }
616
617 TEST_F(LayerTest, verifyPushPropertiesCausesSurfacePropertyChangedForTransform)
618 {
619 scoped_refptr<Layer> testLayer = Layer::Create();
620 scoped_ptr<LayerImpl> implLayer = LayerImpl::Create(m_hostImpl.active_tree() , 1);
621
622 gfx::Transform transform;
623 transform.Rotate(45.0);
624 testLayer->SetTransform(transform);
625
626 EXPECT_FALSE(implLayer->LayerSurfacePropertyChanged());
627
628 testLayer->PushPropertiesTo(implLayer.get());
629
630 EXPECT_TRUE(implLayer->LayerSurfacePropertyChanged());
631 }
632
633 TEST_F(LayerTest, verifyPushPropertiesCausesSurfacePropertyChangedForOpacity)
634 {
635 scoped_refptr<Layer> testLayer = Layer::Create();
636 scoped_ptr<LayerImpl> implLayer = LayerImpl::Create(m_hostImpl.active_tree() , 1);
637
638 testLayer->SetOpacity(0.5);
639
640 EXPECT_FALSE(implLayer->LayerSurfacePropertyChanged());
641
642 testLayer->PushPropertiesTo(implLayer.get());
643
644 EXPECT_TRUE(implLayer->LayerSurfacePropertyChanged());
645 }
646
647 TEST_F(LayerTest, verifyPushPropertiesDoesNotCauseSurfacePropertyChangedDuringIm plOnlyTransformAnimation)
648 {
649 scoped_refptr<Layer> testLayer = Layer::Create();
650 scoped_ptr<LayerImpl> implLayer = LayerImpl::Create(m_hostImpl.active_tree() , 1);
651
652 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::create();
653 implLayer->layer_animation_controller()->SetAnimationRegistrar(registrar.get ());
654
655 addAnimatedTransformToController(*implLayer->layer_animation_controller(), 1 .0, 0, 100);
656
657 gfx::Transform transform;
658 transform.Rotate(45.0);
659 testLayer->SetTransform(transform);
660
661 EXPECT_FALSE(implLayer->LayerSurfacePropertyChanged());
662 testLayer->PushPropertiesTo(implLayer.get());
663 EXPECT_TRUE(implLayer->LayerSurfacePropertyChanged());
664
665 implLayer->ResetAllChangeTrackingForSubtree();
666 addAnimatedTransformToController(*implLayer->layer_animation_controller(), 1 .0, 0, 100);
667 implLayer->layer_animation_controller()->GetAnimation(Animation::Transform)- >set_is_impl_only(true);
668 transform.Rotate(45.0);
669 testLayer->SetTransform(transform);
670
671 EXPECT_FALSE(implLayer->LayerSurfacePropertyChanged());
672 testLayer->PushPropertiesTo(implLayer.get());
673 EXPECT_FALSE(implLayer->LayerSurfacePropertyChanged());
674 }
675
676 TEST_F(LayerTest, verifyPushPropertiesDoesNotCauseSurfacePropertyChangedDuringIm plOnlyOpacityAnimation)
677 {
678 scoped_refptr<Layer> testLayer = Layer::Create();
679 scoped_ptr<LayerImpl> implLayer = LayerImpl::Create(m_hostImpl.active_tree() , 1);
680
681 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::create();
682 implLayer->layer_animation_controller()->SetAnimationRegistrar(registrar.get ());
683
684 addOpacityTransitionToController(*implLayer->layer_animation_controller(), 1 .0, 0.3f, 0.7f, false);
685
686 testLayer->SetOpacity(0.5f);
687
688 EXPECT_FALSE(implLayer->LayerSurfacePropertyChanged());
689 testLayer->PushPropertiesTo(implLayer.get());
690 EXPECT_TRUE(implLayer->LayerSurfacePropertyChanged());
691
692 implLayer->ResetAllChangeTrackingForSubtree();
693 addOpacityTransitionToController(*implLayer->layer_animation_controller(), 1 .0, 0.3f, 0.7f, false);
694 implLayer->layer_animation_controller()->GetAnimation(Animation::Opacity)->s et_is_impl_only(true);
695 testLayer->SetOpacity(0.75f);
696
697 EXPECT_FALSE(implLayer->LayerSurfacePropertyChanged());
698 testLayer->PushPropertiesTo(implLayer.get());
699 EXPECT_FALSE(implLayer->LayerSurfacePropertyChanged());
700 }
701
702
703 TEST_F(LayerTest, maskAndReplicaHasParent)
704 {
705 scoped_refptr<Layer> parent = Layer::Create();
706 scoped_refptr<Layer> child = Layer::Create();
707 scoped_refptr<Layer> mask = Layer::Create();
708 scoped_refptr<Layer> replica = Layer::Create();
709 scoped_refptr<Layer> replicaMask = Layer::Create();
710 scoped_refptr<Layer> maskReplacement = Layer::Create();
711 scoped_refptr<Layer> replicaReplacement = Layer::Create();
712 scoped_refptr<Layer> replicaMaskReplacement = Layer::Create();
713
714 parent->AddChild(child);
715 child->SetMaskLayer(mask.get());
716 child->SetReplicaLayer(replica.get());
717 replica->SetMaskLayer(replicaMask.get());
718
719 EXPECT_EQ(parent, child->parent());
720 EXPECT_EQ(child, mask->parent());
721 EXPECT_EQ(child, replica->parent());
722 EXPECT_EQ(replica, replicaMask->parent());
723
724 replica->SetMaskLayer(replicaMaskReplacement.get());
725 EXPECT_EQ(NULL, replicaMask->parent());
726 EXPECT_EQ(replica, replicaMaskReplacement->parent());
727
728 child->SetMaskLayer(maskReplacement.get());
729 EXPECT_EQ(NULL, mask->parent());
730 EXPECT_EQ(child, maskReplacement->parent());
731
732 child->SetReplicaLayer(replicaReplacement.get());
733 EXPECT_EQ(NULL, replica->parent());
734 EXPECT_EQ(child, replicaReplacement->parent());
735
736 EXPECT_EQ(replica, replica->mask_layer()->parent());
737 }
738
739 class FakeLayerImplTreeHost : public LayerTreeHost {
740 public:
741 static scoped_ptr<FakeLayerImplTreeHost> Create()
742 {
743 scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost(LayerTr eeSettings()));
744 // The initialize call will fail, since our client doesn't provide a val id GraphicsContext3D, but it doesn't matter in the tests that use this fake so i gnore the return value.
745 host->Initialize(scoped_ptr<Thread>(NULL));
746 return host.Pass();
747 }
748
749 static scoped_ptr<FakeLayerImplTreeHost> Create(LayerTreeSettings settings)
750 {
751 scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost(setting s));
752 host->Initialize(scoped_ptr<Thread>(NULL));
753 return host.Pass();
754 }
755
756 private:
757 FakeLayerImplTreeHost(const LayerTreeSettings& settings)
758 : LayerTreeHost(&m_client, settings)
759 {
760 }
761
762 FakeLayerImplTreeHostClient m_client;
763 };
764
765 void assertLayerTreeHostMatchesForSubtree(Layer* layer, LayerTreeHost* host)
766 {
767 EXPECT_EQ(host, layer->layer_tree_host());
768
769 for (size_t i = 0; i < layer->children().size(); ++i)
770 assertLayerTreeHostMatchesForSubtree(layer->children()[i].get(), host);
771
772 if (layer->mask_layer())
773 assertLayerTreeHostMatchesForSubtree(layer->mask_layer(), host);
774
775 if (layer->replica_layer())
776 assertLayerTreeHostMatchesForSubtree(layer->replica_layer(), host);
777 }
778
779 TEST(LayerLayerTreeHostTest, enteringTree)
780 {
781 scoped_refptr<Layer> parent = Layer::Create();
782 scoped_refptr<Layer> child = Layer::Create();
783 scoped_refptr<Layer> mask = Layer::Create();
784 scoped_refptr<Layer> replica = Layer::Create();
785 scoped_refptr<Layer> replicaMask = Layer::Create();
786
787 // Set up a detached tree of layers. The host pointer should be nil for thes e layers.
788 parent->AddChild(child);
789 child->SetMaskLayer(mask.get());
790 child->SetReplicaLayer(replica.get());
791 replica->SetMaskLayer(replicaMask.get());
792
793 assertLayerTreeHostMatchesForSubtree(parent.get(), 0);
794
795 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::Creat e());
796 // Setting the root layer should set the host pointer for all layers in the tree.
797 layerTreeHost->SetRootLayer(parent.get());
798
799 assertLayerTreeHostMatchesForSubtree(parent.get(), layerTreeHost.get());
800
801 // Clearing the root layer should also clear out the host pointers for all l ayers in the tree.
802 layerTreeHost->SetRootLayer(NULL);
803
804 assertLayerTreeHostMatchesForSubtree(parent.get(), 0);
805 }
806
807 TEST(LayerLayerTreeHostTest, addingLayerSubtree)
808 {
809 scoped_refptr<Layer> parent = Layer::Create();
810 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::Creat e());
811
812 layerTreeHost->SetRootLayer(parent.get());
813
814 EXPECT_EQ(parent->layer_tree_host(), layerTreeHost.get());
815
816 // Adding a subtree to a layer already associated with a host should set the host pointer on all layers in that subtree.
817 scoped_refptr<Layer> child = Layer::Create();
818 scoped_refptr<Layer> grandChild = Layer::Create();
819 child->AddChild(grandChild);
820
821 // Masks, replicas, and replica masks should pick up the new host too.
822 scoped_refptr<Layer> childMask = Layer::Create();
823 child->SetMaskLayer(childMask.get());
824 scoped_refptr<Layer> childReplica = Layer::Create();
825 child->SetReplicaLayer(childReplica.get());
826 scoped_refptr<Layer> childReplicaMask = Layer::Create();
827 childReplica->SetMaskLayer(childReplicaMask.get());
828
829 parent->AddChild(child);
830 assertLayerTreeHostMatchesForSubtree(parent.get(), layerTreeHost.get());
831
832 layerTreeHost->SetRootLayer(NULL);
833 }
834
835 TEST(LayerLayerTreeHostTest, changeHost)
836 {
837 scoped_refptr<Layer> parent = Layer::Create();
838 scoped_refptr<Layer> child = Layer::Create();
839 scoped_refptr<Layer> mask = Layer::Create();
840 scoped_refptr<Layer> replica = Layer::Create();
841 scoped_refptr<Layer> replicaMask = Layer::Create();
842
843 // Same setup as the previous test.
844 parent->AddChild(child);
845 child->SetMaskLayer(mask.get());
846 child->SetReplicaLayer(replica.get());
847 replica->SetMaskLayer(replicaMask.get());
848
849 scoped_ptr<FakeLayerImplTreeHost> firstLayerTreeHost(FakeLayerImplTreeHost:: Create());
850 firstLayerTreeHost->SetRootLayer(parent.get());
851
852 assertLayerTreeHostMatchesForSubtree(parent.get(), firstLayerTreeHost.get()) ;
853
854 // Now re-root the tree to a new host (simulating what we do on a context lo st event).
855 // This should update the host pointers for all layers in the tree.
856 scoped_ptr<FakeLayerImplTreeHost> secondLayerTreeHost(FakeLayerImplTreeHost: :Create());
857 secondLayerTreeHost->SetRootLayer(parent.get());
858
859 assertLayerTreeHostMatchesForSubtree(parent.get(), secondLayerTreeHost.get() );
860
861 secondLayerTreeHost->SetRootLayer(NULL);
862 }
863
864 TEST(LayerLayerTreeHostTest, changeHostInSubtree)
865 {
866 scoped_refptr<Layer> firstParent = Layer::Create();
867 scoped_refptr<Layer> firstChild = Layer::Create();
868 scoped_refptr<Layer> secondParent = Layer::Create();
869 scoped_refptr<Layer> secondChild = Layer::Create();
870 scoped_refptr<Layer> secondGrandChild = Layer::Create();
871
872 // First put all children under the first parent and set the first host.
873 firstParent->AddChild(firstChild);
874 secondChild->AddChild(secondGrandChild);
875 firstParent->AddChild(secondChild);
876
877 scoped_ptr<FakeLayerImplTreeHost> firstLayerTreeHost(FakeLayerImplTreeHost:: Create());
878 firstLayerTreeHost->SetRootLayer(firstParent.get());
879
880 assertLayerTreeHostMatchesForSubtree(firstParent.get(), firstLayerTreeHost.g et());
881
882 // Now reparent the subtree starting at secondChild to a layer in a differen t tree.
883 scoped_ptr<FakeLayerImplTreeHost> secondLayerTreeHost(FakeLayerImplTreeHost: :Create());
884 secondLayerTreeHost->SetRootLayer(secondParent.get());
885
886 secondParent->AddChild(secondChild);
887
888 // The moved layer and its children should point to the new host.
889 EXPECT_EQ(secondLayerTreeHost.get(), secondChild->layer_tree_host());
890 EXPECT_EQ(secondLayerTreeHost.get(), secondGrandChild->layer_tree_host());
891
892 // Test over, cleanup time.
893 firstLayerTreeHost->SetRootLayer(NULL);
894 secondLayerTreeHost->SetRootLayer(NULL);
895 }
896
897 TEST(LayerLayerTreeHostTest, replaceMaskAndReplicaLayer)
898 {
899 scoped_refptr<Layer> parent = Layer::Create();
900 scoped_refptr<Layer> mask = Layer::Create();
901 scoped_refptr<Layer> replica = Layer::Create();
902 scoped_refptr<Layer> maskChild = Layer::Create();
903 scoped_refptr<Layer> replicaChild = Layer::Create();
904 scoped_refptr<Layer> maskReplacement = Layer::Create();
905 scoped_refptr<Layer> replicaReplacement = Layer::Create();
906
907 parent->SetMaskLayer(mask.get());
908 parent->SetReplicaLayer(replica.get());
909 mask->AddChild(maskChild);
910 replica->AddChild(replicaChild);
911
912 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::Creat e());
913 layerTreeHost->SetRootLayer(parent.get());
914
915 assertLayerTreeHostMatchesForSubtree(parent.get(), layerTreeHost.get());
916
917 // Replacing the mask should clear out the old mask's subtree's host pointer s.
918 parent->SetMaskLayer(maskReplacement.get());
919 EXPECT_EQ(0, mask->layer_tree_host());
920 EXPECT_EQ(0, maskChild->layer_tree_host());
921
922 // Same for replacing a replica layer.
923 parent->SetReplicaLayer(replicaReplacement.get());
924 EXPECT_EQ(0, replica->layer_tree_host());
925 EXPECT_EQ(0, replicaChild->layer_tree_host());
926
927 // Test over, cleanup time.
928 layerTreeHost->SetRootLayer(NULL);
929 }
930
931 TEST(LayerLayerTreeHostTest, destroyHostWithNonNullRootLayer)
932 {
933 scoped_refptr<Layer> root = Layer::Create();
934 scoped_refptr<Layer> child = Layer::Create();
935 root->AddChild(child);
936 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::Creat e());
937 layerTreeHost->SetRootLayer(root);
938 }
939
940 static bool addTestAnimation(Layer* layer)
941 {
942 scoped_ptr<KeyframedFloatAnimationCurve> curve(KeyframedFloatAnimationCurve: :Create());
943 curve->AddKeyframe(FloatKeyframe::Create(0.0, 0.3f, scoped_ptr<TimingFunctio n>()));
944 curve->AddKeyframe(FloatKeyframe::Create(1.0, 0.7f, scoped_ptr<TimingFunctio n>()));
945 scoped_ptr<Animation> animation(Animation::Create(curve.PassAs<AnimationCurv e>(), 0, 0, Animation::Opacity));
946
947 return layer->AddAnimation(animation.Pass());
948 }
949
950 TEST(LayerLayerTreeHostTest, shouldNotAddAnimationWithoutAnimationRegistrar)
951 {
952 scoped_refptr<Layer> layer = Layer::Create();
953
954 // Case 1: without a LayerTreeHost and without an AnimationRegistrar, the
955 // animation should not be accepted.
956 EXPECT_FALSE(addTestAnimation(layer.get()));
957
958 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::create();
959 layer->layer_animation_controller()->SetAnimationRegistrar(registrar.get());
960
961 // Case 2: with an AnimationRegistrar, the animation should be accepted.
962 EXPECT_TRUE(addTestAnimation(layer.get()));
963
964 LayerTreeSettings settings;
965 settings.acceleratedAnimationEnabled = false;
966 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::Creat e(settings));
967 layerTreeHost->SetRootLayer(layer);
968 layer->SetLayerTreeHost(layerTreeHost.get());
969 assertLayerTreeHostMatchesForSubtree(layer.get(), layerTreeHost.get());
970
971 // Case 3: with a LayerTreeHost where accelerated animation is disabled, the
972 // animation should be rejected.
973 EXPECT_FALSE(addTestAnimation(layer.get()));
974 }
975
976 } // namespace
977 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer_iterator_unittest.cc ('k') | cc/layers/append_quads_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698