| 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 "core/animation/animatable/AnimatableLength.h" | |
| 6 | |
| 7 #include "platform/CalculationValue.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 namespace blink { | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 PassRefPtr<AnimatableLength> create(const Length& length, double zoom = 1) { | |
| 15 return AnimatableLength::create(length, zoom); | |
| 16 } | |
| 17 | |
| 18 } // anonymous namespace | |
| 19 | |
| 20 TEST(AnimationAnimatableLengthTest, RoundTripConversion) { | |
| 21 EXPECT_EQ(Length(0, Fixed), | |
| 22 create(Length(0, Fixed))->getLength(1, ValueRangeAll)); | |
| 23 EXPECT_EQ(Length(0, Percent), | |
| 24 create(Length(0, Percent))->getLength(1, ValueRangeAll)); | |
| 25 EXPECT_EQ(Length(10, Fixed), | |
| 26 create(Length(10, Fixed))->getLength(1, ValueRangeAll)); | |
| 27 EXPECT_EQ(Length(10, Percent), | |
| 28 create(Length(10, Percent))->getLength(1, ValueRangeAll)); | |
| 29 EXPECT_EQ(Length(-10, Fixed), | |
| 30 create(Length(-10, Fixed))->getLength(1, ValueRangeAll)); | |
| 31 EXPECT_EQ(Length(-10, Percent), | |
| 32 create(Length(-10, Percent))->getLength(1, ValueRangeAll)); | |
| 33 Length calc = | |
| 34 Length(CalculationValue::create(PixelsAndPercent(5, 10), ValueRangeAll)); | |
| 35 EXPECT_EQ(calc, create(calc)->getLength(1, ValueRangeAll)); | |
| 36 } | |
| 37 | |
| 38 TEST(AnimationAnimatableLengthTest, ValueRangeNonNegative) { | |
| 39 EXPECT_EQ(Length(10, Fixed), | |
| 40 create(Length(10, Fixed))->getLength(1, ValueRangeNonNegative)); | |
| 41 EXPECT_EQ(Length(10, Percent), | |
| 42 create(Length(10, Percent))->getLength(1, ValueRangeNonNegative)); | |
| 43 EXPECT_EQ(Length(0, Fixed), | |
| 44 create(Length(-10, Fixed))->getLength(1, ValueRangeNonNegative)); | |
| 45 EXPECT_EQ(Length(0, Percent), | |
| 46 create(Length(-10, Percent))->getLength(1, ValueRangeNonNegative)); | |
| 47 Length calc = Length(CalculationValue::create(PixelsAndPercent(-5, -10), | |
| 48 ValueRangeNonNegative)); | |
| 49 EXPECT_TRUE(calc == create(calc)->getLength(1, ValueRangeNonNegative)); | |
| 50 } | |
| 51 | |
| 52 TEST(AnimationAnimatableLengthTest, Zoom) { | |
| 53 EXPECT_EQ(Length(4, Fixed), | |
| 54 create(Length(10, Fixed), 5)->getLength(2, ValueRangeAll)); | |
| 55 EXPECT_EQ(Length(10, Percent), | |
| 56 create(Length(10, Percent), 5)->getLength(2, ValueRangeAll)); | |
| 57 Length calc = | |
| 58 Length(CalculationValue::create(PixelsAndPercent(5, 10), ValueRangeAll)); | |
| 59 Length result = | |
| 60 Length(CalculationValue::create(PixelsAndPercent(2, 10), ValueRangeAll)); | |
| 61 EXPECT_TRUE(result == create(calc, 5)->getLength(2, ValueRangeAll)); | |
| 62 } | |
| 63 | |
| 64 TEST(AnimationAnimatableLengthTest, Equals) { | |
| 65 EXPECT_TRUE( | |
| 66 create(Length(10, Fixed))->equals(create(Length(10, Fixed)).get())); | |
| 67 EXPECT_TRUE( | |
| 68 create(Length(20, Percent))->equals(create(Length(20, Percent)).get())); | |
| 69 EXPECT_FALSE( | |
| 70 create(Length(10, Fixed))->equals(create(Length(10, Percent)).get())); | |
| 71 EXPECT_FALSE( | |
| 72 create(Length(0, Percent))->equals(create(Length(0, Fixed)).get())); | |
| 73 Length calc = | |
| 74 Length(CalculationValue::create(PixelsAndPercent(5, 10), ValueRangeAll)); | |
| 75 EXPECT_TRUE(create(calc)->equals(create(calc).get())); | |
| 76 EXPECT_FALSE(create(calc)->equals(create(Length(10, Percent)).get())); | |
| 77 } | |
| 78 | |
| 79 TEST(AnimationAnimatableLengthTest, Interpolate) { | |
| 80 EXPECT_TRUE(AnimatableValue::interpolate(create(Length(10, Fixed)).get(), | |
| 81 create(Length(0, Fixed)).get(), 0.2) | |
| 82 ->equals(create(Length(8, Fixed)).get())); | |
| 83 EXPECT_TRUE(AnimatableValue::interpolate(create(Length(4, Percent)).get(), | |
| 84 create(Length(12, Percent)).get(), | |
| 85 0.25) | |
| 86 ->equals(create(Length(6, Percent)).get())); | |
| 87 Length calc = | |
| 88 Length(CalculationValue::create(PixelsAndPercent(12, 4), ValueRangeAll)); | |
| 89 EXPECT_TRUE(AnimatableValue::interpolate(create(Length(20, Fixed)).get(), | |
| 90 create(Length(10, Percent)).get(), | |
| 91 0.4) | |
| 92 ->equals(create(calc).get())); | |
| 93 } | |
| 94 | |
| 95 } // namespace blink | |
| OLD | NEW |