Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1271)

Side by Side Diff: sky/engine/core/animation/CompositorAnimationsTest.cpp

Issue 772673002: Fix Animations, Remove Compostior Animations. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: CompositorPendingAnimations -> PendingAnimations Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 "sky/engine/config.h"
32
33 #include "sky/engine/core/animation/CompositorAnimations.h"
34
35 #include "sky/engine/core/animation/CompositorAnimationsImpl.h"
36 #include "sky/engine/core/animation/CompositorAnimationsTestHelper.h"
37 #include "sky/engine/core/animation/animatable/AnimatableDouble.h"
38 #include "sky/engine/core/animation/animatable/AnimatableFilterOperations.h"
39 #include "sky/engine/core/animation/animatable/AnimatableTransform.h"
40 #include "sky/engine/core/animation/animatable/AnimatableValueTestHelper.h"
41 #include "sky/engine/platform/geometry/FloatBox.h"
42 #include "sky/engine/platform/geometry/IntSize.h"
43 #include "sky/engine/platform/graphics/filters/FilterOperations.h"
44 #include "sky/engine/platform/transforms/TransformOperations.h"
45 #include "sky/engine/platform/transforms/TranslateTransformOperation.h"
46 #include "sky/engine/public/platform/WebCompositorAnimation.h"
47 #include "sky/engine/wtf/HashFunctions.h"
48 #include "sky/engine/wtf/OwnPtr.h"
49 #include "sky/engine/wtf/PassOwnPtr.h"
50 #include "sky/engine/wtf/PassRefPtr.h"
51 #include "sky/engine/wtf/RefPtr.h"
52
53 #include <gmock/gmock.h>
54 #include <gtest/gtest.h>
55
56 namespace blink {
57
58 using ::testing::CloneToPassOwnPtr;
59 using ::testing::ExpectationSet;
60 using ::testing::Ref;
61 using ::testing::Return;
62 using ::testing::_;
63
64 class AnimationCompositorAnimationsTest : public AnimationCompositorAnimationsTe stBase {
65 protected:
66 RefPtr<TimingFunction> m_linearTimingFunction;
67 RefPtr<TimingFunction> m_cubicEaseTimingFunction;
68 RefPtr<TimingFunction> m_cubicCustomTimingFunction;
69 RefPtr<TimingFunction> m_stepTimingFunction;
70
71 Timing m_timing;
72 CompositorAnimationsImpl::CompositorTiming m_compositorTiming;
73 OwnPtr<AnimatableValueKeyframeVector> m_keyframeVector2;
74 RefPtr<AnimatableValueKeyframeEffectModel> m_keyframeAnimationEffect2;
75 OwnPtr<AnimatableValueKeyframeVector> m_keyframeVector5;
76 RefPtr<AnimatableValueKeyframeEffectModel> m_keyframeAnimationEffect5;
77
78 virtual void SetUp()
79 {
80 AnimationCompositorAnimationsTestBase::SetUp();
81
82 m_linearTimingFunction = LinearTimingFunction::shared();
83 m_cubicEaseTimingFunction = CubicBezierTimingFunction::preset(CubicBezie rTimingFunction::Ease);
84 m_cubicCustomTimingFunction = CubicBezierTimingFunction::create(1, 2, 3, 4);
85 m_stepTimingFunction = StepsTimingFunction::create(1, StepsTimingFunctio n::StepAtEnd);
86
87 m_timing = createCompositableTiming();
88 m_compositorTiming = CompositorAnimationsImpl::CompositorTiming();
89 // Make sure the CompositableTiming is really compositable, otherwise
90 // most other tests will fail.
91 ASSERT(convertTimingForCompositor(m_timing, m_compositorTiming));
92
93 m_keyframeVector2 = createCompositableFloatKeyframeVector(2);
94 m_keyframeAnimationEffect2 = AnimatableValueKeyframeEffectModel::create( *m_keyframeVector2);
95
96 m_keyframeVector5 = createCompositableFloatKeyframeVector(5);
97 m_keyframeAnimationEffect5 = AnimatableValueKeyframeEffectModel::create( *m_keyframeVector5);
98 }
99
100 public:
101
102 bool convertTimingForCompositor(const Timing& t, CompositorAnimationsImpl::C ompositorTiming& out)
103 {
104 return CompositorAnimationsImpl::convertTimingForCompositor(t, 0, out);
105 }
106 bool isCandidateForAnimationOnCompositor(const Timing& timing, const Animati onEffect& effect)
107 {
108 return CompositorAnimations::instance()->isCandidateForAnimationOnCompos itor(timing, effect);
109 }
110 void getAnimationOnCompositor(Timing& timing, AnimatableValueKeyframeEffectM odel& effect, Vector<OwnPtr<WebCompositorAnimation> >& animations)
111 {
112 return CompositorAnimationsImpl::getAnimationOnCompositor(timing, std::n umeric_limits<double>::quiet_NaN(), 0, effect, animations);
113 }
114 bool getAnimationBounds(FloatBox& boundingBox, const AnimationEffect& effect , double minValue, double maxValue)
115 {
116 return CompositorAnimations::instance()->getAnimatedBoundingBox(bounding Box, effect, minValue, maxValue);
117 }
118
119 bool duplicateSingleKeyframeAndTestIsCandidateOnResult(AnimatableValueKeyfra me* frame)
120 {
121 EXPECT_EQ(frame->offset(), 0);
122 AnimatableValueKeyframeVector frames;
123 RefPtr<Keyframe> second = frame->cloneWithOffset(1);
124
125 frames.append(frame);
126 frames.append(toAnimatableValueKeyframe(second.get()));
127 return isCandidateForAnimationOnCompositor(m_timing, *AnimatableValueKey frameEffectModel::create(frames).get());
128 }
129
130 // -------------------------------------------------------------------
131
132 Timing createCompositableTiming()
133 {
134 Timing timing;
135 timing.startDelay = 0;
136 timing.fillMode = Timing::FillModeNone;
137 timing.iterationStart = 0;
138 timing.iterationCount = 1;
139 timing.iterationDuration = 1.0;
140 timing.playbackRate = 1.0;
141 timing.direction = Timing::PlaybackDirectionNormal;
142 ASSERT(m_linearTimingFunction);
143 timing.timingFunction = m_linearTimingFunction;
144 return timing;
145 }
146
147 PassRefPtr<AnimatableValueKeyframe> createReplaceOpKeyframe(CSSPropertyID id , AnimatableValue* value, double offset = 0)
148 {
149 RefPtr<AnimatableValueKeyframe> keyframe = AnimatableValueKeyframe::crea te();
150 keyframe->setPropertyValue(id, value);
151 keyframe->setComposite(AnimationEffect::CompositeReplace);
152 keyframe->setOffset(offset);
153 keyframe->setEasing(LinearTimingFunction::shared());
154 return keyframe;
155 }
156
157 PassRefPtr<AnimatableValueKeyframe> createDefaultKeyframe(CSSPropertyID id, AnimationEffect::CompositeOperation op, double offset = 0)
158 {
159 RefPtr<AnimatableValue> value = nullptr;
160 if (id == CSSPropertyTransform)
161 value = AnimatableTransform::create(TransformOperations());
162 else
163 value = AnimatableDouble::create(10.0);
164
165 RefPtr<AnimatableValueKeyframe> keyframe = createReplaceOpKeyframe(id, v alue.get(), offset);
166 keyframe->setComposite(op);
167 return keyframe;
168 }
169
170 PassOwnPtr<AnimatableValueKeyframeVector> createCompositableFloatKeyframeVec tor(size_t n)
171 {
172 Vector<double> values;
173 for (size_t i = 0; i < n; i++) {
174 values.append(static_cast<double>(i));
175 }
176 return createCompositableFloatKeyframeVector(values);
177 }
178
179 PassOwnPtr<AnimatableValueKeyframeVector> createCompositableFloatKeyframeVec tor(Vector<double>& values)
180 {
181 OwnPtr<AnimatableValueKeyframeVector> frames = adoptPtr(new AnimatableVa lueKeyframeVector);
182 for (size_t i = 0; i < values.size(); i++) {
183 double offset = 1.0 / (values.size() - 1) * i;
184 RefPtr<AnimatableDouble> value = AnimatableDouble::create(values[i]) ;
185 frames->append(createReplaceOpKeyframe(CSSPropertyOpacity, value.get (), offset).get());
186 }
187 return frames.release();
188 }
189
190 PassOwnPtr<AnimatableValueKeyframeVector> createCompositableTransformKeyfram eVector(const Vector<TransformOperations>& values)
191 {
192 OwnPtr<AnimatableValueKeyframeVector> frames = adoptPtr(new AnimatableVa lueKeyframeVector);
193 for (size_t i = 0; i < values.size(); ++i) {
194 double offset = 1.0f / (values.size() - 1) * i;
195 RefPtr<AnimatableTransform> value = AnimatableTransform::create(valu es[i]);
196 frames->append(createReplaceOpKeyframe(CSSPropertyTransform, value.g et(), offset).get());
197 }
198 return frames.release();
199 }
200
201 PassRefPtr<AnimatableValueKeyframeEffectModel> createKeyframeEffectModel(Pas sRefPtr<AnimatableValueKeyframe> prpFrom, PassRefPtr<AnimatableValueKeyframe> pr pTo, PassRefPtr<AnimatableValueKeyframe> prpC = nullptr, PassRefPtr<AnimatableVa lueKeyframe> prpD = nullptr)
202 {
203 RefPtr<AnimatableValueKeyframe> from = prpFrom;
204 RefPtr<AnimatableValueKeyframe> to = prpTo;
205 RefPtr<AnimatableValueKeyframe> c = prpC;
206 RefPtr<AnimatableValueKeyframe> d = prpD;
207
208 EXPECT_EQ(from->offset(), 0);
209 AnimatableValueKeyframeVector frames;
210 frames.append(from);
211 EXPECT_LE(from->offset(), to->offset());
212 frames.append(to);
213 if (c) {
214 EXPECT_LE(to->offset(), c->offset());
215 frames.append(c);
216 }
217 if (d) {
218 frames.append(d);
219 EXPECT_LE(c->offset(), d->offset());
220 EXPECT_EQ(d->offset(), 1.0);
221 } else {
222 EXPECT_EQ(to->offset(), 1.0);
223 }
224 if (!HasFatalFailure()) {
225 return AnimatableValueKeyframeEffectModel::create(frames);
226 }
227 return nullptr;
228 }
229
230 };
231
232 // -----------------------------------------------------------------------
233 // -----------------------------------------------------------------------
234
235 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorKey frameMultipleCSSProperties)
236 {
237 RefPtr<AnimatableValueKeyframe> keyframeGoodMultiple = createDefaultKeyframe (CSSPropertyOpacity, AnimationEffect::CompositeReplace);
238 keyframeGoodMultiple->setPropertyValue(CSSPropertyTransform, AnimatableTrans form::create(TransformOperations()).get());
239 EXPECT_TRUE(duplicateSingleKeyframeAndTestIsCandidateOnResult(keyframeGoodMu ltiple.get()));
240
241 RefPtr<AnimatableValueKeyframe> keyframeBadMultipleID = createDefaultKeyfram e(CSSPropertyColor, AnimationEffect::CompositeReplace);
242 keyframeBadMultipleID->setPropertyValue(CSSPropertyOpacity, AnimatableDouble ::create(10.0).get());
243 EXPECT_FALSE(duplicateSingleKeyframeAndTestIsCandidateOnResult(keyframeBadMu ltipleID.get()));
244 }
245
246 TEST_F(AnimationCompositorAnimationsTest, isNotCandidateForCompositorAnimationTr ansformDependsOnBoxSize)
247 {
248 TransformOperations ops;
249 ops.operations().append(TranslateTransformOperation::create(Length(2, Fixed) , Length(2, Fixed), TransformOperation::TranslateX));
250 RefPtr<AnimatableValueKeyframe> goodKeyframe = createReplaceOpKeyframe(CSSPr opertyTransform, AnimatableTransform::create(ops).get());
251 EXPECT_TRUE(duplicateSingleKeyframeAndTestIsCandidateOnResult(goodKeyframe.g et()));
252
253 ops.operations().append(TranslateTransformOperation::create(Length(50, Perce nt), Length(2, Fixed), TransformOperation::TranslateX));
254 RefPtr<AnimatableValueKeyframe> badKeyframe = createReplaceOpKeyframe(CSSPro pertyTransform, AnimatableTransform::create(ops).get());
255 EXPECT_FALSE(duplicateSingleKeyframeAndTestIsCandidateOnResult(badKeyframe.g et()));
256
257 TransformOperations ops2;
258 Length calcLength = Length(100, Percent).blend(Length(100, Fixed), 0.5, Valu eRangeAll);
259 ops2.operations().append(TranslateTransformOperation::create(calcLength, Len gth(0, Fixed), TransformOperation::TranslateX));
260 RefPtr<AnimatableValueKeyframe> badKeyframe2 = createReplaceOpKeyframe(CSSPr opertyTransform, AnimatableTransform::create(ops2).get());
261 EXPECT_FALSE(duplicateSingleKeyframeAndTestIsCandidateOnResult(badKeyframe2. get()));
262 }
263
264 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorKey frameEffectModelMultipleFramesOkay)
265 {
266 AnimatableValueKeyframeVector framesSame;
267 framesSame.append(createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect: :CompositeReplace, 0.0).get());
268 framesSame.append(createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect: :CompositeReplace, 1.0).get());
269 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *AnimatableValueKe yframeEffectModel::create(framesSame).get()));
270
271 AnimatableValueKeyframeVector framesMixed;
272 framesMixed.append(createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect ::CompositeReplace, 0.0).get());
273 framesMixed.append(createDefaultKeyframe(CSSPropertyTransform, AnimationEffe ct::CompositeReplace, 1.0).get());
274 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *AnimatableValueK eyframeEffectModel::create(framesMixed).get()));
275 }
276
277 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorKey frameEffectModel)
278 {
279 AnimatableValueKeyframeVector framesSame;
280 framesSame.append(createDefaultKeyframe(CSSPropertyColor, AnimationEffect::C ompositeReplace, 0.0).get());
281 framesSame.append(createDefaultKeyframe(CSSPropertyColor, AnimationEffect::C ompositeReplace, 1.0).get());
282 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *AnimatableValueK eyframeEffectModel::create(framesSame).get()));
283
284 AnimatableValueKeyframeVector framesMixedProperties;
285 framesMixedProperties.append(createDefaultKeyframe(CSSPropertyOpacity, Anima tionEffect::CompositeReplace, 0.0).get());
286 framesMixedProperties.append(createDefaultKeyframe(CSSPropertyColor, Animati onEffect::CompositeReplace, 1.0).get());
287 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *AnimatableValueK eyframeEffectModel::create(framesMixedProperties).get()));
288 }
289
290 TEST_F(AnimationCompositorAnimationsTest, AnimatedBoundingBox)
291 {
292 Vector<TransformOperations> transformVector;
293 transformVector.append(TransformOperations());
294 transformVector.last().operations().append(TranslateTransformOperation::crea te(Length(0, Fixed), Length(0, Fixed), 0.0, TransformOperation::Translate3D));
295 transformVector.append(TransformOperations());
296 transformVector.last().operations().append(TranslateTransformOperation::crea te(Length(200, Fixed), Length(200, Fixed), 0.0, TransformOperation::Translate3D) );
297 OwnPtr<AnimatableValueKeyframeVector> frames = createCompositableTransformKe yframeVector(transformVector);
298 FloatBox bounds;
299 EXPECT_TRUE(getAnimationBounds(bounds, *AnimatableValueKeyframeEffectModel:: create(*frames).get(), 0, 1));
300 EXPECT_EQ(FloatBox(0.0f, 0.f, 0.0f, 200.0f, 200.0f, 0.0f), bounds);
301 bounds = FloatBox();
302 EXPECT_TRUE(getAnimationBounds(bounds, *AnimatableValueKeyframeEffectModel:: create(*frames).get(), -1, 1));
303 EXPECT_EQ(FloatBox(-200.0f, -200.0, 0.0, 400.0f, 400.0f, 0.0f), bounds);
304 transformVector.append(TransformOperations());
305 transformVector.last().operations().append(TranslateTransformOperation::crea te(Length(-300, Fixed), Length(-400, Fixed), 1.0f, TransformOperation::Translate 3D));
306 bounds = FloatBox();
307 frames = createCompositableTransformKeyframeVector(transformVector);
308 EXPECT_TRUE(getAnimationBounds(bounds, *AnimatableValueKeyframeEffectModel:: create(*frames).get(), 0, 1));
309 EXPECT_EQ(FloatBox(-300.0f, -400.f, 0.0f, 500.0f, 600.0f, 1.0f), bounds);
310 bounds = FloatBox();
311 EXPECT_TRUE(getAnimationBounds(bounds, *AnimatableValueKeyframeEffectModel:: create(*frames).get(), -1, 2));
312 EXPECT_EQ(FloatBox(-1300.0f, -1600.f, 0.0f, 1500.0f, 1800.0f, 3.0f), bounds) ;
313 }
314
315 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorStartDelay)
316 {
317 m_timing.iterationDuration = 20.0;
318
319 m_timing.startDelay = 2.0;
320 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
321 EXPECT_DOUBLE_EQ(-2.0, m_compositorTiming.scaledTimeOffset);
322
323 m_timing.startDelay = -2.0;
324 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
325 EXPECT_DOUBLE_EQ(2.0, m_compositorTiming.scaledTimeOffset);
326 }
327
328 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorIterationSta rt)
329 {
330 m_timing.iterationStart = 2.2;
331 EXPECT_FALSE(convertTimingForCompositor(m_timing, m_compositorTiming));
332 }
333
334 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorIterationCou nt)
335 {
336 m_timing.iterationCount = 5.0;
337 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
338 EXPECT_EQ(5, m_compositorTiming.adjustedIterationCount);
339
340 m_timing.iterationCount = 5.5;
341 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
342 EXPECT_EQ(5.5, m_compositorTiming.adjustedIterationCount);
343
344 // EXPECT_DEATH tests are flaky on Android.
345 #if ENABLE(ASSERT) && !OS(ANDROID)
346 m_timing.iterationCount = -1;
347 EXPECT_DEATH(convertTimingForCompositor(m_timing, m_compositorTiming), "");
348 #endif
349
350 m_timing.iterationCount = std::numeric_limits<double>::infinity();
351 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
352 EXPECT_EQ(-1, m_compositorTiming.adjustedIterationCount);
353
354 m_timing.iterationCount = std::numeric_limits<double>::infinity();
355 m_timing.iterationDuration = 5.0;
356 m_timing.startDelay = -6.0;
357 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
358 EXPECT_DOUBLE_EQ(6.0, m_compositorTiming.scaledTimeOffset);
359 EXPECT_EQ(-1, m_compositorTiming.adjustedIterationCount);
360 }
361
362 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorIterationsAn dStartDelay)
363 {
364 m_timing.iterationCount = 4.0;
365 m_timing.iterationDuration = 5.0;
366
367 m_timing.startDelay = 6.0;
368 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
369 EXPECT_DOUBLE_EQ(-6.0, m_compositorTiming.scaledTimeOffset);
370 EXPECT_DOUBLE_EQ(4.0, m_compositorTiming.adjustedIterationCount);
371
372 m_timing.startDelay = -6.0;
373 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
374 EXPECT_DOUBLE_EQ(6.0, m_compositorTiming.scaledTimeOffset);
375 EXPECT_DOUBLE_EQ(4.0, m_compositorTiming.adjustedIterationCount);
376
377 m_timing.startDelay = 21.0;
378 EXPECT_FALSE(convertTimingForCompositor(m_timing, m_compositorTiming));
379 }
380
381 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorPlaybackRate )
382 {
383 m_timing.playbackRate = 2.0;
384 EXPECT_FALSE(convertTimingForCompositor(m_timing, m_compositorTiming));
385
386 m_timing.playbackRate = 0.0;
387 EXPECT_FALSE(convertTimingForCompositor(m_timing, m_compositorTiming));
388
389 m_timing.playbackRate = -2.0;
390 EXPECT_FALSE(convertTimingForCompositor(m_timing, m_compositorTiming));
391 }
392
393 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorDirection)
394 {
395 m_timing.direction = Timing::PlaybackDirectionAlternate;
396 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
397 EXPECT_TRUE(m_compositorTiming.alternate);
398 EXPECT_FALSE(m_compositorTiming.reverse);
399
400 m_timing.direction = Timing::PlaybackDirectionAlternateReverse;
401 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
402 EXPECT_TRUE(m_compositorTiming.alternate);
403 EXPECT_TRUE(m_compositorTiming.reverse);
404
405 m_timing.direction = Timing::PlaybackDirectionReverse;
406 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
407 EXPECT_FALSE(m_compositorTiming.alternate);
408 EXPECT_TRUE(m_compositorTiming.reverse);
409 }
410
411 TEST_F(AnimationCompositorAnimationsTest, ConvertTimingForCompositorDirectionIte rationsAndStartDelay)
412 {
413 m_timing.direction = Timing::PlaybackDirectionAlternate;
414 m_timing.iterationCount = 4.0;
415 m_timing.iterationDuration = 5.0;
416 m_timing.startDelay = -6.0;
417 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
418 EXPECT_DOUBLE_EQ(6.0, m_compositorTiming.scaledTimeOffset);
419 EXPECT_EQ(4, m_compositorTiming.adjustedIterationCount);
420 EXPECT_TRUE(m_compositorTiming.alternate);
421 EXPECT_FALSE(m_compositorTiming.reverse);
422
423 m_timing.direction = Timing::PlaybackDirectionAlternate;
424 m_timing.iterationCount = 4.0;
425 m_timing.iterationDuration = 5.0;
426 m_timing.startDelay = -11.0;
427 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
428 EXPECT_DOUBLE_EQ(11.0, m_compositorTiming.scaledTimeOffset);
429 EXPECT_EQ(4, m_compositorTiming.adjustedIterationCount);
430 EXPECT_TRUE(m_compositorTiming.alternate);
431 EXPECT_FALSE(m_compositorTiming.reverse);
432
433 m_timing.direction = Timing::PlaybackDirectionAlternateReverse;
434 m_timing.iterationCount = 4.0;
435 m_timing.iterationDuration = 5.0;
436 m_timing.startDelay = -6.0;
437 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
438 EXPECT_DOUBLE_EQ(6.0, m_compositorTiming.scaledTimeOffset);
439 EXPECT_EQ(4, m_compositorTiming.adjustedIterationCount);
440 EXPECT_TRUE(m_compositorTiming.alternate);
441 EXPECT_TRUE(m_compositorTiming.reverse);
442
443 m_timing.direction = Timing::PlaybackDirectionAlternateReverse;
444 m_timing.iterationCount = 4.0;
445 m_timing.iterationDuration = 5.0;
446 m_timing.startDelay = -11.0;
447 EXPECT_TRUE(convertTimingForCompositor(m_timing, m_compositorTiming));
448 EXPECT_DOUBLE_EQ(11.0, m_compositorTiming.scaledTimeOffset);
449 EXPECT_EQ(4, m_compositorTiming.adjustedIterationCount);
450 EXPECT_TRUE(m_compositorTiming.alternate);
451 EXPECT_TRUE(m_compositorTiming.reverse);
452 }
453
454 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTim ingTimingFunctionPassThru)
455 {
456 m_timing.timingFunction = m_stepTimingFunction;
457 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimat ionEffect2.get()));
458 }
459
460 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTim ingFunctionLinear)
461 {
462 m_timing.timingFunction = m_linearTimingFunction;
463 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimati onEffect2.get()));
464 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimati onEffect5.get()));
465 }
466
467 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTim ingFunctionCubic)
468 {
469 m_timing.timingFunction = m_cubicEaseTimingFunction;
470 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimati onEffect2.get()));
471 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimat ionEffect5.get()));
472
473 m_timing.timingFunction = m_cubicCustomTimingFunction;
474 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimati onEffect2.get()));
475 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimat ionEffect5.get()));
476 }
477
478 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTim ingFunctionSteps)
479 {
480 m_timing.timingFunction = m_stepTimingFunction;
481 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimat ionEffect2.get()));
482 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimat ionEffect5.get()));
483 }
484
485 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTim ingFunctionChainedLinear)
486 {
487 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimati onEffect2.get()));
488 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimati onEffect5.get()));
489 }
490
491 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorNon LinearTimingFunctionOnFirstFrame)
492 {
493 m_timing.timingFunction = m_cubicEaseTimingFunction;
494
495 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimati onEffect2.get()));
496
497 (*m_keyframeVector2)[0]->setEasing(m_cubicEaseTimingFunction.get());
498 m_keyframeAnimationEffect2 = AnimatableValueKeyframeEffectModel::create(*m_k eyframeVector2);
499 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimat ionEffect2.get()));
500 }
501
502 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTim ingFunctionChainedCubicMatchingOffsets)
503 {
504 (*m_keyframeVector2)[0]->setEasing(m_cubicEaseTimingFunction.get());
505 m_keyframeAnimationEffect2 = AnimatableValueKeyframeEffectModel::create(*m_k eyframeVector2);
506 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimati onEffect2.get()));
507
508 (*m_keyframeVector2)[0]->setEasing(m_cubicCustomTimingFunction.get());
509 m_keyframeAnimationEffect2 = AnimatableValueKeyframeEffectModel::create(*m_k eyframeVector2);
510 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimati onEffect2.get()));
511
512 (*m_keyframeVector5)[0]->setEasing(m_cubicEaseTimingFunction.get());
513 (*m_keyframeVector5)[1]->setEasing(m_cubicCustomTimingFunction.get());
514 (*m_keyframeVector5)[2]->setEasing(m_cubicCustomTimingFunction.get());
515 (*m_keyframeVector5)[3]->setEasing(m_cubicCustomTimingFunction.get());
516 m_keyframeAnimationEffect5 = AnimatableValueKeyframeEffectModel::create(*m_k eyframeVector5);
517 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimati onEffect5.get()));
518 }
519
520 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTim ingFunctionMixedGood)
521 {
522 (*m_keyframeVector5)[0]->setEasing(m_linearTimingFunction.get());
523 (*m_keyframeVector5)[1]->setEasing(m_cubicEaseTimingFunction.get());
524 (*m_keyframeVector5)[2]->setEasing(m_cubicEaseTimingFunction.get());
525 (*m_keyframeVector5)[3]->setEasing(m_linearTimingFunction.get());
526 m_keyframeAnimationEffect5 = AnimatableValueKeyframeEffectModel::create(*m_k eyframeVector5);
527 EXPECT_TRUE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimati onEffect5.get()));
528 }
529
530 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorTim ingFunctionWithStepNotOkay)
531 {
532 (*m_keyframeVector2)[0]->setEasing(m_stepTimingFunction.get());
533 m_keyframeAnimationEffect2 = AnimatableValueKeyframeEffectModel::create(*m_k eyframeVector2);
534 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimat ionEffect2.get()));
535
536 (*m_keyframeVector5)[0]->setEasing(m_stepTimingFunction.get());
537 (*m_keyframeVector5)[1]->setEasing(m_linearTimingFunction.get());
538 (*m_keyframeVector5)[2]->setEasing(m_cubicEaseTimingFunction.get());
539 (*m_keyframeVector5)[3]->setEasing(m_linearTimingFunction.get());
540 m_keyframeAnimationEffect5 = AnimatableValueKeyframeEffectModel::create(*m_k eyframeVector5);
541 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimat ionEffect5.get()));
542
543 (*m_keyframeVector5)[0]->setEasing(m_linearTimingFunction.get());
544 (*m_keyframeVector5)[1]->setEasing(m_stepTimingFunction.get());
545 (*m_keyframeVector5)[2]->setEasing(m_cubicEaseTimingFunction.get());
546 (*m_keyframeVector5)[3]->setEasing(m_linearTimingFunction.get());
547 m_keyframeAnimationEffect5 = AnimatableValueKeyframeEffectModel::create(*m_k eyframeVector5);
548 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimat ionEffect5.get()));
549
550 (*m_keyframeVector5)[0]->setEasing(m_linearTimingFunction.get());
551 (*m_keyframeVector5)[1]->setEasing(m_cubicEaseTimingFunction.get());
552 (*m_keyframeVector5)[2]->setEasing(m_cubicEaseTimingFunction.get());
553 (*m_keyframeVector5)[3]->setEasing(m_stepTimingFunction.get());
554 m_keyframeAnimationEffect5 = AnimatableValueKeyframeEffectModel::create(*m_k eyframeVector5);
555 EXPECT_FALSE(isCandidateForAnimationOnCompositor(m_timing, *m_keyframeAnimat ionEffect5.get()));
556 }
557
558 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositor)
559 {
560 Timing linearTiming(createCompositableTiming());
561
562 AnimatableValueKeyframeVector basicFramesVector;
563 basicFramesVector.append(createDefaultKeyframe(CSSPropertyOpacity, Animation Effect::CompositeReplace, 0.0).get());
564 basicFramesVector.append(createDefaultKeyframe(CSSPropertyOpacity, Animation Effect::CompositeReplace, 1.0).get());
565
566 AnimatableValueKeyframeVector nonBasicFramesVector;
567 nonBasicFramesVector.append(createDefaultKeyframe(CSSPropertyOpacity, Animat ionEffect::CompositeReplace, 0.0).get());
568 nonBasicFramesVector.append(createDefaultKeyframe(CSSPropertyOpacity, Animat ionEffect::CompositeReplace, 0.5).get());
569 nonBasicFramesVector.append(createDefaultKeyframe(CSSPropertyOpacity, Animat ionEffect::CompositeReplace, 1.0).get());
570
571 basicFramesVector[0]->setEasing(m_linearTimingFunction.get());
572 RefPtr<AnimatableValueKeyframeEffectModel> basicFrames = AnimatableValueKeyf rameEffectModel::create(basicFramesVector).get();
573 EXPECT_TRUE(isCandidateForAnimationOnCompositor(linearTiming, *basicFrames.g et()));
574
575 basicFramesVector[0]->setEasing(CubicBezierTimingFunction::preset(CubicBezie rTimingFunction::EaseIn));
576 basicFrames = AnimatableValueKeyframeEffectModel::create(basicFramesVector). get();
577 EXPECT_TRUE(isCandidateForAnimationOnCompositor(linearTiming, *basicFrames.g et()));
578
579 nonBasicFramesVector[0]->setEasing(m_linearTimingFunction.get());
580 nonBasicFramesVector[1]->setEasing(CubicBezierTimingFunction::preset(CubicBe zierTimingFunction::EaseIn));
581 RefPtr<AnimatableValueKeyframeEffectModel> nonBasicFrames = AnimatableValueK eyframeEffectModel::create(nonBasicFramesVector).get();
582 EXPECT_TRUE(CompositorAnimations::instance()->isCandidateForAnimationOnCompo sitor(linearTiming, *nonBasicFrames.get()));
583 }
584
585 // -----------------------------------------------------------------------
586 // -----------------------------------------------------------------------
587
588 TEST_F(AnimationCompositorAnimationsTest, createSimpleOpacityAnimation)
589 {
590 // Animation to convert
591 RefPtr<AnimatableValueKeyframeEffectModel> effect = createKeyframeEffectMode l(
592 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(2.0 ).get(), 0),
593 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(5.0 ).get(), 1.0));
594 // --
595
596 WebCompositorSupportMock mockCompositor;
597
598 // Curve is created
599 WebFloatAnimationCurveMock* mockCurvePtr = new WebFloatAnimationCurveMock;
600 ExpectationSet usesMockCurve;
601 EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
602 .WillOnce(Return(mockCurvePtr));
603
604 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(0.0, 2.0), WebCompositorAnimationCurve::TimingFunctionTypeLinear));
605 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(1.0, 5.0))) ;
606
607 // Create animation
608 WebCompositorAnimationMock* mockAnimationPtr = new WebCompositorAnimationMoc k(WebCompositorAnimation::TargetPropertyOpacity);
609 ExpectationSet usesMockAnimation;
610
611 usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurveP tr), WebCompositorAnimation::TargetPropertyOpacity, _))
612 .WillOnce(Return(mockAnimationPtr));
613
614 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(1));
615 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(0.0));
616 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(f alse));
617
618 EXPECT_CALL(*mockAnimationPtr, delete_())
619 .Times(1)
620 .After(usesMockAnimation);
621 EXPECT_CALL(*mockCurvePtr, delete_())
622 .Times(1)
623 .After(usesMockCurve);
624
625 // Go!
626 setCompositorForTesting(mockCompositor);
627 Vector<OwnPtr<WebCompositorAnimation> > result;
628 getAnimationOnCompositor(m_timing, *effect.get(), result);
629 EXPECT_EQ(1U, result.size());
630 result[0].clear();
631 }
632
633 TEST_F(AnimationCompositorAnimationsTest, createSimpleOpacityAnimationDuration)
634 {
635 // Animation to convert
636 RefPtr<AnimatableValueKeyframeEffectModel> effect = createKeyframeEffectMode l(
637 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(2.0 ).get(), 0),
638 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(5.0 ).get(), 1.0));
639
640 m_timing.iterationDuration = 10.0;
641 // --
642
643 WebCompositorSupportMock mockCompositor;
644
645 // Curve is created
646 WebFloatAnimationCurveMock* mockCurvePtr = new WebFloatAnimationCurveMock;
647 ExpectationSet usesMockCurve;
648 EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
649 .WillOnce(Return(mockCurvePtr));
650
651 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(0.0, 2.0), WebCompositorAnimationCurve::TimingFunctionTypeLinear));
652 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(10.0, 5.0)) );
653
654 // Create animation
655 WebCompositorAnimationMock* mockAnimationPtr = new WebCompositorAnimationMoc k(WebCompositorAnimation::TargetPropertyOpacity);
656 ExpectationSet usesMockAnimation;
657
658 usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurveP tr), WebCompositorAnimation::TargetPropertyOpacity, _))
659 .WillOnce(Return(mockAnimationPtr));
660
661 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(1));
662 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(0.0));
663 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(f alse));
664
665 EXPECT_CALL(*mockAnimationPtr, delete_())
666 .Times(1)
667 .After(usesMockAnimation);
668 EXPECT_CALL(*mockCurvePtr, delete_())
669 .Times(1)
670 .After(usesMockCurve);
671
672 // Go!
673 setCompositorForTesting(mockCompositor);
674 Vector<OwnPtr<WebCompositorAnimation> > result;
675 getAnimationOnCompositor(m_timing, *effect.get(), result);
676 EXPECT_EQ(1U, result.size());
677 result[0].clear();
678 }
679
680 TEST_F(AnimationCompositorAnimationsTest, createMultipleKeyframeOpacityAnimation Linear)
681 {
682 // Animation to convert
683 RefPtr<AnimatableValueKeyframeEffectModel> effect = createKeyframeEffectMode l(
684 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(2.0 ).get(), 0),
685 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(-1. 0).get(), 0.25),
686 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(20. 0).get(), 0.5),
687 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(5.0 ).get(), 1.0));
688
689 m_timing.iterationCount = 5;
690 m_timing.direction = Timing::PlaybackDirectionAlternate;
691 // --
692
693 WebCompositorSupportMock mockCompositor;
694
695 // Curve is created
696 WebFloatAnimationCurveMock* mockCurvePtr = new WebFloatAnimationCurveMock();
697 ExpectationSet usesMockCurve;
698
699 EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
700 .WillOnce(Return(mockCurvePtr));
701
702 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(0.0, 2.0), WebCompositorAnimationCurve::TimingFunctionTypeLinear));
703 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(0.25, -1.0) , WebCompositorAnimationCurve::TimingFunctionTypeLinear));
704 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(0.5, 20.0), WebCompositorAnimationCurve::TimingFunctionTypeLinear));
705 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(1.0, 5.0))) ;
706
707 // Animation is created
708 WebCompositorAnimationMock* mockAnimationPtr = new WebCompositorAnimationMoc k(WebCompositorAnimation::TargetPropertyOpacity);
709 ExpectationSet usesMockAnimation;
710
711 usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurveP tr), WebCompositorAnimation::TargetPropertyOpacity, _))
712 .WillOnce(Return(mockAnimationPtr));
713
714 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(5));
715 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(0.0));
716 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(t rue));
717
718 EXPECT_CALL(*mockAnimationPtr, delete_())
719 .Times(1)
720 .After(usesMockAnimation);
721 EXPECT_CALL(*mockCurvePtr, delete_())
722 .Times(1)
723 .After(usesMockCurve);
724
725 // Go!
726 setCompositorForTesting(mockCompositor);
727 Vector<OwnPtr<WebCompositorAnimation> > result;
728 getAnimationOnCompositor(m_timing, *effect.get(), result);
729 EXPECT_EQ(1U, result.size());
730 result[0].clear();
731 }
732
733 TEST_F(AnimationCompositorAnimationsTest, createSimpleOpacityAnimationStartDelay )
734 {
735 // Animation to convert
736 RefPtr<AnimatableValueKeyframeEffectModel> effect = createKeyframeEffectMode l(
737 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(2.0 ).get(), 0),
738 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(5.0 ).get(), 1.0));
739
740 m_timing.iterationCount = 5.0;
741 m_timing.iterationDuration = 1.75;
742 m_timing.startDelay = 3.25;
743 // --
744
745 WebCompositorSupportMock mockCompositor;
746
747 // Curve is created
748 WebFloatAnimationCurveMock* mockCurvePtr = new WebFloatAnimationCurveMock;
749 ExpectationSet usesMockCurve;
750 EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
751 .WillOnce(Return(mockCurvePtr));
752
753 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(0.0, 2.0), WebCompositorAnimationCurve::TimingFunctionTypeLinear));
754 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(1.75, 5.0)) );
755
756 // Create animation
757 WebCompositorAnimationMock* mockAnimationPtr = new WebCompositorAnimationMoc k(WebCompositorAnimation::TargetPropertyOpacity);
758 ExpectationSet usesMockAnimation;
759
760 usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurveP tr), WebCompositorAnimation::TargetPropertyOpacity, _))
761 .WillOnce(Return(mockAnimationPtr));
762
763 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(5));
764 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(-3.25));
765 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(f alse));
766
767 EXPECT_CALL(*mockAnimationPtr, delete_())
768 .Times(1)
769 .After(usesMockAnimation);
770 EXPECT_CALL(*mockCurvePtr, delete_())
771 .Times(1)
772 .After(usesMockCurve);
773
774 // Go!
775 setCompositorForTesting(mockCompositor);
776 Vector<OwnPtr<WebCompositorAnimation> > result;
777 getAnimationOnCompositor(m_timing, *effect.get(), result);
778 EXPECT_EQ(1U, result.size());
779 result[0].clear();
780 }
781
782 TEST_F(AnimationCompositorAnimationsTest, createMultipleKeyframeOpacityAnimation Chained)
783 {
784 // Animation to convert
785 AnimatableValueKeyframeVector frames;
786 frames.append(createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble:: create(2.0).get(), 0));
787 frames.append(createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble:: create(-1.0).get(), 0.25));
788 frames.append(createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble:: create(20.0).get(), 0.5));
789 frames.append(createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble:: create(5.0).get(), 1.0));
790 frames[0]->setEasing(m_cubicEaseTimingFunction.get());
791 frames[1]->setEasing(m_linearTimingFunction.get());
792 frames[2]->setEasing(m_cubicCustomTimingFunction.get());
793 RefPtr<AnimatableValueKeyframeEffectModel> effect = AnimatableValueKeyframeE ffectModel::create(frames);
794
795 m_timing.timingFunction = m_linearTimingFunction.get();
796 m_timing.iterationDuration = 2.0;
797 m_timing.iterationCount = 10;
798 m_timing.direction = Timing::PlaybackDirectionAlternate;
799 // --
800
801 WebCompositorSupportMock mockCompositor;
802
803 // Curve is created
804 WebFloatAnimationCurveMock* mockCurvePtr = new WebFloatAnimationCurveMock();
805 ExpectationSet usesMockCurve;
806
807 EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
808 .WillOnce(Return(mockCurvePtr));
809
810 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(0.0, 2.0), WebCompositorAnimationCurve::TimingFunctionTypeEase));
811 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(0.5, -1.0), WebCompositorAnimationCurve::TimingFunctionTypeLinear));
812 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(1.0, 20.0), 1.0, 2.0, 3.0, 4.0));
813 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(2.0, 5.0))) ;
814
815 // Animation is created
816 WebCompositorAnimationMock* mockAnimationPtr = new WebCompositorAnimationMoc k(WebCompositorAnimation::TargetPropertyOpacity);
817 ExpectationSet usesMockAnimation;
818
819 usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurveP tr), WebCompositorAnimation::TargetPropertyOpacity, _))
820 .WillOnce(Return(mockAnimationPtr));
821
822 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(10));
823 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(0.0));
824 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(t rue));
825
826 EXPECT_CALL(*mockAnimationPtr, delete_())
827 .Times(1)
828 .After(usesMockAnimation);
829 EXPECT_CALL(*mockCurvePtr, delete_())
830 .Times(1)
831 .After(usesMockCurve);
832
833 // Go!
834 setCompositorForTesting(mockCompositor);
835 Vector<OwnPtr<WebCompositorAnimation> > result;
836 getAnimationOnCompositor(m_timing, *effect.get(), result);
837 EXPECT_EQ(1U, result.size());
838 result[0].clear();
839 }
840
841 TEST_F(AnimationCompositorAnimationsTest, createReversedOpacityAnimation)
842 {
843 RefPtr<TimingFunction> cubicEasyFlipTimingFunction = CubicBezierTimingFuncti on::create(0.0, 0.0, 0.0, 1.0);
844
845 // Animation to convert
846 AnimatableValueKeyframeVector frames;
847 frames.append(createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble:: create(2.0).get(), 0));
848 frames.append(createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble:: create(-1.0).get(), 0.25));
849 frames.append(createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble:: create(20.0).get(), 0.5));
850 frames.append(createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble:: create(5.0).get(), 1.0));
851 frames[0]->setEasing(CubicBezierTimingFunction::preset(CubicBezierTimingFunc tion::EaseIn));
852 frames[1]->setEasing(m_linearTimingFunction.get());
853 frames[2]->setEasing(cubicEasyFlipTimingFunction.get());
854 RefPtr<AnimatableValueKeyframeEffectModel> effect = AnimatableValueKeyframeE ffectModel::create(frames);
855
856 m_timing.timingFunction = m_linearTimingFunction.get();
857 m_timing.iterationCount = 10;
858 m_timing.direction = Timing::PlaybackDirectionAlternateReverse;
859 // --
860
861 WebCompositorSupportMock mockCompositor;
862
863 // Curve is created
864 WebFloatAnimationCurveMock* mockCurvePtr = new WebFloatAnimationCurveMock();
865 ExpectationSet usesMockCurve;
866
867 EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
868 .WillOnce(Return(mockCurvePtr));
869
870 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(0.0, 5.0), 1.0, 0.0, 1.0, 1.0));
871 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(0.5, 20.0), WebCompositorAnimationCurve::TimingFunctionTypeLinear));
872 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(0.75, -1.0) , WebCompositorAnimationCurve::TimingFunctionTypeEaseOut));
873 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(1.0, 2.0))) ;
874
875 // Create the animation
876 WebCompositorAnimationMock* mockAnimationPtr = new WebCompositorAnimationMoc k(WebCompositorAnimation::TargetPropertyOpacity);
877 ExpectationSet usesMockAnimation;
878
879 usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurveP tr), WebCompositorAnimation::TargetPropertyOpacity, _))
880 .WillOnce(Return(mockAnimationPtr));
881
882 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(10));
883 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(0.0));
884 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(t rue));
885
886 EXPECT_CALL(*mockAnimationPtr, delete_())
887 .Times(1)
888 .After(usesMockAnimation);
889 EXPECT_CALL(*mockCurvePtr, delete_())
890 .Times(1)
891 .After(usesMockCurve);
892
893 // Go!
894 setCompositorForTesting(mockCompositor);
895 Vector<OwnPtr<WebCompositorAnimation> > result;
896 getAnimationOnCompositor(m_timing, *effect.get(), result);
897 EXPECT_EQ(1U, result.size());
898 result[0].clear();
899 }
900
901 TEST_F(AnimationCompositorAnimationsTest, createReversedOpacityAnimationNegative StartDelay)
902 {
903 // Animation to convert
904 RefPtr<AnimatableValueKeyframeEffectModel> effect = createKeyframeEffectMode l(
905 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(2.0 ).get(), 0),
906 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(5.0 ).get(), 1.0));
907
908 m_timing.iterationCount = 5.0;
909 m_timing.iterationDuration = 1.5;
910 m_timing.startDelay = -3;
911 m_timing.direction = Timing::PlaybackDirectionAlternateReverse;
912 // --
913
914 WebCompositorSupportMock mockCompositor;
915
916 // Curve is created
917 WebFloatAnimationCurveMock* mockCurvePtr = new WebFloatAnimationCurveMock;
918 ExpectationSet usesMockCurve;
919 EXPECT_CALL(mockCompositor, createFloatAnimationCurve())
920 .WillOnce(Return(mockCurvePtr));
921
922 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(0.0, 5.0), WebCompositorAnimationCurve::TimingFunctionTypeLinear));
923 usesMockCurve += EXPECT_CALL(*mockCurvePtr, add(WebFloatKeyframe(1.5, 2.0))) ;
924
925 // Create animation
926 WebCompositorAnimationMock* mockAnimationPtr = new WebCompositorAnimationMoc k(WebCompositorAnimation::TargetPropertyOpacity);
927 ExpectationSet usesMockAnimation;
928
929 usesMockCurve += EXPECT_CALL(mockCompositor, createAnimation(Ref(*mockCurveP tr), WebCompositorAnimation::TargetPropertyOpacity, _))
930 .WillOnce(Return(mockAnimationPtr));
931
932 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setIterations(5));
933 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setTimeOffset(3.0));
934 usesMockAnimation += EXPECT_CALL(*mockAnimationPtr, setAlternatesDirection(t rue));
935
936 EXPECT_CALL(*mockAnimationPtr, delete_())
937 .Times(1)
938 .After(usesMockAnimation);
939 EXPECT_CALL(*mockCurvePtr, delete_())
940 .Times(1)
941 .After(usesMockCurve);
942
943 // Go!
944 setCompositorForTesting(mockCompositor);
945 Vector<OwnPtr<WebCompositorAnimation> > result;
946 getAnimationOnCompositor(m_timing, *effect.get(), result);
947 EXPECT_EQ(1U, result.size());
948 result[0].clear();
949 }
950
951
952 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/animation/CompositorAnimationsImpl.h ('k') | sky/engine/core/animation/CompositorAnimationsTestHelper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698