1 <!DOCTYPE html><!-- webkit-test-runner [ enableCSSAnimationsAndCSSTransitionsBackedByWebAnimations=true ] -->
3 <script src="../../resources/js-test-pre.js"></script>
6 @-webkit-keyframes example {
42 #before.animate:before {
46 -webkit-animation: example 2s;
47 -moz-animation: example 2s;
48 animation: example 2s;
53 display: inline-block;
54 border: 1px solid black;
64 <div id="before"></div>
65 <div id="after"></div>
68 description('Animations on :before and :after pseudo elements should run');
70 if (window.testRunner)
71 testRunner.dumpAsText();
73 function getPseudoComputedTop(id)
75 return Math.round(parseFloat(getComputedStyle(document.getElementById(id), ':' + id).top));
78 // FIXME: This test should be modified so subpixel doesn't cause off by one
79 // below and it no longer needs shouldBeCloseTo.
81 function pauseAnimationAtTimeOnPseudoElement(animationName, time, element, pseudoId)
83 const pseudoElement = internals.pseudoElement(element, pseudoId);
85 console.log("Failed to find pseudo element");
89 const animations = pseudoElement.getAnimations();
90 for (let animation of animations) {
91 if (animation instanceof CSSAnimation && animation.animationName == animationName && animation.effect.getKeyframes().length) {
92 animation.currentTime = time * 1000;
100 function testAnimation(id)
102 var div = document.getElementById(id);
103 div.className = 'animate';
105 shouldBe('div.offsetWidth', '52');
106 if (window.internals) {
107 pauseAnimationAtTimeOnPseudoElement('example', 1.0, div, id);
108 shouldBeCloseTo('div.offsetWidth', 20, 1);
109 computedTop = getPseudoComputedTop(id);
110 shouldBeCloseTo('computedTop', 170, 1);
111 pauseAnimationAtTimeOnPseudoElement('example', 2.0, div, id);
112 shouldBeCloseTo('div.offsetWidth', 12, 1);
113 computedTop = getPseudoComputedTop(id);
114 shouldBeCloseTo('computedTop', 200, 1);
116 // This will be flaky, but it's a reasonable approximation for testing
117 // in a browser instead of DRT.
118 setTimeout(function() {
120 shouldBeCloseTo('div.offsetWidth', 20, 1);
121 computedTop = getPseudoComputedTop(id);
122 shouldBeCloseTo('computedTop', 170, 1);
124 setTimeout(function() {
126 shouldBeCloseTo('div.offsetWidth', 12, 1);
127 computedTop = getPseudoComputedTop(id);
128 shouldBeCloseTo('computedTop', 200, 1);
133 onload = function() {
134 testAnimation('before');
135 testAnimation('after');
136 if (window.internals)
137 isSuccessfullyParsed();
139 setTimeout(isSuccessfullyParsed, 2000);