Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: ui/gfx/compositor/layer_animation_sequence_unittest.cc

Issue 8247009: Explicit animation support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix VS2010 Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/compositor/layer_animation_sequence.cc ('k') | ui/gfx/compositor/layer_animator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/gfx/compositor/layer_animation_sequence.h"
6
7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/gfx/rect.h"
13 #include "ui/gfx/transform.h"
14 #include "ui/gfx/compositor/layer_animation_delegate.h"
15 #include "ui/gfx/compositor/layer_animation_element.h"
16 #include "ui/gfx/compositor/test_utils.h"
17 #include "ui/gfx/compositor/test_layer_animation_delegate.h"
18
19 namespace ui {
20
21 namespace {
22
23 // Check that the sequence behaves sanely when it contains no elements.
24 TEST(LayerAnimationSequenceTest, NoElement) {
25 LayerAnimationSequence sequence;
26 EXPECT_EQ(sequence.duration(), base::TimeDelta());
27 EXPECT_TRUE(sequence.properties().size() == 0);
28 LayerAnimationElement::AnimatableProperties properties;
29 EXPECT_FALSE(sequence.HasCommonProperty(properties));
30 }
31
32 // Check that the sequences progresses the delegate as expected when it contains
33 // a single element.
34 TEST(LayerAnimationSequenceTest, SingleElement) {
35 LayerAnimationSequence sequence;
36 TestLayerAnimationDelegate delegate;
37 float start = 0.0;
38 float middle = 0.5;
39 float target = 1.0;
40 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
41 sequence.AddElement(
42 LayerAnimationElement::CreateOpacityElement(target, delta));
43
44 for (int i = 0; i < 2; ++i) {
45 delegate.SetOpacityFromAnimation(start);
46 sequence.Progress(base::TimeDelta::FromMilliseconds(0), &delegate);
47 EXPECT_FLOAT_EQ(start, delegate.GetOpacityForAnimation());
48 sequence.Progress(base::TimeDelta::FromMilliseconds(500), &delegate);
49 EXPECT_FLOAT_EQ(middle, delegate.GetOpacityForAnimation());
50 sequence.Progress(base::TimeDelta::FromMilliseconds(1000), &delegate);
51 EXPECT_FLOAT_EQ(target, delegate.GetOpacityForAnimation());
52 }
53
54 EXPECT_TRUE(sequence.properties().size() == 1);
55 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::OPACITY) !=
56 sequence.properties().end());
57 EXPECT_EQ(delta, sequence.duration());
58 }
59
60 // Check that the sequences progresses the delegate as expected when it contains
61 // multiple elements. Note, see the layer animator tests for cyclic sequences.
62 TEST(LayerAnimationSequenceTest, MultipleElement) {
63 LayerAnimationSequence sequence;
64 TestLayerAnimationDelegate delegate;
65 float start_opacity = 0.0;
66 float middle_opacity = 0.5;
67 float target_opacity = 1.0;
68 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
69 sequence.AddElement(
70 LayerAnimationElement::CreateOpacityElement(target_opacity, delta));
71
72 // Pause bounds for a second.
73 LayerAnimationElement::AnimatableProperties properties;
74 properties.insert(LayerAnimationElement::BOUNDS);
75
76 sequence.AddElement(
77 LayerAnimationElement::CreatePauseElement(properties, delta));
78
79 Transform start_transform, target_transform, middle_transform;
80 start_transform.SetRotate(-90);
81 target_transform.SetRotate(90);
82
83 sequence.AddElement(
84 LayerAnimationElement::CreateTransformElement(target_transform, delta));
85
86 for (int i = 0; i < 2; ++i) {
87 delegate.SetOpacityFromAnimation(start_opacity);
88 delegate.SetTransformFromAnimation(start_transform);
89
90 sequence.Progress(base::TimeDelta::FromMilliseconds(0), &delegate);
91 EXPECT_FLOAT_EQ(start_opacity, delegate.GetOpacityForAnimation());
92 sequence.Progress(base::TimeDelta::FromMilliseconds(500), &delegate);
93 EXPECT_FLOAT_EQ(middle_opacity, delegate.GetOpacityForAnimation());
94 sequence.Progress(base::TimeDelta::FromMilliseconds(1000), &delegate);
95 EXPECT_FLOAT_EQ(target_opacity, delegate.GetOpacityForAnimation());
96 TestLayerAnimationDelegate copy = delegate;
97
98 // In the middle of the pause -- nothing should have changed.
99 sequence.Progress(base::TimeDelta::FromMilliseconds(1500), &delegate);
100 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(),
101 copy.GetBoundsForAnimation());
102 CheckApproximatelyEqual(delegate.GetTransformForAnimation(),
103 copy.GetTransformForAnimation());
104 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(),
105 copy.GetOpacityForAnimation());
106
107
108 sequence.Progress(base::TimeDelta::FromMilliseconds(2000), &delegate);
109 CheckApproximatelyEqual(start_transform,
110 delegate.GetTransformForAnimation());
111 sequence.Progress(base::TimeDelta::FromMilliseconds(2500), &delegate);
112 CheckApproximatelyEqual(middle_transform,
113 delegate.GetTransformForAnimation());
114 sequence.Progress(base::TimeDelta::FromMilliseconds(3000), &delegate);
115 CheckApproximatelyEqual(target_transform,
116 delegate.GetTransformForAnimation());
117 }
118
119 EXPECT_TRUE(sequence.properties().size() == 3);
120 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::OPACITY) !=
121 sequence.properties().end());
122 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::TRANSFORM) !=
123 sequence.properties().end());
124 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::BOUNDS) !=
125 sequence.properties().end());
126 EXPECT_EQ(delta + delta + delta, sequence.duration());
127 }
128
129 // Check that a sequence can still be aborted if it has cycled many times.
130 TEST(LayerAnimationSequenceTest, AbortingCyclicSequence) {
131 LayerAnimationSequence sequence;
132 TestLayerAnimationDelegate delegate;
133 float start_opacity = 0.0;
134 float target_opacity = 1.0;
135 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
136 sequence.AddElement(
137 LayerAnimationElement::CreateOpacityElement(target_opacity, delta));
138
139 sequence.AddElement(
140 LayerAnimationElement::CreateOpacityElement(start_opacity, delta));
141
142 sequence.set_is_cyclic(true);
143
144 delegate.SetOpacityFromAnimation(start_opacity);
145
146 sequence.Progress(base::TimeDelta::FromMilliseconds(101000), &delegate);
147 EXPECT_FLOAT_EQ(target_opacity, delegate.GetOpacityForAnimation());
148 sequence.Abort();
149
150 // Should be able to reuse the sequence after aborting.
151 delegate.SetOpacityFromAnimation(start_opacity);
152 sequence.Progress(base::TimeDelta::FromMilliseconds(100000), &delegate);
153 EXPECT_FLOAT_EQ(start_opacity, delegate.GetOpacityForAnimation());
154 }
155
156 } // namespace
157
158 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/compositor/layer_animation_sequence.cc ('k') | ui/gfx/compositor/layer_animator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698