This source file includes following definitions.
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#include "base/memory/scoped_ptr.h"
#include "cc/animation/timing_function.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/renderer/compositor_bindings/web_float_animation_curve_impl.h"
using blink::WebAnimationCurve;
using blink::WebFloatAnimationCurve;
using blink::WebFloatKeyframe;
namespace webkit {
namespace {
TEST(WebFloatAnimationCurveTest, OneFloatKeyframe) {
scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
curve->add(WebFloatKeyframe(0, 2),
WebAnimationCurve::TimingFunctionTypeLinear);
EXPECT_FLOAT_EQ(2, curve->getValue(-1));
EXPECT_FLOAT_EQ(2, curve->getValue(0));
EXPECT_FLOAT_EQ(2, curve->getValue(0.5));
EXPECT_FLOAT_EQ(2, curve->getValue(1));
EXPECT_FLOAT_EQ(2, curve->getValue(2));
}
TEST(WebFloatAnimationCurveTest, TwoFloatKeyframe) {
scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
curve->add(WebFloatKeyframe(0, 2),
WebAnimationCurve::TimingFunctionTypeLinear);
curve->add(WebFloatKeyframe(1, 4),
WebAnimationCurve::TimingFunctionTypeLinear);
EXPECT_FLOAT_EQ(2, curve->getValue(-1));
EXPECT_FLOAT_EQ(2, curve->getValue(0));
EXPECT_FLOAT_EQ(3, curve->getValue(0.5));
EXPECT_FLOAT_EQ(4, curve->getValue(1));
EXPECT_FLOAT_EQ(4, curve->getValue(2));
}
TEST(WebFloatAnimationCurveTest, ThreeFloatKeyframe) {
scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
curve->add(WebFloatKeyframe(0, 2),
WebAnimationCurve::TimingFunctionTypeLinear);
curve->add(WebFloatKeyframe(1, 4),
WebAnimationCurve::TimingFunctionTypeLinear);
curve->add(WebFloatKeyframe(2, 8),
WebAnimationCurve::TimingFunctionTypeLinear);
EXPECT_FLOAT_EQ(2, curve->getValue(-1));
EXPECT_FLOAT_EQ(2, curve->getValue(0));
EXPECT_FLOAT_EQ(3, curve->getValue(0.5));
EXPECT_FLOAT_EQ(4, curve->getValue(1));
EXPECT_FLOAT_EQ(6, curve->getValue(1.5));
EXPECT_FLOAT_EQ(8, curve->getValue(2));
EXPECT_FLOAT_EQ(8, curve->getValue(3));
}
TEST(WebFloatAnimationCurveTest, RepeatedFloatKeyTimes) {
scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
curve->add(WebFloatKeyframe(0, 4),
WebAnimationCurve::TimingFunctionTypeLinear);
curve->add(WebFloatKeyframe(1, 4),
WebAnimationCurve::TimingFunctionTypeLinear);
curve->add(WebFloatKeyframe(1, 6),
WebAnimationCurve::TimingFunctionTypeLinear);
curve->add(WebFloatKeyframe(2, 6),
WebAnimationCurve::TimingFunctionTypeLinear);
EXPECT_FLOAT_EQ(4, curve->getValue(-1));
EXPECT_FLOAT_EQ(4, curve->getValue(0));
EXPECT_FLOAT_EQ(4, curve->getValue(0.5));
float value = curve->getValue(1);
EXPECT_TRUE(value >= 4 && value <= 6);
EXPECT_FLOAT_EQ(6, curve->getValue(1.5));
EXPECT_FLOAT_EQ(6, curve->getValue(2));
EXPECT_FLOAT_EQ(6, curve->getValue(3));
}
TEST(WebFloatAnimationCurveTest, UnsortedKeyframes) {
scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
curve->add(WebFloatKeyframe(2, 8),
WebAnimationCurve::TimingFunctionTypeLinear);
curve->add(WebFloatKeyframe(0, 2),
WebAnimationCurve::TimingFunctionTypeLinear);
curve->add(WebFloatKeyframe(1, 4),
WebAnimationCurve::TimingFunctionTypeLinear);
EXPECT_FLOAT_EQ(2, curve->getValue(-1));
EXPECT_FLOAT_EQ(2, curve->getValue(0));
EXPECT_FLOAT_EQ(3, curve->getValue(0.5));
EXPECT_FLOAT_EQ(4, curve->getValue(1));
EXPECT_FLOAT_EQ(6, curve->getValue(1.5));
EXPECT_FLOAT_EQ(8, curve->getValue(2));
EXPECT_FLOAT_EQ(8, curve->getValue(3));
}
TEST(WebFloatAnimationCurveTest, CubicBezierTimingFunction) {
scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
curve->add(WebFloatKeyframe(0, 0), 0.25, 0, 0.75, 1);
curve->add(WebFloatKeyframe(1, 1),
WebAnimationCurve::TimingFunctionTypeLinear);
EXPECT_FLOAT_EQ(0, curve->getValue(0));
EXPECT_LT(0, curve->getValue(0.25));
EXPECT_GT(0.25, curve->getValue(0.25));
EXPECT_NEAR(curve->getValue(0.5), 0.5, 0.00015);
EXPECT_LT(0.75, curve->getValue(0.75));
EXPECT_GT(1, curve->getValue(0.75));
EXPECT_FLOAT_EQ(1, curve->getValue(1));
}
TEST(WebFloatAnimationCurveTest, EaseTimingFunction) {
scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
curve->add(WebFloatKeyframe(0, 0), WebAnimationCurve::TimingFunctionTypeEase);
curve->add(WebFloatKeyframe(1, 1),
WebAnimationCurve::TimingFunctionTypeLinear);
scoped_ptr<cc::TimingFunction> timing_function(
cc::EaseTimingFunction::Create());
for (int i = 0; i <= 4; ++i) {
const double time = i * 0.25;
EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time));
}
}
TEST(WebFloatAnimationCurveTest, LinearTimingFunction) {
scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
curve->add(WebFloatKeyframe(0, 0),
WebAnimationCurve::TimingFunctionTypeLinear);
curve->add(WebFloatKeyframe(1, 1),
WebAnimationCurve::TimingFunctionTypeLinear);
for (int i = 0; i <= 4; ++i) {
const double time = i * 0.25;
EXPECT_FLOAT_EQ(time, curve->getValue(time));
}
}
TEST(WebFloatAnimationCurveTest, EaseInTimingFunction) {
scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
curve->add(WebFloatKeyframe(0, 0),
WebAnimationCurve::TimingFunctionTypeEaseIn);
curve->add(WebFloatKeyframe(1, 1),
WebAnimationCurve::TimingFunctionTypeLinear);
scoped_ptr<cc::TimingFunction> timing_function(
cc::EaseInTimingFunction::Create());
for (int i = 0; i <= 4; ++i) {
const double time = i * 0.25;
EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time));
}
}
TEST(WebFloatAnimationCurveTest, EaseOutTimingFunction) {
scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
curve->add(WebFloatKeyframe(0, 0),
WebAnimationCurve::TimingFunctionTypeEaseOut);
curve->add(WebFloatKeyframe(1, 1),
WebAnimationCurve::TimingFunctionTypeLinear);
scoped_ptr<cc::TimingFunction> timing_function(
cc::EaseOutTimingFunction::Create());
for (int i = 0; i <= 4; ++i) {
const double time = i * 0.25;
EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time));
}
}
TEST(WebFloatAnimationCurveTest, EaseInOutTimingFunction) {
scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
curve->add(WebFloatKeyframe(0, 0),
WebAnimationCurve::TimingFunctionTypeEaseInOut);
curve->add(WebFloatKeyframe(1, 1),
WebAnimationCurve::TimingFunctionTypeLinear);
scoped_ptr<cc::TimingFunction> timing_function(
cc::EaseInOutTimingFunction::Create());
for (int i = 0; i <= 4; ++i) {
const double time = i * 0.25;
EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time));
}
}
TEST(WebFloatAnimationCurveTest, CustomBezierTimingFunction) {
scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
double x1 = 0.3;
double y1 = 0.2;
double x2 = 0.8;
double y2 = 0.7;
curve->add(WebFloatKeyframe(0, 0), x1, y1, x2, y2);
curve->add(WebFloatKeyframe(1, 1),
WebAnimationCurve::TimingFunctionTypeLinear);
scoped_ptr<cc::TimingFunction> timing_function(
cc::CubicBezierTimingFunction::Create(x1, y1, x2, y2));
for (int i = 0; i <= 4; ++i) {
const double time = i * 0.25;
EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time));
}
}
TEST(WebFloatAnimationCurveTest, DefaultTimingFunction) {
scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl);
curve->add(WebFloatKeyframe(0, 0));
curve->add(WebFloatKeyframe(1, 1),
WebAnimationCurve::TimingFunctionTypeLinear);
scoped_ptr<cc::TimingFunction> timing_function(
cc::EaseTimingFunction::Create());
for (int i = 0; i <= 4; ++i) {
const double time = i * 0.25;
EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time));
}
}
}
}