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/animation/ElementAnimation.h" |
| 6 #include "core/css/PropertyDescriptor.h" |
| 7 #include "core/css/PropertyRegistration.h" |
| 8 #include "public/web/WebScriptSource.h" |
| 9 #include "web/WebLocalFrameImpl.h" |
| 10 #include "web/tests/sim/SimCompositor.h" |
| 11 #include "web/tests/sim/SimDisplayItemList.h" |
| 12 #include "web/tests/sim/SimRequest.h" |
| 13 #include "web/tests/sim/SimTest.h" |
| 14 |
| 15 namespace blink { |
| 16 |
| 17 class AnimationSimTest : public SimTest {}; |
| 18 |
| 19 TEST_F(AnimationSimTest, CustomPropertyBaseComputedStyle) { |
| 20 // This is a regression test for bug where custom property animations failed |
| 21 // to disable the baseComputedStyle optimisation. When custom property |
| 22 // animations are in effect we lose the guarantee that the baseComputedStyle |
| 23 // optimisation relies on where the non-animated style rules always produce |
| 24 // the same ComputedStyle. This is not the case if they use var() references |
| 25 // to custom properties that are being animated. |
| 26 // The bug was that we never cleared the existing baseComputedStyle during a |
| 27 // custom property animation so the stale ComputedStyle object would hang |
| 28 // around and not be valid in the exit frame of the next custom property |
| 29 // animation. |
| 30 |
| 31 RuntimeEnabledFeatures::setCSSVariables2Enabled(true); |
| 32 RuntimeEnabledFeatures::setCSSAdditiveAnimationsEnabled(true); |
| 33 RuntimeEnabledFeatures::setStackedCSSPropertyAnimationsEnabled(true); |
| 34 |
| 35 SimRequest mainResource("https://example.com/", "text/html"); |
| 36 loadURL("https://example.com/"); |
| 37 mainResource.complete("<div id=\"target\"></div>"); |
| 38 |
| 39 Element* target = document().getElementById("target"); |
| 40 |
| 41 // CSS.registerProperty({ |
| 42 // name: '--x', |
| 43 // syntax: '<percentage>', |
| 44 // initialValue: '0%', |
| 45 // }) |
| 46 DummyExceptionStateForTesting exceptionState; |
| 47 PropertyDescriptor propertyDescriptor; |
| 48 propertyDescriptor.setName("--x"); |
| 49 propertyDescriptor.setSyntax("<percentage>"); |
| 50 propertyDescriptor.setInitialValue("0%"); |
| 51 PropertyRegistration::registerProperty(&document(), propertyDescriptor, |
| 52 exceptionState); |
| 53 EXPECT_FALSE(exceptionState.hadException()); |
| 54 |
| 55 // target.style.setProperty('--x', '100%'); |
| 56 target->style()->setProperty("--x", "100%", emptyString, exceptionState); |
| 57 EXPECT_FALSE(exceptionState.hadException()); |
| 58 |
| 59 // target.animate({'--x': '100%'}, 1000); |
| 60 RefPtr<StringKeyframe> keyframe = StringKeyframe::create(); |
| 61 keyframe->setCSSPropertyValue("--x", document().propertyRegistry(), "100%", |
| 62 document().elementSheet().contents()); |
| 63 StringKeyframeVector keyframes; |
| 64 keyframes.push_back(keyframe.release()); |
| 65 Timing timing; |
| 66 timing.iterationDuration = 1; // Seconds. |
| 67 ElementAnimation::animate( |
| 68 *target, StringKeyframeEffectModel::create(keyframes), timing); |
| 69 |
| 70 // This sets the baseComputedStyle on the animation exit frame. |
| 71 compositor().beginFrame(1); |
| 72 EXPECT_EQ(nullptr, target->elementAnimations()->baseComputedStyle()); |
| 73 compositor().beginFrame(1); |
| 74 EXPECT_NE(nullptr, target->elementAnimations()->baseComputedStyle()); |
| 75 |
| 76 // target.style.setProperty('--x', '0%'); |
| 77 target->style()->setProperty("--x", "0%", emptyString, exceptionState); |
| 78 EXPECT_FALSE(exceptionState.hadException()); |
| 79 |
| 80 // target.animate({'--x': '100%'}, 1000); |
| 81 keyframe = StringKeyframe::create(); |
| 82 keyframe->setCSSPropertyValue("--x", document().propertyRegistry(), "100%", |
| 83 document().elementSheet().contents()); |
| 84 keyframes.clear(); |
| 85 keyframes.push_back(keyframe.release()); |
| 86 timing = Timing::defaults(); |
| 87 timing.iterationDuration = 1; // Seconds. |
| 88 ElementAnimation::animate( |
| 89 *target, StringKeyframeEffectModel::create(keyframes), timing); |
| 90 |
| 91 // This (previously) would not clear the existing baseComputedStyle and would |
| 92 // crash on the equality assertion in the exit frame when it tried to update |
| 93 // it. |
| 94 compositor().beginFrame(1); |
| 95 compositor().beginFrame(1); |
| 96 } |
| 97 |
| 98 } // namespace blink |
OLD | NEW |