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

Side by Side Diff: chrome/browser/android/vr_shell/ui_element_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
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_element.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 "device/vr/vr_types.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 #define EXPECT_VEC3F_EQ(a, b) \ 15 #define EXPECT_VEC3F_EQ(a, b) \
(...skipping 21 matching lines...) Expand all
37 return base::TimeTicks::FromInternalValue(us); 37 return base::TimeTicks::FromInternalValue(us);
38 } 38 }
39 39
40 base::TimeDelta usToDelta(uint64_t us) { 40 base::TimeDelta usToDelta(uint64_t us) {
41 return base::TimeDelta::FromInternalValue(us); 41 return base::TimeDelta::FromInternalValue(us);
42 } 42 }
43 43
44 } // namespace 44 } // namespace
45 45
46 TEST(UiElements, AnimateCopyRect) { 46 TEST(UiElements, AnimateCopyRect) {
47 ContentRectangle rect; 47 UiElement rect;
48 rect.copy_rect = {10, 100, 1000, 10000}; 48 rect.copy_rect = {10, 100, 1000, 10000};
49 std::unique_ptr<Animation> animation(new Animation( 49 std::unique_ptr<Animation> animation(new Animation(
50 0, Animation::Property::COPYRECT, 50 0, Animation::Property::COPYRECT,
51 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, 51 std::unique_ptr<easing::Easing>(new easing::Linear()), {},
52 {20, 200, 2000, 20000}, usToTicks(50000), usToDelta(10000))); 52 {20, 200, 2000, 20000}, usToTicks(50000), usToDelta(10000)));
53 rect.animations.emplace_back(std::move(animation)); 53 rect.animations.emplace_back(std::move(animation));
54 rect.Animate(usToTicks(50000)); 54 rect.Animate(usToTicks(50000));
55 EXPECT_RECTF_EQ(rect.copy_rect, gfx::RectF(10, 100, 1000, 10000)); 55 EXPECT_RECTF_EQ(rect.copy_rect, gfx::RectF(10, 100, 1000, 10000));
56 rect.Animate(usToTicks(60000)); 56 rect.Animate(usToTicks(60000));
57 EXPECT_RECTF_EQ(rect.copy_rect, gfx::RectF(20, 200, 2000, 20000)); 57 EXPECT_RECTF_EQ(rect.copy_rect, gfx::RectF(20, 200, 2000, 20000));
58 } 58 }
59 59
60 TEST(UiElements, AnimateSize) { 60 TEST(UiElements, AnimateSize) {
61 ContentRectangle rect; 61 UiElement rect;
62 rect.size = {10, 100, 1}; 62 rect.size = {10, 100, 1};
63 std::unique_ptr<Animation> animation( 63 std::unique_ptr<Animation> animation(
64 new Animation(0, Animation::Property::SIZE, 64 new Animation(0, Animation::Property::SIZE,
65 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, 65 std::unique_ptr<easing::Easing>(new easing::Linear()), {},
66 {20, 200}, usToTicks(50000), usToDelta(10000))); 66 {20, 200}, usToTicks(50000), usToDelta(10000)));
67 rect.animations.emplace_back(std::move(animation)); 67 rect.animations.emplace_back(std::move(animation));
68 rect.Animate(usToTicks(50000)); 68 rect.Animate(usToTicks(50000));
69 EXPECT_VEC3F_EQ(rect.size, gfx::Vector3dF(10, 100, 1)); 69 EXPECT_VEC3F_EQ(rect.size, gfx::Vector3dF(10, 100, 1));
70 rect.Animate(usToTicks(60000)); 70 rect.Animate(usToTicks(60000));
71 EXPECT_VEC3F_EQ(rect.size, gfx::Vector3dF(20, 200, 1)); 71 EXPECT_VEC3F_EQ(rect.size, gfx::Vector3dF(20, 200, 1));
72 } 72 }
73 73
74 TEST(UiElements, AnimateTranslation) { 74 TEST(UiElements, AnimateTranslation) {
75 ContentRectangle rect; 75 UiElement rect;
76 rect.translation = {10, 100, 1000}; 76 rect.translation = {10, 100, 1000};
77 std::unique_ptr<Animation> animation( 77 std::unique_ptr<Animation> animation(
78 new Animation(0, Animation::Property::TRANSLATION, 78 new Animation(0, Animation::Property::TRANSLATION,
79 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, 79 std::unique_ptr<easing::Easing>(new easing::Linear()), {},
80 {20, 200, 2000}, usToTicks(50000), usToDelta(10000))); 80 {20, 200, 2000}, usToTicks(50000), usToDelta(10000)));
81 rect.animations.emplace_back(std::move(animation)); 81 rect.animations.emplace_back(std::move(animation));
82 rect.Animate(usToTicks(50000)); 82 rect.Animate(usToTicks(50000));
83 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(10, 100, 1000)); 83 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(10, 100, 1000));
84 rect.Animate(usToTicks(60000)); 84 rect.Animate(usToTicks(60000));
85 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(20, 200, 2000)); 85 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(20, 200, 2000));
86 } 86 }
87 87
88 TEST(UiElements, AnimateRotation) { 88 TEST(UiElements, AnimateRotation) {
89 ContentRectangle rect; 89 UiElement rect;
90 rect.rotation = {10, 100, 1000, 10000}; 90 rect.rotation = {10, 100, 1000, 10000};
91 std::unique_ptr<Animation> animation(new Animation( 91 std::unique_ptr<Animation> animation(new Animation(
92 0, Animation::Property::ROTATION, 92 0, Animation::Property::ROTATION,
93 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, 93 std::unique_ptr<easing::Easing>(new easing::Linear()), {},
94 {20, 200, 2000, 20000}, usToTicks(50000), usToDelta(10000))); 94 {20, 200, 2000, 20000}, usToTicks(50000), usToDelta(10000)));
95 rect.animations.emplace_back(std::move(animation)); 95 rect.animations.emplace_back(std::move(animation));
96 rect.Animate(usToTicks(50000)); 96 rect.Animate(usToTicks(50000));
97 EXPECT_ROTATION(rect.rotation, vr::RotationAxisAngle({10, 100, 1000, 10000})); 97 EXPECT_ROTATION(rect.rotation, vr::RotationAxisAngle({10, 100, 1000, 10000}));
98 rect.Animate(usToTicks(60000)); 98 rect.Animate(usToTicks(60000));
99 EXPECT_ROTATION(rect.rotation, vr::RotationAxisAngle({20, 200, 2000, 20000})); 99 EXPECT_ROTATION(rect.rotation, vr::RotationAxisAngle({20, 200, 2000, 20000}));
100 } 100 }
101 101
102 TEST(UiElements, AnimationHasNoEffectBeforeScheduledStart) { 102 TEST(UiElements, AnimationHasNoEffectBeforeScheduledStart) {
103 ContentRectangle rect; 103 UiElement rect;
104 std::unique_ptr<Animation> animation(new Animation( 104 std::unique_ptr<Animation> animation(new Animation(
105 0, Animation::Property::TRANSLATION, 105 0, Animation::Property::TRANSLATION,
106 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000}, 106 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000},
107 {20, 200, 2000}, usToTicks(50000), usToDelta(10000))); 107 {20, 200, 2000}, usToTicks(50000), usToDelta(10000)));
108 rect.animations.emplace_back(std::move(animation)); 108 rect.animations.emplace_back(std::move(animation));
109 rect.Animate(usToTicks(49999)); 109 rect.Animate(usToTicks(49999));
110 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(0, 0, 0)); 110 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(0, 0, 0));
111 } 111 }
112 112
113 TEST(UiElements, AnimationPurgedWhenDone) { 113 TEST(UiElements, AnimationPurgedWhenDone) {
114 ContentRectangle rect; 114 UiElement rect;
115 std::unique_ptr<Animation> animation(new Animation( 115 std::unique_ptr<Animation> animation(new Animation(
116 0, Animation::Property::TRANSLATION, 116 0, Animation::Property::TRANSLATION,
117 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000}, 117 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000},
118 {20, 200, 2000}, usToTicks(50000), usToDelta(10000))); 118 {20, 200, 2000}, usToTicks(50000), usToDelta(10000)));
119 rect.animations.emplace_back(std::move(animation)); 119 rect.animations.emplace_back(std::move(animation));
120 rect.Animate(usToTicks(60000)); 120 rect.Animate(usToTicks(60000));
121 EXPECT_EQ(0u, rect.animations.size()); 121 EXPECT_EQ(0u, rect.animations.size());
122 } 122 }
123 123
124 TEST(UiElements, AnimationLinearEasing) { 124 TEST(UiElements, AnimationLinearEasing) {
125 ContentRectangle rect; 125 UiElement rect;
126 std::unique_ptr<Animation> animation(new Animation( 126 std::unique_ptr<Animation> animation(new Animation(
127 0, Animation::Property::TRANSLATION, 127 0, Animation::Property::TRANSLATION,
128 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000}, 128 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000},
129 {20, 200, 2000}, usToTicks(50000), usToDelta(10000))); 129 {20, 200, 2000}, usToTicks(50000), usToDelta(10000)));
130 rect.animations.emplace_back(std::move(animation)); 130 rect.animations.emplace_back(std::move(animation));
131 rect.Animate(usToTicks(50000)); 131 rect.Animate(usToTicks(50000));
132 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(10, 100, 1000)); 132 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(10, 100, 1000));
133 rect.Animate(usToTicks(55000)); 133 rect.Animate(usToTicks(55000));
134 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(15, 150, 1500)); 134 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(15, 150, 1500));
135 rect.Animate(usToTicks(60000)); 135 rect.Animate(usToTicks(60000));
136 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(20, 200, 2000)); 136 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(20, 200, 2000));
137 } 137 }
138 138
139 TEST(UiElements, AnimationStartFromSpecifiedLocation) { 139 TEST(UiElements, AnimationStartFromSpecifiedLocation) {
140 ContentRectangle rect; 140 UiElement rect;
141 std::unique_ptr<Animation> animation(new Animation( 141 std::unique_ptr<Animation> animation(new Animation(
142 0, Animation::Property::TRANSLATION, 142 0, Animation::Property::TRANSLATION,
143 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000}, 143 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000},
144 {20, 200, 2000}, usToTicks(50000), usToDelta(10000))); 144 {20, 200, 2000}, usToTicks(50000), usToDelta(10000)));
145 rect.animations.emplace_back(std::move(animation)); 145 rect.animations.emplace_back(std::move(animation));
146 rect.Animate(usToTicks(50000)); 146 rect.Animate(usToTicks(50000));
147 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(10, 100, 1000)); 147 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(10, 100, 1000));
148 rect.Animate(usToTicks(60000)); 148 rect.Animate(usToTicks(60000));
149 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(20, 200, 2000)); 149 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(20, 200, 2000));
150 } 150 }
151 151
152 // 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
153 // newly added animation overrides the original. For example: 153 // newly added animation overrides the original. For example:
154 // Animation 1: ? .......... 20 154 // Animation 1: ? .......... 20
155 // Animation 2: ? .......... 50 155 // Animation 2: ? .......... 50
156 // Result: 0 ... 10 ... 30 ... 50 156 // Result: 0 ... 10 ... 30 ... 50
157 TEST(UiElements, AnimationOverlap) { 157 TEST(UiElements, AnimationOverlap) {
158 ContentRectangle rect; 158 UiElement rect;
159 std::unique_ptr<Animation> animation( 159 std::unique_ptr<Animation> animation(
160 new Animation(0, Animation::Property::TRANSLATION, 160 new Animation(0, Animation::Property::TRANSLATION,
161 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, 161 std::unique_ptr<easing::Easing>(new easing::Linear()), {},
162 {20, 200, 2000}, usToTicks(50000), usToDelta(10000))); 162 {20, 200, 2000}, usToTicks(50000), usToDelta(10000)));
163 std::unique_ptr<Animation> animation2( 163 std::unique_ptr<Animation> animation2(
164 new Animation(0, Animation::Property::TRANSLATION, 164 new Animation(0, Animation::Property::TRANSLATION,
165 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, 165 std::unique_ptr<easing::Easing>(new easing::Linear()), {},
166 {50, 500, 5000}, usToTicks(55000), usToDelta(10000))); 166 {50, 500, 5000}, usToTicks(55000), usToDelta(10000)));
167 rect.animations.emplace_back(std::move(animation)); 167 rect.animations.emplace_back(std::move(animation));
168 rect.animations.emplace_back(std::move(animation2)); 168 rect.animations.emplace_back(std::move(animation2));
169 rect.Animate(usToTicks(55000)); 169 rect.Animate(usToTicks(55000));
170 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(10, 100, 1000)); 170 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(10, 100, 1000));
171 rect.Animate(usToTicks(60000)); 171 rect.Animate(usToTicks(60000));
172 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(30, 300, 3000)); 172 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(30, 300, 3000));
173 rect.Animate(usToTicks(65000)); 173 rect.Animate(usToTicks(65000));
174 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(50, 500, 5000)); 174 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(50, 500, 5000));
175 } 175 }
176 176
177 } // namespace vr_shell 177 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/ui_element.cc ('k') | chrome/browser/android/vr_shell/ui_elements.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698