Home | History | Annotate | Download | only in animation
      1 /*
      2  * Copyright (c) 2013, Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      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
     13  * distribution.
     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.
     17  *
     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.
     29  */
     30 
     31 #include "config.h"
     32 
     33 #include "core/animation/CompositorAnimations.h"
     34 
     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"
     51 
     52 #include <gmock/gmock.h>
     53 #include <gtest/gtest.h>
     54 
     55 namespace WebCore {
     56 
     57 using ::testing::CloneToPassOwnPtr;
     58 using ::testing::ExpectationSet;
     59 using ::testing::Ref;
     60 using ::testing::Return;
     61 using ::testing::_;
     62 
     63 class AnimationCompositorAnimationsTest : public AnimationCompositorAnimationsTestBase {
     64 protected:
     65     RefPtr<TimingFunction> m_linearTimingFunction;
     66     RefPtr<TimingFunction> m_cubicEaseTimingFunction;
     67     RefPtr<TimingFunction> m_cubicCustomTimingFunction;
     68     RefPtr<TimingFunction> m_stepTimingFunction;
     69 
     70     Timing m_timing;
     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;
     76 
     77     virtual void SetUp()
     78     {
     79         AnimationCompositorAnimationsTestBase::SetUp();
     80 
     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);
     85 
     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));
     91 
     92         m_keyframeVector2 = createCompositableFloatKeyframeVector(2);
     93         m_keyframeAnimationEffect2 = AnimatableValueKeyframeEffectModel::create(*m_keyframeVector2);
     94 
     95         m_keyframeVector5 = createCompositableFloatKeyframeVector(5);
     96         m_keyframeAnimationEffect5 = AnimatableValueKeyframeEffectModel::create(*m_keyframeVector5);
     97     }
     98 
     99 public:
    100 
    101     bool convertTimingForCompositor(const Timing& t, CompositorAnimationsImpl::CompositorTiming& out)
    102     {
    103         return CompositorAnimationsImpl::convertTimingForCompositor(t, out);
    104     }
    105     bool isCandidateForAnimationOnCompositor(const Timing& timing, const AnimationEffect& effect)
    106     {
    107         return CompositorAnimations::instance()->isCandidateForAnimationOnCompositor(timing, effect);
    108     }
    109     void getAnimationOnCompositor(Timing& timing, AnimatableValueKeyframeEffectModel& effect, Vector<OwnPtr<blink::WebAnimation> >& animations)
    110     {
    111         return CompositorAnimationsImpl::getAnimationOnCompositor(timing, std::numeric_limits<double>::quiet_NaN(), effect, animations);
    112     }
    113 
    114     bool duplicateSingleKeyframeAndTestIsCandidateOnResult(AnimatableValueKeyframe* frame)
    115     {
    116         EXPECT_EQ(frame->offset(), 0);
    117         AnimatableValueKeyframeVector frames;
    118         RefPtrWillBeRawPtr<Keyframe> second = frame->cloneWithOffset(1);
    119 
    120         frames.append(frame);
    121         frames.append(toAnimatableValueKeyframe(second.get()));
    122         return isCandidateForAnimationOnCompositor(m_timing, *AnimatableValueKeyframeEffectModel::create(frames).get());
    123     }
    124 
    125     // -------------------------------------------------------------------
    126 
    127     Timing createCompositableTiming()
    128     {
    129         Timing timing;
    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;
    139         return timing;
    140     }
    141 
    142     PassRefPtrWillBeRawPtr<AnimatableValueKeyframe> createReplaceOpKeyframe(CSSPropertyID id, AnimatableValue* value, double offset = 0)
    143     {
    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());
    149         return keyframe;
    150     }
    151 
    152     PassRefPtrWillBeRawPtr<AnimatableValueKeyframe> createDefaultKeyframe(CSSPropertyID id, AnimationEffect::CompositeOperation op, double offset = 0)
    153     {
    154         RefPtrWillBeRawPtr<AnimatableValue> value = nullptr;
    155         if (id == CSSPropertyTransform)
    156             value = AnimatableTransform::create(TransformOperations());
    157         else
    158             value = AnimatableDouble::create(10.0);
    159 
    160         RefPtrWillBeRawPtr<AnimatableValueKeyframe> keyframe = createReplaceOpKeyframe(id, value.get(), offset);
    161         keyframe->setComposite(op);
    162         return keyframe;
    163     }
    164 
    165     PassOwnPtrWillBeRawPtr<AnimatableValueKeyframeVector> createCompositableFloatKeyframeVector(size_t n)
    166     {
    167         Vector<double> values;
    168         for (size_t i = 0; i < n; i++) {
    169             values.append(static_cast<double>(i));
    170         }
    171         return createCompositableFloatKeyframeVector(values);
    172     }
    173 
    174     PassOwnPtrWillBeRawPtr<AnimatableValueKeyframeVector> createCompositableFloatKeyframeVector(Vector<double>& values)
    175     {
    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());
    181         }
    182         return frames.release();
    183     }
    184 
    185     PassRefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> createKeyframeEffectModel(PassRefPtrWillBeRawPtr<AnimatableValueKeyframe> prpFrom, PassRefPtrWillBeRawPtr<AnimatableValueKeyframe> prpTo, PassRefPtrWillBeRawPtr<AnimatableValueKeyframe> prpC = nullptr, PassRefPtrWillBeRawPtr<AnimatableValueKeyframe> prpD = nullptr)
    186     {
    187         RefPtrWillBeRawPtr<AnimatableValueKeyframe> from = prpFrom;
    188         RefPtrWillBeRawPtr<AnimatableValueKeyframe> to = prpTo;
    189         RefPtrWillBeRawPtr<AnimatableValueKeyframe> c = prpC;
    190         RefPtrWillBeRawPtr<AnimatableValueKeyframe> d = prpD;
    191 
    192         EXPECT_EQ(from->offset(), 0);
    193         AnimatableValueKeyframeVector frames;
    194         frames.append(from);
    195         EXPECT_LE(from->offset(), to->offset());
    196         frames.append(to);
    197         if (c) {
    198             EXPECT_LE(to->offset(), c->offset());
    199             frames.append(c);
    200         }
    201         if (d) {
    202             frames.append(d);
    203             EXPECT_LE(c->offset(), d->offset());
    204             EXPECT_EQ(d->offset(), 1.0);
    205         } else {
    206             EXPECT_EQ(to->offset(), 1.0);
    207         }
    208         if (!HasFatalFailure()) {
    209             return AnimatableValueKeyframeEffectModel::create(frames);
    210         }
    211         return nullptr;
    212     }
    213 
    214 };
    215 
    216 // -----------------------------------------------------------------------
    217 // -----------------------------------------------------------------------
    218 
    219 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorKeyframeMultipleCSSProperties)
    220 {
    221     RefPtrWillBeRawPtr<AnimatableValueKeyframe> keyframeGoodMultiple = createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect::CompositeReplace);
    222     keyframeGoodMultiple->setPropertyValue(CSSPropertyTransform, AnimatableTransform::create(TransformOperations()).get());
    223     EXPECT_TRUE(duplicateSingleKeyframeAndTestIsCandidateOnResult(keyframeGoodMultiple.get()));
    224 
    225     RefPtrWillBeRawPtr<AnimatableValueKeyframe> keyframeBadMultipleID = createDefaultKeyframe(CSSPropertyColor, AnimationEffect::CompositeReplace);
    226     keyframeBadMultipleID->setPropertyValue(CSSPropertyOpacity, AnimatableDouble::create(10.0).get());
    227     EXPECT_FALSE(duplicateSingleKeyframeAndTestIsCandidateOnResult(keyframeBadMultipleID.get()));
    228 }
    229 
    230 TEST_F(AnimationCompositorAnimationsTest, isNotCandidateForCompositorAnimationTransformDependsOnBoxSize)
    231 {
    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()));
    236 
    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()));
    240 
    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()));
    246 }
    247 
    248 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorKeyframeEffectModelMultipleFramesOkay)
    249 {
    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()));
    254 
    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()));
    259 }
    260 
    261 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorKeyframeEffectModel)
    262 {
    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()));
    267 
    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()));
    272 }
    273 
    274 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorStartDelay)
    275 {
    276     m_timing.iterationDuration = 20.0;
    277 
    278     m_timing.startDelay = 2.0;
    279     EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
    280     EXPECT_DOUBLE_EQ(-2.0, m_compositorTiming.scaledTimeOffset);
    281 
    282     m_timing.startDelay = -2.0;
    283     EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
    284     EXPECT_DOUBLE_EQ(2.0, m_compositorTiming.scaledTimeOffset);
    285 }
    286 
    287 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorIterationStart)
    288 {
    289     m_timing.iterationStart = 2.2;
    290     EXPECT_FALSE(convertTimingForCompositor(m_timing, m_compositorTiming));
    291 }
    292 
    293 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorIterationCount)
    294 {
    295     m_timing.iterationCount = 5.0;
    296     EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
    297     EXPECT_EQ(5, m_compositorTiming.adjustedIterationCount);
    298 
    299     m_timing.iterationCount = 5.5;
    300     EXPECT_FALSE(convertTimingForCompositor(m_timing, m_compositorTiming));
    301 
    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), "");
    307 #endif
    308 
    309     m_timing.iterationCount = std::numeric_limits<double>::infinity();
    310     EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
    311     EXPECT_EQ(-1, m_compositorTiming.adjustedIterationCount);
    312 
    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);
    319 }
    320 
    321 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorIterationsAndStartDelay)
    322 {
    323     m_timing.iterationCount = 4.0;
    324     m_timing.iterationDuration = 5.0;
    325 
    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);
    330 
    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);
    335 
    336     m_timing.startDelay = 21.0;
    337     EXPECT_FALSE(convertTimingForCompositor(m_timing, m_compositorTiming));
    338 }
    339 
    340 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorPlaybackRate)
    341 {
    342     m_timing.playbackRate = 2.0;
    343     EXPECT_FALSE(convertTimingForCompositor(m_timing, m_compositorTiming));
    344 
    345     m_timing.playbackRate = 0.0;
    346     EXPECT_FALSE(convertTimingForCompositor(m_timing, m_compositorTiming));
    347 
    348     m_timing.playbackRate = -2.0;
    349     EXPECT_FALSE(convertTimingForCompositor(m_timing, m_compositorTiming));
    350 }
    351 
    352 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorDirection)
    353 {
    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);
    358 
    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);
    363 
    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);
    368 }
    369 
    370 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorDirectionIterationsAndStartDelay)
    371 {
    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);
    381 
    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);
    391 
    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);
    401 
    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);
    411 }
    412 
    413 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTimingTimingFunctionPassThru)
    414 {
    415     m_timing.timingFunction = m_stepTimingFunction;
    416     EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect2.get()));
    417 }
    418 
    419 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTimingFunctionLinear)
    420 {
    421     m_timing.timingFunction = m_linearTimingFunction;
    422     EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect2.get()));
    423     EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect5.get()));
    424 }
    425 
    426 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTimingFunctionCubic)
    427 {
    428     m_timing.timingFunction = m_cubicEaseTimingFunction;
    429     EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect2.get()));
    430     EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect5.get()));
    431 
    432     m_timing.timingFunction = m_cubicCustomTimingFunction;
    433     EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect2.get()));
    434     EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect5.get()));
    435 }
    436 
    437 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTimingFunctionSteps)
    438 {
    439     m_timing.timingFunction = m_stepTimingFunction;
    440     EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect2.get()));
    441     EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect5.get()));
    442 }
    443 
    444 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTimingFunctionChainedLinear)
    445 {
    446     EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect2.get()));
    447     EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect5.get()));
    448 }
    449 
    450 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTimingFunctionChainedCubicMatchingOffsets)
    451 {
    452     (*m_keyframeVector2)[0]->setEasing(m_cubicEaseTimingFunction.get());
    453     m_keyframeAnimationEffect2 = AnimatableValueKeyframeEffectModel::create(*m_keyframeVector2);
    454     EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect2.get()));
    455 
    456     (*m_keyframeVector2)[0]->setEasing(m_cubicCustomTimingFunction.get());
    457     m_keyframeAnimationEffect2 = AnimatableValueKeyframeEffectModel::create(*m_keyframeVector2);
    458     EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect2.get()));
    459 
    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()));
    466 }
    467 
    468 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTimingFunctionMixedGood)
    469 {
    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()));
    476 }
    477 
    478 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTimingFunctionWithStepNotOkay)
    479 {
    480     (*m_keyframeVector2)[0]->setEasing(m_stepTimingFunction.get());
    481     m_keyframeAnimationEffect2 = AnimatableValueKeyframeEffectModel::create(*m_keyframeVector2);
    482     EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimationEffect2.get()));
    483 
    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()));
    490 
    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()));
    497 
    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()));
    504 }
    505 
    506 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositor)
    507 {
    508     Timing linearTiming(createCompositableTiming());
    509 
    510     AnimatableValueKeyframeVector basicFramesVector;
    511     basicFramesVector.append(createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect::CompositeReplace, 0.0).get());
    512     basicFramesVector.append(createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect::CompositeReplace, 1.0).get());
    513 
    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());
    518 
    519     basicFramesVector[0]->setEasing(m_linearTimingFunction.get());
    520     RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> basicFrames = AnimatableValueKeyframeEffectModel::create(basicFramesVector).get();
    521     EXPECT_TRUE(isCandidateForAnimationOnCompositor(linearTiming, *basicFrames.get()));
    522 
    523     basicFramesVector[0]->setEasing(CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseIn));
    524     basicFrames = AnimatableValueKeyframeEffectModel::create(basicFramesVector).get();
    525     EXPECT_TRUE(isCandidateForAnimationOnCompositor(linearTiming, *basicFrames.get()));
    526 
    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()));
    531 }
    532 
    533 // -----------------------------------------------------------------------
    534 // -----------------------------------------------------------------------
    535 
    536 TEST_F(AnimationCompositorAnimationsTest, createSimpleOpacityAnimation)
    537 {
    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));
    542     // --
    543 
    544     WebCompositorSupportMock mockCompositor;
    545 
    546     // Curve is created
    547     blink::WebFloatAnimationCurveMock* mockCurvePtr = new blink::WebFloatAnimationCurveMock;
    548     ExpectationSet usesMockCurve;
    549     EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
    550         .WillOnce(Return(mockCurvePtr));
    551 
    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)));
    554 
    555     // Create animation
    556     blink::WebAnimationMock* mockAnimationPtr = new blink::WebAnimationMock(blink::WebAnimation::TargetPropertyOpacity);
    557     ExpectationSet usesMockAnimation;
    558 
    559     usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurvePtr), blink::WebAnimation::TargetPropertyOpacity, _))
    560         .WillOnce(Return(mockAnimationPtr));
    561 
    562     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(1));
    563     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(0.0));
    564     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(false));
    565 
    566     EXPECT_CALL(*mockAnimationPtr, delete_())
    567         .Times(1)
    568         .After(usesMockAnimation);
    569     EXPECT_CALL(*mockCurvePtr, delete_())
    570         .Times(1)
    571         .After(usesMockCurve);
    572 
    573     // Go!
    574     setCompositorForTesting(mockCompositor);
    575     Vector<OwnPtr<blink::WebAnimation> > result;
    576     getAnimationOnCompositor(m_timing, *effect.get(), result);
    577     EXPECT_EQ(1U, result.size());
    578     result[0].clear();
    579 }
    580 
    581 TEST_F(AnimationCompositorAnimationsTest, createSimpleOpacityAnimationDuration)
    582 {
    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));
    587 
    588     m_timing.iterationDuration = 10.0;
    589     // --
    590 
    591     WebCompositorSupportMock mockCompositor;
    592 
    593     // Curve is created
    594     blink::WebFloatAnimationCurveMock* mockCurvePtr = new blink::WebFloatAnimationCurveMock;
    595     ExpectationSet usesMockCurve;
    596     EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
    597         .WillOnce(Return(mockCurvePtr));
    598 
    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)));
    601 
    602     // Create animation
    603     blink::WebAnimationMock* mockAnimationPtr = new blink::WebAnimationMock(blink::WebAnimation::TargetPropertyOpacity);
    604     ExpectationSet usesMockAnimation;
    605 
    606     usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurvePtr), blink::WebAnimation::TargetPropertyOpacity, _))
    607         .WillOnce(Return(mockAnimationPtr));
    608 
    609     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(1));
    610     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(0.0));
    611     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(false));
    612 
    613     EXPECT_CALL(*mockAnimationPtr, delete_())
    614         .Times(1)
    615         .After(usesMockAnimation);
    616     EXPECT_CALL(*mockCurvePtr, delete_())
    617         .Times(1)
    618         .After(usesMockCurve);
    619 
    620     // Go!
    621     setCompositorForTesting(mockCompositor);
    622     Vector<OwnPtr<blink::WebAnimation> > result;
    623     getAnimationOnCompositor(m_timing, *effect.get(), result);
    624     EXPECT_EQ(1U, result.size());
    625     result[0].clear();
    626 }
    627 
    628 TEST_F(AnimationCompositorAnimationsTest, createMultipleKeyframeOpacityAnimationLinear)
    629 {
    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));
    636 
    637     m_timing.iterationCount = 5;
    638     m_timing.direction = Timing::PlaybackDirectionAlternate;
    639     // --
    640 
    641     WebCompositorSupportMock mockCompositor;
    642 
    643     // Curve is created
    644     blink::WebFloatAnimationCurveMock* mockCurvePtr = new blink::WebFloatAnimationCurveMock();
    645     ExpectationSet usesMockCurve;
    646 
    647     EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
    648         .WillOnce(Return(mockCurvePtr));
    649 
    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)));
    654 
    655     // Animation is created
    656     blink::WebAnimationMock* mockAnimationPtr = new blink::WebAnimationMock(blink::WebAnimation::TargetPropertyOpacity);
    657     ExpectationSet usesMockAnimation;
    658 
    659     usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurvePtr), blink::WebAnimation::TargetPropertyOpacity, _))
    660         .WillOnce(Return(mockAnimationPtr));
    661 
    662     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(5));
    663     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(0.0));
    664     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(true));
    665 
    666     EXPECT_CALL(*mockAnimationPtr, delete_())
    667         .Times(1)
    668         .After(usesMockAnimation);
    669     EXPECT_CALL(*mockCurvePtr, delete_())
    670         .Times(1)
    671         .After(usesMockCurve);
    672 
    673     // Go!
    674     setCompositorForTesting(mockCompositor);
    675     Vector<OwnPtr<blink::WebAnimation> > result;
    676     getAnimationOnCompositor(m_timing, *effect.get(), result);
    677     EXPECT_EQ(1U, result.size());
    678     result[0].clear();
    679 }
    680 
    681 TEST_F(AnimationCompositorAnimationsTest, createSimpleOpacityAnimationStartDelay)
    682 {
    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));
    687 
    688     m_timing.iterationCount = 5.0;
    689     m_timing.iterationDuration = 1.75;
    690     m_timing.startDelay = 3.25;
    691     // --
    692 
    693     WebCompositorSupportMock mockCompositor;
    694 
    695     // Curve is created
    696     blink::WebFloatAnimationCurveMock* mockCurvePtr = new blink::WebFloatAnimationCurveMock;
    697     ExpectationSet usesMockCurve;
    698     EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
    699         .WillOnce(Return(mockCurvePtr));
    700 
    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)));
    703 
    704     // Create animation
    705     blink::WebAnimationMock* mockAnimationPtr = new blink::WebAnimationMock(blink::WebAnimation::TargetPropertyOpacity);
    706     ExpectationSet usesMockAnimation;
    707 
    708     usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurvePtr), blink::WebAnimation::TargetPropertyOpacity, _))
    709         .WillOnce(Return(mockAnimationPtr));
    710 
    711     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(5));
    712     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(-3.25));
    713     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(false));
    714 
    715     EXPECT_CALL(*mockAnimationPtr, delete_())
    716         .Times(1)
    717         .After(usesMockAnimation);
    718     EXPECT_CALL(*mockCurvePtr, delete_())
    719         .Times(1)
    720         .After(usesMockCurve);
    721 
    722     // Go!
    723     setCompositorForTesting(mockCompositor);
    724     Vector<OwnPtr<blink::WebAnimation> > result;
    725     getAnimationOnCompositor(m_timing, *effect.get(), result);
    726     EXPECT_EQ(1U, result.size());
    727     result[0].clear();
    728 }
    729 
    730 TEST_F(AnimationCompositorAnimationsTest, createMultipleKeyframeOpacityAnimationChained)
    731 {
    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);
    742 
    743     m_timing.timingFunction = m_linearTimingFunction.get();
    744     m_timing.iterationDuration = 2.0;
    745     m_timing.iterationCount = 10;
    746     m_timing.direction = Timing::PlaybackDirectionAlternate;
    747     // --
    748 
    749     WebCompositorSupportMock mockCompositor;
    750 
    751     // Curve is created
    752     blink::WebFloatAnimationCurveMock* mockCurvePtr = new blink::WebFloatAnimationCurveMock();
    753     ExpectationSet usesMockCurve;
    754 
    755     EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
    756         .WillOnce(Return(mockCurvePtr));
    757 
    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)));
    762 
    763     // Animation is created
    764     blink::WebAnimationMock* mockAnimationPtr = new blink::WebAnimationMock(blink::WebAnimation::TargetPropertyOpacity);
    765     ExpectationSet usesMockAnimation;
    766 
    767     usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurvePtr), blink::WebAnimation::TargetPropertyOpacity, _))
    768         .WillOnce(Return(mockAnimationPtr));
    769 
    770     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(10));
    771     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(0.0));
    772     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(true));
    773 
    774     EXPECT_CALL(*mockAnimationPtr, delete_())
    775         .Times(1)
    776         .After(usesMockAnimation);
    777     EXPECT_CALL(*mockCurvePtr, delete_())
    778         .Times(1)
    779         .After(usesMockCurve);
    780 
    781     // Go!
    782     setCompositorForTesting(mockCompositor);
    783     Vector<OwnPtr<blink::WebAnimation> > result;
    784     getAnimationOnCompositor(m_timing, *effect.get(), result);
    785     EXPECT_EQ(1U, result.size());
    786     result[0].clear();
    787 }
    788 
    789 TEST_F(AnimationCompositorAnimationsTest, createReversedOpacityAnimation)
    790 {
    791     RefPtr<TimingFunction> cubicEasyFlipTimingFunction = CubicBezierTimingFunction::create(0.0, 0.0, 0.0, 1.0);
    792 
    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);
    803 
    804     m_timing.timingFunction = m_linearTimingFunction.get();
    805     m_timing.iterationCount = 10;
    806     m_timing.direction = Timing::PlaybackDirectionAlternateReverse;
    807     // --
    808 
    809     WebCompositorSupportMock mockCompositor;
    810 
    811     // Curve is created
    812     blink::WebFloatAnimationCurveMock* mockCurvePtr = new blink::WebFloatAnimationCurveMock();
    813     ExpectationSet usesMockCurve;
    814 
    815     EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
    816         .WillOnce(Return(mockCurvePtr));
    817 
    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)));
    822 
    823     // Create the animation
    824     blink::WebAnimationMock* mockAnimationPtr = new blink::WebAnimationMock(blink::WebAnimation::TargetPropertyOpacity);
    825     ExpectationSet usesMockAnimation;
    826 
    827     usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurvePtr), blink::WebAnimation::TargetPropertyOpacity, _))
    828         .WillOnce(Return(mockAnimationPtr));
    829 
    830     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(10));
    831     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(0.0));
    832     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(true));
    833 
    834     EXPECT_CALL(*mockAnimationPtr, delete_())
    835         .Times(1)
    836         .After(usesMockAnimation);
    837     EXPECT_CALL(*mockCurvePtr, delete_())
    838         .Times(1)
    839         .After(usesMockCurve);
    840 
    841     // Go!
    842     setCompositorForTesting(mockCompositor);
    843     Vector<OwnPtr<blink::WebAnimation> > result;
    844     getAnimationOnCompositor(m_timing, *effect.get(), result);
    845     EXPECT_EQ(1U, result.size());
    846     result[0].clear();
    847 }
    848 
    849 TEST_F(AnimationCompositorAnimationsTest, createReversedOpacityAnimationNegativeStartDelay)
    850 {
    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));
    855 
    856     m_timing.iterationCount = 5.0;
    857     m_timing.iterationDuration = 1.5;
    858     m_timing.startDelay = -3;
    859     m_timing.direction = Timing::PlaybackDirectionAlternateReverse;
    860     // --
    861 
    862     WebCompositorSupportMock mockCompositor;
    863 
    864     // Curve is created
    865     blink::WebFloatAnimationCurveMock* mockCurvePtr = new blink::WebFloatAnimationCurveMock;
    866     ExpectationSet usesMockCurve;
    867     EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
    868         .WillOnce(Return(mockCurvePtr));
    869 
    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)));
    872 
    873     // Create animation
    874     blink::WebAnimationMock* mockAnimationPtr = new blink::WebAnimationMock(blink::WebAnimation::TargetPropertyOpacity);
    875     ExpectationSet usesMockAnimation;
    876 
    877     usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurvePtr), blink::WebAnimation::TargetPropertyOpacity, _))
    878         .WillOnce(Return(mockAnimationPtr));
    879 
    880     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(5));
    881     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(3.0));
    882     usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(true));
    883 
    884     EXPECT_CALL(*mockAnimationPtr, delete_())
    885         .Times(1)
    886         .After(usesMockAnimation);
    887     EXPECT_CALL(*mockCurvePtr, delete_())
    888         .Times(1)
    889         .After(usesMockCurve);
    890 
    891     // Go!
    892     setCompositorForTesting(mockCompositor);
    893     Vector<OwnPtr<blink::WebAnimation> > result;
    894     getAnimationOnCompositor(m_timing, *effect.get(), result);
    895     EXPECT_EQ(1U, result.size());
    896     result[0].clear();
    897 }
    898 
    899 
    900 } // namespace WebCore
    901