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