OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/layout/compositing/PaintLayerCompositor.h" |
| 6 |
| 7 #include "core/animation/Animation.h" |
| 8 #include "core/animation/ElementAnimation.h" |
| 9 #include "core/layout/LayoutTestHelper.h" |
| 10 #include "core/paint/PaintLayer.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 namespace { |
| 15 class PaintLayerCompositorTest : public RenderingTest { |
| 16 public: |
| 17 PaintLayerCompositorTest() |
| 18 : RenderingTest(SingleChildLocalFrameClient::Create()) {} |
| 19 |
| 20 private: |
| 21 void SetUp() { |
| 22 RenderingTest::SetUp(); |
| 23 EnableCompositing(); |
| 24 } |
| 25 }; |
| 26 } |
| 27 |
| 28 TEST_F(PaintLayerCompositorTest, AdvancingToCompositingInputsClean) { |
| 29 SetBodyInnerHTML("<div id='box' style='position: relative'></div>"); |
| 30 |
| 31 PaintLayer* box_layer = |
| 32 ToLayoutBox(GetLayoutObjectByElementId("box"))->Layer(); |
| 33 ASSERT_TRUE(box_layer); |
| 34 EXPECT_FALSE(box_layer->NeedsCompositingInputsUpdate()); |
| 35 |
| 36 box_layer->SetNeedsCompositingInputsUpdate(); |
| 37 |
| 38 GetDocument().View()->UpdateLifecycleToCompositingInputsClean(); |
| 39 EXPECT_EQ(DocumentLifecycle::kCompositingInputsClean, |
| 40 GetDocument().Lifecycle().GetState()); |
| 41 EXPECT_FALSE(box_layer->NeedsCompositingInputsUpdate()); |
| 42 } |
| 43 |
| 44 TEST_F(PaintLayerCompositorTest, |
| 45 CompositingInputsCleanDoesNotTriggerAnimations) { |
| 46 SetBodyInnerHTML( |
| 47 "<style>@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }" |
| 48 ".animate { animation: fadeOut 2s; }</style>" |
| 49 "<div id='box'></div>" |
| 50 "<div id='otherBox'></div>"); |
| 51 |
| 52 Element* box = GetDocument().GetElementById("box"); |
| 53 Element* otherBox = GetDocument().GetElementById("otherBox"); |
| 54 ASSERT_TRUE(box); |
| 55 ASSERT_TRUE(otherBox); |
| 56 |
| 57 box->setAttribute("class", "animate", ASSERT_NO_EXCEPTION); |
| 58 |
| 59 // Update the lifecycle to CompositingInputsClean. This should not start the |
| 60 // animation lifecycle. |
| 61 GetDocument().View()->UpdateLifecycleToCompositingInputsClean(); |
| 62 EXPECT_EQ(DocumentLifecycle::kCompositingInputsClean, |
| 63 GetDocument().Lifecycle().GetState()); |
| 64 |
| 65 otherBox->setAttribute("class", "animate", ASSERT_NO_EXCEPTION); |
| 66 |
| 67 // Now run the rest of the lifecycle. Because both 'box' and 'otherBox' were |
| 68 // given animations separated only by a lifecycle update to |
| 69 // CompositingInputsClean, they should both be started in the same lifecycle |
| 70 // and as such grouped together. |
| 71 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 72 EXPECT_EQ(DocumentLifecycle::kPaintClean, |
| 73 GetDocument().Lifecycle().GetState()); |
| 74 |
| 75 HeapVector<Member<Animation>> boxAnimations = |
| 76 ElementAnimation::getAnimations(*box); |
| 77 HeapVector<Member<Animation>> otherBoxAnimations = |
| 78 ElementAnimation::getAnimations(*box); |
| 79 |
| 80 EXPECT_EQ(1ul, boxAnimations.size()); |
| 81 EXPECT_EQ(1ul, otherBoxAnimations.size()); |
| 82 EXPECT_EQ(boxAnimations.front()->CompositorGroup(), |
| 83 otherBoxAnimations.front()->CompositorGroup()); |
| 84 } |
| 85 } |
OLD | NEW |