| 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/ui_element.h" | 5 #include "chrome/browser/android/vr_shell/ui_elements/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" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 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, AnimateSize) { | 46 TEST(UiElements, AnimateSize) { |
| 47 UiElement rect; | 47 UiElement rect; |
| 48 rect.size = {10, 100, 1}; | 48 rect.set_size({10, 100, 1}); |
| 49 std::unique_ptr<Animation> animation( | 49 std::unique_ptr<Animation> animation( |
| 50 new Animation(0, Animation::Property::SIZE, | 50 new Animation(0, Animation::Property::SIZE, |
| 51 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, | 51 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, |
| 52 {20, 200}, usToTicks(50000), usToDelta(10000))); | 52 {20, 200}, 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_VEC3F_EQ(rect.size, gfx::Vector3dF(10, 100, 1)); | 55 EXPECT_VEC3F_EQ(gfx::Vector3dF(10, 100, 1), rect.size()); |
| 56 rect.Animate(usToTicks(60000)); | 56 rect.Animate(usToTicks(60000)); |
| 57 EXPECT_VEC3F_EQ(rect.size, gfx::Vector3dF(20, 200, 1)); | 57 EXPECT_VEC3F_EQ(gfx::Vector3dF(20, 200, 1), rect.size()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 TEST(UiElements, AnimateTranslation) { | 60 TEST(UiElements, AnimateTranslation) { |
| 61 UiElement rect; | 61 UiElement rect; |
| 62 rect.translation = {10, 100, 1000}; | 62 rect.set_translation({10, 100, 1000}); |
| 63 std::unique_ptr<Animation> animation( | 63 std::unique_ptr<Animation> animation( |
| 64 new Animation(0, Animation::Property::TRANSLATION, | 64 new Animation(0, Animation::Property::TRANSLATION, |
| 65 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, | 65 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, |
| 66 {20, 200, 2000}, usToTicks(50000), usToDelta(10000))); | 66 {20, 200, 2000}, 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.translation, gfx::Vector3dF(10, 100, 1000)); | 69 EXPECT_VEC3F_EQ(gfx::Vector3dF(10, 100, 1000), rect.translation()); |
| 70 rect.Animate(usToTicks(60000)); | 70 rect.Animate(usToTicks(60000)); |
| 71 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(20, 200, 2000)); | 71 EXPECT_VEC3F_EQ(gfx::Vector3dF(20, 200, 2000), rect.translation()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 TEST(UiElements, AnimateRotation) { | 74 TEST(UiElements, AnimateRotation) { |
| 75 UiElement rect; | 75 UiElement rect; |
| 76 rect.rotation = {10, 100, 1000, 10000}; | 76 rect.set_rotation({10, 100, 1000, 10000}); |
| 77 std::unique_ptr<Animation> animation(new Animation( | 77 std::unique_ptr<Animation> animation(new Animation( |
| 78 0, Animation::Property::ROTATION, | 78 0, Animation::Property::ROTATION, |
| 79 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, | 79 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, |
| 80 {20, 200, 2000, 20000}, usToTicks(50000), usToDelta(10000))); | 80 {20, 200, 2000, 20000}, 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_ROTATION(rect.rotation, vr::RotationAxisAngle({10, 100, 1000, 10000})); | 83 EXPECT_ROTATION(vr::RotationAxisAngle({10, 100, 1000, 10000}), |
| 84 rect.rotation()); |
| 84 rect.Animate(usToTicks(60000)); | 85 rect.Animate(usToTicks(60000)); |
| 85 EXPECT_ROTATION(rect.rotation, vr::RotationAxisAngle({20, 200, 2000, 20000})); | 86 EXPECT_ROTATION(vr::RotationAxisAngle({20, 200, 2000, 20000}), |
| 87 rect.rotation()); |
| 86 } | 88 } |
| 87 | 89 |
| 88 TEST(UiElements, AnimationHasNoEffectBeforeScheduledStart) { | 90 TEST(UiElements, AnimationHasNoEffectBeforeScheduledStart) { |
| 89 UiElement rect; | 91 UiElement rect; |
| 90 std::unique_ptr<Animation> animation(new Animation( | 92 std::unique_ptr<Animation> animation(new Animation( |
| 91 0, Animation::Property::TRANSLATION, | 93 0, Animation::Property::TRANSLATION, |
| 92 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000}, | 94 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000}, |
| 93 {20, 200, 2000}, usToTicks(50000), usToDelta(10000))); | 95 {20, 200, 2000}, usToTicks(50000), usToDelta(10000))); |
| 94 rect.animations.emplace_back(std::move(animation)); | 96 rect.animations().emplace_back(std::move(animation)); |
| 95 rect.Animate(usToTicks(49999)); | 97 rect.Animate(usToTicks(49999)); |
| 96 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(0, 0, 0)); | 98 EXPECT_VEC3F_EQ(gfx::Vector3dF(0, 0, 0), rect.translation()); |
| 97 } | 99 } |
| 98 | 100 |
| 99 TEST(UiElements, AnimationPurgedWhenDone) { | 101 TEST(UiElements, AnimationPurgedWhenDone) { |
| 100 UiElement rect; | 102 UiElement rect; |
| 101 std::unique_ptr<Animation> animation(new Animation( | 103 std::unique_ptr<Animation> animation(new Animation( |
| 102 0, Animation::Property::TRANSLATION, | 104 0, Animation::Property::TRANSLATION, |
| 103 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000}, | 105 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000}, |
| 104 {20, 200, 2000}, usToTicks(50000), usToDelta(10000))); | 106 {20, 200, 2000}, usToTicks(50000), usToDelta(10000))); |
| 105 rect.animations.emplace_back(std::move(animation)); | 107 rect.animations().emplace_back(std::move(animation)); |
| 106 rect.Animate(usToTicks(60000)); | 108 rect.Animate(usToTicks(60000)); |
| 107 EXPECT_EQ(0u, rect.animations.size()); | 109 EXPECT_EQ(0u, rect.animations().size()); |
| 108 } | 110 } |
| 109 | 111 |
| 110 TEST(UiElements, AnimationLinearEasing) { | 112 TEST(UiElements, AnimationLinearEasing) { |
| 111 UiElement rect; | 113 UiElement rect; |
| 112 std::unique_ptr<Animation> animation(new Animation( | 114 std::unique_ptr<Animation> animation(new Animation( |
| 113 0, Animation::Property::TRANSLATION, | 115 0, Animation::Property::TRANSLATION, |
| 114 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000}, | 116 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000}, |
| 115 {20, 200, 2000}, usToTicks(50000), usToDelta(10000))); | 117 {20, 200, 2000}, usToTicks(50000), usToDelta(10000))); |
| 116 rect.animations.emplace_back(std::move(animation)); | 118 rect.animations().emplace_back(std::move(animation)); |
| 117 rect.Animate(usToTicks(50000)); | 119 rect.Animate(usToTicks(50000)); |
| 118 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(10, 100, 1000)); | 120 EXPECT_VEC3F_EQ(gfx::Vector3dF(10, 100, 1000), rect.translation()); |
| 119 rect.Animate(usToTicks(55000)); | 121 rect.Animate(usToTicks(55000)); |
| 120 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(15, 150, 1500)); | 122 EXPECT_VEC3F_EQ(gfx::Vector3dF(15, 150, 1500), rect.translation()); |
| 121 rect.Animate(usToTicks(60000)); | 123 rect.Animate(usToTicks(60000)); |
| 122 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(20, 200, 2000)); | 124 EXPECT_VEC3F_EQ(gfx::Vector3dF(20, 200, 2000), rect.translation()); |
| 123 } | 125 } |
| 124 | 126 |
| 125 TEST(UiElements, AnimationStartFromSpecifiedLocation) { | 127 TEST(UiElements, AnimationStartFromSpecifiedLocation) { |
| 126 UiElement rect; | 128 UiElement rect; |
| 127 std::unique_ptr<Animation> animation(new Animation( | 129 std::unique_ptr<Animation> animation(new Animation( |
| 128 0, Animation::Property::TRANSLATION, | 130 0, Animation::Property::TRANSLATION, |
| 129 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000}, | 131 std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000}, |
| 130 {20, 200, 2000}, usToTicks(50000), usToDelta(10000))); | 132 {20, 200, 2000}, usToTicks(50000), usToDelta(10000))); |
| 131 rect.animations.emplace_back(std::move(animation)); | 133 rect.animations().emplace_back(std::move(animation)); |
| 132 rect.Animate(usToTicks(50000)); | 134 rect.Animate(usToTicks(50000)); |
| 133 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(10, 100, 1000)); | 135 EXPECT_VEC3F_EQ(gfx::Vector3dF(10, 100, 1000), rect.translation()); |
| 134 rect.Animate(usToTicks(60000)); | 136 rect.Animate(usToTicks(60000)); |
| 135 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(20, 200, 2000)); | 137 EXPECT_VEC3F_EQ(gfx::Vector3dF(20, 200, 2000), rect.translation()); |
| 136 } | 138 } |
| 137 | 139 |
| 138 // 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 |
| 139 // newly added animation overrides the original. For example: | 141 // newly added animation overrides the original. For example: |
| 140 // Animation 1: ? .......... 20 | 142 // Animation 1: ? .......... 20 |
| 141 // Animation 2: ? .......... 50 | 143 // Animation 2: ? .......... 50 |
| 142 // Result: 0 ... 10 ... 30 ... 50 | 144 // Result: 0 ... 10 ... 30 ... 50 |
| 143 TEST(UiElements, AnimationOverlap) { | 145 TEST(UiElements, AnimationOverlap) { |
| 144 UiElement rect; | 146 UiElement rect; |
| 145 std::unique_ptr<Animation> animation( | 147 std::unique_ptr<Animation> animation( |
| 146 new Animation(0, Animation::Property::TRANSLATION, | 148 new Animation(0, Animation::Property::TRANSLATION, |
| 147 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, | 149 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, |
| 148 {20, 200, 2000}, usToTicks(50000), usToDelta(10000))); | 150 {20, 200, 2000}, usToTicks(50000), usToDelta(10000))); |
| 149 std::unique_ptr<Animation> animation2( | 151 std::unique_ptr<Animation> animation2( |
| 150 new Animation(0, Animation::Property::TRANSLATION, | 152 new Animation(0, Animation::Property::TRANSLATION, |
| 151 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, | 153 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, |
| 152 {50, 500, 5000}, usToTicks(55000), usToDelta(10000))); | 154 {50, 500, 5000}, usToTicks(55000), usToDelta(10000))); |
| 153 rect.animations.emplace_back(std::move(animation)); | 155 rect.animations().emplace_back(std::move(animation)); |
| 154 rect.animations.emplace_back(std::move(animation2)); | 156 rect.animations().emplace_back(std::move(animation2)); |
| 155 rect.Animate(usToTicks(55000)); | 157 rect.Animate(usToTicks(55000)); |
| 156 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(10, 100, 1000)); | 158 EXPECT_VEC3F_EQ(gfx::Vector3dF(10, 100, 1000), rect.translation()); |
| 157 rect.Animate(usToTicks(60000)); | 159 rect.Animate(usToTicks(60000)); |
| 158 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(30, 300, 3000)); | 160 EXPECT_VEC3F_EQ(gfx::Vector3dF(30, 300, 3000), rect.translation()); |
| 159 rect.Animate(usToTicks(65000)); | 161 rect.Animate(usToTicks(65000)); |
| 160 EXPECT_VEC3F_EQ(rect.translation, gfx::Vector3dF(50, 500, 5000)); | 162 EXPECT_VEC3F_EQ(gfx::Vector3dF(50, 500, 5000), rect.translation()); |
| 161 } | 163 } |
| 162 | 164 |
| 163 } // namespace vr_shell | 165 } // namespace vr_shell |
| OLD | NEW |