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

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: . Created 9 years, 2 months 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
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 "base/basictypes.h"
6 #include "base/compiler_specific.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/time.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/gfx/rect.h"
11 #include "ui/gfx/transform.h"
12 #include "ui/gfx/compositor/layer_animation_delegate.h"
13 #include "ui/gfx/compositor/layer_animation_element.h"
14 #include "ui/gfx/compositor/layer_animation_sequence.h"
15 #include "ui/gfx/compositor/test_utils.h"
16 #include "ui/gfx/compositor/test_layer_animation_delegate.h"
17
18 namespace ui {
19
20 namespace {
21
22 // Check that the sequence behaves sanely when it contains no elements.
23 TEST(LayerAnimationSequenceTest, NoElement) {
24 LayerAnimationSequence sequence;
25 EXPECT_EQ(sequence.duration(), base::TimeDelta());
26 EXPECT_TRUE(sequence.properties().size() == 0);
27 LayerAnimationElement::AnimatableProperties properties;
28 EXPECT_FALSE(sequence.HasCommonProperty(properties));
29 }
30
31 // Check that the sequences progresses the delegate as expected when it contains
32 // a single element.
33 TEST(LayerAnimationSequenceTest, SingleElement) {
34 LayerAnimationSequence sequence;
35 TestLayerAnimationDelegate delegate;
36 float start = 0.0;
37 float middle = 0.5;
38 float target = 1.0;
39 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
40 sequence.AddElement(
41 LayerAnimationElement::CreateOpacityElement(target, delta));
42
43 for (int i = 0; i < 2; ++i) {
44 delegate.SetOpacityFromAnimation(start);
45 sequence.Progress(base::TimeDelta::FromMilliseconds(0), &delegate);
46 EXPECT_FLOAT_EQ(start, delegate.GetOpacityForAnimation());
47 sequence.Progress(base::TimeDelta::FromMilliseconds(500), &delegate);
48 EXPECT_FLOAT_EQ(middle, delegate.GetOpacityForAnimation());
49 sequence.Progress(base::TimeDelta::FromMilliseconds(1000), &delegate);
50 EXPECT_FLOAT_EQ(target, delegate.GetOpacityForAnimation());
51 }
52
53 EXPECT_TRUE(sequence.properties().size() == 1);
54 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::OPACITY) !=
55 sequence.properties().end());
56 EXPECT_EQ(delta, sequence.duration());
57 }
58
59 // Check that the sequences progresses the delegate as expected when it contains
60 // multiple elements. Note, see the layer animator tests for cyclic sequences.
61 TEST(LayerAnimationSequenceTest, MultipleElement) {
62 LayerAnimationSequence sequence;
63 TestLayerAnimationDelegate delegate;
64 float start_opacity = 0.0;
65 float middle_opacity = 0.5;
66 float target_opacity = 1.0;
67 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
68 sequence.AddElement(
69 LayerAnimationElement::CreateOpacityElement(target_opacity, delta));
70
71 // Pause bounds for a second.
72 LayerAnimationElement::AnimatableProperties properties;
73 properties.insert(LayerAnimationElement::BOUNDS);
74
75 sequence.AddElement(
76 LayerAnimationElement::CreatePauseElement(properties, delta));
77
78 Transform start_transform, target_transform, middle_transform;
79 start_transform.SetRotate(-90);
80 target_transform.SetRotate(90);
81
82 sequence.AddElement(
83 LayerAnimationElement::CreateTransformElement(target_transform, delta));
84
85 for (int i = 0; i < 2; ++i) {
86 delegate.SetOpacityFromAnimation(start_opacity);
87 delegate.SetTransformFromAnimation(start_transform);
88
89 sequence.Progress(base::TimeDelta::FromMilliseconds(0), &delegate);
90 EXPECT_FLOAT_EQ(start_opacity, delegate.GetOpacityForAnimation());
91 sequence.Progress(base::TimeDelta::FromMilliseconds(500), &delegate);
92 EXPECT_FLOAT_EQ(middle_opacity, delegate.GetOpacityForAnimation());
93 sequence.Progress(base::TimeDelta::FromMilliseconds(1000), &delegate);
94 EXPECT_FLOAT_EQ(target_opacity, delegate.GetOpacityForAnimation());
95 TestLayerAnimationDelegate copy = delegate;
96
97 // In the middle of the pause -- nothing should have changed.
98 sequence.Progress(base::TimeDelta::FromMilliseconds(1500), &delegate);
99 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(),
100 copy.GetBoundsForAnimation());
101 CheckApproximatelyEqual(delegate.GetTransformForAnimation(),
102 copy.GetTransformForAnimation());
103 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(),
104 copy.GetOpacityForAnimation());
105
106
107 sequence.Progress(base::TimeDelta::FromMilliseconds(2000), &delegate);
108 CheckApproximatelyEqual(start_transform,
109 delegate.GetTransformForAnimation());
110 sequence.Progress(base::TimeDelta::FromMilliseconds(2500), &delegate);
111 CheckApproximatelyEqual(middle_transform,
112 delegate.GetTransformForAnimation());
113 sequence.Progress(base::TimeDelta::FromMilliseconds(3000), &delegate);
114 CheckApproximatelyEqual(target_transform,
115 delegate.GetTransformForAnimation());
116 }
117
118 EXPECT_TRUE(sequence.properties().size() == 3);
119 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::OPACITY) !=
120 sequence.properties().end());
121 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::TRANSFORM) !=
122 sequence.properties().end());
123 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::BOUNDS) !=
124 sequence.properties().end());
125 EXPECT_EQ(delta + delta + delta, sequence.duration());
126 }
127
128 } // namespace
129
130 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698