This source file includes following definitions.
- TEST
- TEST
- TEST
- TEST
#include "ui/gfx/animation/multi_animation.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/animation/animation_container_element.h"
namespace gfx {
TEST(MultiAnimationTest, Basic) {
MultiAnimation::Parts parts;
parts.push_back(MultiAnimation::Part(100, Tween::LINEAR));
parts.push_back(MultiAnimation::Part(100, Tween::EASE_OUT));
MultiAnimation animation(parts, MultiAnimation::GetDefaultTimerInterval());
AnimationContainerElement* as_element =
static_cast<AnimationContainerElement*>(&animation);
as_element->SetStartTime(base::TimeTicks());
as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(50));
EXPECT_EQ(.5, animation.GetCurrentValue());
as_element->Step(base::TimeTicks() +
base::TimeDelta::FromMilliseconds(120));
EXPECT_DOUBLE_EQ(Tween::CalculateValue(Tween::EASE_OUT, .2),
animation.GetCurrentValue());
as_element->Step(base::TimeTicks() +
base::TimeDelta::FromMilliseconds(320));
EXPECT_DOUBLE_EQ(Tween::CalculateValue(Tween::EASE_OUT, .2),
animation.GetCurrentValue());
}
TEST(MultiAnimationTest, DifferingStartAndEnd) {
MultiAnimation::Parts parts;
parts.push_back(MultiAnimation::Part(200, Tween::LINEAR));
parts[0].start_time_ms = 100;
parts[0].end_time_ms = 400;
MultiAnimation animation(parts, MultiAnimation::GetDefaultTimerInterval());
AnimationContainerElement* as_element =
static_cast<AnimationContainerElement*>(&animation);
as_element->SetStartTime(base::TimeTicks());
as_element->Step(base::TimeTicks());
EXPECT_EQ(.25, animation.GetCurrentValue());
as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(100));
EXPECT_EQ(.5, animation.GetCurrentValue());
}
TEST(MultiAnimationTest, DontCycle) {
MultiAnimation::Parts parts;
parts.push_back(MultiAnimation::Part(200, Tween::LINEAR));
MultiAnimation animation(parts, MultiAnimation::GetDefaultTimerInterval());
AnimationContainerElement* as_element =
static_cast<AnimationContainerElement*>(&animation);
as_element->SetStartTime(base::TimeTicks());
animation.set_continuous(false);
as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(300));
EXPECT_EQ(1.0, animation.GetCurrentValue());
EXPECT_FALSE(animation.is_animating());
}
TEST(MultiAnimationTest, Cycle) {
MultiAnimation::Parts parts;
parts.push_back(MultiAnimation::Part(200, Tween::LINEAR));
MultiAnimation animation(parts, MultiAnimation::GetDefaultTimerInterval());
AnimationContainerElement* as_element =
static_cast<AnimationContainerElement*>(&animation);
as_element->SetStartTime(base::TimeTicks());
as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(300));
EXPECT_EQ(.5, animation.GetCurrentValue());
}
}