This source file includes following definitions.
- empty_
- progressed_count
- empty
- AnimationContainerProgressed
- AnimationContainerEmpty
- AnimateToState
- TEST_F
- TEST_F
- TEST_F
#include "ui/gfx/animation/animation_container.h"
#include "base/memory/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/animation/animation_container_observer.h"
#include "ui/gfx/animation/linear_animation.h"
#include "ui/gfx/animation/test_animation_delegate.h"
namespace gfx {
namespace {
class FakeAnimationContainerObserver : public AnimationContainerObserver {
public:
FakeAnimationContainerObserver()
: progressed_count_(0),
empty_(false) {
}
int progressed_count() const { return progressed_count_; }
bool empty() const { return empty_; }
private:
virtual void AnimationContainerProgressed(
AnimationContainer* container) OVERRIDE {
progressed_count_++;
}
virtual void AnimationContainerEmpty(AnimationContainer* container) OVERRIDE {
empty_ = true;
}
int progressed_count_;
bool empty_;
DISALLOW_COPY_AND_ASSIGN(FakeAnimationContainerObserver);
};
class TestAnimation : public LinearAnimation {
public:
explicit TestAnimation(AnimationDelegate* delegate)
: LinearAnimation(20, 20, delegate) {
}
virtual void AnimateToState(double state) OVERRIDE {
}
private:
DISALLOW_COPY_AND_ASSIGN(TestAnimation);
};
}
class AnimationContainerTest: public testing::Test {
private:
base::MessageLoopForUI message_loop_;
};
TEST_F(AnimationContainerTest, Ownership) {
TestAnimationDelegate delegate;
scoped_refptr<AnimationContainer> container(new AnimationContainer());
scoped_ptr<Animation> animation(new TestAnimation(&delegate));
animation->SetContainer(container.get());
EXPECT_FALSE(container->HasOneRef());
animation.reset();
EXPECT_TRUE(container->HasOneRef());
}
TEST_F(AnimationContainerTest, Multi) {
TestAnimationDelegate delegate1;
TestAnimationDelegate delegate2;
scoped_refptr<AnimationContainer> container(new AnimationContainer());
TestAnimation animation1(&delegate1);
TestAnimation animation2(&delegate2);
animation1.SetContainer(container.get());
animation2.SetContainer(container.get());
animation1.Start();
EXPECT_TRUE(container->is_running());
animation2.Start();
EXPECT_TRUE(container->is_running());
base::MessageLoop::current()->Run();
EXPECT_TRUE(delegate1.finished());
EXPECT_TRUE(delegate2.finished());
EXPECT_FALSE(container->is_running());
}
TEST_F(AnimationContainerTest, Observer) {
FakeAnimationContainerObserver observer;
TestAnimationDelegate delegate1;
scoped_refptr<AnimationContainer> container(new AnimationContainer());
container->set_observer(&observer);
TestAnimation animation1(&delegate1);
animation1.SetContainer(container.get());
animation1.Start();
EXPECT_TRUE(container->is_running());
base::MessageLoop::current()->Run();
EXPECT_EQ(1, observer.progressed_count());
EXPECT_TRUE(delegate1.finished());
EXPECT_TRUE(observer.empty());
EXPECT_FALSE(container->is_running());
container->set_observer(NULL);
}
}