1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
// Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h"
#include "ui/base/animation/animation_container_element.h"
#include "ui/base/animation/multi_animation.h"
namespace ui {
typedef testing::Test MultiAnimationTest;
TEST_F(MultiAnimationTest, Basic) {
// Create a MultiAnimation with two parts.
MultiAnimation::Parts parts;
parts.push_back(MultiAnimation::Part(100, Tween::LINEAR));
parts.push_back(MultiAnimation::Part(100, Tween::EASE_OUT));
MultiAnimation animation(parts);
AnimationContainerElement* as_element =
static_cast<AnimationContainerElement*>(&animation);
as_element->SetStartTime(base::TimeTicks());
// Step to 50, which is half way through the first part.
as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(50));
EXPECT_EQ(.5, animation.GetCurrentValue());
// Step to 120, which is 20% through the second part.
as_element->Step(base::TimeTicks() +
base::TimeDelta::FromMilliseconds(120));
EXPECT_EQ(Tween::CalculateValue(Tween::EASE_OUT, .2),
animation.GetCurrentValue());
// Step to 320, which is 20% through the second part.
as_element->Step(base::TimeTicks() +
base::TimeDelta::FromMilliseconds(320));
EXPECT_EQ(Tween::CalculateValue(Tween::EASE_OUT, .2),
animation.GetCurrentValue());
}
TEST_F(MultiAnimationTest, DifferingStartAndEnd) {
// Create a MultiAnimation with two parts.
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);
AnimationContainerElement* as_element =
static_cast<AnimationContainerElement*>(&animation);
as_element->SetStartTime(base::TimeTicks());
// Step to 0. Because the start_time is 100, this should be 100ms into the
// animation
as_element->Step(base::TimeTicks());
EXPECT_EQ(.25, animation.GetCurrentValue());
// Step to 100, which is effectively 200ms into the animation.
as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(100));
EXPECT_EQ(.5, animation.GetCurrentValue());
}
// Makes sure multi-animation stops if cycles is false.
TEST_F(MultiAnimationTest, DontCycle) {
MultiAnimation::Parts parts;
parts.push_back(MultiAnimation::Part(200, Tween::LINEAR));
MultiAnimation animation(parts);
AnimationContainerElement* as_element =
static_cast<AnimationContainerElement*>(&animation);
as_element->SetStartTime(base::TimeTicks());
animation.set_continuous(false);
// Step to 300, which is greater than the cycle time.
as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(300));
EXPECT_EQ(1.0, animation.GetCurrentValue());
EXPECT_FALSE(animation.is_animating());
}
// Makes sure multi-animation cycles correctly.
TEST_F(MultiAnimationTest, Cycle) {
MultiAnimation::Parts parts;
parts.push_back(MultiAnimation::Part(200, Tween::LINEAR));
MultiAnimation animation(parts);
AnimationContainerElement* as_element =
static_cast<AnimationContainerElement*>(&animation);
as_element->SetStartTime(base::TimeTicks());
// Step to 300, which is greater than the cycle time.
as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(300));
EXPECT_EQ(.5, animation.GetCurrentValue());
}
} // namespace ui
|