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

Unified Diff: chrome/browser/android/vr_shell/ui_scene_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
« no previous file with comments | « chrome/browser/android/vr_shell/ui_scene_manager.cc ('k') | chrome/browser/android/vr_shell/vr_shell_gl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/vr_shell/ui_scene_unittest.cc
diff --git a/chrome/browser/android/vr_shell/ui_scene_unittest.cc b/chrome/browser/android/vr_shell/ui_scene_unittest.cc
index fe09178930d66f59eeb7a7fba21e1de5c5c235f0..79b31b78f60ce26ad66d3282d0433f9e9212ad40 100644
--- a/chrome/browser/android/vr_shell/ui_scene_unittest.cc
+++ b/chrome/browser/android/vr_shell/ui_scene_unittest.cc
@@ -11,10 +11,9 @@
#include "base/memory/ptr_util.h"
#include "base/values.h"
-#include "chrome/browser/android/vr_shell/animation.h"
-#include "chrome/browser/android/vr_shell/easing.h"
#include "chrome/browser/android/vr_shell/ui_elements/ui_element.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/transform_util.h"
#define TOLERANCE 0.0001
@@ -31,79 +30,38 @@ base::TimeTicks usToTicks(uint64_t us) {
return base::TimeTicks::FromInternalValue(us);
}
-base::TimeDelta usToDelta(uint64_t us) {
- return base::TimeDelta::FromInternalValue(us);
-}
-
void addElement(UiScene* scene, int id) {
- auto element = base::MakeUnique<UiElement>();
- element->set_id(id);
+ auto element = base::MakeUnique<UiElement>(id);
scene->AddUiElement(std::move(element));
}
-void addAnimation(UiScene* scene,
- int element_id,
- int animation_id,
- Animation::Property property) {
- std::unique_ptr<easing::Easing> easing = base::MakeUnique<easing::Linear>();
- std::vector<float> from;
- std::vector<float> to = {1, 1, 1, 1};
- auto animation =
- base::MakeUnique<Animation>(animation_id, property, std::move(easing),
- from, to, usToTicks(0), usToDelta(1));
- scene->AddAnimation(element_id, std::move(animation));
-}
-
} // namespace
TEST(UiScene, AddRemoveElements) {
UiScene scene;
EXPECT_EQ(scene.GetUiElements().size(), 0u);
- addElement(&scene, 0);
+ addElement(&scene, 1);
EXPECT_EQ(scene.GetUiElements().size(), 1u);
addElement(&scene, 99);
EXPECT_EQ(scene.GetUiElements().size(), 2u);
- EXPECT_NE(scene.GetUiElementById(0), nullptr);
+ EXPECT_NE(scene.GetUiElementById(1), nullptr);
EXPECT_NE(scene.GetUiElementById(99), nullptr);
- EXPECT_EQ(scene.GetUiElementById(1), nullptr);
+ EXPECT_EQ(scene.GetUiElementById(2), nullptr);
- scene.RemoveUiElement(0);
+ scene.RemoveUiElement(1);
EXPECT_EQ(scene.GetUiElements().size(), 1u);
- EXPECT_EQ(scene.GetUiElementById(0), nullptr);
+ EXPECT_EQ(scene.GetUiElementById(1), nullptr);
scene.RemoveUiElement(99);
EXPECT_EQ(scene.GetUiElements().size(), 0u);
EXPECT_EQ(scene.GetUiElementById(99), nullptr);
- scene.RemoveUiElement(0);
+ scene.RemoveUiElement(1);
scene.RemoveUiElement(99);
EXPECT_EQ(scene.GetUiElements().size(), 0u);
}
-TEST(UiScene, AddRemoveAnimations) {
- UiScene scene;
- addElement(&scene, 0);
- auto* element = scene.GetUiElementById(0);
-
- EXPECT_EQ(element->animations().size(), 0u);
- addAnimation(&scene, 0, 0, Animation::Property::SIZE);
- EXPECT_EQ(element->animations().size(), 1u);
- EXPECT_EQ(element->animations()[0]->property, Animation::Property::SIZE);
- addAnimation(&scene, 0, 1, Animation::Property::SCALE);
- EXPECT_EQ(element->animations().size(), 2u);
- EXPECT_EQ(element->animations()[1]->property, Animation::Property::SCALE);
-
- scene.RemoveAnimation(0, 0);
- EXPECT_EQ(element->animations().size(), 1u);
- EXPECT_EQ(element->animations()[0]->property, Animation::Property::SCALE);
- scene.RemoveAnimation(0, 1);
- EXPECT_EQ(element->animations().size(), 0u);
-
- scene.RemoveAnimation(0, 0);
- EXPECT_EQ(element->animations().size(), 0u);
-}
-
// This test creates a parent and child UI element, each with their own
// transformations, and ensures that the child's computed total transform
// incorporates the parent's transform as well as its own.
@@ -112,31 +70,35 @@ TEST(UiScene, ParentTransformAppliesToChild) {
// Add a parent element, with distinct transformations.
// Size of the parent should be ignored by the child.
- auto element = base::MakeUnique<UiElement>();
- element->set_id(0);
+ auto element = base::MakeUnique<UiElement>(1);
element->set_size({1000, 1000, 1});
- element->set_scale({3, 3, 1});
- element->set_rotation(gfx::Quaternion(gfx::Vector3dF(0, 0, 1), M_PI / 2));
- element->set_translation({6, 1, 0});
+
+ cc::TransformOperations operations;
+ operations.AppendTranslate(6, 1, 0);
+ operations.AppendRotate(0, 0, 1, 180 / 2);
+ operations.AppendScale(3, 3, 1);
+ element->set_transform_operations(operations);
scene.AddUiElement(std::move(element));
// Add a child to the parent, with different transformations.
- element = base::MakeUnique<UiElement>();
- element->set_id(1);
- element->set_parent_id(0);
+ element = base::MakeUnique<UiElement>(2);
+ element->set_parent_id(1);
element->set_size({1, 1, 1});
- element->set_scale({2, 2, 1});
- element->set_rotation(gfx::Quaternion(gfx::Vector3dF(0, 0, 1), M_PI / 2));
- element->set_translation({3, 0, 0});
+
+ cc::TransformOperations child_operations;
+ child_operations.AppendTranslate(3, 0, 0);
+ child_operations.AppendRotate(0, 0, 1, 180 / 2);
+ child_operations.AppendScale(2, 2, 1);
+ element->set_transform_operations(child_operations);
scene.AddUiElement(std::move(element));
- const UiElement* child = scene.GetUiElementById(1);
+ const UiElement* child = scene.GetUiElementById(2);
gfx::Point3F origin(0, 0, 0);
gfx::Point3F point(1, 0, 0);
- scene.OnBeginFrame(usToTicks(0));
- child->transform().TransformPoint(&origin);
- child->transform().TransformPoint(&point);
+ scene.OnBeginFrame(usToTicks(1));
+ child->screen_space_transform().TransformPoint(&origin);
+ child->screen_space_transform().TransformPoint(&point);
EXPECT_VEC3F_NEAR(gfx::Point3F(6, 10, 0), origin);
EXPECT_VEC3F_NEAR(gfx::Point3F(0, 10, 0), point);
}
@@ -144,39 +106,35 @@ TEST(UiScene, ParentTransformAppliesToChild) {
TEST(UiScene, Opacity) {
UiScene scene;
- auto element = base::MakeUnique<UiElement>();
- element->set_id(0);
+ auto element = base::MakeUnique<UiElement>(1);
element->set_opacity(0.5);
scene.AddUiElement(std::move(element));
- element = base::MakeUnique<UiElement>();
- element->set_id(1);
- element->set_parent_id(0);
+ element = base::MakeUnique<UiElement>(2);
+ element->set_parent_id(1);
element->set_opacity(0.5);
scene.AddUiElement(std::move(element));
- scene.OnBeginFrame(usToTicks(0));
- EXPECT_EQ(0.5f, scene.GetUiElementById(0)->computed_opacity());
- EXPECT_EQ(0.25f, scene.GetUiElementById(1)->computed_opacity());
+ scene.OnBeginFrame(usToTicks(1));
+ EXPECT_EQ(0.5f, scene.GetUiElementById(1)->computed_opacity());
+ EXPECT_EQ(0.25f, scene.GetUiElementById(2)->computed_opacity());
}
TEST(UiScene, LockToFov) {
UiScene scene;
- auto element = base::MakeUnique<UiElement>();
- element->set_id(0);
+ auto element = base::MakeUnique<UiElement>(1);
element->set_lock_to_fov(true);
scene.AddUiElement(std::move(element));
- element = base::MakeUnique<UiElement>();
- element->set_id(1);
- element->set_parent_id(0);
+ element = base::MakeUnique<UiElement>(2);
+ element->set_parent_id(1);
element->set_lock_to_fov(false);
scene.AddUiElement(std::move(element));
- scene.OnBeginFrame(usToTicks(0));
- EXPECT_TRUE(scene.GetUiElementById(0)->computed_lock_to_fov());
+ scene.OnBeginFrame(usToTicks(1));
EXPECT_TRUE(scene.GetUiElementById(1)->computed_lock_to_fov());
+ EXPECT_TRUE(scene.GetUiElementById(2)->computed_lock_to_fov());
}
typedef struct {
@@ -192,25 +150,25 @@ TEST_P(AnchoringTest, VerifyCorrectPosition) {
UiScene scene;
// Create a parent element with non-unity size and scale.
- auto element = base::MakeUnique<UiElement>();
- element->set_id(0);
+ auto element = base::MakeUnique<UiElement>(1);
element->set_size({2, 2, 1});
- element->set_scale({2, 2, 1});
+ cc::TransformOperations operations;
+ operations.AppendScale(2, 2, 1);
+ element->set_transform_operations(operations);
scene.AddUiElement(std::move(element));
// Add a child to the parent, with anchoring.
- element = base::MakeUnique<UiElement>();
- element->set_id(1);
- element->set_parent_id(0);
+ element = base::MakeUnique<UiElement>(2);
+ element->set_parent_id(1);
element->set_x_anchoring(GetParam().x_anchoring);
element->set_y_anchoring(GetParam().y_anchoring);
scene.AddUiElement(std::move(element));
- scene.OnBeginFrame(usToTicks(0));
- const UiElement* child = scene.GetUiElementById(1);
+ scene.OnBeginFrame(usToTicks(1));
+ const UiElement* child = scene.GetUiElementById(2);
EXPECT_NEAR(GetParam().expected_x, child->GetCenter().x(), TOLERANCE);
EXPECT_NEAR(GetParam().expected_y, child->GetCenter().y(), TOLERANCE);
- scene.RemoveUiElement(1);
+ scene.RemoveUiElement(2);
}
const std::vector<AnchoringTestCase> anchoring_test_cases = {
« no previous file with comments | « chrome/browser/android/vr_shell/ui_scene_manager.cc ('k') | chrome/browser/android/vr_shell/vr_shell_gl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698