| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 | |
| 7 #include "core/animation/AnimatableLength.h" | |
| 8 #include "platform/CalculationValue.h" | |
| 9 | |
| 10 #include <gtest/gtest.h> | |
| 11 | |
| 12 namespace WebCore { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 PassRefPtrWillBeRawPtr<AnimatableLength> create(const Length& length, double
zoom = 1) | |
| 17 { | |
| 18 return AnimatableLength::create(length, zoom); | |
| 19 } | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 TEST(AnimationAnimatableLengthTest, RoundTripConversion) | |
| 24 { | |
| 25 EXPECT_EQ(Length(0, Fixed), create(Length(0, Fixed))->length(1, ValueRangeAl
l)); | |
| 26 EXPECT_EQ(Length(0, Percent), create(Length(0, Percent))->length(1, ValueRan
geAll)); | |
| 27 EXPECT_EQ(Length(10, Fixed), create(Length(10, Fixed))->length(1, ValueRange
All)); | |
| 28 EXPECT_EQ(Length(10, Percent), create(Length(10, Percent))->length(1, ValueR
angeAll)); | |
| 29 EXPECT_EQ(Length(-10, Fixed), create(Length(-10, Fixed))->length(1, ValueRan
geAll)); | |
| 30 EXPECT_EQ(Length(-10, Percent), create(Length(-10, Percent))->length(1, Valu
eRangeAll)); | |
| 31 Length calc = Length(CalculationValue::create(PixelsAndPercent(5, 10), Value
RangeAll)); | |
| 32 EXPECT_EQ(calc, create(calc)->length(1, ValueRangeAll)); | |
| 33 } | |
| 34 | |
| 35 TEST(AnimationAnimatableLengthTest, ValueRangeNonNegative) | |
| 36 { | |
| 37 EXPECT_EQ(Length(10, Fixed), create(Length(10, Fixed))->length(1, ValueRange
NonNegative)); | |
| 38 EXPECT_EQ(Length(10, Percent), create(Length(10, Percent))->length(1, ValueR
angeNonNegative)); | |
| 39 EXPECT_EQ(Length(0, Fixed), create(Length(-10, Fixed))->length(1, ValueRange
NonNegative)); | |
| 40 EXPECT_EQ(Length(0, Percent), create(Length(-10, Percent))->length(1, ValueR
angeNonNegative)); | |
| 41 Length calc = Length(CalculationValue::create(PixelsAndPercent(-5, -10), Val
ueRangeNonNegative)); | |
| 42 EXPECT_TRUE(calc == create(calc)->length(1, ValueRangeNonNegative)); | |
| 43 } | |
| 44 | |
| 45 TEST(AnimationAnimatableLengthTest, Zoom) | |
| 46 { | |
| 47 EXPECT_EQ(Length(4, Fixed), create(Length(10, Fixed), 5)->length(2, ValueRan
geAll)); | |
| 48 EXPECT_EQ(Length(10, Percent), create(Length(10, Percent), 5)->length(2, Val
ueRangeAll)); | |
| 49 Length calc = Length(CalculationValue::create(PixelsAndPercent(5, 10), Value
RangeAll)); | |
| 50 Length result = Length(CalculationValue::create(PixelsAndPercent(2, 10), Val
ueRangeAll)); | |
| 51 EXPECT_TRUE(result == create(calc, 5)->length(2, ValueRangeAll)); | |
| 52 } | |
| 53 | |
| 54 TEST(AnimationAnimatableLengthTest, Equals) | |
| 55 { | |
| 56 EXPECT_TRUE(create(Length(10, Fixed))->equals(create(Length(10, Fixed)).get(
))); | |
| 57 EXPECT_TRUE(create(Length(20, Percent))->equals(create(Length(20, Percent)).
get())); | |
| 58 EXPECT_FALSE(create(Length(10, Fixed))->equals(create(Length(10, Percent)).g
et())); | |
| 59 EXPECT_FALSE(create(Length(0, Percent))->equals(create(Length(0, Fixed)).get
())); | |
| 60 Length calc = Length(CalculationValue::create(PixelsAndPercent(5, 10), Value
RangeAll)); | |
| 61 EXPECT_TRUE(create(calc)->equals(create(calc).get())); | |
| 62 EXPECT_FALSE(create(calc)->equals(create(Length(10, Percent)).get())); | |
| 63 } | |
| 64 | |
| 65 TEST(AnimationAnimatableLengthTest, Interpolate) | |
| 66 { | |
| 67 EXPECT_TRUE(AnimatableValue::interpolate(create(Length(10, Fixed)).get(), cr
eate(Length(0, Fixed)).get(), 0.2)->equals(create(Length(8, Fixed)).get())); | |
| 68 EXPECT_TRUE(AnimatableValue::interpolate(create(Length(4, Percent)).get(), c
reate(Length(12, Percent)).get(), 0.25)->equals(create(Length(6, Percent)).get()
)); | |
| 69 Length calc = Length(CalculationValue::create(PixelsAndPercent(12, 4), Value
RangeAll)); | |
| 70 EXPECT_TRUE(AnimatableValue::interpolate(create(Length(20, Fixed)).get(), cr
eate(Length(10, Percent)).get(), 0.4)->equals(create(calc).get())); | |
| 71 } | |
| 72 | |
| 73 } // namespace WebCore | |
| OLD | NEW |