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

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

Issue 8400059: Revert 107715 - Enable the new layer animation framework. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/gfx/compositor/layer_animation_element.h" 5 #include "ui/gfx/compositor/layer_animation_element.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.h" 10 #include "base/time.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/gfx/rect.h" 12 #include "ui/gfx/rect.h"
13 #include "ui/gfx/transform.h" 13 #include "ui/gfx/transform.h"
14 #include "ui/gfx/compositor/dummy_layer_animation_delegate.h"
15 #include "ui/gfx/compositor/layer_animation_delegate.h" 14 #include "ui/gfx/compositor/layer_animation_delegate.h"
16 #include "ui/gfx/compositor/test_utils.h" 15 #include "ui/gfx/compositor/test_utils.h"
16 #include "ui/gfx/compositor/test_layer_animation_delegate.h"
17 17
18 namespace ui { 18 namespace ui {
19 19
20 namespace { 20 namespace {
21 21
22 // Check that the transformation element progresses the delegate as expected and 22 // Check that the transformation element progresses the delegate as expected and
23 // that the element can be reused after it completes. 23 // that the element can be reused after it completes.
24 TEST(LayerAnimationElementTest, TransformElement) { 24 TEST(LayerAnimationElementTest, TransformElement) {
25 DummyLayerAnimationDelegate delegate; 25 TestLayerAnimationDelegate delegate;
26 Transform start_transform, target_transform, middle_transform; 26 Transform start_transform, target_transform, middle_transform;
27 start_transform.SetRotate(-90); 27 start_transform.SetRotate(-90);
28 target_transform.SetRotate(90); 28 target_transform.SetRotate(90);
29 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 29 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
30 30
31 scoped_ptr<LayerAnimationElement> element( 31 scoped_ptr<LayerAnimationElement> element(
32 LayerAnimationElement::CreateTransformElement(target_transform, delta)); 32 LayerAnimationElement::CreateTransformElement(target_transform, delta));
33 33
34 for (int i = 0; i < 2; ++i) { 34 for (int i = 0; i < 2; ++i) {
35 delegate.SetTransformFromAnimation(start_transform); 35 delegate.SetTransformFromAnimation(start_transform);
36 element->Progress(0.0, &delegate); 36 element->Progress(0.0, &delegate);
37 CheckApproximatelyEqual(start_transform, 37 CheckApproximatelyEqual(start_transform,
38 delegate.GetTransformForAnimation()); 38 delegate.GetTransformForAnimation());
39 element->Progress(0.5, &delegate); 39 element->Progress(0.5, &delegate);
40 CheckApproximatelyEqual(middle_transform, 40 CheckApproximatelyEqual(middle_transform,
41 delegate.GetTransformForAnimation()); 41 delegate.GetTransformForAnimation());
42 element->Progress(1.0, &delegate); 42 element->Progress(1.0, &delegate);
43 CheckApproximatelyEqual(target_transform, 43 CheckApproximatelyEqual(target_transform,
44 delegate.GetTransformForAnimation()); 44 delegate.GetTransformForAnimation());
45 } 45 }
46 46
47 LayerAnimationElement::TargetValue target_value;
48 element->GetTargetValue(&target_value);
49 CheckApproximatelyEqual(target_transform, target_value.transform);
50
51 EXPECT_EQ(delta, element->duration()); 47 EXPECT_EQ(delta, element->duration());
52 } 48 }
53 49
54 // Check that the bounds element progresses the delegate as expected and 50 // Check that the bounds element progresses the delegate as expected and
55 // that the element can be reused after it completes. 51 // that the element can be reused after it completes.
56 TEST(LayerAnimationElementTest, BoundsElement) { 52 TEST(LayerAnimationElementTest, BoundsElement) {
57 DummyLayerAnimationDelegate delegate; 53 TestLayerAnimationDelegate delegate;
58 gfx::Rect start, target, middle; 54 gfx::Rect start, target, middle;
59 start = target = middle = gfx::Rect(0, 0, 50, 50); 55 start = target = middle = gfx::Rect(0, 0, 50, 50);
60 start.set_x(-90); 56 start.set_x(-90);
61 target.set_x(90); 57 target.set_x(90);
62 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 58 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
63 59
64 scoped_ptr<LayerAnimationElement> element( 60 scoped_ptr<LayerAnimationElement> element(
65 LayerAnimationElement::CreateBoundsElement(target, delta)); 61 LayerAnimationElement::CreateBoundsElement(target, delta));
66 62
67 for (int i = 0; i < 2; ++i) { 63 for (int i = 0; i < 2; ++i) {
68 delegate.SetBoundsFromAnimation(start); 64 delegate.SetBoundsFromAnimation(start);
69 element->Progress(0.0, &delegate); 65 element->Progress(0.0, &delegate);
70 CheckApproximatelyEqual(start, delegate.GetBoundsForAnimation()); 66 CheckApproximatelyEqual(start, delegate.GetBoundsForAnimation());
71 element->Progress(0.5, &delegate); 67 element->Progress(0.5, &delegate);
72 CheckApproximatelyEqual(middle, delegate.GetBoundsForAnimation()); 68 CheckApproximatelyEqual(middle, delegate.GetBoundsForAnimation());
73 element->Progress(1.0, &delegate); 69 element->Progress(1.0, &delegate);
74 CheckApproximatelyEqual(target, delegate.GetBoundsForAnimation()); 70 CheckApproximatelyEqual(target, delegate.GetBoundsForAnimation());
75 } 71 }
76 72
77 LayerAnimationElement::TargetValue target_value;
78 element->GetTargetValue(&target_value);
79 CheckApproximatelyEqual(target, target_value.bounds);
80
81 EXPECT_EQ(delta, element->duration()); 73 EXPECT_EQ(delta, element->duration());
82 } 74 }
83 75
84 // Check that the opacity element progresses the delegate as expected and 76 // Check that the opacity element progresses the delegate as expected and
85 // that the element can be reused after it completes. 77 // that the element can be reused after it completes.
86 TEST(LayerAnimationElementTest, OpacityElement) { 78 TEST(LayerAnimationElementTest, OpacityElement) {
87 DummyLayerAnimationDelegate delegate; 79 TestLayerAnimationDelegate delegate;
88 float start = 0.0; 80 float start = 0.0;
89 float middle = 0.5; 81 float middle = 0.5;
90 float target = 1.0; 82 float target = 1.0;
91 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 83 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
92 scoped_ptr<LayerAnimationElement> element( 84 scoped_ptr<LayerAnimationElement> element(
93 LayerAnimationElement::CreateOpacityElement(target, delta)); 85 LayerAnimationElement::CreateOpacityElement(target, delta));
94 86
95 for (int i = 0; i < 2; ++i) { 87 for (int i = 0; i < 2; ++i) {
96 delegate.SetOpacityFromAnimation(start); 88 delegate.SetOpacityFromAnimation(start);
97 element->Progress(0.0, &delegate); 89 element->Progress(0.0, &delegate);
98 EXPECT_FLOAT_EQ(start, delegate.GetOpacityForAnimation()); 90 EXPECT_FLOAT_EQ(start, delegate.GetOpacityForAnimation());
99 element->Progress(0.5, &delegate); 91 element->Progress(0.5, &delegate);
100 EXPECT_FLOAT_EQ(middle, delegate.GetOpacityForAnimation()); 92 EXPECT_FLOAT_EQ(middle, delegate.GetOpacityForAnimation());
101 element->Progress(1.0, &delegate); 93 element->Progress(1.0, &delegate);
102 EXPECT_FLOAT_EQ(target, delegate.GetOpacityForAnimation()); 94 EXPECT_FLOAT_EQ(target, delegate.GetOpacityForAnimation());
103 } 95 }
104 96
105 LayerAnimationElement::TargetValue target_value;
106 element->GetTargetValue(&target_value);
107 EXPECT_FLOAT_EQ(target, target_value.opacity);
108
109 EXPECT_EQ(delta, element->duration()); 97 EXPECT_EQ(delta, element->duration());
110 } 98 }
111 99
112 // Check that the pause element progresses the delegate as expected and 100 // Check that the pause element progresses the delegate as expected and
113 // that the element can be reused after it completes. 101 // that the element can be reused after it completes.
114 TEST(LayerAnimationElementTest, PauseElement) { 102 TEST(LayerAnimationElementTest, PauseElement) {
115 LayerAnimationElement::AnimatableProperties properties; 103 LayerAnimationElement::AnimatableProperties properties;
116 properties.insert(LayerAnimationElement::TRANSFORM); 104 properties.insert(LayerAnimationElement::TRANSFORM);
117 properties.insert(LayerAnimationElement::BOUNDS); 105 properties.insert(LayerAnimationElement::BOUNDS);
118 properties.insert(LayerAnimationElement::OPACITY); 106 properties.insert(LayerAnimationElement::OPACITY);
119 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 107 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
120 108
121 scoped_ptr<LayerAnimationElement> element( 109 scoped_ptr<LayerAnimationElement> element(
122 LayerAnimationElement::CreatePauseElement(properties, delta)); 110 LayerAnimationElement::CreatePauseElement(properties, delta));
123 111
124 DummyLayerAnimationDelegate delegate; 112 TestLayerAnimationDelegate delegate;
125 DummyLayerAnimationDelegate copy = delegate; 113 TestLayerAnimationDelegate copy = delegate;
126 114
127 element->Progress(1.0, &delegate); 115 element->Progress(1.0, &delegate);
128 116
129 // Nothing should have changed. 117 // Nothing should have changed.
130 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), 118 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(),
131 copy.GetBoundsForAnimation()); 119 copy.GetBoundsForAnimation());
132 CheckApproximatelyEqual(delegate.GetTransformForAnimation(), 120 CheckApproximatelyEqual(delegate.GetTransformForAnimation(),
133 copy.GetTransformForAnimation()); 121 copy.GetTransformForAnimation());
134 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 122 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(),
135 copy.GetOpacityForAnimation()); 123 copy.GetOpacityForAnimation());
136 124
137 // Pause should last for |delta|. 125 // Pause should last for |delta|.
138 EXPECT_EQ(delta, element->duration()); 126 EXPECT_EQ(delta, element->duration());
139 } 127 }
140 128
141 } // namespace 129 } // namespace
142 130
143 } // namespace ui 131 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/compositor/layer_animation_element.cc ('k') | ui/gfx/compositor/layer_animation_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698