OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016 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 "chrome/browser/android/vr_shell/ui_elements.h" | |
6 | |
7 #include "base/macros.h" | |
8 #include "base/strings/stringprintf.h" | |
9 #include "chrome/browser/android/vr_shell/animation.h" | |
10 #include "chrome/browser/android/vr_shell/easing.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 #define EXPECT_VEC3F_EQ(a, b) \ | |
14 EXPECT_FLOAT_EQ(a.x, b.x); \ | |
15 EXPECT_FLOAT_EQ(a.y, b.y); \ | |
16 EXPECT_FLOAT_EQ(a.z, b.z); | |
17 | |
18 #define EXPECT_RECTF_EQ(a, b) \ | |
19 EXPECT_FLOAT_EQ(a.x, b.x); \ | |
20 EXPECT_FLOAT_EQ(a.y, b.y); \ | |
21 EXPECT_FLOAT_EQ(a.width, b.width); \ | |
22 EXPECT_FLOAT_EQ(a.height, b.height); | |
23 | |
24 #define EXPECT_VECTOR_FLOAT_4_EQ(a, b) \ | |
25 EXPECT_EQ(a.size(), 4u); \ | |
26 EXPECT_EQ(b.size(), 4u); \ | |
27 EXPECT_FLOAT_EQ(a[0], b[0]); \ | |
28 EXPECT_FLOAT_EQ(a[1], b[1]); \ | |
29 EXPECT_FLOAT_EQ(a[2], b[2]); \ | |
30 EXPECT_FLOAT_EQ(a[3], b[3]); | |
31 | |
32 namespace vr_shell { | |
33 | |
34 TEST(Animation, copy_rect) { | |
bshe
2016/09/12 15:38:26
nit: s/copy_rect/CopyRect
bshe
2016/09/12 15:38:27
Rename "Animation" to "UiElements" since this is u
cjgrant
2016/09/13 17:32:16
Done.
cjgrant
2016/09/13 17:32:16
Done.
| |
35 ContentRectangle rect; | |
36 rect.copy_rect = {10, 100, 1000, 10000}; | |
37 std::unique_ptr<Animation> animation(new Animation( | |
38 0, Animation::Property::COPYRECT, | |
39 std::unique_ptr<Easing>(new easing::Linear()), | |
bshe
2016/09/12 15:38:26
perhaps add test for other type of easing too?
cjgrant
2016/09/13 17:32:16
To exercise easing more extensively, I'd prefer a
bshe
2016/09/13 19:37:22
Separate change sounds good.
| |
40 {}, {20, 200, 2000, 20000}, 50000, 10000)); | |
41 rect.animations.emplace_back(std::move(animation)); | |
42 rect.Animate(50000); | |
43 EXPECT_RECTF_EQ(rect.copy_rect, Rectf({10, 100, 1000, 10000})); | |
44 rect.Animate(60000); | |
45 EXPECT_RECTF_EQ(rect.copy_rect, Rectf({20, 200, 2000, 20000})); | |
46 } | |
47 | |
48 TEST(Animation, Size) { | |
49 ContentRectangle rect; | |
50 rect.size = {10, 100, 1000}; | |
51 std::unique_ptr<Animation> animation(new Animation( | |
52 0, Animation::Property::SIZE, | |
53 std::unique_ptr<Easing>(new easing::Linear()), | |
54 {}, {20, 200, 2000}, 50000, 10000)); | |
55 rect.animations.emplace_back(std::move(animation)); | |
56 rect.Animate(50000); | |
57 EXPECT_VEC3F_EQ(rect.size, gvr::Vec3f({10, 100, 1000})); | |
58 rect.Animate(60000); | |
59 EXPECT_VEC3F_EQ(rect.size, gvr::Vec3f({20, 200, 2000})); | |
60 } | |
61 | |
62 TEST(Animation, Translation) { | |
63 ContentRectangle rect; | |
64 rect.translation = {10, 100, 1000}; | |
65 std::unique_ptr<Animation> animation(new Animation( | |
66 0, Animation::Property::TRANSLATION, | |
67 std::unique_ptr<Easing>(new easing::Linear()), | |
68 {}, {20, 200, 2000}, 50000, 10000)); | |
69 rect.animations.emplace_back(std::move(animation)); | |
70 rect.Animate(50000); | |
71 EXPECT_VEC3F_EQ(rect.translation, gvr::Vec3f({10, 100, 1000})); | |
72 rect.Animate(60000); | |
73 EXPECT_VEC3F_EQ(rect.translation, gvr::Vec3f({20, 200, 2000})); | |
74 } | |
75 | |
76 TEST(Animation, Rotation) { | |
77 ContentRectangle rect; | |
78 rect.rotation_axis_angle = {10, 100, 1000, 10000}; | |
79 std::unique_ptr<Animation> animation(new Animation( | |
80 0, Animation::Property::ROTATION, | |
81 std::unique_ptr<Easing>(new easing::Linear()), | |
82 {}, {20, 200, 2000, 20000}, 50000, 10000)); | |
83 rect.animations.emplace_back(std::move(animation)); | |
84 rect.Animate(50000); | |
85 EXPECT_VECTOR_FLOAT_4_EQ(rect.rotation_axis_angle, | |
86 std::vector<float>({10, 100, 1000, 10000})); | |
87 rect.Animate(60000); | |
88 EXPECT_VECTOR_FLOAT_4_EQ(rect.rotation_axis_angle, | |
89 std::vector<float>({20, 200, 2000, 20000})); | |
90 } | |
91 | |
92 TEST(Animation, NoEffectBeforeScheduledStart) { | |
93 ContentRectangle rect; | |
94 std::unique_ptr<Animation> animation(new Animation( | |
95 0, Animation::Property::TRANSLATION, | |
96 std::unique_ptr<Easing>(new easing::Linear()), | |
97 {10, 100, 1000}, {20, 200, 2000}, 50000, 10000)); | |
98 rect.animations.emplace_back(std::move(animation)); | |
99 rect.Animate(49999); | |
100 EXPECT_VEC3F_EQ(rect.translation, gvr::Vec3f({0, 0, 0})); | |
101 } | |
102 | |
103 TEST(Animation, PurgedWhenDone) { | |
104 ContentRectangle rect; | |
105 std::unique_ptr<Animation> animation(new Animation( | |
106 0, Animation::Property::TRANSLATION, | |
107 std::unique_ptr<Easing>(new easing::Linear()), | |
108 {10, 100, 1000}, {20, 200, 2000}, 50000, 10000)); | |
109 rect.animations.emplace_back(std::move(animation)); | |
110 rect.Animate(60000); | |
111 EXPECT_EQ(0u, rect.animations.size()); | |
112 } | |
113 | |
114 TEST(Animation, LinearEasing) { | |
115 ContentRectangle rect; | |
116 std::unique_ptr<Animation> animation(new Animation( | |
117 0, Animation::Property::TRANSLATION, | |
118 std::unique_ptr<Easing>(new easing::Linear()), | |
119 {10, 100, 1000}, {20, 200, 2000}, 50000, 10000)); | |
120 rect.animations.emplace_back(std::move(animation)); | |
121 rect.Animate(50000); | |
122 EXPECT_VEC3F_EQ(rect.translation, gvr::Vec3f({10, 100, 1000})); | |
123 rect.Animate(55000); | |
124 EXPECT_VEC3F_EQ(rect.translation, gvr::Vec3f({15, 150, 1500})); | |
125 rect.Animate(60000); | |
126 EXPECT_VEC3F_EQ(rect.translation, gvr::Vec3f({20, 200, 2000})); | |
127 } | |
128 | |
129 TEST(Animation, StartFromSpecifiedLocation) { | |
130 ContentRectangle rect; | |
131 std::unique_ptr<Animation> animation(new Animation( | |
132 0, Animation::Property::TRANSLATION, | |
133 std::unique_ptr<Easing>(new easing::Linear()), | |
134 {10, 100, 1000}, {20, 200, 2000}, 50000, 10000)); | |
135 rect.animations.emplace_back(std::move(animation)); | |
136 rect.Animate(50000); | |
137 EXPECT_VEC3F_EQ(rect.translation, gvr::Vec3f({10, 100, 1000})); | |
138 rect.Animate(60000); | |
139 EXPECT_VEC3F_EQ(rect.translation, gvr::Vec3f({20, 200, 2000})); | |
140 } | |
141 | |
142 // Ensure that when a new animation overlaps another of the same type, the | |
143 // newly added animation overrides the original. For example: | |
144 // Animation 1: ? .......... 20 | |
145 // Animation 2: ? .......... 50 | |
146 // Result: 0 ... 10 ... 30 ... 50 | |
147 TEST(Animation, Overlap) { | |
148 ContentRectangle rect; | |
149 std::unique_ptr<Animation> animation(new Animation( | |
150 0, Animation::Property::TRANSLATION, | |
151 std::unique_ptr<Easing>(new easing::Linear()), | |
152 {}, {20, 200, 2000}, 50000, 10000)); | |
153 std::unique_ptr<Animation> animation2(new Animation( | |
154 0, Animation::Property::TRANSLATION, | |
155 std::unique_ptr<Easing>(new easing::Linear()), | |
156 {}, {50, 500, 5000}, 55000, 10000)); | |
157 rect.animations.emplace_back(std::move(animation)); | |
158 rect.animations.emplace_back(std::move(animation2)); | |
159 rect.Animate(55000); | |
160 EXPECT_VEC3F_EQ(rect.translation, gvr::Vec3f({10, 100, 1000})); | |
161 rect.Animate(60000); | |
162 EXPECT_VEC3F_EQ(rect.translation, gvr::Vec3f({30, 300, 3000})); | |
163 rect.Animate(65000); | |
164 EXPECT_VEC3F_EQ(rect.translation, gvr::Vec3f({50, 500, 5000})); | |
165 } | |
166 | |
167 } // namespace vr_shell | |
OLD | NEW |