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

Unified Diff: chrome/browser/android/vr_shell/ui_elements/ui_element_unittest.cc

Issue 2966793002: NOT FOR REVIEW - convert to cc animation
Patch Set: switch to transform operations Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/vr_shell/ui_elements/ui_element_unittest.cc
diff --git a/chrome/browser/android/vr_shell/ui_elements/ui_element_unittest.cc b/chrome/browser/android/vr_shell/ui_elements/ui_element_unittest.cc
index e6ecdbb02127cb4668c28c5cb6012a354c2b0c82..f229111438e67335d07a99a165bc11be5d19ec35 100644
--- a/chrome/browser/android/vr_shell/ui_elements/ui_element_unittest.cc
+++ b/chrome/browser/android/vr_shell/ui_elements/ui_element_unittest.cc
@@ -7,27 +7,12 @@
#include <utility>
#include "base/macros.h"
-#include "chrome/browser/android/vr_shell/animation.h"
-#include "chrome/browser/android/vr_shell/easing.h"
+#include "cc/animation/animation.h"
+#include "cc/animation/animation_player.h"
+#include "cc/animation/keyframed_animation_curve.h"
+#include "cc/test/geometry_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
-#define EXPECT_VEC3F_EQ(a, b) \
- EXPECT_FLOAT_EQ(a.x(), b.x()); \
- EXPECT_FLOAT_EQ(a.y(), b.y()); \
- EXPECT_FLOAT_EQ(a.z(), b.z());
-
-#define EXPECT_RECTF_EQ(a, b) \
- EXPECT_FLOAT_EQ(a.x(), b.x()); \
- EXPECT_FLOAT_EQ(a.y(), b.y()); \
- EXPECT_FLOAT_EQ(a.width(), b.width()); \
- EXPECT_FLOAT_EQ(a.height(), b.height());
-
-#define EXPECT_ROTATION(a, b) \
- EXPECT_FLOAT_EQ(a.x(), b.x()); \
- EXPECT_FLOAT_EQ(a.y(), b.y()); \
- EXPECT_FLOAT_EQ(a.z(), b.z()); \
- EXPECT_FLOAT_EQ(a.w(), b.w());
-
namespace vr_shell {
namespace {
@@ -40,129 +25,84 @@ base::TimeDelta usToDelta(uint64_t us) {
return base::TimeDelta::FromInternalValue(us);
}
+// A convenience class for generating cc::Animations
+class AnimationCreator {
+ public:
+ AnimationCreator() : end_time_(usToDelta(10000)) {}
+
+ std::unique_ptr<cc::Animation> transform_animation() {
+ std::unique_ptr<cc::KeyframedTransformAnimationCurve> curve(
+ cc::KeyframedTransformAnimationCurve::Create());
+ curve->AddKeyframe(
+ cc::TransformKeyframe::Create(begin_time_, from_operations_, nullptr));
+ curve->AddKeyframe(
+ cc::TransformKeyframe::Create(end_time_, to_operations_, nullptr));
+ std::unique_ptr<cc::Animation> animation(cc::Animation::Create(
+ std::move(curve), 1, 1, cc::TargetProperty::TRANSFORM));
+ return animation;
+ }
+
+ std::unique_ptr<cc::Animation> size_animation() {
+ std::unique_ptr<cc::KeyframedSizeAnimationCurve> curve(
+ cc::KeyframedSizeAnimationCurve::Create());
+ curve->AddKeyframe(
+ cc::SizeKeyframe::Create(begin_time_, from_size_, nullptr));
+ curve->AddKeyframe(cc::SizeKeyframe::Create(end_time_, to_size_, nullptr));
+ std::unique_ptr<cc::Animation> animation(cc::Animation::Create(
+ std::move(curve), 1, 1, cc::TargetProperty::BOUNDS));
+ return animation;
+ }
+
+ cc::TransformOperations& from_operations() { return from_operations_; }
+ cc::TransformOperations& to_operations() { return to_operations_; }
+
+ void set_from_size(const gfx::SizeF& size) { from_size_ = size; }
+ void set_to_size(const gfx::SizeF& size) { to_size_ = size; }
+
+ void set_time_offset(const base::TimeDelta& offset) { time_offset_ = offset; }
+
+ private:
+ base::TimeDelta begin_time_;
+ base::TimeDelta end_time_;
+ base::TimeDelta time_offset_;
+
+ cc::TransformOperations from_operations_;
+ cc::TransformOperations to_operations_;
+ gfx::SizeF from_size_;
+ gfx::SizeF to_size_;
+};
+
} // namespace
TEST(UiElements, AnimateSize) {
- UiElement rect;
+ UiElement rect(1);
+ AnimationCreator creator;
rect.set_size({10, 100, 1});
- std::unique_ptr<Animation> animation(new Animation(
- 0, Animation::Property::SIZE,
- std::unique_ptr<easing::Easing>(new easing::Linear()),
- std::vector<float>(), {20, 200}, usToTicks(50000), usToDelta(10000)));
- rect.animations().emplace_back(std::move(animation));
- rect.Animate(usToTicks(50000));
- EXPECT_VEC3F_EQ(gfx::Vector3dF(10, 100, 1), rect.size());
- rect.Animate(usToTicks(60000));
- EXPECT_VEC3F_EQ(gfx::Vector3dF(20, 200, 1), rect.size());
-}
-
-TEST(UiElements, AnimateTranslation) {
- UiElement rect;
- rect.set_translation({10, 100, 1000});
- std::unique_ptr<Animation> animation(
- new Animation(0, Animation::Property::TRANSLATION,
- std::unique_ptr<easing::Easing>(new easing::Linear()),
- std::vector<float>(), {20, 200, 2000}, usToTicks(50000),
- usToDelta(10000)));
- rect.animations().emplace_back(std::move(animation));
- rect.Animate(usToTicks(50000));
- EXPECT_VEC3F_EQ(gfx::Vector3dF(10, 100, 1000), rect.translation());
- rect.Animate(usToTicks(60000));
- EXPECT_VEC3F_EQ(gfx::Vector3dF(20, 200, 2000), rect.translation());
-}
-
-TEST(UiElements, AnimateRotation) {
- UiElement rect;
- gfx::Quaternion from(gfx::Vector3dF(10, 100, 1000), 10000);
- gfx::Quaternion to(gfx::Vector3dF(20, 200, 2000), 20000);
- rect.set_rotation(from);
- std::unique_ptr<Animation> animation(
- new Animation(0, Animation::Property::ROTATION,
- std::unique_ptr<easing::Easing>(new easing::Linear()),
- std::vector<float>(), {to.x(), to.y(), to.z(), to.w()},
- usToTicks(50000), usToDelta(10000)));
- rect.animations().emplace_back(std::move(animation));
- rect.Animate(usToTicks(50000));
- EXPECT_ROTATION(from, rect.rotation());
- rect.Animate(usToTicks(60000));
- EXPECT_ROTATION(to, rect.rotation());
-}
-
-TEST(UiElements, AnimationHasNoEffectBeforeScheduledStart) {
- UiElement rect;
- std::unique_ptr<Animation> animation(new Animation(
- 0, Animation::Property::TRANSLATION,
- std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000},
- {20, 200, 2000}, usToTicks(50000), usToDelta(10000)));
- rect.animations().emplace_back(std::move(animation));
- rect.Animate(usToTicks(49999));
- EXPECT_VEC3F_EQ(gfx::Vector3dF(0, 0, 0), rect.translation());
-}
-
-TEST(UiElements, AnimationPurgedWhenDone) {
- UiElement rect;
- std::unique_ptr<Animation> animation(new Animation(
- 0, Animation::Property::TRANSLATION,
- std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000},
- {20, 200, 2000}, usToTicks(50000), usToDelta(10000)));
- rect.animations().emplace_back(std::move(animation));
- rect.Animate(usToTicks(60000));
- EXPECT_EQ(0u, rect.animations().size());
-}
-
-TEST(UiElements, AnimationLinearEasing) {
- UiElement rect;
- std::unique_ptr<Animation> animation(new Animation(
- 0, Animation::Property::TRANSLATION,
- std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000},
- {20, 200, 2000}, usToTicks(50000), usToDelta(10000)));
- rect.animations().emplace_back(std::move(animation));
- rect.Animate(usToTicks(50000));
- EXPECT_VEC3F_EQ(gfx::Vector3dF(10, 100, 1000), rect.translation());
- rect.Animate(usToTicks(55000));
- EXPECT_VEC3F_EQ(gfx::Vector3dF(15, 150, 1500), rect.translation());
- rect.Animate(usToTicks(60000));
- EXPECT_VEC3F_EQ(gfx::Vector3dF(20, 200, 2000), rect.translation());
-}
-
-TEST(UiElements, AnimationStartFromSpecifiedLocation) {
- UiElement rect;
- std::unique_ptr<Animation> animation(new Animation(
- 0, Animation::Property::TRANSLATION,
- std::unique_ptr<easing::Easing>(new easing::Linear()), {10, 100, 1000},
- {20, 200, 2000}, usToTicks(50000), usToDelta(10000)));
- rect.animations().emplace_back(std::move(animation));
- rect.Animate(usToTicks(50000));
- EXPECT_VEC3F_EQ(gfx::Vector3dF(10, 100, 1000), rect.translation());
- rect.Animate(usToTicks(60000));
- EXPECT_VEC3F_EQ(gfx::Vector3dF(20, 200, 2000), rect.translation());
+ creator.set_from_size({10, 100});
+ creator.set_to_size({20, 200});
+ rect.animation_player().AddAnimation(creator.size_animation());
+ base::TimeTicks start_time = usToTicks(1);
+ rect.Animate(start_time);
+ EXPECT_VECTOR3DF_EQ(gfx::Vector3dF(10, 100, 1), rect.size());
+ rect.Animate(start_time + usToDelta(10000));
+ EXPECT_VECTOR3DF_EQ(gfx::Vector3dF(20, 200, 1), rect.size());
}
-// Ensure that when a new animation overlaps another of the same type, the
-// newly added animation overrides the original. For example:
-// Animation 1: ? .......... 20
-// Animation 2: ? .......... 50
-// Result: 0 ... 10 ... 30 ... 50
-TEST(UiElements, AnimationOverlap) {
- UiElement rect;
- std::unique_ptr<Animation> animation(
- new Animation(0, Animation::Property::TRANSLATION,
- std::unique_ptr<easing::Easing>(new easing::Linear()),
- std::vector<float>(), {20, 200, 2000}, usToTicks(50000),
- usToDelta(10000)));
- std::unique_ptr<Animation> animation2(
- new Animation(0, Animation::Property::TRANSLATION,
- std::unique_ptr<easing::Easing>(new easing::Linear()),
- std::vector<float>(), {50, 500, 5000}, usToTicks(55000),
- usToDelta(10000)));
- rect.animations().emplace_back(std::move(animation));
- rect.animations().emplace_back(std::move(animation2));
- rect.Animate(usToTicks(55000));
- EXPECT_VEC3F_EQ(gfx::Vector3dF(10, 100, 1000), rect.translation());
- rect.Animate(usToTicks(60000));
- EXPECT_VEC3F_EQ(gfx::Vector3dF(30, 300, 3000), rect.translation());
- rect.Animate(usToTicks(65000));
- EXPECT_VEC3F_EQ(gfx::Vector3dF(50, 500, 5000), rect.translation());
+TEST(UiElements, AnimationAffectsInheritableTransform) {
+ UiElement rect(1);
+ AnimationCreator creator;
+ creator.from_operations().AppendTranslate(10, 100, 1000);
+ creator.to_operations().AppendTranslate(20, 200, 2000);
+ rect.animation_player().AddAnimation(creator.transform_animation());
+ base::TimeTicks start_time = usToTicks(1);
+ rect.Animate(start_time);
+ gfx::Point3F p;
+ rect.transform_operations().Apply().TransformPoint(&p);
+ EXPECT_VECTOR3DF_EQ(gfx::Vector3dF(10, 100, 1000), p);
+ p = gfx::Point3F();
+ rect.Animate(start_time + usToDelta(10000));
+ rect.transform_operations().Apply().TransformPoint(&p);
+ EXPECT_VECTOR3DF_EQ(gfx::Vector3dF(20, 200, 2000), p);
}
} // namespace vr_shell
« no previous file with comments | « chrome/browser/android/vr_shell/ui_elements/ui_element.cc ('k') | chrome/browser/android/vr_shell/ui_elements/url_bar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698