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

Side by Side Diff: chrome/browser/android/vr_shell/ui_elements_unittest.cc

Issue 2807293002: VR: Rename ContentRectangle to UiElement (Closed)
Patch Set: Rebase onto Michael's landed GVR types CL. Created 3 years, 8 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
OLDNEW
(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 <utility>
8
9 #include "base/macros.h"
10 #include "chrome/browser/android/vr_shell/animation.h"
11 #include "chrome/browser/android/vr_shell/easing.h"
12 #include "device/vr/vr_types.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 #define EXPECT_VEC3F_EQ(a, b) \
16 EXPECT_FLOAT_EQ(a.x(), b.x()); \
17 EXPECT_FLOAT_EQ(a.y(), b.y()); \
18 EXPECT_FLOAT_EQ(a.z(), b.z());
19
20 #define EXPECT_RECTF_EQ(a, b) \
21 EXPECT_FLOAT_EQ(a.x(), b.x()); \
22 EXPECT_FLOAT_EQ(a.y(), b.y()); \
23 EXPECT_FLOAT_EQ(a.width(), b.width()); \
24 EXPECT_FLOAT_EQ(a.height(), b.height());
25
26 #define EXPECT_ROTATION(a, b) \
27 EXPECT_FLOAT_EQ(a.x, b.x); \
28 EXPECT_FLOAT_EQ(a.y, b.y); \
29 EXPECT_FLOAT_EQ(a.z, b.z); \
30 EXPECT_FLOAT_EQ(a.angle, b.angle);
31
32 namespace vr_shell {
33
34 namespace {
35
36 base::TimeTicks usToTicks(uint64_t us) {
37 return base::TimeTicks::FromInternalValue(us);
38 }
39
40 base::TimeDelta usToDelta(uint64_t us) {
41 return base::TimeDelta::FromInternalValue(us);
42 }
43
44 } // namespace
45
46 TEST(UiElements, AnimateCopyRect) {
47 ContentRectangle rect;
48 rect.copy_rect = {10, 100, 1000, 10000};
49 std::unique_ptr<Animation> animation(new Animation(
50 0, Animation::Property::COPYRECT,
51 std::unique_ptr<easing::Easing>(new easing::Linear()), {},
52 {20, 200, 2000, 20000}, usToTicks(50000), usToDelta(10000)));
53 rect.animations.emplace_back(std::move(animation));
54 rect.Animate(usToTicks(50000));
55 EXPECT_RECTF_EQ(rect.copy_rect, gfx::RectF(10, 100, 1000, 10000));
56 rect.Animate(usToTicks(60000));
57 EXPECT_RECTF_EQ(rect.copy_rect, gfx::RectF(20, 200, 2000, 20000));
58 }
59
60 TEST(UiElements, AnimateSize) {
61 ContentRectangle rect;
62 rect.size = {10, 100, 1};
63 std::unique_ptr<Animation> animation(
64 new Animation(0, Animation::Property::SIZE,
65 std::unique_ptr<easing::Easing>(new easing::Linear()), {},
66 {20, 200}, usToTicks(50000), usToDelta(10000)));
67 rect.animations.emplace_back(std::move(animation));
68 rect.Animate(usToTicks(50000));
69 EXPECT_VEC3F_EQ(rect.size, gfx::Vector3dF(10, 100, 1));
70 rect.Animate(usToTicks(60000));
71 EXPECT_VEC3F_EQ(rect.size, gfx::Vector3dF(20, 200, 1));
72 }
73
74 TEST(UiElements, AnimateTranslation) {
75 ContentRectangle rect;
76 rect.translation = {10, 100, 1000};
77 std::unique_ptr<Animation> animation(
78 new Animation(0, Animation::Property::TRANSLATION,
79 std::unique_ptr<easing::Easing>(new easing::Linear()), {},
80 {20, 200, 2000}, usToTicks(50000), usToDelta(10000)));
81 rect.animations.emplace_back(std::move(animation));
82 rect.Animate(usToTicks(50000));
83 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(10, 100, 1000));
84 rect.Animate(usToTicks(60000));
85 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(20, 200, 2000));
86 }
87
88 TEST(UiElements, AnimateRotation) {
89 ContentRectangle rect;
90 rect.rotation = {10, 100, 1000, 10000};
91 std::unique_ptr<Animation> animation(new Animation(
92 0, Animation::Property::ROTATION,
93 std::unique_ptr<easing::Easing>(new easing::Linear()), {},
94 {20, 200, 2000, 20000}, usToTicks(50000), usToDelta(10000)));
95 rect.animations.emplace_back(std::move(animation));
96 rect.Animate(usToTicks(50000));
97 EXPECT_ROTATION(rect.rotation, vr::RotationAxisAngle({10, 100, 1000, 10000}));
98 rect.Animate(usToTicks(60000));
99 EXPECT_ROTATION(rect.rotation, vr::RotationAxisAngle({20, 200, 2000, 20000}));
100 }
101
102 TEST(UiElements, AnimationHasNoEffectBeforeScheduledStart) {
103 ContentRectangle rect;
104 std::unique_ptr<Animation> animation(new Animation(
105 0, Animation::Property::TRANSLATION,
106 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000},
107 {20, 200, 2000}, usToTicks(50000), usToDelta(10000)));
108 rect.animations.emplace_back(std::move(animation));
109 rect.Animate(usToTicks(49999));
110 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(0, 0, 0));
111 }
112
113 TEST(UiElements, AnimationPurgedWhenDone) {
114 ContentRectangle rect;
115 std::unique_ptr<Animation> animation(new Animation(
116 0, Animation::Property::TRANSLATION,
117 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000},
118 {20, 200, 2000}, usToTicks(50000), usToDelta(10000)));
119 rect.animations.emplace_back(std::move(animation));
120 rect.Animate(usToTicks(60000));
121 EXPECT_EQ(0u, rect.animations.size());
122 }
123
124 TEST(UiElements, AnimationLinearEasing) {
125 ContentRectangle rect;
126 std::unique_ptr<Animation> animation(new Animation(
127 0, Animation::Property::TRANSLATION,
128 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000},
129 {20, 200, 2000}, usToTicks(50000), usToDelta(10000)));
130 rect.animations.emplace_back(std::move(animation));
131 rect.Animate(usToTicks(50000));
132 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(10, 100, 1000));
133 rect.Animate(usToTicks(55000));
134 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(15, 150, 1500));
135 rect.Animate(usToTicks(60000));
136 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(20, 200, 2000));
137 }
138
139 TEST(UiElements, AnimationStartFromSpecifiedLocation) {
140 ContentRectangle rect;
141 std::unique_ptr<Animation> animation(new Animation(
142 0, Animation::Property::TRANSLATION,
143 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000},
144 {20, 200, 2000}, usToTicks(50000), usToDelta(10000)));
145 rect.animations.emplace_back(std::move(animation));
146 rect.Animate(usToTicks(50000));
147 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(10, 100, 1000));
148 rect.Animate(usToTicks(60000));
149 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(20, 200, 2000));
150 }
151
152 // Ensure that when a new animation overlaps another of the same type, the
153 // newly added animation overrides the original. For example:
154 // Animation 1: ? .......... 20
155 // Animation 2: ? .......... 50
156 // Result: 0 ... 10 ... 30 ... 50
157 TEST(UiElements, AnimationOverlap) {
158 ContentRectangle rect;
159 std::unique_ptr<Animation> animation(
160 new Animation(0, Animation::Property::TRANSLATION,
161 std::unique_ptr<easing::Easing>(new easing::Linear()), {},
162 {20, 200, 2000}, usToTicks(50000), usToDelta(10000)));
163 std::unique_ptr<Animation> animation2(
164 new Animation(0, Animation::Property::TRANSLATION,
165 std::unique_ptr<easing::Easing>(new easing::Linear()), {},
166 {50, 500, 5000}, usToTicks(55000), usToDelta(10000)));
167 rect.animations.emplace_back(std::move(animation));
168 rect.animations.emplace_back(std::move(animation2));
169 rect.Animate(usToTicks(55000));
170 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(10, 100, 1000));
171 rect.Animate(usToTicks(60000));
172 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(30, 300, 3000));
173 rect.Animate(usToTicks(65000));
174 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(50, 500, 5000));
175 }
176
177 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/ui_elements.cc ('k') | chrome/browser/android/vr_shell/ui_scene.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698