| OLD | NEW |
| (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 "config.h" | |
| 32 #include "core/animation/TimedItemCalculations.h" | |
| 33 | |
| 34 #include <gtest/gtest.h> | |
| 35 | |
| 36 using namespace WebCore; | |
| 37 | |
| 38 namespace { | |
| 39 | |
| 40 TEST(AnimationTimedItemCalculationsTest, ActiveTime) | |
| 41 { | |
| 42 Timing timing; | |
| 43 | |
| 44 // calculateActiveTime(activeDuration, fillMode, localTime, parentPhase, pha
se, timing) | |
| 45 | |
| 46 // Before Phase | |
| 47 timing.startDelay = 10; | |
| 48 EXPECT_TRUE(isNull(calculateActiveTime(20, Timing::FillModeForwards, 0, Time
dItem::PhaseActive, TimedItem::PhaseBefore, timing))); | |
| 49 EXPECT_TRUE(isNull(calculateActiveTime(20, Timing::FillModeNone, 0, TimedIte
m::PhaseActive, TimedItem::PhaseBefore, timing))); | |
| 50 EXPECT_EQ(0, calculateActiveTime(20, Timing::FillModeBackwards, 0, TimedItem
::PhaseActive, TimedItem::PhaseBefore, timing)); | |
| 51 EXPECT_EQ(0, calculateActiveTime(20, Timing::FillModeBoth, 0, TimedItem::Pha
seActive, TimedItem::PhaseBefore, timing)); | |
| 52 | |
| 53 // Active Phase | |
| 54 timing.startDelay = 10; | |
| 55 // Active, and parent Before | |
| 56 EXPECT_TRUE(isNull(calculateActiveTime(20, Timing::FillModeNone, 15, TimedIt
em::PhaseBefore, TimedItem::PhaseActive, timing))); | |
| 57 EXPECT_TRUE(isNull(calculateActiveTime(20, Timing::FillModeForwards, 15, Tim
edItem::PhaseBefore, TimedItem::PhaseActive, timing))); | |
| 58 // Active, and parent After | |
| 59 EXPECT_TRUE(isNull(calculateActiveTime(20, Timing::FillModeNone, 15, TimedIt
em::PhaseAfter, TimedItem::PhaseActive, timing))); | |
| 60 EXPECT_TRUE(isNull(calculateActiveTime(20, Timing::FillModeBackwards, 15, Ti
medItem::PhaseAfter, TimedItem::PhaseActive, timing))); | |
| 61 // Active, and parent Active | |
| 62 EXPECT_EQ(5, calculateActiveTime(20, Timing::FillModeForwards, 15, TimedItem
::PhaseActive, TimedItem::PhaseActive, timing)); | |
| 63 | |
| 64 // After Phase | |
| 65 timing.startDelay = 10; | |
| 66 EXPECT_EQ(21, calculateActiveTime(21, Timing::FillModeForwards, 45, TimedIte
m::PhaseActive, TimedItem::PhaseAfter, timing)); | |
| 67 EXPECT_EQ(21, calculateActiveTime(21, Timing::FillModeBoth, 45, TimedItem::P
haseActive, TimedItem::PhaseAfter, timing)); | |
| 68 EXPECT_TRUE(isNull(calculateActiveTime(21, Timing::FillModeBackwards, 45, Ti
medItem::PhaseActive, TimedItem::PhaseAfter, timing))); | |
| 69 EXPECT_TRUE(isNull(calculateActiveTime(21, Timing::FillModeNone, 45, TimedIt
em::PhaseActive, TimedItem::PhaseAfter, timing))); | |
| 70 | |
| 71 // None | |
| 72 EXPECT_TRUE(isNull(calculateActiveTime(32, Timing::FillModeNone, nullValue()
, TimedItem::PhaseNone, TimedItem::PhaseNone, timing))); | |
| 73 } | |
| 74 | |
| 75 TEST(AnimationTimedItemCalculationsTest, ScaledActiveTime) | |
| 76 { | |
| 77 Timing timing; | |
| 78 | |
| 79 // calculateScaledActiveTime(activeDuration, activeTime, startOffset, timing
) | |
| 80 | |
| 81 // if the active time is null | |
| 82 EXPECT_TRUE(isNull(calculateScaledActiveTime(4, nullValue(), 5, timing))); | |
| 83 | |
| 84 // if the playback rate is negative | |
| 85 timing.playbackRate = -1; | |
| 86 EXPECT_EQ(35, calculateScaledActiveTime(40, 10, 5, timing)); | |
| 87 | |
| 88 // otherwise | |
| 89 timing.playbackRate = 0; | |
| 90 EXPECT_EQ(5, calculateScaledActiveTime(40, 10, 5, timing)); | |
| 91 timing.playbackRate = 1; | |
| 92 EXPECT_EQ(15, calculateScaledActiveTime(40, 10, 5, timing)); | |
| 93 | |
| 94 // infinte activeTime | |
| 95 timing.playbackRate = 0; | |
| 96 EXPECT_EQ(0, calculateScaledActiveTime(std::numeric_limits<double>::infinity
(), std::numeric_limits<double>::infinity(), 0, timing)); | |
| 97 timing.playbackRate = 1; | |
| 98 EXPECT_EQ(std::numeric_limits<double>::infinity(), calculateScaledActiveTime
(std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity(
), 0, timing)); | |
| 99 } | |
| 100 | |
| 101 TEST(AnimationTimedItemCalculationsTest, IterationTime) | |
| 102 { | |
| 103 Timing timing; | |
| 104 | |
| 105 // calculateIterationTime(iterationDuration, repeatedDuration, scaledActiveT
ime, startOffset, timing) | |
| 106 | |
| 107 // if the scaled active time is null | |
| 108 EXPECT_TRUE(isNull(calculateIterationTime(1, 1, nullValue(), 1, timing))); | |
| 109 | |
| 110 // if (complex-conditions)... | |
| 111 EXPECT_EQ(12, calculateIterationTime(12, 12, 12, 0, timing)); | |
| 112 | |
| 113 // otherwise | |
| 114 timing.iterationCount = 10; | |
| 115 EXPECT_EQ(5, calculateIterationTime(10, 100, 25, 4, timing)); | |
| 116 EXPECT_EQ(7, calculateIterationTime(11, 110, 29, 1, timing)); | |
| 117 timing.iterationStart = 1.1; | |
| 118 EXPECT_EQ(8, calculateIterationTime(12, 120, 20, 7, timing)); | |
| 119 } | |
| 120 | |
| 121 TEST(AnimationTimedItemCalculationsTest, CurrentIteration) | |
| 122 { | |
| 123 Timing timing; | |
| 124 | |
| 125 // calculateCurrentIteration(iterationDuration, iterationTime, scaledActiveT
ime, timing) | |
| 126 | |
| 127 // if the scaled active time is null | |
| 128 EXPECT_TRUE(isNull(calculateCurrentIteration(1, 1, nullValue(), timing))); | |
| 129 | |
| 130 // if the scaled active time is zero | |
| 131 EXPECT_EQ(0, calculateCurrentIteration(1, 1, 0, timing)); | |
| 132 | |
| 133 // if the iteration time equals the iteration duration | |
| 134 timing.iterationStart = 4; | |
| 135 timing.iterationCount = 7; | |
| 136 EXPECT_EQ(10, calculateCurrentIteration(5, 5, 9, timing)); | |
| 137 | |
| 138 // otherwise | |
| 139 EXPECT_EQ(3, calculateCurrentIteration(3.2, 3.1, 10, timing)); | |
| 140 } | |
| 141 | |
| 142 TEST(AnimationTimedItemCalculationsTest, DirectedTime) | |
| 143 { | |
| 144 Timing timing; | |
| 145 | |
| 146 // calculateDirectedTime(currentIteration, iterationDuration, iterationTime,
timing) | |
| 147 | |
| 148 // if the iteration time is null | |
| 149 EXPECT_TRUE(isNull(calculateDirectedTime(1, 2, nullValue(), timing))); | |
| 150 | |
| 151 // forwards | |
| 152 EXPECT_EQ(17, calculateDirectedTime(0, 20, 17, timing)); | |
| 153 EXPECT_EQ(17, calculateDirectedTime(1, 20, 17, timing)); | |
| 154 timing.direction = Timing::PlaybackDirectionAlternate; | |
| 155 EXPECT_EQ(17, calculateDirectedTime(0, 20, 17, timing)); | |
| 156 EXPECT_EQ(17, calculateDirectedTime(2, 20, 17, timing)); | |
| 157 timing.direction = Timing::PlaybackDirectionAlternateReverse; | |
| 158 EXPECT_EQ(17, calculateDirectedTime(1, 20, 17, timing)); | |
| 159 EXPECT_EQ(17, calculateDirectedTime(3, 20, 17, timing)); | |
| 160 | |
| 161 // reverse | |
| 162 timing.direction = Timing::PlaybackDirectionReverse; | |
| 163 EXPECT_EQ(3, calculateDirectedTime(0, 20, 17, timing)); | |
| 164 EXPECT_EQ(3, calculateDirectedTime(1, 20, 17, timing)); | |
| 165 timing.direction = Timing::PlaybackDirectionAlternate; | |
| 166 EXPECT_EQ(3, calculateDirectedTime(1, 20, 17, timing)); | |
| 167 EXPECT_EQ(3, calculateDirectedTime(3, 20, 17, timing)); | |
| 168 timing.direction = Timing::PlaybackDirectionAlternateReverse; | |
| 169 EXPECT_EQ(3, calculateDirectedTime(0, 20, 17, timing)); | |
| 170 EXPECT_EQ(3, calculateDirectedTime(2, 20, 17, timing)); | |
| 171 } | |
| 172 | |
| 173 TEST(AnimationTimedItemCalculationsTest, TransformedTime) | |
| 174 { | |
| 175 Timing timing; | |
| 176 | |
| 177 // calculateTransformedTime(currentIteration, iterationDuration, iterationTi
me, timing) | |
| 178 | |
| 179 // Iteration time is null | |
| 180 EXPECT_TRUE(isNull(calculateTransformedTime(1, 2, nullValue(), timing))); | |
| 181 | |
| 182 // PlaybackDirectionForwards | |
| 183 EXPECT_EQ(12, calculateTransformedTime(0, 20, 12, timing)); | |
| 184 EXPECT_EQ(12, calculateTransformedTime(1, 20, 12, timing)); | |
| 185 | |
| 186 // PlaybackDirectionForwards with timing function | |
| 187 timing.timingFunction = StepsTimingFunction::create(4, StepsTimingFunction::
StepAtEnd); | |
| 188 EXPECT_EQ(10, calculateTransformedTime(0, 20, 12, timing)); | |
| 189 EXPECT_EQ(10, calculateTransformedTime(1, 20, 12, timing)); | |
| 190 | |
| 191 // PlaybackDirectionReverse | |
| 192 timing.timingFunction = Timing::defaults().timingFunction; | |
| 193 timing.direction = Timing::PlaybackDirectionReverse; | |
| 194 EXPECT_EQ(8, calculateTransformedTime(0, 20, 12, timing)); | |
| 195 EXPECT_EQ(8, calculateTransformedTime(1, 20, 12, timing)); | |
| 196 | |
| 197 // PlaybackDirectionReverse with timing function | |
| 198 timing.timingFunction = StepsTimingFunction::create(4, StepsTimingFunction::
StepAtEnd); | |
| 199 EXPECT_EQ(5, calculateTransformedTime(0, 20, 12, timing)); | |
| 200 EXPECT_EQ(5, calculateTransformedTime(1, 20, 12, timing)); | |
| 201 | |
| 202 // Timing function when directed time is null. | |
| 203 EXPECT_TRUE(isNull(calculateTransformedTime(1, 2, nullValue(), timing))); | |
| 204 | |
| 205 // Timing function when iterationDuration is infinity | |
| 206 timing.direction = Timing::PlaybackDirectionNormal; | |
| 207 EXPECT_EQ(0, calculateTransformedTime(0, std::numeric_limits<double>::infini
ty(), 0, timing)); | |
| 208 EXPECT_EQ(1, calculateTransformedTime(0, std::numeric_limits<double>::infini
ty(), 1, timing)); | |
| 209 timing.direction = Timing::PlaybackDirectionReverse; | |
| 210 EXPECT_EQ(std::numeric_limits<double>::infinity(), calculateTransformedTime(
0, std::numeric_limits<double>::infinity(), 0, timing)); | |
| 211 EXPECT_EQ(std::numeric_limits<double>::infinity(), calculateTransformedTime(
0, std::numeric_limits<double>::infinity(), 1, timing)); | |
| 212 } | |
| 213 | |
| 214 } | |
| OLD | NEW |