2 * Copyright (c) 2013, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "core/animation/CompositorAnimations.h"
35 #include "core/animation/AnimatableDouble.h"
36 #include "core/animation/AnimatableFilterOperations.h"
37 #include "core/animation/AnimatableTransform.h"
38 #include "core/animation/AnimatableValueTestHelper.h"
39 #include "core/animation/CompositorAnimationsImpl.h"
40 #include "core/animation/CompositorAnimationsTestHelper.h"
41 #include "platform/geometry/IntSize.h"
42 #include "platform/graphics/filters/FilterOperations.h"
43 #include "platform/transforms/TransformOperations.h"
44 #include "platform/transforms/TranslateTransformOperation.h"
45 #include "public/platform/WebAnimation.h"
46 #include "wtf/HashFunctions.h"
47 #include "wtf/OwnPtr.h"
48 #include "wtf/PassOwnPtr.h"
49 #include "wtf/PassRefPtr.h"
50 #include "wtf/RefPtr.h"
52 #include <gmock/gmock.h>
53 #include <gtest/gtest.h>
57 using ::testing::CloneToPassOwnPtr;
58 using ::testing::ExpectationSet;
60 using ::testing::Return;
63 class AnimationCompositorAnimationsTest : public AnimationCompositorAnimationsTestBase {
65 RefPtr<TimingFunction> m_linearTimingFunction;
66 RefPtr<TimingFunction> m_cubicEaseTimingFunction;
67 RefPtr<TimingFunction> m_cubicCustomTimingFunction;
68 RefPtr<TimingFunction> m_stepTimingFunction;
71 CompositorAnimationsImpl::CompositorTiming m_compositorTiming;
72 OwnPtrWillBePersistent<AnimatableValueKeyframeVector> m_keyframeVector2;
73 RefPtrWillBePersistent<AnimatableValueKeyframeEffectModel> m_keyframeAnimationEffect2;
74 OwnPtrWillBePersistent<AnimatableValueKeyframeVector> m_keyframeVector5;
75 RefPtrWillBePersistent<AnimatableValueKeyframeEffectModel> m_keyframeAnimationEffect5;
79 AnimationCompositorAnimationsTestBase::SetUp();
81 m_linearTimingFunction = LinearTimingFunction::shared();
82 m_cubicEaseTimingFunction = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Ease);
83 m_cubicCustomTimingFunction = CubicBezierTimingFunction::create(1, 2, 3, 4);
84 m_stepTimingFunction = StepsTimingFunction::create(1, StepsTimingFunction::StepAtEnd);
86 m_timing = createCompositableTiming();
87 m_compositorTiming = CompositorAnimationsImpl::CompositorTiming();
88 // Make sure the CompositableTiming is really compositable, otherwise
89 // most other tests will fail.
90 ASSERT(convertTimingForCompositor(m_timing, m_compositorTiming));
92 m_keyframeVector2 = createCompositableFloatKeyframeVector(2);
93 m_keyframeAnimationEffect2 = AnimatableValueKeyframeEffectModel::create(*m_keyframeVector2);
95 m_keyframeVector5 = createCompositableFloatKeyframeVector(5);
96 m_keyframeAnimationEffect5 = AnimatableValueKeyframeEffectModel::create(*m_keyframeVector5);
101 bool convertTimingForCompositor(const Timing& t, CompositorAnimationsImpl::CompositorTiming& out)
103 return CompositorAnimationsImpl::convertTimingForCompositor(t, out);
105 bool isCandidateForAnimationOnCompositor(const Timing& timing, const AnimationEffect& effect)
107 return CompositorAnimations::instance()->isCandidateForAnimationOnCompositor(timing, effect);
109 void getAnimationOnCompositor(Timing& timing, AnimatableValueKeyframeEffectModel& effect, Vector<OwnPtr<blink::WebAnimation> >& animations)
111 return CompositorAnimationsImpl::getAnimationOnCompositor(timing, std::numeric_limits<double>::quiet_NaN(), effect, animations);
114 bool duplicateSingleKeyframeAndTestIsCandidateOnResult(AnimatableValueKeyframe* frame)
116 EXPECT_EQ(frame->offset(), 0);
117 AnimatableValueKeyframeVector frames;
118 RefPtrWillBeRawPtr<Keyframe> second = frame->cloneWithOffset(1);
120 frames.append(frame);
121 frames.append(toAnimatableValueKeyframe(second.get()));
122 return isCandidateForAnimationOnCompositor(m_timing, *AnimatableValueKeyframeEffectModel::create(frames).get());
125 // -------------------------------------------------------------------
127 Timing createCompositableTiming()
130 timing.startDelay = 0;
131 timing.fillMode = Timing::FillModeNone;
132 timing.iterationStart = 0;
133 timing.iterationCount = 1;
134 timing.iterationDuration = 1.0;
135 timing.playbackRate = 1.0;
136 timing.direction = Timing::PlaybackDirectionNormal;
137 ASSERT(m_linearTimingFunction);
138 timing.timingFunction = m_linearTimingFunction;
142 PassRefPtrWillBeRawPtr<AnimatableValueKeyframe> createReplaceOpKeyframe(CSSPropertyID id, AnimatableValue* value, double offset = 0)
144 RefPtrWillBeRawPtr<AnimatableValueKeyframe> keyframe = AnimatableValueKeyframe::create();
145 keyframe->setPropertyValue(id, value);
146 keyframe->setComposite(AnimationEffect::CompositeReplace);
147 keyframe->setOffset(offset);
148 keyframe->setEasing(LinearTimingFunction::shared());
152 PassRefPtrWillBeRawPtr<AnimatableValueKeyframe> createDefaultKeyframe(CSSPropertyID id, AnimationEffect::CompositeOperation op, double offset = 0)
154 RefPtrWillBeRawPtr<AnimatableValue> value = nullptr;
155 if (id == CSSPropertyTransform)
156 value = AnimatableTransform::create(TransformOperations());
158 value = AnimatableDouble::create(10.0);
160 RefPtrWillBeRawPtr<AnimatableValueKeyframe> keyframe = createReplaceOpKeyframe(id, value.get(), offset);
161 keyframe->setComposite(op);
165 PassOwnPtrWillBeRawPtr<AnimatableValueKeyframeVector> createCompositableFloatKeyframeVector(size_t n)
167 Vector<double> values;
168 for (size_t i = 0; i < n; i++) {
169 values.append(static_cast<double>(i));
171 return createCompositableFloatKeyframeVector(values);
174 PassOwnPtrWillBeRawPtr<AnimatableValueKeyframeVector> createCompositableFloatKeyframeVector(Vector<double>& values)
176 OwnPtrWillBeRawPtr<AnimatableValueKeyframeVector> frames = adoptPtrWillBeNoop(new AnimatableValueKeyframeVector);
177 for (size_t i = 0; i < values.size(); i++) {
178 double offset = 1.0 / (values.size() - 1) * i;
179 RefPtrWillBeRawPtr<AnimatableDouble> value = AnimatableDouble::create(values[i]);
180 frames->append(createReplaceOpKeyframe(CSSPropertyOpacity, value.get(), offset).get());
182 return frames.release();
185 PassRefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> createKeyframeEffectModel(PassRefPtrWillBeRawPtr<AnimatableValueKeyframe> prpFrom, PassRefPtrWillBeRawPtr<AnimatableValueKeyframe> prpTo, PassRefPtrWillBeRawPtr<AnimatableValueKeyframe> prpC = nullptr, PassRefPtrWillBeRawPtr<AnimatableValueKeyframe> prpD = nullptr)
187 RefPtrWillBeRawPtr<AnimatableValueKeyframe> from = prpFrom;
188 RefPtrWillBeRawPtr<AnimatableValueKeyframe> to = prpTo;
189 RefPtrWillBeRawPtr<AnimatableValueKeyframe> c = prpC;
190 RefPtrWillBeRawPtr<AnimatableValueKeyframe> d = prpD;
192 EXPECT_EQ(from->offset(), 0);
193 AnimatableValueKeyframeVector frames;
195 EXPECT_LE(from->offset(), to->offset());
198 EXPECT_LE(to->offset(), c->offset());
203 EXPECT_LE(c->offset(), d->offset());
204 EXPECT_EQ(d->offset(), 1.0);
206 EXPECT_EQ(to->offset(), 1.0);
208 if (!HasFatalFailure()) {
209 return AnimatableValueKeyframeEffectModel::create(frames);
216 // -----------------------------------------------------------------------
217 // -----------------------------------------------------------------------
219 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorKeyframeMultipleCSSProperties)
221 RefPtrWillBeRawPtr<AnimatableValueKeyframe> keyframeGoodMultiple = createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect::CompositeReplace);
222 keyframeGoodMultiple->setPropertyValue(CSSPropertyTransform, AnimatableTransform::create(TransformOperations()).get());
223 EXPECT_TRUE(duplicateSingleKeyframeAndTestIsCandidateOnResult(keyframeGoodMultiple.get()));
225 RefPtrWillBeRawPtr<AnimatableValueKeyframe> keyframeBadMultipleID = createDefaultKeyframe(CSSPropertyColor, AnimationEffect::CompositeReplace);
226 keyframeBadMultipleID->setPropertyValue(CSSPropertyOpacity, AnimatableDouble::create(10.0).get());
227 EXPECT_FALSE(duplicateSingleKeyframeAndTestIsCandidateOnResult(keyframeBadMultipleID.get()));
230 TEST_F(AnimationCompositorAnimationsTest, isNotCandidateForCompositorAnimationTransformDependsOnBoxSize)
232 TransformOperations ops;
233 ops.operations().append(TranslateTransformOperation::create(Length(2, WebCore::Fixed), Length(2, WebCore::Fixed), TransformOperation::TranslateX));
234 RefPtrWillBeRawPtr<AnimatableValueKeyframe> goodKeyframe = createReplaceOpKeyframe(CSSPropertyTransform, AnimatableTransform::create(ops).get());
235 EXPECT_TRUE(duplicateSingleKeyframeAndTestIsCandidateOnResult(goodKeyframe.get()));
237 ops.operations().append(TranslateTransformOperation::create(Length(50, WebCore::Percent), Length(2, WebCore::Fixed), TransformOperation::TranslateX));
238 RefPtrWillBeRawPtr<AnimatableValueKeyframe> badKeyframe = createReplaceOpKeyframe(CSSPropertyTransform, AnimatableTransform::create(ops).get());
239 EXPECT_FALSE(duplicateSingleKeyframeAndTestIsCandidateOnResult(badKeyframe.get()));
241 TransformOperations ops2;
242 Length calcLength = Length(100, WebCore::Percent).blend(Length(100, WebCore::Fixed), 0.5, WebCore::ValueRangeAll);
243 ops2.operations().append(TranslateTransformOperation::create(calcLength, Length(0, WebCore::Fixed), TransformOperation::TranslateX));
244 RefPtrWillBeRawPtr<AnimatableValueKeyframe> badKeyframe2 = createReplaceOpKeyframe(CSSPropertyTransform, AnimatableTransform::create(ops2).get());
245 EXPECT_FALSE(duplicateSingleKeyframeAndTestIsCandidateOnResult(badKeyframe2.get()));
248 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorKeyframeEffectModelMultipleFramesOkay)
250 AnimatableValueKeyframeVector framesSame;
251 framesSame.append(createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect::CompositeReplace, 0.0).get());
252 framesSame.append(createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect::CompositeReplace, 1.0).get());
253 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *AnimatableValueKeyframeEffectModel::create(framesSame).get()));
255 AnimatableValueKeyframeVector framesMixed;
256 framesMixed.append(createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect::CompositeReplace, 0.0).get());
257 framesMixed.append(createDefaultKeyframe(CSSPropertyTransform, AnimationEffect::CompositeReplace, 1.0).get());
258 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *AnimatableValueKeyframeEffectModel::create(framesMixed).get()));
261 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorKeyframeEffectModel)
263 AnimatableValueKeyframeVector framesSame;
264 framesSame.append(createDefaultKeyframe(CSSPropertyColor, AnimationEffect::CompositeReplace, 0.0).get());
265 framesSame.append(createDefaultKeyframe(CSSPropertyColor, AnimationEffect::CompositeReplace, 1.0).get());
266 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *AnimatableValueKeyframeEffectModel::create(framesSame).get()));
268 AnimatableValueKeyframeVector framesMixedProperties;
269 framesMixedProperties.append(createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect::CompositeReplace, 0.0).get());
270 framesMixedProperties.append(createDefaultKeyframe(CSSPropertyColor, AnimationEffect::CompositeReplace, 1.0).get());
271 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *AnimatableValueKeyframeEffectModel::create(framesMixedProperties).get()));
274 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorStartDelay)
276 m_timing.iterationDuration = 20.0;
278 m_timing.startDelay = 2.0;
279 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
280 EXPECT_DOUBLE_EQ(-2.0, m_compositorTiming.scaledTimeOffset);
282 m_timing.startDelay = -2.0;
283 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
284 EXPECT_DOUBLE_EQ(2.0, m_compositorTiming.scaledTimeOffset);
287 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorIterationStart)
289 m_timing.iterationStart = 2.2;
290 EXPECT_FALSE(convertTimingForCompositor(m_timing, m_compositorTiming));
293 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorIterationCount)
295 m_timing.iterationCount = 5.0;
296 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
297 EXPECT_EQ(5, m_compositorTiming.adjustedIterationCount);
299 m_timing.iterationCount = 5.5;
300 EXPECT_FALSE(convertTimingForCompositor(m_timing, m_compositorTiming));
302 // Asserts will only trigger on DEBUG build.
303 // EXPECT_DEATH tests are flaky on Android.
304 #if !defined(NDEBUG) && !OS(ANDROID)
305 m_timing.iterationCount = -1;
306 EXPECT_DEATH(convertTimingForCompositor(m_timing, m_compositorTiming), "");
309 m_timing.iterationCount = std::numeric_limits<double>::infinity();
310 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
311 EXPECT_EQ(-1, m_compositorTiming.adjustedIterationCount);
313 m_timing.iterationCount = std::numeric_limits<double>::infinity();
314 m_timing.iterationDuration = 5.0;
315 m_timing.startDelay = -6.0;
316 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
317 EXPECT_DOUBLE_EQ(6.0, m_compositorTiming.scaledTimeOffset);
318 EXPECT_EQ(-1, m_compositorTiming.adjustedIterationCount);
321 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorIterationsAndStartDelay)
323 m_timing.iterationCount = 4.0;
324 m_timing.iterationDuration = 5.0;
326 m_timing.startDelay = 6.0;
327 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
328 EXPECT_DOUBLE_EQ(-6.0, m_compositorTiming.scaledTimeOffset);
329 EXPECT_DOUBLE_EQ(4.0, m_compositorTiming.adjustedIterationCount);
331 m_timing.startDelay = -6.0;
332 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
333 EXPECT_DOUBLE_EQ(6.0, m_compositorTiming.scaledTimeOffset);
334 EXPECT_DOUBLE_EQ(4.0, m_compositorTiming.adjustedIterationCount);
336 m_timing.startDelay = 21.0;
337 EXPECT_FALSE(convertTimingForCompositor(m_timing, m_compositorTiming));
340 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorPlaybackRate)
342 m_timing.playbackRate = 2.0;
343 EXPECT_FALSE(convertTimingForCompositor(m_timing, m_compositorTiming));
345 m_timing.playbackRate = 0.0;
346 EXPECT_FALSE(convertTimingForCompositor(m_timing, m_compositorTiming));
348 m_timing.playbackRate = -2.0;
349 EXPECT_FALSE(convertTimingForCompositor(m_timing, m_compositorTiming));
352 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorDirection)
354 m_timing.direction = Timing::PlaybackDirectionAlternate;
355 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
356 EXPECT_TRUE(m_compositorTiming.alternate);
357 EXPECT_FALSE(m_compositorTiming.reverse);
359 m_timing.direction = Timing::PlaybackDirectionAlternateReverse;
360 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
361 EXPECT_TRUE(m_compositorTiming.alternate);
362 EXPECT_TRUE(m_compositorTiming.reverse);
364 m_timing.direction = Timing::PlaybackDirectionReverse;
365 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
366 EXPECT_FALSE(m_compositorTiming.alternate);
367 EXPECT_TRUE(m_compositorTiming.reverse);
370 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorDirectionIterationsAndStartDelay)
372 m_timing.direction = Timing::PlaybackDirectionAlternate;
373 m_timing.iterationCount = 4.0;
374 m_timing.iterationDuration = 5.0;
375 m_timing.startDelay = -6.0;
376 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
377 EXPECT_DOUBLE_EQ(6.0, m_compositorTiming.scaledTimeOffset);
378 EXPECT_EQ(4, m_compositorTiming.adjustedIterationCount);
379 EXPECT_TRUE(m_compositorTiming.alternate);
380 EXPECT_FALSE(m_compositorTiming.reverse);
382 m_timing.direction = Timing::PlaybackDirectionAlternate;
383 m_timing.iterationCount = 4.0;
384 m_timing.iterationDuration = 5.0;
385 m_timing.startDelay = -11.0;
386 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
387 EXPECT_DOUBLE_EQ(11.0, m_compositorTiming.scaledTimeOffset);
388 EXPECT_EQ(4, m_compositorTiming.adjustedIterationCount);
389 EXPECT_TRUE(m_compositorTiming.alternate);
390 EXPECT_FALSE(m_compositorTiming.reverse);
392 m_timing.direction = Timing::PlaybackDirectionAlternateReverse;
393 m_timing.iterationCount = 4.0;
394 m_timing.iterationDuration = 5.0;
395 m_timing.startDelay = -6.0;
396 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
397 EXPECT_DOUBLE_EQ(6.0, m_compositorTiming.scaledTimeOffset);
398 EXPECT_EQ(4, m_compositorTiming.adjustedIterationCount);
399 EXPECT_TRUE(m_compositorTiming.alternate);
400 EXPECT_TRUE(m_compositorTiming.reverse);
402 m_timing.direction = Timing::PlaybackDirectionAlternateReverse;
403 m_timing.iterationCount = 4.0;
404 m_timing.iterationDuration = 5.0;
405 m_timing.startDelay = -11.0;
406 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
407 EXPECT_DOUBLE_EQ(11.0, m_compositorTiming.scaledTimeOffset);
408 EXPECT_EQ(4, m_compositorTiming.adjustedIterationCount);
409 EXPECT_TRUE(m_compositorTiming.alternate);
410 EXPECT_TRUE(m_compositorTiming.reverse);
413 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTimingTimingFunctionPassThru)
415 m_timing.timingFunction = m_stepTimingFunction;
416 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect2.get()));
419 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTimingFunctionLinear)
421 m_timing.timingFunction = m_linearTimingFunction;
422 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect2.get()));
423 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect5.get()));
426 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTimingFunctionCubic)
428 m_timing.timingFunction = m_cubicEaseTimingFunction;
429 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect2.get()));
430 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect5.get()));
432 m_timing.timingFunction = m_cubicCustomTimingFunction;
433 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect2.get()));
434 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect5.get()));
437 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTimingFunctionSteps)
439 m_timing.timingFunction = m_stepTimingFunction;
440 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect2.get()));
441 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect5.get()));
444 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTimingFunctionChainedLinear)
446 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect2.get()));
447 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect5.get()));
450 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTimingFunctionChainedCubicMatchingOffsets)
452 (*m_keyframeVector2)[0]->setEasing(m_cubicEaseTimingFunction.get());
453 m_keyframeAnimationEffect2 = AnimatableValueKeyframeEffectModel::create(*m_keyframeVector2);
454 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect2.get()));
456 (*m_keyframeVector2)[0]->setEasing(m_cubicCustomTimingFunction.get());
457 m_keyframeAnimationEffect2 = AnimatableValueKeyframeEffectModel::create(*m_keyframeVector2);
458 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect2.get()));
460 (*m_keyframeVector5)[0]->setEasing(m_cubicEaseTimingFunction.get());
461 (*m_keyframeVector5)[1]->setEasing(m_cubicCustomTimingFunction.get());
462 (*m_keyframeVector5)[2]->setEasing(m_cubicCustomTimingFunction.get());
463 (*m_keyframeVector5)[3]->setEasing(m_cubicCustomTimingFunction.get());
464 m_keyframeAnimationEffect5 = AnimatableValueKeyframeEffectModel::create(*m_keyframeVector5);
465 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect5.get()));
468 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTimingFunctionMixedGood)
470 (*m_keyframeVector5)[0]->setEasing(m_linearTimingFunction.get());
471 (*m_keyframeVector5)[1]->setEasing(m_cubicEaseTimingFunction.get());
472 (*m_keyframeVector5)[2]->setEasing(m_cubicEaseTimingFunction.get());
473 (*m_keyframeVector5)[3]->setEasing(m_linearTimingFunction.get());
474 m_keyframeAnimationEffect5 = AnimatableValueKeyframeEffectModel::create(*m_keyframeVector5);
475 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect5.get()));
478 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTimingFunctionWithStepNotOkay)
480 (*m_keyframeVector2)[0]->setEasing(m_stepTimingFunction.get());
481 m_keyframeAnimationEffect2 = AnimatableValueKeyframeEffectModel::create(*m_keyframeVector2);
482 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect2.get()));
484 (*m_keyframeVector5)[0]->setEasing(m_stepTimingFunction.get());
485 (*m_keyframeVector5)[1]->setEasing(m_linearTimingFunction.get());
486 (*m_keyframeVector5)[2]->setEasing(m_cubicEaseTimingFunction.get());
487 (*m_keyframeVector5)[3]->setEasing(m_linearTimingFunction.get());
488 m_keyframeAnimationEffect5 = AnimatableValueKeyframeEffectModel::create(*m_keyframeVector5);
489 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect5.get()));
491 (*m_keyframeVector5)[0]->setEasing(m_linearTimingFunction.get());
492 (*m_keyframeVector5)[1]->setEasing(m_stepTimingFunction.get());
493 (*m_keyframeVector5)[2]->setEasing(m_cubicEaseTimingFunction.get());
494 (*m_keyframeVector5)[3]->setEasing(m_linearTimingFunction.get());
495 m_keyframeAnimationEffect5 = AnimatableValueKeyframeEffectModel::create(*m_keyframeVector5);
496 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect5.get()));
498 (*m_keyframeVector5)[0]->setEasing(m_linearTimingFunction.get());
499 (*m_keyframeVector5)[1]->setEasing(m_cubicEaseTimingFunction.get());
500 (*m_keyframeVector5)[2]->setEasing(m_cubicEaseTimingFunction.get());
501 (*m_keyframeVector5)[3]->setEasing(m_stepTimingFunction.get());
502 m_keyframeAnimationEffect5 = AnimatableValueKeyframeEffectModel::create(*m_keyframeVector5);
503 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect5.get()));
506 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositor)
508 Timing linearTiming(createCompositableTiming());
510 AnimatableValueKeyframeVector basicFramesVector;
511 basicFramesVector.append(createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect::CompositeReplace, 0.0).get());
512 basicFramesVector.append(createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect::CompositeReplace, 1.0).get());
514 AnimatableValueKeyframeVector nonBasicFramesVector;
515 nonBasicFramesVector.append(createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect::CompositeReplace, 0.0).get());
516 nonBasicFramesVector.append(createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect::CompositeReplace, 0.5).get());
517 nonBasicFramesVector.append(createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect::CompositeReplace, 1.0).get());
519 basicFramesVector[0]->setEasing(m_linearTimingFunction.get());
520 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> basicFrames = AnimatableValueKeyframeEffectModel::create(basicFramesVector).get();
521 EXPECT_TRUE(isCandidateForAnimationOnCompositor(linearTiming, *basicFrames.get()));
523 basicFramesVector[0]->setEasing(CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseIn));
524 basicFrames = AnimatableValueKeyframeEffectModel::create(basicFramesVector).get();
525 EXPECT_TRUE(isCandidateForAnimationOnCompositor(linearTiming, *basicFrames.get()));
527 nonBasicFramesVector[0]->setEasing(m_linearTimingFunction.get());
528 nonBasicFramesVector[1]->setEasing(CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseIn));
529 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> nonBasicFrames = AnimatableValueKeyframeEffectModel::create(nonBasicFramesVector).get();
530 EXPECT_TRUE(CompositorAnimations::instance()->isCandidateForAnimationOnCompositor(linearTiming, *nonBasicFrames.get()));
533 // -----------------------------------------------------------------------
534 // -----------------------------------------------------------------------
536 TEST_F(AnimationCompositorAnimationsTest, createSimpleOpacityAnimation)
538 // Animation to convert
539 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = createKeyframeEffectModel(
540 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(2.0).get(), 0),
541 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(5.0).get(), 1.0));
544 WebCompositorSupportMock mockCompositor;
547 blink::WebFloatAnimationCurveMock* mockCurvePtr = new blink::WebFloatAnimationCurveMock;
548 ExpectationSet usesMockCurve;
549 EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
550 .WillOnce(Return(mockCurvePtr));
552 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(0.0, 2.0), blink::WebAnimationCurve::TimingFunctionTypeLinear));
553 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(1.0, 5.0)));
556 blink::WebAnimationMock* mockAnimationPtr = new blink::WebAnimationMock(blink::WebAnimation::TargetPropertyOpacity);
557 ExpectationSet usesMockAnimation;
559 usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurvePtr), blink::WebAnimation::TargetPropertyOpacity, _))
560 .WillOnce(Return(mockAnimationPtr));
562 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(1));
563 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(0.0));
564 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(false));
566 EXPECT_CALL(*mockAnimationPtr, delete_())
568 .After(usesMockAnimation);
569 EXPECT_CALL(*mockCurvePtr, delete_())
571 .After(usesMockCurve);
574 setCompositorForTesting(mockCompositor);
575 Vector<OwnPtr<blink::WebAnimation> > result;
576 getAnimationOnCompositor(m_timing, *effect.get(), result);
577 EXPECT_EQ(1U, result.size());
581 TEST_F(AnimationCompositorAnimationsTest, createSimpleOpacityAnimationDuration)
583 // Animation to convert
584 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = createKeyframeEffectModel(
585 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(2.0).get(), 0),
586 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(5.0).get(), 1.0));
588 m_timing.iterationDuration = 10.0;
591 WebCompositorSupportMock mockCompositor;
594 blink::WebFloatAnimationCurveMock* mockCurvePtr = new blink::WebFloatAnimationCurveMock;
595 ExpectationSet usesMockCurve;
596 EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
597 .WillOnce(Return(mockCurvePtr));
599 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(0.0, 2.0), blink::WebAnimationCurve::TimingFunctionTypeLinear));
600 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(10.0, 5.0)));
603 blink::WebAnimationMock* mockAnimationPtr = new blink::WebAnimationMock(blink::WebAnimation::TargetPropertyOpacity);
604 ExpectationSet usesMockAnimation;
606 usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurvePtr), blink::WebAnimation::TargetPropertyOpacity, _))
607 .WillOnce(Return(mockAnimationPtr));
609 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(1));
610 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(0.0));
611 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(false));
613 EXPECT_CALL(*mockAnimationPtr, delete_())
615 .After(usesMockAnimation);
616 EXPECT_CALL(*mockCurvePtr, delete_())
618 .After(usesMockCurve);
621 setCompositorForTesting(mockCompositor);
622 Vector<OwnPtr<blink::WebAnimation> > result;
623 getAnimationOnCompositor(m_timing, *effect.get(), result);
624 EXPECT_EQ(1U, result.size());
628 TEST_F(AnimationCompositorAnimationsTest, createMultipleKeyframeOpacityAnimationLinear)
630 // Animation to convert
631 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = createKeyframeEffectModel(
632 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(2.0).get(), 0),
633 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(-1.0).get(), 0.25),
634 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(20.0).get(), 0.5),
635 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(5.0).get(), 1.0));
637 m_timing.iterationCount = 5;
638 m_timing.direction = Timing::PlaybackDirectionAlternate;
641 WebCompositorSupportMock mockCompositor;
644 blink::WebFloatAnimationCurveMock* mockCurvePtr = new blink::WebFloatAnimationCurveMock();
645 ExpectationSet usesMockCurve;
647 EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
648 .WillOnce(Return(mockCurvePtr));
650 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(0.0, 2.0), blink::WebAnimationCurve::TimingFunctionTypeLinear));
651 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(0.25, -1.0), blink::WebAnimationCurve::TimingFunctionTypeLinear));
652 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(0.5, 20.0), blink::WebAnimationCurve::TimingFunctionTypeLinear));
653 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(1.0, 5.0)));
655 // Animation is created
656 blink::WebAnimationMock* mockAnimationPtr = new blink::WebAnimationMock(blink::WebAnimation::TargetPropertyOpacity);
657 ExpectationSet usesMockAnimation;
659 usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurvePtr), blink::WebAnimation::TargetPropertyOpacity, _))
660 .WillOnce(Return(mockAnimationPtr));
662 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(5));
663 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(0.0));
664 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(true));
666 EXPECT_CALL(*mockAnimationPtr, delete_())
668 .After(usesMockAnimation);
669 EXPECT_CALL(*mockCurvePtr, delete_())
671 .After(usesMockCurve);
674 setCompositorForTesting(mockCompositor);
675 Vector<OwnPtr<blink::WebAnimation> > result;
676 getAnimationOnCompositor(m_timing, *effect.get(), result);
677 EXPECT_EQ(1U, result.size());
681 TEST_F(AnimationCompositorAnimationsTest, createSimpleOpacityAnimationStartDelay)
683 // Animation to convert
684 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = createKeyframeEffectModel(
685 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(2.0).get(), 0),
686 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(5.0).get(), 1.0));
688 m_timing.iterationCount = 5.0;
689 m_timing.iterationDuration = 1.75;
690 m_timing.startDelay = 3.25;
693 WebCompositorSupportMock mockCompositor;
696 blink::WebFloatAnimationCurveMock* mockCurvePtr = new blink::WebFloatAnimationCurveMock;
697 ExpectationSet usesMockCurve;
698 EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
699 .WillOnce(Return(mockCurvePtr));
701 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(0.0, 2.0), blink::WebAnimationCurve::TimingFunctionTypeLinear));
702 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(1.75, 5.0)));
705 blink::WebAnimationMock* mockAnimationPtr = new blink::WebAnimationMock(blink::WebAnimation::TargetPropertyOpacity);
706 ExpectationSet usesMockAnimation;
708 usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurvePtr), blink::WebAnimation::TargetPropertyOpacity, _))
709 .WillOnce(Return(mockAnimationPtr));
711 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(5));
712 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(-3.25));
713 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(false));
715 EXPECT_CALL(*mockAnimationPtr, delete_())
717 .After(usesMockAnimation);
718 EXPECT_CALL(*mockCurvePtr, delete_())
720 .After(usesMockCurve);
723 setCompositorForTesting(mockCompositor);
724 Vector<OwnPtr<blink::WebAnimation> > result;
725 getAnimationOnCompositor(m_timing, *effect.get(), result);
726 EXPECT_EQ(1U, result.size());
730 TEST_F(AnimationCompositorAnimationsTest, createMultipleKeyframeOpacityAnimationChained)
732 // Animation to convert
733 AnimatableValueKeyframeVector frames;
734 frames.append(createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(2.0).get(), 0));
735 frames.append(createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(-1.0).get(), 0.25));
736 frames.append(createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(20.0).get(), 0.5));
737 frames.append(createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(5.0).get(), 1.0));
738 frames[0]->setEasing(m_cubicEaseTimingFunction.get());
739 frames[1]->setEasing(m_linearTimingFunction.get());
740 frames[2]->setEasing(m_cubicCustomTimingFunction.get());
741 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = AnimatableValueKeyframeEffectModel::create(frames);
743 m_timing.timingFunction = m_linearTimingFunction.get();
744 m_timing.iterationDuration = 2.0;
745 m_timing.iterationCount = 10;
746 m_timing.direction = Timing::PlaybackDirectionAlternate;
749 WebCompositorSupportMock mockCompositor;
752 blink::WebFloatAnimationCurveMock* mockCurvePtr = new blink::WebFloatAnimationCurveMock();
753 ExpectationSet usesMockCurve;
755 EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
756 .WillOnce(Return(mockCurvePtr));
758 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(0.0, 2.0), blink::WebAnimationCurve::TimingFunctionTypeEase));
759 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(0.5, -1.0), blink::WebAnimationCurve::TimingFunctionTypeLinear));
760 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(1.0, 20.0), 1.0, 2.0, 3.0, 4.0));
761 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(2.0, 5.0)));
763 // Animation is created
764 blink::WebAnimationMock* mockAnimationPtr = new blink::WebAnimationMock(blink::WebAnimation::TargetPropertyOpacity);
765 ExpectationSet usesMockAnimation;
767 usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurvePtr), blink::WebAnimation::TargetPropertyOpacity, _))
768 .WillOnce(Return(mockAnimationPtr));
770 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(10));
771 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(0.0));
772 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(true));
774 EXPECT_CALL(*mockAnimationPtr, delete_())
776 .After(usesMockAnimation);
777 EXPECT_CALL(*mockCurvePtr, delete_())
779 .After(usesMockCurve);
782 setCompositorForTesting(mockCompositor);
783 Vector<OwnPtr<blink::WebAnimation> > result;
784 getAnimationOnCompositor(m_timing, *effect.get(), result);
785 EXPECT_EQ(1U, result.size());
789 TEST_F(AnimationCompositorAnimationsTest, createReversedOpacityAnimation)
791 RefPtr<TimingFunction> cubicEasyFlipTimingFunction = CubicBezierTimingFunction::create(0.0, 0.0, 0.0, 1.0);
793 // Animation to convert
794 AnimatableValueKeyframeVector frames;
795 frames.append(createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(2.0).get(), 0));
796 frames.append(createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(-1.0).get(), 0.25));
797 frames.append(createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(20.0).get(), 0.5));
798 frames.append(createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(5.0).get(), 1.0));
799 frames[0]->setEasing(CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseIn));
800 frames[1]->setEasing(m_linearTimingFunction.get());
801 frames[2]->setEasing(cubicEasyFlipTimingFunction.get());
802 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = AnimatableValueKeyframeEffectModel::create(frames);
804 m_timing.timingFunction = m_linearTimingFunction.get();
805 m_timing.iterationCount = 10;
806 m_timing.direction = Timing::PlaybackDirectionAlternateReverse;
809 WebCompositorSupportMock mockCompositor;
812 blink::WebFloatAnimationCurveMock* mockCurvePtr = new blink::WebFloatAnimationCurveMock();
813 ExpectationSet usesMockCurve;
815 EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
816 .WillOnce(Return(mockCurvePtr));
818 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(0.0, 5.0), 1.0, 0.0, 1.0, 1.0));
819 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(0.5, 20.0), blink::WebAnimationCurve::TimingFunctionTypeLinear));
820 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(0.75, -1.0), blink::WebAnimationCurve::TimingFunctionTypeEaseOut));
821 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(1.0, 2.0)));
823 // Create the animation
824 blink::WebAnimationMock* mockAnimationPtr = new blink::WebAnimationMock(blink::WebAnimation::TargetPropertyOpacity);
825 ExpectationSet usesMockAnimation;
827 usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurvePtr), blink::WebAnimation::TargetPropertyOpacity, _))
828 .WillOnce(Return(mockAnimationPtr));
830 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(10));
831 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(0.0));
832 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(true));
834 EXPECT_CALL(*mockAnimationPtr, delete_())
836 .After(usesMockAnimation);
837 EXPECT_CALL(*mockCurvePtr, delete_())
839 .After(usesMockCurve);
842 setCompositorForTesting(mockCompositor);
843 Vector<OwnPtr<blink::WebAnimation> > result;
844 getAnimationOnCompositor(m_timing, *effect.get(), result);
845 EXPECT_EQ(1U, result.size());
849 TEST_F(AnimationCompositorAnimationsTest, createReversedOpacityAnimationNegativeStartDelay)
851 // Animation to convert
852 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = createKeyframeEffectModel(
853 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(2.0).get(), 0),
854 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(5.0).get(), 1.0));
856 m_timing.iterationCount = 5.0;
857 m_timing.iterationDuration = 1.5;
858 m_timing.startDelay = -3;
859 m_timing.direction = Timing::PlaybackDirectionAlternateReverse;
862 WebCompositorSupportMock mockCompositor;
865 blink::WebFloatAnimationCurveMock* mockCurvePtr = new blink::WebFloatAnimationCurveMock;
866 ExpectationSet usesMockCurve;
867 EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
868 .WillOnce(Return(mockCurvePtr));
870 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(0.0, 5.0), blink::WebAnimationCurve::TimingFunctionTypeLinear));
871 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(blink::WebFloatKeyframe(1.5, 2.0)));
874 blink::WebAnimationMock* mockAnimationPtr = new blink::WebAnimationMock(blink::WebAnimation::TargetPropertyOpacity);
875 ExpectationSet usesMockAnimation;
877 usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurvePtr), blink::WebAnimation::TargetPropertyOpacity, _))
878 .WillOnce(Return(mockAnimationPtr));
880 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(5));
881 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(3.0));
882 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(true));
884 EXPECT_CALL(*mockAnimationPtr, delete_())
886 .After(usesMockAnimation);
887 EXPECT_CALL(*mockCurvePtr, delete_())
889 .After(usesMockCurve);
892 setCompositorForTesting(mockCompositor);
893 Vector<OwnPtr<blink::WebAnimation> > result;
894 getAnimationOnCompositor(m_timing, *effect.get(), result);
895 EXPECT_EQ(1U, result.size());
900 } // namespace WebCore