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

Side by Side Diff: cc/animation/scroll_offset_animation_curve_unittest.cc

Issue 584503005: Make scroll offset type of float in cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: link crbug to TODO Created 6 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
« no previous file with comments | « cc/animation/scroll_offset_animation_curve.cc ('k') | cc/base/math_util.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "cc/animation/scroll_offset_animation_curve.h" 5 #include "cc/animation/scroll_offset_animation_curve.h"
6 6
7 #include "cc/animation/timing_function.h" 7 #include "cc/animation/timing_function.h"
8 #include "cc/test/geometry_test_utils.h" 8 #include "cc/test/geometry_test_utils.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace cc { 11 namespace cc {
12 namespace { 12 namespace {
13 13
14 TEST(ScrollOffsetAnimationCurveTest, Duration) { 14 TEST(ScrollOffsetAnimationCurveTest, Duration) {
15 gfx::Vector2dF target_value(100.f, 200.f); 15 gfx::ScrollOffset target_value(100.f, 200.f);
16 scoped_ptr<ScrollOffsetAnimationCurve> curve( 16 scoped_ptr<ScrollOffsetAnimationCurve> curve(
17 ScrollOffsetAnimationCurve::Create( 17 ScrollOffsetAnimationCurve::Create(
18 target_value, 18 target_value,
19 EaseInOutTimingFunction::Create().Pass())); 19 EaseInOutTimingFunction::Create().Pass()));
20 20
21 curve->SetInitialValue(target_value); 21 curve->SetInitialValue(target_value);
22 EXPECT_DOUBLE_EQ(0.0, curve->Duration()); 22 EXPECT_DOUBLE_EQ(0.0, curve->Duration());
23 23
24 // x decreases, y stays the same. 24 // x decreases, y stays the same.
25 curve->SetInitialValue(gfx::Vector2dF(136.f, 200.f)); 25 curve->SetInitialValue(gfx::ScrollOffset(136.f, 200.f));
26 EXPECT_DOUBLE_EQ(0.1, curve->Duration()); 26 EXPECT_DOUBLE_EQ(0.1, curve->Duration());
27 27
28 // x increases, y stays the same. 28 // x increases, y stays the same.
29 curve->SetInitialValue(gfx::Vector2dF(19.f, 200.f)); 29 curve->SetInitialValue(gfx::ScrollOffset(19.f, 200.f));
30 EXPECT_DOUBLE_EQ(0.15, curve->Duration()); 30 EXPECT_DOUBLE_EQ(0.15, curve->Duration());
31 31
32 // x stays the same, y decreases. 32 // x stays the same, y decreases.
33 curve->SetInitialValue(gfx::Vector2dF(100.f, 344.f)); 33 curve->SetInitialValue(gfx::ScrollOffset(100.f, 344.f));
34 EXPECT_DOUBLE_EQ(0.2, curve->Duration()); 34 EXPECT_DOUBLE_EQ(0.2, curve->Duration());
35 35
36 // x stays the same, y increases. 36 // x stays the same, y increases.
37 curve->SetInitialValue(gfx::Vector2dF(100.f, 191.f)); 37 curve->SetInitialValue(gfx::ScrollOffset(100.f, 191.f));
38 EXPECT_DOUBLE_EQ(0.05, curve->Duration()); 38 EXPECT_DOUBLE_EQ(0.05, curve->Duration());
39 39
40 // x decreases, y decreases. 40 // x decreases, y decreases.
41 curve->SetInitialValue(gfx::Vector2dF(32500.f, 500.f)); 41 curve->SetInitialValue(gfx::ScrollOffset(32500.f, 500.f));
42 EXPECT_DOUBLE_EQ(3.0, curve->Duration()); 42 EXPECT_DOUBLE_EQ(3.0, curve->Duration());
43 43
44 // x decreases, y increases. 44 // x decreases, y increases.
45 curve->SetInitialValue(gfx::Vector2dF(150.f, 119.f)); 45 curve->SetInitialValue(gfx::ScrollOffset(150.f, 119.f));
46 EXPECT_DOUBLE_EQ(0.15, curve->Duration()); 46 EXPECT_DOUBLE_EQ(0.15, curve->Duration());
47 47
48 // x increases, y decreases. 48 // x increases, y decreases.
49 curve->SetInitialValue(gfx::Vector2dF(0.f, 14600.f)); 49 curve->SetInitialValue(gfx::ScrollOffset(0.f, 14600.f));
50 EXPECT_DOUBLE_EQ(2.0, curve->Duration()); 50 EXPECT_DOUBLE_EQ(2.0, curve->Duration());
51 51
52 // x increases, y increases. 52 // x increases, y increases.
53 curve->SetInitialValue(gfx::Vector2dF(95.f, 191.f)); 53 curve->SetInitialValue(gfx::ScrollOffset(95.f, 191.f));
54 EXPECT_DOUBLE_EQ(0.05, curve->Duration()); 54 EXPECT_DOUBLE_EQ(0.05, curve->Duration());
55 } 55 }
56 56
57 TEST(ScrollOffsetAnimationCurveTest, GetValue) { 57 TEST(ScrollOffsetAnimationCurveTest, GetValue) {
58 gfx::Vector2dF initial_value(2.f, 40.f); 58 gfx::ScrollOffset initial_value(2.f, 40.f);
59 gfx::Vector2dF target_value(10.f, 20.f); 59 gfx::ScrollOffset target_value(10.f, 20.f);
60 scoped_ptr<ScrollOffsetAnimationCurve> curve( 60 scoped_ptr<ScrollOffsetAnimationCurve> curve(
61 ScrollOffsetAnimationCurve::Create( 61 ScrollOffsetAnimationCurve::Create(
62 target_value, 62 target_value,
63 EaseInOutTimingFunction::Create().Pass())); 63 EaseInOutTimingFunction::Create().Pass()));
64 curve->SetInitialValue(initial_value); 64 curve->SetInitialValue(initial_value);
65 65
66 double duration = curve->Duration(); 66 double duration = curve->Duration();
67 EXPECT_GT(curve->Duration(), 0); 67 EXPECT_GT(curve->Duration(), 0);
68 EXPECT_LT(curve->Duration(), 0.1); 68 EXPECT_LT(curve->Duration(), 0.1);
69 69
70 EXPECT_EQ(AnimationCurve::ScrollOffset, curve->Type()); 70 EXPECT_EQ(AnimationCurve::ScrollOffset, curve->Type());
71 EXPECT_EQ(duration, curve->Duration()); 71 EXPECT_EQ(duration, curve->Duration());
72 72
73 EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(-1.0)); 73 EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(-1.0));
74 EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(0.0)); 74 EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(0.0));
75 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(6.f, 30.f), curve->GetValue(duration/2.0)); 75 EXPECT_VECTOR2DF_EQ(gfx::ScrollOffset(6.f, 30.f),
76 curve->GetValue(duration/2.0));
76 EXPECT_VECTOR2DF_EQ(target_value, curve->GetValue(duration)); 77 EXPECT_VECTOR2DF_EQ(target_value, curve->GetValue(duration));
77 EXPECT_VECTOR2DF_EQ(target_value, curve->GetValue(duration+1.0)); 78 EXPECT_VECTOR2DF_EQ(target_value, curve->GetValue(duration+1.0));
78 79
79 // Verify that GetValue takes the timing function into account. 80 // Verify that GetValue takes the timing function into account.
80 gfx::Vector2dF value = curve->GetValue(duration/4.0); 81 gfx::ScrollOffset value = curve->GetValue(duration/4.0);
81 EXPECT_NEAR(3.0333f, value.x(), 0.00015f); 82 EXPECT_NEAR(3.0333f, value.x(), 0.00015f);
82 EXPECT_NEAR(37.4168f, value.y(), 0.00015f); 83 EXPECT_NEAR(37.4168f, value.y(), 0.00015f);
83 } 84 }
84 85
85 // Verify that a clone behaves exactly like the original. 86 // Verify that a clone behaves exactly like the original.
86 TEST(ScrollOffsetAnimationCurveTest, Clone) { 87 TEST(ScrollOffsetAnimationCurveTest, Clone) {
87 gfx::Vector2dF initial_value(2.f, 40.f); 88 gfx::ScrollOffset initial_value(2.f, 40.f);
88 gfx::Vector2dF target_value(10.f, 20.f); 89 gfx::ScrollOffset target_value(10.f, 20.f);
89 scoped_ptr<ScrollOffsetAnimationCurve> curve( 90 scoped_ptr<ScrollOffsetAnimationCurve> curve(
90 ScrollOffsetAnimationCurve::Create( 91 ScrollOffsetAnimationCurve::Create(
91 target_value, 92 target_value,
92 EaseInOutTimingFunction::Create().Pass())); 93 EaseInOutTimingFunction::Create().Pass()));
93 curve->SetInitialValue(initial_value); 94 curve->SetInitialValue(initial_value);
94 double duration = curve->Duration(); 95 double duration = curve->Duration();
95 96
96 scoped_ptr<AnimationCurve> clone(curve->Clone().Pass()); 97 scoped_ptr<AnimationCurve> clone(curve->Clone().Pass());
97 98
98 EXPECT_EQ(AnimationCurve::ScrollOffset, clone->Type()); 99 EXPECT_EQ(AnimationCurve::ScrollOffset, clone->Type());
99 EXPECT_EQ(duration, clone->Duration()); 100 EXPECT_EQ(duration, clone->Duration());
100 101
101 EXPECT_VECTOR2DF_EQ(initial_value, 102 EXPECT_VECTOR2DF_EQ(initial_value,
102 clone->ToScrollOffsetAnimationCurve()->GetValue(-1.0)); 103 clone->ToScrollOffsetAnimationCurve()->GetValue(-1.0));
103 EXPECT_VECTOR2DF_EQ(initial_value, 104 EXPECT_VECTOR2DF_EQ(initial_value,
104 clone->ToScrollOffsetAnimationCurve()->GetValue(0.0)); 105 clone->ToScrollOffsetAnimationCurve()->GetValue(0.0));
105 EXPECT_VECTOR2DF_EQ( 106 EXPECT_VECTOR2DF_EQ(
106 gfx::Vector2dF(6.f, 30.f), 107 gfx::ScrollOffset(6.f, 30.f),
107 clone->ToScrollOffsetAnimationCurve()->GetValue(duration / 2.0)); 108 clone->ToScrollOffsetAnimationCurve()->GetValue(duration / 2.0));
108 EXPECT_VECTOR2DF_EQ( 109 EXPECT_VECTOR2DF_EQ(
109 target_value, 110 target_value,
110 clone->ToScrollOffsetAnimationCurve()->GetValue(duration)); 111 clone->ToScrollOffsetAnimationCurve()->GetValue(duration));
111 EXPECT_VECTOR2DF_EQ( 112 EXPECT_VECTOR2DF_EQ(
112 target_value, 113 target_value,
113 clone->ToScrollOffsetAnimationCurve()->GetValue(duration + 1.0)); 114 clone->ToScrollOffsetAnimationCurve()->GetValue(duration + 1.0));
114 115
115 // Verify that the timing function was cloned correctly. 116 // Verify that the timing function was cloned correctly.
116 gfx::Vector2dF value = 117 gfx::ScrollOffset value =
117 clone->ToScrollOffsetAnimationCurve()->GetValue(duration / 4.0); 118 clone->ToScrollOffsetAnimationCurve()->GetValue(duration / 4.0);
118 EXPECT_NEAR(3.0333f, value.x(), 0.00015f); 119 EXPECT_NEAR(3.0333f, value.x(), 0.00015f);
119 EXPECT_NEAR(37.4168f, value.y(), 0.00015f); 120 EXPECT_NEAR(37.4168f, value.y(), 0.00015f);
120 } 121 }
121 122
122 TEST(ScrollOffsetAnimationCurveTest, UpdateTarget) { 123 TEST(ScrollOffsetAnimationCurveTest, UpdateTarget) {
123 gfx::Vector2dF initial_value(0.f, 0.f); 124 gfx::ScrollOffset initial_value(0.f, 0.f);
124 gfx::Vector2dF target_value(0.f, 3600.f); 125 gfx::ScrollOffset target_value(0.f, 3600.f);
125 scoped_ptr<ScrollOffsetAnimationCurve> curve( 126 scoped_ptr<ScrollOffsetAnimationCurve> curve(
126 ScrollOffsetAnimationCurve::Create( 127 ScrollOffsetAnimationCurve::Create(
127 target_value, EaseInOutTimingFunction::Create().Pass())); 128 target_value, EaseInOutTimingFunction::Create().Pass()));
128 curve->SetInitialValue(initial_value); 129 curve->SetInitialValue(initial_value);
129 EXPECT_EQ(1.0, curve->Duration()); 130 EXPECT_EQ(1.0, curve->Duration());
130 EXPECT_EQ(1800.0, curve->GetValue(0.5).y()); 131 EXPECT_EQ(1800.0, curve->GetValue(0.5).y());
131 EXPECT_EQ(3600.0, curve->GetValue(1.0).y()); 132 EXPECT_EQ(3600.0, curve->GetValue(1.0).y());
132 133
133 curve->UpdateTarget(0.5, gfx::Vector2dF(0.0, 9900.0)); 134 curve->UpdateTarget(0.5, gfx::ScrollOffset(0.0, 9900.0));
134 135
135 EXPECT_EQ(2.0, curve->Duration()); 136 EXPECT_EQ(2.0, curve->Duration());
136 EXPECT_EQ(1800.0, curve->GetValue(0.5).y()); 137 EXPECT_EQ(1800.0, curve->GetValue(0.5).y());
137 EXPECT_NEAR(5566.49, curve->GetValue(1.0).y(), 0.01); 138 EXPECT_NEAR(5566.49, curve->GetValue(1.0).y(), 0.01);
138 EXPECT_EQ(9900.0, curve->GetValue(2.0).y()); 139 EXPECT_EQ(9900.0, curve->GetValue(2.0).y());
139 140
140 curve->UpdateTarget(1.0, gfx::Vector2dF(0.0, 7200.0)); 141 curve->UpdateTarget(1.0, gfx::ScrollOffset(0.0, 7200.0));
141 142
142 EXPECT_NEAR(1.674, curve->Duration(), 0.01); 143 EXPECT_NEAR(1.674, curve->Duration(), 0.01);
143 EXPECT_NEAR(5566.49, curve->GetValue(1.0).y(), 0.01); 144 EXPECT_NEAR(5566.49, curve->GetValue(1.0).y(), 0.01);
144 EXPECT_EQ(7200.0, curve->GetValue(1.674).y()); 145 EXPECT_EQ(7200.0, curve->GetValue(1.674).y());
145 } 146 }
146 147
147 } // namespace 148 } // namespace
148 } // namespace cc 149 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/scroll_offset_animation_curve.cc ('k') | cc/base/math_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698