This source file includes following definitions.
- TestApi
- SetStartTime
- Step
- TEST_F
- TEST_F
- TEST_F
#include "ui/gfx/animation/slide_animation.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/animation/test_animation_delegate.h"
namespace gfx {
class SlideAnimation::TestApi {
public:
explicit TestApi(SlideAnimation* animation) : animation_(animation) {}
void SetStartTime(base::TimeTicks ticks) {
animation_->SetStartTime(ticks);
}
void Step(base::TimeTicks ticks) {
animation_->Step(ticks);
}
private:
SlideAnimation* animation_;
DISALLOW_COPY_AND_ASSIGN(TestApi);
};
class SlideAnimationTest: public testing::Test {
private:
base::MessageLoopForUI message_loop_;
};
TEST_F(SlideAnimationTest, InitialState) {
SlideAnimation animation(NULL);
EXPECT_EQ(1000 / 60, animation.timer_interval().InMilliseconds());
EXPECT_EQ(120, animation.GetSlideDuration());
EXPECT_FALSE(animation.IsShowing());
EXPECT_FALSE(animation.IsClosing());
EXPECT_EQ(0.0, animation.GetCurrentValue());
}
TEST_F(SlideAnimationTest, Basics) {
SlideAnimation animation(NULL);
SlideAnimation::TestApi test_api(&animation);
animation.SetTweenType(Tween::LINEAR);
animation.SetSlideDuration(100);
EXPECT_EQ(100, animation.GetSlideDuration());
animation.Show();
EXPECT_TRUE(animation.IsShowing());
EXPECT_FALSE(animation.IsClosing());
test_api.SetStartTime(base::TimeTicks());
test_api.Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(50));
EXPECT_EQ(0.5, animation.GetCurrentValue());
animation.Hide();
EXPECT_FALSE(animation.IsShowing());
EXPECT_TRUE(animation.IsClosing());
animation.Reset();
EXPECT_EQ(0.0, animation.GetCurrentValue());
EXPECT_FALSE(animation.IsShowing());
EXPECT_FALSE(animation.IsClosing());
}
TEST_F(SlideAnimationTest, DontNotifyOnDelete) {
TestAnimationDelegate delegate;
scoped_ptr<SlideAnimation> animation(new SlideAnimation(&delegate));
animation->Show();
animation.reset();
EXPECT_FALSE(delegate.finished());
EXPECT_FALSE(delegate.canceled());
}
}