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

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

Issue 26880010: gfx: Add FrameTime and DisplayTime classes (Closed) Base URL: http://git.chromium.org/chromium/src.git@checkHighResNow4
Patch Set: WIP Created 7 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
« no previous file with comments | « ui/compositor/layer_animation_sequence.cc ('k') | ui/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
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"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/compositor/layer_animation_delegate.h" 12 #include "ui/compositor/layer_animation_delegate.h"
13 #include "ui/compositor/layer_animation_element.h" 13 #include "ui/compositor/layer_animation_element.h"
14 #include "ui/compositor/test/test_layer_animation_delegate.h" 14 #include "ui/compositor/test/test_layer_animation_delegate.h"
15 #include "ui/compositor/test/test_layer_animation_observer.h" 15 #include "ui/compositor/test/test_layer_animation_observer.h"
16 #include "ui/compositor/test/test_utils.h" 16 #include "ui/compositor/test/test_utils.h"
17 #include "ui/gfx/frame_time.h"
17 #include "ui/gfx/rect.h" 18 #include "ui/gfx/rect.h"
18 #include "ui/gfx/transform.h" 19 #include "ui/gfx/transform.h"
19 20
20 namespace ui { 21 namespace ui {
21 22
22 namespace { 23 namespace {
23 24
24 // Check that the sequence behaves sanely when it contains no elements. 25 // Check that the sequence behaves sanely when it contains no elements.
25 TEST(LayerAnimationSequenceTest, NoElement) { 26 TEST(LayerAnimationSequenceTest, NoElement) {
26 LayerAnimationSequence sequence; 27 LayerAnimationSequence sequence;
27 base::TimeTicks start_time; 28 gfx::FrameTime start_time;
28 start_time += base::TimeDelta::FromSeconds(1); 29 start_time += base::TimeDelta::FromSeconds(1);
29 sequence.set_start_time(start_time); 30 sequence.set_start_time(start_time);
30 EXPECT_TRUE(sequence.IsFinished(start_time)); 31 EXPECT_TRUE(sequence.IsFinished(start_time));
31 EXPECT_TRUE(sequence.properties().size() == 0); 32 EXPECT_TRUE(sequence.properties().size() == 0);
32 LayerAnimationElement::AnimatableProperties properties; 33 LayerAnimationElement::AnimatableProperties properties;
33 EXPECT_FALSE(sequence.HasConflictingProperty(properties)); 34 EXPECT_FALSE(sequence.HasConflictingProperty(properties));
34 } 35 }
35 36
36 // Check that the sequences progresses the delegate as expected when it contains 37 // Check that the sequences progresses the delegate as expected when it contains
37 // a single non-threaded element. 38 // a single non-threaded element.
38 TEST(LayerAnimationSequenceTest, SingleElement) { 39 TEST(LayerAnimationSequenceTest, SingleElement) {
39 LayerAnimationSequence sequence; 40 LayerAnimationSequence sequence;
40 TestLayerAnimationDelegate delegate; 41 TestLayerAnimationDelegate delegate;
41 float start = 0.0f; 42 float start = 0.0f;
42 float middle = 0.5f; 43 float middle = 0.5f;
43 float target = 1.0f; 44 float target = 1.0f;
44 base::TimeTicks start_time; 45 gfx::FrameTime start_time;
45 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 46 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
46 sequence.AddElement( 47 sequence.AddElement(
47 LayerAnimationElement::CreateBrightnessElement(target, delta)); 48 LayerAnimationElement::CreateBrightnessElement(target, delta));
48 49
49 for (int i = 0; i < 2; ++i) { 50 for (int i = 0; i < 2; ++i) {
50 start_time += delta; 51 start_time += delta;
51 sequence.set_start_time(start_time); 52 sequence.set_start_time(start_time);
52 delegate.SetBrightnessFromAnimation(start); 53 delegate.SetBrightnessFromAnimation(start);
53 sequence.Start(&delegate); 54 sequence.Start(&delegate);
54 sequence.Progress(start_time, &delegate); 55 sequence.Progress(start_time, &delegate);
(...skipping 13 matching lines...) Expand all
68 } 69 }
69 70
70 // Check that the sequences progresses the delegate as expected when it contains 71 // Check that the sequences progresses the delegate as expected when it contains
71 // a single threaded element. 72 // a single threaded element.
72 TEST(LayerAnimationSequenceTest, SingleThreadedElement) { 73 TEST(LayerAnimationSequenceTest, SingleThreadedElement) {
73 LayerAnimationSequence sequence; 74 LayerAnimationSequence sequence;
74 TestLayerAnimationDelegate delegate; 75 TestLayerAnimationDelegate delegate;
75 float start = 0.0f; 76 float start = 0.0f;
76 float middle = 0.5f; 77 float middle = 0.5f;
77 float target = 1.0f; 78 float target = 1.0f;
78 base::TimeTicks start_time; 79 gfx::FrameTime start_time;
79 base::TimeTicks effective_start; 80 gfx::FrameTime effective_start;
80 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 81 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
81 sequence.AddElement( 82 sequence.AddElement(
82 LayerAnimationElement::CreateOpacityElement(target, delta)); 83 LayerAnimationElement::CreateOpacityElement(target, delta));
83 84
84 for (int i = 0; i < 2; ++i) { 85 for (int i = 0; i < 2; ++i) {
85 int starting_group_id = 1; 86 int starting_group_id = 1;
86 sequence.set_animation_group_id(starting_group_id); 87 sequence.set_animation_group_id(starting_group_id);
87 start_time = effective_start + delta; 88 start_time = effective_start + delta;
88 sequence.set_start_time(start_time); 89 sequence.set_start_time(start_time);
89 delegate.SetOpacityFromAnimation(start); 90 delegate.SetOpacityFromAnimation(start);
90 sequence.Start(&delegate); 91 sequence.Start(&delegate);
91 sequence.Progress(start_time, &delegate); 92 sequence.Progress(start_time, &delegate);
92 EXPECT_FLOAT_EQ(start, sequence.last_progressed_fraction()); 93 EXPECT_FLOAT_EQ(start, sequence.last_progressed_fraction());
93 effective_start = start_time + delta; 94 effective_start = start_time + delta;
94 sequence.OnThreadedAnimationStarted(cc::AnimationEvent( 95 sequence.OnThreadedAnimationStarted(cc::AnimationEvent(
95 cc::AnimationEvent::Started, 96 cc::AnimationEvent::Started,
96 0, 97 0,
97 sequence.animation_group_id(), 98 sequence.animation_group_id(),
98 cc::Animation::Opacity, 99 cc::Animation::Opacity,
99 (effective_start - base::TimeTicks()).InSecondsF())); 100 (effective_start - gfx::FrameTime()).InSecondsF()));
100 sequence.Progress(effective_start + delta/2, &delegate); 101 sequence.Progress(effective_start + delta/2, &delegate);
101 EXPECT_FLOAT_EQ(middle, sequence.last_progressed_fraction()); 102 EXPECT_FLOAT_EQ(middle, sequence.last_progressed_fraction());
102 EXPECT_TRUE(sequence.IsFinished(effective_start + delta)); 103 EXPECT_TRUE(sequence.IsFinished(effective_start + delta));
103 sequence.Progress(effective_start + delta, &delegate); 104 sequence.Progress(effective_start + delta, &delegate);
104 EXPECT_FLOAT_EQ(target, sequence.last_progressed_fraction()); 105 EXPECT_FLOAT_EQ(target, sequence.last_progressed_fraction());
105 EXPECT_FLOAT_EQ(target, delegate.GetOpacityForAnimation()); 106 EXPECT_FLOAT_EQ(target, delegate.GetOpacityForAnimation());
106 } 107 }
107 108
108 EXPECT_TRUE(sequence.properties().size() == 1); 109 EXPECT_TRUE(sequence.properties().size() == 1);
109 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::OPACITY) != 110 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::OPACITY) !=
110 sequence.properties().end()); 111 sequence.properties().end());
111 } 112 }
112 113
113 // Check that the sequences progresses the delegate as expected when it contains 114 // Check that the sequences progresses the delegate as expected when it contains
114 // multiple elements. Note, see the layer animator tests for cyclic sequences. 115 // multiple elements. Note, see the layer animator tests for cyclic sequences.
115 TEST(LayerAnimationSequenceTest, MultipleElement) { 116 TEST(LayerAnimationSequenceTest, MultipleElement) {
116 LayerAnimationSequence sequence; 117 LayerAnimationSequence sequence;
117 TestLayerAnimationDelegate delegate; 118 TestLayerAnimationDelegate delegate;
118 float start_opacity = 0.0f; 119 float start_opacity = 0.0f;
119 float target_opacity = 1.0f; 120 float target_opacity = 1.0f;
120 base::TimeTicks start_time; 121 gfx::FrameTime start_time;
121 base::TimeTicks opacity_effective_start; 122 gfx::FrameTime opacity_effective_start;
122 base::TimeTicks transform_effective_start; 123 gfx::FrameTime transform_effective_start;
123 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 124 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
124 sequence.AddElement( 125 sequence.AddElement(
125 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)); 126 LayerAnimationElement::CreateOpacityElement(target_opacity, delta));
126 127
127 // Pause bounds for a second. 128 // Pause bounds for a second.
128 LayerAnimationElement::AnimatableProperties properties; 129 LayerAnimationElement::AnimatableProperties properties;
129 properties.insert(LayerAnimationElement::BOUNDS); 130 properties.insert(LayerAnimationElement::BOUNDS);
130 131
131 sequence.AddElement( 132 sequence.AddElement(
132 LayerAnimationElement::CreatePauseElement(properties, delta)); 133 LayerAnimationElement::CreatePauseElement(properties, delta));
(...skipping 16 matching lines...) Expand all
149 sequence.Start(&delegate); 150 sequence.Start(&delegate);
150 sequence.Progress(start_time, &delegate); 151 sequence.Progress(start_time, &delegate);
151 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); 152 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction());
152 opacity_effective_start = start_time + delta; 153 opacity_effective_start = start_time + delta;
153 EXPECT_EQ(starting_group_id, sequence.animation_group_id()); 154 EXPECT_EQ(starting_group_id, sequence.animation_group_id());
154 sequence.OnThreadedAnimationStarted(cc::AnimationEvent( 155 sequence.OnThreadedAnimationStarted(cc::AnimationEvent(
155 cc::AnimationEvent::Started, 156 cc::AnimationEvent::Started,
156 0, 157 0,
157 sequence.animation_group_id(), 158 sequence.animation_group_id(),
158 cc::Animation::Opacity, 159 cc::Animation::Opacity,
159 (opacity_effective_start - base::TimeTicks()).InSecondsF())); 160 (opacity_effective_start - gfx::FrameTime()).InSecondsF()));
160 sequence.Progress(opacity_effective_start + delta/2, &delegate); 161 sequence.Progress(opacity_effective_start + delta/2, &delegate);
161 EXPECT_FLOAT_EQ(0.5, sequence.last_progressed_fraction()); 162 EXPECT_FLOAT_EQ(0.5, sequence.last_progressed_fraction());
162 sequence.Progress(opacity_effective_start + delta, &delegate); 163 sequence.Progress(opacity_effective_start + delta, &delegate);
163 EXPECT_FLOAT_EQ(target_opacity, delegate.GetOpacityForAnimation()); 164 EXPECT_FLOAT_EQ(target_opacity, delegate.GetOpacityForAnimation());
164 165
165 // Now at the start of the pause. 166 // Now at the start of the pause.
166 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); 167 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction());
167 TestLayerAnimationDelegate copy = delegate; 168 TestLayerAnimationDelegate copy = delegate;
168 169
169 // In the middle of the pause -- nothing should have changed. 170 // In the middle of the pause -- nothing should have changed.
(...skipping 10 matching lines...) Expand all
180 CheckApproximatelyEqual(start_transform, 181 CheckApproximatelyEqual(start_transform,
181 delegate.GetTransformForAnimation()); 182 delegate.GetTransformForAnimation());
182 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); 183 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction());
183 transform_effective_start = opacity_effective_start + 3 * delta; 184 transform_effective_start = opacity_effective_start + 3 * delta;
184 EXPECT_NE(starting_group_id, sequence.animation_group_id()); 185 EXPECT_NE(starting_group_id, sequence.animation_group_id());
185 sequence.OnThreadedAnimationStarted(cc::AnimationEvent( 186 sequence.OnThreadedAnimationStarted(cc::AnimationEvent(
186 cc::AnimationEvent::Started, 187 cc::AnimationEvent::Started,
187 0, 188 0,
188 sequence.animation_group_id(), 189 sequence.animation_group_id(),
189 cc::Animation::Transform, 190 cc::Animation::Transform,
190 (transform_effective_start - base::TimeTicks()).InSecondsF())); 191 (transform_effective_start - gfx::FrameTime()).InSecondsF()));
191 sequence.Progress(transform_effective_start + delta/2, &delegate); 192 sequence.Progress(transform_effective_start + delta/2, &delegate);
192 EXPECT_FLOAT_EQ(0.5, sequence.last_progressed_fraction()); 193 EXPECT_FLOAT_EQ(0.5, sequence.last_progressed_fraction());
193 EXPECT_TRUE(sequence.IsFinished(transform_effective_start + delta)); 194 EXPECT_TRUE(sequence.IsFinished(transform_effective_start + delta));
194 sequence.Progress(transform_effective_start + delta, &delegate); 195 sequence.Progress(transform_effective_start + delta, &delegate);
195 CheckApproximatelyEqual(target_transform, 196 CheckApproximatelyEqual(target_transform,
196 delegate.GetTransformForAnimation()); 197 delegate.GetTransformForAnimation());
197 } 198 }
198 199
199 EXPECT_TRUE(sequence.properties().size() == 3); 200 EXPECT_TRUE(sequence.properties().size() == 3);
200 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::OPACITY) != 201 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::OPACITY) !=
201 sequence.properties().end()); 202 sequence.properties().end());
202 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::TRANSFORM) != 203 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::TRANSFORM) !=
203 sequence.properties().end()); 204 sequence.properties().end());
204 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::BOUNDS) != 205 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::BOUNDS) !=
205 sequence.properties().end()); 206 sequence.properties().end());
206 } 207 }
207 208
208 // Check that a sequence can still be aborted if it has cycled many times. 209 // Check that a sequence can still be aborted if it has cycled many times.
209 TEST(LayerAnimationSequenceTest, AbortingCyclicSequence) { 210 TEST(LayerAnimationSequenceTest, AbortingCyclicSequence) {
210 LayerAnimationSequence sequence; 211 LayerAnimationSequence sequence;
211 TestLayerAnimationDelegate delegate; 212 TestLayerAnimationDelegate delegate;
212 float start_brightness = 0.0f; 213 float start_brightness = 0.0f;
213 float target_brightness = 1.0f; 214 float target_brightness = 1.0f;
214 base::TimeTicks start_time; 215 gfx::FrameTime start_time;
215 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 216 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
216 sequence.AddElement( 217 sequence.AddElement(
217 LayerAnimationElement::CreateBrightnessElement(target_brightness, delta)); 218 LayerAnimationElement::CreateBrightnessElement(target_brightness, delta));
218 219
219 sequence.AddElement( 220 sequence.AddElement(
220 LayerAnimationElement::CreateBrightnessElement(start_brightness, delta)); 221 LayerAnimationElement::CreateBrightnessElement(start_brightness, delta));
221 222
222 sequence.set_is_cyclic(true); 223 sequence.set_is_cyclic(true);
223 224
224 delegate.SetBrightnessFromAnimation(start_brightness); 225 delegate.SetBrightnessFromAnimation(start_brightness);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 sequence.GetTargetValue(&target_value); 257 sequence.GetTargetValue(&target_value);
257 EXPECT_FLOAT_EQ(target_opacity, target_value.opacity); 258 EXPECT_FLOAT_EQ(target_opacity, target_value.opacity);
258 259
259 sequence.set_is_cyclic(true); 260 sequence.set_is_cyclic(true);
260 target_value.opacity = start_opacity; 261 target_value.opacity = start_opacity;
261 sequence.GetTargetValue(&target_value); 262 sequence.GetTargetValue(&target_value);
262 EXPECT_FLOAT_EQ(start_opacity, target_value.opacity); 263 EXPECT_FLOAT_EQ(start_opacity, target_value.opacity);
263 } 264 }
264 265
265 TEST(LayerAnimationSequenceTest, AddObserver) { 266 TEST(LayerAnimationSequenceTest, AddObserver) {
266 base::TimeTicks start_time; 267 gfx::FrameTime start_time;
267 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 268 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
268 LayerAnimationSequence sequence; 269 LayerAnimationSequence sequence;
269 sequence.AddElement( 270 sequence.AddElement(
270 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); 271 LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
271 for (int i = 0; i < 2; ++i) { 272 for (int i = 0; i < 2; ++i) {
272 start_time += delta; 273 start_time += delta;
273 sequence.set_start_time(start_time); 274 sequence.set_start_time(start_time);
274 TestLayerAnimationObserver observer; 275 TestLayerAnimationObserver observer;
275 TestLayerAnimationDelegate delegate; 276 TestLayerAnimationDelegate delegate;
276 sequence.AddObserver(&observer); 277 sequence.AddObserver(&observer);
277 EXPECT_TRUE(!observer.last_ended_sequence()); 278 EXPECT_TRUE(!observer.last_ended_sequence());
278 sequence.Progress(start_time + delta, &delegate); 279 sequence.Progress(start_time + delta, &delegate);
279 EXPECT_EQ(observer.last_ended_sequence(), &sequence); 280 EXPECT_EQ(observer.last_ended_sequence(), &sequence);
280 sequence.RemoveObserver(&observer); 281 sequence.RemoveObserver(&observer);
281 } 282 }
282 } 283 }
283 284
284 } // namespace 285 } // namespace
285 286
286 } // namespace ui 287 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer_animation_sequence.cc ('k') | ui/compositor/layer_animator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698