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