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