Commit fe6f35b2 authored by newcomer's avatar newcomer Committed by Commit Bot

Added a nested class to gfx::Animation

The new class is a reimplementation of SlideAnimation::TestApi which
allows tests to manipulate animations.

BUG=741076

Review-Url: https://codereview.chromium.org/2976873003
Cr-Commit-Position: refs/heads/master@{#486887}
parent edc09064
...@@ -578,6 +578,8 @@ component("gfx_switches") { ...@@ -578,6 +578,8 @@ component("gfx_switches") {
static_library("test_support") { static_library("test_support") {
testonly = true testonly = true
sources = [ sources = [
"animation/animation_test_api.cc",
"animation/animation_test_api.h",
"animation/test_animation_delegate.h", "animation/test_animation_delegate.h",
"geometry/test/rect_test_util.cc", "geometry/test/rect_test_util.cc",
"geometry/test/rect_test_util.h", "geometry/test/rect_test_util.h",
......
...@@ -19,6 +19,7 @@ namespace gfx { ...@@ -19,6 +19,7 @@ namespace gfx {
class AnimationContainer; class AnimationContainer;
class AnimationDelegate; class AnimationDelegate;
class AnimationTestApi;
// Base class used in implementing animations. You only need use this class if // Base class used in implementing animations. You only need use this class if
// you're implementing a new animation type, otherwise you'll likely want one of // you're implementing a new animation type, otherwise you'll likely want one of
...@@ -92,6 +93,8 @@ class ANIMATION_EXPORT Animation : public AnimationContainerElement { ...@@ -92,6 +93,8 @@ class ANIMATION_EXPORT Animation : public AnimationContainerElement {
base::TimeDelta GetTimerInterval() const override; base::TimeDelta GetTimerInterval() const override;
private: private:
friend class AnimationTestApi;
// Interval for the animation. // Interval for the animation.
const base::TimeDelta timer_interval_; const base::TimeDelta timer_interval_;
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gfx/animation/animation_test_api.h"
#include "base/time/time.h"
#include "ui/gfx/animation/animation.h"
namespace gfx {
AnimationTestApi::AnimationTestApi(Animation* animation)
: animation_(animation) {}
AnimationTestApi::~AnimationTestApi() {}
void AnimationTestApi::SetStartTime(base::TimeTicks ticks) {
animation_->SetStartTime(ticks);
}
void AnimationTestApi::Step(base::TimeTicks ticks) {
animation_->Step(ticks);
}
} // namespace gfx
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GFX_ANIMATION_ANIMATION_TEST_API_H_
#define UI_GFX_ANIMATION_ANIMATION_TEST_API_H_
#include "base/macros.h"
#include "ui/gfx/animation/animation.h"
namespace gfx {
// Class to provide access to Animation internals for testing.
class AnimationTestApi {
public:
explicit AnimationTestApi(Animation* animation);
~AnimationTestApi();
// Sets the start of the animation.
void SetStartTime(base::TimeTicks ticks);
// Manually steps the animation forward
void Step(base::TimeTicks ticks);
private:
Animation* animation_;
DISALLOW_COPY_AND_ASSIGN(AnimationTestApi);
};
} // namespace gfx
#endif // UI_GFX_ANIMATION_ANIMATION_TEST_API_H_
...@@ -10,32 +10,14 @@ ...@@ -10,32 +10,14 @@
#include "base/test/scoped_task_environment.h" #include "base/test/scoped_task_environment.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/animation/animation_test_api.h"
#include "ui/gfx/animation/test_animation_delegate.h" #include "ui/gfx/animation/test_animation_delegate.h"
namespace gfx { namespace gfx {
// Class to provide access to SlideAnimation internals for testing.
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);
};
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// SlideAnimationTest // SlideAnimationTest
class SlideAnimationTest: public testing::Test { class SlideAnimationTest : public testing::Test {
protected: protected:
SlideAnimationTest() SlideAnimationTest()
: scoped_task_environment_( : scoped_task_environment_(
...@@ -62,7 +44,7 @@ TEST_F(SlideAnimationTest, InitialState) { ...@@ -62,7 +44,7 @@ TEST_F(SlideAnimationTest, InitialState) {
TEST_F(SlideAnimationTest, Basics) { TEST_F(SlideAnimationTest, Basics) {
SlideAnimation animation(nullptr); SlideAnimation animation(nullptr);
SlideAnimation::TestApi test_api(&animation); AnimationTestApi test_api(&animation);
// Use linear tweening to make the math easier below. // Use linear tweening to make the math easier below.
animation.SetTweenType(Tween::LINEAR); animation.SetTweenType(Tween::LINEAR);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment