| 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 28 matching lines...) Expand all Loading... |
| 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.set_size({10, 100, 1}); | 48 rect.set_size({10, 100, 1}); |
| 49 std::unique_ptr<Animation> animation( | 49 std::unique_ptr<Animation> animation(new Animation( |
| 50 new Animation(0, Animation::Property::SIZE, | 50 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 std::vector<float>(), {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(gfx::Vector3dF(10, 100, 1), rect.size()); | 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(gfx::Vector3dF(20, 200, 1), rect.size()); | 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.set_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 std::vector<float>(), {20, 200, 2000}, usToTicks(50000), |
| 67 usToDelta(10000))); |
| 67 rect.animations().emplace_back(std::move(animation)); | 68 rect.animations().emplace_back(std::move(animation)); |
| 68 rect.Animate(usToTicks(50000)); | 69 rect.Animate(usToTicks(50000)); |
| 69 EXPECT_VEC3F_EQ(gfx::Vector3dF(10, 100, 1000), rect.translation()); | 70 EXPECT_VEC3F_EQ(gfx::Vector3dF(10, 100, 1000), rect.translation()); |
| 70 rect.Animate(usToTicks(60000)); | 71 rect.Animate(usToTicks(60000)); |
| 71 EXPECT_VEC3F_EQ(gfx::Vector3dF(20, 200, 2000), rect.translation()); | 72 EXPECT_VEC3F_EQ(gfx::Vector3dF(20, 200, 2000), rect.translation()); |
| 72 } | 73 } |
| 73 | 74 |
| 74 TEST(UiElements, AnimateRotation) { | 75 TEST(UiElements, AnimateRotation) { |
| 75 UiElement rect; | 76 UiElement rect; |
| 76 rect.set_rotation({10, 100, 1000, 10000}); | 77 rect.set_rotation({10, 100, 1000, 10000}); |
| 77 std::unique_ptr<Animation> animation(new Animation( | 78 std::unique_ptr<Animation> animation( |
| 78 0, Animation::Property::ROTATION, | 79 new Animation(0, Animation::Property::ROTATION, |
| 79 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, | 80 std::unique_ptr<easing::Easing>(new easing::Linear()), |
| 80 {20, 200, 2000, 20000}, usToTicks(50000), usToDelta(10000))); | 81 std::vector<float>(), {20, 200, 2000, 20000}, |
| 82 usToTicks(50000), usToDelta(10000))); |
| 81 rect.animations().emplace_back(std::move(animation)); | 83 rect.animations().emplace_back(std::move(animation)); |
| 82 rect.Animate(usToTicks(50000)); | 84 rect.Animate(usToTicks(50000)); |
| 83 EXPECT_ROTATION(vr::RotationAxisAngle({10, 100, 1000, 10000}), | 85 EXPECT_ROTATION(vr::RotationAxisAngle({10, 100, 1000, 10000}), |
| 84 rect.rotation()); | 86 rect.rotation()); |
| 85 rect.Animate(usToTicks(60000)); | 87 rect.Animate(usToTicks(60000)); |
| 86 EXPECT_ROTATION(vr::RotationAxisAngle({20, 200, 2000, 20000}), | 88 EXPECT_ROTATION(vr::RotationAxisAngle({20, 200, 2000, 20000}), |
| 87 rect.rotation()); | 89 rect.rotation()); |
| 88 } | 90 } |
| 89 | 91 |
| 90 TEST(UiElements, AnimationHasNoEffectBeforeScheduledStart) { | 92 TEST(UiElements, AnimationHasNoEffectBeforeScheduledStart) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 141 |
| 140 // Ensure that when a new animation overlaps another of the same type, the | 142 // Ensure that when a new animation overlaps another of the same type, the |
| 141 // newly added animation overrides the original. For example: | 143 // newly added animation overrides the original. For example: |
| 142 // Animation 1: ? .......... 20 | 144 // Animation 1: ? .......... 20 |
| 143 // Animation 2: ? .......... 50 | 145 // Animation 2: ? .......... 50 |
| 144 // Result: 0 ... 10 ... 30 ... 50 | 146 // Result: 0 ... 10 ... 30 ... 50 |
| 145 TEST(UiElements, AnimationOverlap) { | 147 TEST(UiElements, AnimationOverlap) { |
| 146 UiElement rect; | 148 UiElement rect; |
| 147 std::unique_ptr<Animation> animation( | 149 std::unique_ptr<Animation> animation( |
| 148 new Animation(0, Animation::Property::TRANSLATION, | 150 new Animation(0, Animation::Property::TRANSLATION, |
| 149 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, | 151 std::unique_ptr<easing::Easing>(new easing::Linear()), |
| 150 {20, 200, 2000}, usToTicks(50000), usToDelta(10000))); | 152 std::vector<float>(), {20, 200, 2000}, usToTicks(50000), |
| 153 usToDelta(10000))); |
| 151 std::unique_ptr<Animation> animation2( | 154 std::unique_ptr<Animation> animation2( |
| 152 new Animation(0, Animation::Property::TRANSLATION, | 155 new Animation(0, Animation::Property::TRANSLATION, |
| 153 std::unique_ptr<easing::Easing>(new easing::Linear()), {}, | 156 std::unique_ptr<easing::Easing>(new easing::Linear()), |
| 154 {50, 500, 5000}, usToTicks(55000), usToDelta(10000))); | 157 std::vector<float>(), {50, 500, 5000}, usToTicks(55000), |
| 158 usToDelta(10000))); |
| 155 rect.animations().emplace_back(std::move(animation)); | 159 rect.animations().emplace_back(std::move(animation)); |
| 156 rect.animations().emplace_back(std::move(animation2)); | 160 rect.animations().emplace_back(std::move(animation2)); |
| 157 rect.Animate(usToTicks(55000)); | 161 rect.Animate(usToTicks(55000)); |
| 158 EXPECT_VEC3F_EQ(gfx::Vector3dF(10, 100, 1000), rect.translation()); | 162 EXPECT_VEC3F_EQ(gfx::Vector3dF(10, 100, 1000), rect.translation()); |
| 159 rect.Animate(usToTicks(60000)); | 163 rect.Animate(usToTicks(60000)); |
| 160 EXPECT_VEC3F_EQ(gfx::Vector3dF(30, 300, 3000), rect.translation()); | 164 EXPECT_VEC3F_EQ(gfx::Vector3dF(30, 300, 3000), rect.translation()); |
| 161 rect.Animate(usToTicks(65000)); | 165 rect.Animate(usToTicks(65000)); |
| 162 EXPECT_VEC3F_EQ(gfx::Vector3dF(50, 500, 5000), rect.translation()); | 166 EXPECT_VEC3F_EQ(gfx::Vector3dF(50, 500, 5000), rect.translation()); |
| 163 } | 167 } |
| 164 | 168 |
| 165 } // namespace vr_shell | 169 } // namespace vr_shell |
| OLD | NEW |