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/AnimatableColor.h" 33 34 #include <gtest/gtest.h> 35 36 using namespace WebCore; 37 38 namespace { 39 40 TEST(AnimationAnimatableColorTest, ToColor) 41 { 42 Color transparent = AnimatableColorImpl(Color::transparent).toColor(); 43 EXPECT_EQ(transparent.rgb(), Color::transparent); 44 Color red = AnimatableColorImpl(Color(0xFFFF0000)).toColor(); 45 EXPECT_EQ(red.rgb(), 0xFFFF0000); 46 } 47 48 TEST(AnimationAnimatableColorTest, Interpolate) 49 { 50 EXPECT_EQ(AnimatableColorImpl(Color(0xFF00FF00)).interpolateTo(Color(0xFF00FF00), -10).toColor().rgb(), 0xFF00FF00); 51 EXPECT_EQ(AnimatableColorImpl(Color(0xFF00FF00)).interpolateTo(Color(0xFFFF00FF), -10).toColor().rgb(), 0xFF00FF00); 52 EXPECT_EQ(AnimatableColorImpl(Color(0xFF00FF00)).interpolateTo(Color(0xFFFF00FF), 0).toColor().rgb(), 0xFF00FF00); 53 EXPECT_EQ(AnimatableColorImpl(Color(0xFF00FF00)).interpolateTo(Color(0xFFFF00FF), 1. / 255).toColor().rgb(), 0xFF01FE01); 54 EXPECT_EQ(AnimatableColorImpl(Color(0xFF00FF00)).interpolateTo(Color(0xFFFF00FF), 0.5).toColor().rgb(), 0xFF808080); 55 EXPECT_EQ(AnimatableColorImpl(Color(0xFF00FF00)).interpolateTo(Color(0xFFFF00FF), 254. / 255).toColor().rgb(), 0xFFFE01FE); 56 EXPECT_EQ(AnimatableColorImpl(Color(0xFF00FF00)).interpolateTo(Color(0xFFFF00FF), 1).toColor().rgb(), 0xFFFF00FF); 57 EXPECT_EQ(AnimatableColorImpl(Color(0xFF00FF00)).interpolateTo(Color(0xFFFF00FF), 10).toColor().rgb(), 0xFFFF00FF); 58 59 EXPECT_EQ(AnimatableColorImpl(Color(0xFF001020)).interpolateTo(Color(0xFF4080C0), 3. / 16).toColor().rgb(), 0xFF0C253E); 60 61 EXPECT_EQ(AnimatableColorImpl(Color(0x0000FF00)).interpolateTo(Color(0xFFFF00FF), 0.5).toColor().rgb(), 0x80FF00FF); 62 EXPECT_EQ(AnimatableColorImpl(Color(0x4000FF00)).interpolateTo(Color(0x80FF00FF), 0.5).toColor().rgb(), 0x60AA55AAu); 63 EXPECT_EQ(AnimatableColorImpl(Color(0x40FF00FF)).interpolateTo(Color(0x80FFFFFF), 0.5).toColor().rgb(), 0x60FFAAFFu); 64 65 EXPECT_EQ(AnimatableColorImpl(Color(0x10204080)).interpolateTo(Color(0x104080C0), 0.5).toColor().rgb(), 0x103060A0u); 66 } 67 68 TEST(AnimationAnimatableColorTest, Distance) 69 { 70 EXPECT_NEAR(1.0, AnimatableColorImpl(Color(0xFF000000)).distanceTo(Color(0xFFFF0000)), 0.00000001); 71 EXPECT_NEAR(13.0 / 255, AnimatableColorImpl(Color(0xFF53647C)).distanceTo(Color(0xFF506070)), 0.00000001); 72 EXPECT_NEAR(60.0 / 255, AnimatableColorImpl(Color(0x3C000000)).distanceTo(Color(0x00FFFFFF)), 0.00000001); 73 EXPECT_NEAR(60.0 / 255, AnimatableColorImpl(Color(0x3C000000)).distanceTo(Color(0x3C00FF00)), 0.00000001); 74 75 RefPtrWillBeRawPtr<AnimatableColor> first = AnimatableColor::create(AnimatableColorImpl(Color(0xFF53647C)), AnimatableColorImpl(Color(0xFF000000))); 76 RefPtrWillBeRawPtr<AnimatableColor> second = AnimatableColor::create(AnimatableColorImpl(Color(0xFF506070)), AnimatableColorImpl(Color(0xFF000000))); 77 EXPECT_NEAR(13.0 / 255, AnimatableValue::distance(first.get(), second.get()), 0.00000001); 78 } 79 80 } 81