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

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

Issue 134453004: Use a bitfield to store animatable properties. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win build error Created 6 years, 11 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/compositor/layer_animation_sequence.h" 5 #include "ui/compositor/layer_animation_sequence.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 10 matching lines...) Expand all
21 21
22 namespace { 22 namespace {
23 23
24 // Check that the sequence behaves sanely when it contains no elements. 24 // Check that the sequence behaves sanely when it contains no elements.
25 TEST(LayerAnimationSequenceTest, NoElement) { 25 TEST(LayerAnimationSequenceTest, NoElement) {
26 LayerAnimationSequence sequence; 26 LayerAnimationSequence sequence;
27 base::TimeTicks start_time; 27 base::TimeTicks start_time;
28 start_time += base::TimeDelta::FromSeconds(1); 28 start_time += base::TimeDelta::FromSeconds(1);
29 sequence.set_start_time(start_time); 29 sequence.set_start_time(start_time);
30 EXPECT_TRUE(sequence.IsFinished(start_time)); 30 EXPECT_TRUE(sequence.IsFinished(start_time));
31 EXPECT_TRUE(sequence.properties().size() == 0); 31 EXPECT_TRUE(sequence.properties() == LayerAnimationElement::UNKNOWN);
sky 2014/01/13 14:26:42 EXPECT_EQ (here and similar places in this file).
Ian Vollick 2014/01/13 19:03:59 Done.
32 LayerAnimationElement::AnimatableProperties properties; 32 EXPECT_FALSE(sequence.HasConflictingProperty(LayerAnimationElement::UNKNOWN));
33 EXPECT_FALSE(sequence.HasConflictingProperty(properties));
34 } 33 }
35 34
36 // Check that the sequences progresses the delegate as expected when it contains 35 // Check that the sequences progresses the delegate as expected when it contains
37 // a single non-threaded element. 36 // a single non-threaded element.
38 TEST(LayerAnimationSequenceTest, SingleElement) { 37 TEST(LayerAnimationSequenceTest, SingleElement) {
39 LayerAnimationSequence sequence; 38 LayerAnimationSequence sequence;
40 TestLayerAnimationDelegate delegate; 39 TestLayerAnimationDelegate delegate;
41 float start = 0.0f; 40 float start = 0.0f;
42 float middle = 0.5f; 41 float middle = 0.5f;
43 float target = 1.0f; 42 float target = 1.0f;
(...skipping 11 matching lines...) Expand all
55 EXPECT_FLOAT_EQ(start, delegate.GetBrightnessForAnimation()); 54 EXPECT_FLOAT_EQ(start, delegate.GetBrightnessForAnimation());
56 sequence.Progress(start_time + base::TimeDelta::FromMilliseconds(500), 55 sequence.Progress(start_time + base::TimeDelta::FromMilliseconds(500),
57 &delegate); 56 &delegate);
58 EXPECT_FLOAT_EQ(middle, delegate.GetBrightnessForAnimation()); 57 EXPECT_FLOAT_EQ(middle, delegate.GetBrightnessForAnimation());
59 EXPECT_TRUE(sequence.IsFinished(start_time + delta)); 58 EXPECT_TRUE(sequence.IsFinished(start_time + delta));
60 sequence.Progress(start_time + base::TimeDelta::FromMilliseconds(1000), 59 sequence.Progress(start_time + base::TimeDelta::FromMilliseconds(1000),
61 &delegate); 60 &delegate);
62 EXPECT_FLOAT_EQ(target, delegate.GetBrightnessForAnimation()); 61 EXPECT_FLOAT_EQ(target, delegate.GetBrightnessForAnimation());
63 } 62 }
64 63
65 EXPECT_TRUE(sequence.properties().size() == 1); 64 EXPECT_TRUE(sequence.properties() == LayerAnimationElement::BRIGHTNESS);
66 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::BRIGHTNESS) !=
67 sequence.properties().end());
68 } 65 }
69 66
70 // Check that the sequences progresses the delegate as expected when it contains 67 // Check that the sequences progresses the delegate as expected when it contains
71 // a single threaded element. 68 // a single threaded element.
72 TEST(LayerAnimationSequenceTest, SingleThreadedElement) { 69 TEST(LayerAnimationSequenceTest, SingleThreadedElement) {
73 LayerAnimationSequence sequence; 70 LayerAnimationSequence sequence;
74 TestLayerAnimationDelegate delegate; 71 TestLayerAnimationDelegate delegate;
75 float start = 0.0f; 72 float start = 0.0f;
76 float middle = 0.5f; 73 float middle = 0.5f;
77 float target = 1.0f; 74 float target = 1.0f;
(...skipping 20 matching lines...) Expand all
98 cc::Animation::Opacity, 95 cc::Animation::Opacity,
99 (effective_start - base::TimeTicks()).InSecondsF())); 96 (effective_start - base::TimeTicks()).InSecondsF()));
100 sequence.Progress(effective_start + delta/2, &delegate); 97 sequence.Progress(effective_start + delta/2, &delegate);
101 EXPECT_FLOAT_EQ(middle, sequence.last_progressed_fraction()); 98 EXPECT_FLOAT_EQ(middle, sequence.last_progressed_fraction());
102 EXPECT_TRUE(sequence.IsFinished(effective_start + delta)); 99 EXPECT_TRUE(sequence.IsFinished(effective_start + delta));
103 sequence.Progress(effective_start + delta, &delegate); 100 sequence.Progress(effective_start + delta, &delegate);
104 EXPECT_FLOAT_EQ(target, sequence.last_progressed_fraction()); 101 EXPECT_FLOAT_EQ(target, sequence.last_progressed_fraction());
105 EXPECT_FLOAT_EQ(target, delegate.GetOpacityForAnimation()); 102 EXPECT_FLOAT_EQ(target, delegate.GetOpacityForAnimation());
106 } 103 }
107 104
108 EXPECT_TRUE(sequence.properties().size() == 1); 105 EXPECT_TRUE(sequence.properties() == LayerAnimationElement::OPACITY);
109 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::OPACITY) !=
110 sequence.properties().end());
111 } 106 }
112 107
113 // Check that the sequences progresses the delegate as expected when it contains 108 // Check that the sequences progresses the delegate as expected when it contains
114 // multiple elements. Note, see the layer animator tests for cyclic sequences. 109 // multiple elements. Note, see the layer animator tests for cyclic sequences.
115 TEST(LayerAnimationSequenceTest, MultipleElement) { 110 TEST(LayerAnimationSequenceTest, MultipleElement) {
116 LayerAnimationSequence sequence; 111 LayerAnimationSequence sequence;
117 TestLayerAnimationDelegate delegate; 112 TestLayerAnimationDelegate delegate;
118 float start_opacity = 0.0f; 113 float start_opacity = 0.0f;
119 float target_opacity = 1.0f; 114 float target_opacity = 1.0f;
120 base::TimeTicks start_time; 115 base::TimeTicks start_time;
121 base::TimeTicks opacity_effective_start; 116 base::TimeTicks opacity_effective_start;
122 base::TimeTicks transform_effective_start; 117 base::TimeTicks transform_effective_start;
123 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 118 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
124 sequence.AddElement( 119 sequence.AddElement(
125 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)); 120 LayerAnimationElement::CreateOpacityElement(target_opacity, delta));
126 121
127 // Pause bounds for a second. 122 // Pause bounds for a second.
128 LayerAnimationElement::AnimatableProperties properties; 123 sequence.AddElement(LayerAnimationElement::CreatePauseElement(
129 properties.insert(LayerAnimationElement::BOUNDS); 124 LayerAnimationElement::BOUNDS, delta));
130
131 sequence.AddElement(
132 LayerAnimationElement::CreatePauseElement(properties, delta));
133 125
134 gfx::Transform start_transform, target_transform, middle_transform; 126 gfx::Transform start_transform, target_transform, middle_transform;
135 start_transform.Rotate(-30.0); 127 start_transform.Rotate(-30.0);
136 target_transform.Rotate(30.0); 128 target_transform.Rotate(30.0);
137 129
138 sequence.AddElement( 130 sequence.AddElement(
139 LayerAnimationElement::CreateTransformElement(target_transform, delta)); 131 LayerAnimationElement::CreateTransformElement(target_transform, delta));
140 132
141 for (int i = 0; i < 2; ++i) { 133 for (int i = 0; i < 2; ++i) {
142 int starting_group_id = 1; 134 int starting_group_id = 1;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 cc::Animation::Transform, 181 cc::Animation::Transform,
190 (transform_effective_start - base::TimeTicks()).InSecondsF())); 182 (transform_effective_start - base::TimeTicks()).InSecondsF()));
191 sequence.Progress(transform_effective_start + delta/2, &delegate); 183 sequence.Progress(transform_effective_start + delta/2, &delegate);
192 EXPECT_FLOAT_EQ(0.5, sequence.last_progressed_fraction()); 184 EXPECT_FLOAT_EQ(0.5, sequence.last_progressed_fraction());
193 EXPECT_TRUE(sequence.IsFinished(transform_effective_start + delta)); 185 EXPECT_TRUE(sequence.IsFinished(transform_effective_start + delta));
194 sequence.Progress(transform_effective_start + delta, &delegate); 186 sequence.Progress(transform_effective_start + delta, &delegate);
195 CheckApproximatelyEqual(target_transform, 187 CheckApproximatelyEqual(target_transform,
196 delegate.GetTransformForAnimation()); 188 delegate.GetTransformForAnimation());
197 } 189 }
198 190
199 EXPECT_TRUE(sequence.properties().size() == 3); 191 EXPECT_TRUE(sequence.properties() == (LayerAnimationElement::OPACITY |
200 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::OPACITY) != 192 LayerAnimationElement::TRANSFORM |
201 sequence.properties().end()); 193 LayerAnimationElement::BOUNDS));
202 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::TRANSFORM) !=
203 sequence.properties().end());
204 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::BOUNDS) !=
205 sequence.properties().end());
206 } 194 }
207 195
208 // Check that a sequence can still be aborted if it has cycled many times. 196 // Check that a sequence can still be aborted if it has cycled many times.
209 TEST(LayerAnimationSequenceTest, AbortingCyclicSequence) { 197 TEST(LayerAnimationSequenceTest, AbortingCyclicSequence) {
210 LayerAnimationSequence sequence; 198 LayerAnimationSequence sequence;
211 TestLayerAnimationDelegate delegate; 199 TestLayerAnimationDelegate delegate;
212 float start_brightness = 0.0f; 200 float start_brightness = 0.0f;
213 float target_brightness = 1.0f; 201 float target_brightness = 1.0f;
214 base::TimeTicks start_time; 202 base::TimeTicks start_time;
215 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 203 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 EXPECT_TRUE(!observer.last_ended_sequence()); 265 EXPECT_TRUE(!observer.last_ended_sequence());
278 sequence.Progress(start_time + delta, &delegate); 266 sequence.Progress(start_time + delta, &delegate);
279 EXPECT_EQ(observer.last_ended_sequence(), &sequence); 267 EXPECT_EQ(observer.last_ended_sequence(), &sequence);
280 sequence.RemoveObserver(&observer); 268 sequence.RemoveObserver(&observer);
281 } 269 }
282 } 270 }
283 271
284 } // namespace 272 } // namespace
285 273
286 } // namespace ui 274 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698