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