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

Unified Diff: ui/gfx/compositor/layer_animation_element_unittest.cc

Issue 8247009: Explicit animation support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix VS2010 Created 9 years, 2 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 | « ui/gfx/compositor/layer_animation_element.cc ('k') | ui/gfx/compositor/layer_animation_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/compositor/layer_animation_element_unittest.cc
diff --git a/ui/gfx/compositor/layer_animation_element_unittest.cc b/ui/gfx/compositor/layer_animation_element_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..efbc1ca3cbfb77cc526eab157187b469a3a02bcd
--- /dev/null
+++ b/ui/gfx/compositor/layer_animation_element_unittest.cc
@@ -0,0 +1,131 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/compositor/layer_animation_element.h"
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/transform.h"
+#include "ui/gfx/compositor/layer_animation_delegate.h"
+#include "ui/gfx/compositor/test_utils.h"
+#include "ui/gfx/compositor/test_layer_animation_delegate.h"
+
+namespace ui {
+
+namespace {
+
+// Check that the transformation element progresses the delegate as expected and
+// that the element can be reused after it completes.
+TEST(LayerAnimationElementTest, TransformElement) {
+ TestLayerAnimationDelegate delegate;
+ Transform start_transform, target_transform, middle_transform;
+ start_transform.SetRotate(-90);
+ target_transform.SetRotate(90);
+ base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
+
+ scoped_ptr<LayerAnimationElement> element(
+ LayerAnimationElement::CreateTransformElement(target_transform, delta));
+
+ for (int i = 0; i < 2; ++i) {
+ delegate.SetTransformFromAnimation(start_transform);
+ element->Progress(0.0, &delegate);
+ CheckApproximatelyEqual(start_transform,
+ delegate.GetTransformForAnimation());
+ element->Progress(0.5, &delegate);
+ CheckApproximatelyEqual(middle_transform,
+ delegate.GetTransformForAnimation());
+ element->Progress(1.0, &delegate);
+ CheckApproximatelyEqual(target_transform,
+ delegate.GetTransformForAnimation());
+ }
+
+ EXPECT_EQ(delta, element->duration());
+}
+
+// Check that the bounds element progresses the delegate as expected and
+// that the element can be reused after it completes.
+TEST(LayerAnimationElementTest, BoundsElement) {
+ TestLayerAnimationDelegate delegate;
+ gfx::Rect start, target, middle;
+ start = target = middle = gfx::Rect(0, 0, 50, 50);
+ start.set_x(-90);
+ target.set_x(90);
+ base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
+
+ scoped_ptr<LayerAnimationElement> element(
+ LayerAnimationElement::CreateBoundsElement(target, delta));
+
+ for (int i = 0; i < 2; ++i) {
+ delegate.SetBoundsFromAnimation(start);
+ element->Progress(0.0, &delegate);
+ CheckApproximatelyEqual(start, delegate.GetBoundsForAnimation());
+ element->Progress(0.5, &delegate);
+ CheckApproximatelyEqual(middle, delegate.GetBoundsForAnimation());
+ element->Progress(1.0, &delegate);
+ CheckApproximatelyEqual(target, delegate.GetBoundsForAnimation());
+ }
+
+ EXPECT_EQ(delta, element->duration());
+}
+
+// Check that the opacity element progresses the delegate as expected and
+// that the element can be reused after it completes.
+TEST(LayerAnimationElementTest, OpacityElement) {
+ TestLayerAnimationDelegate delegate;
+ float start = 0.0;
+ float middle = 0.5;
+ float target = 1.0;
+ base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
+ scoped_ptr<LayerAnimationElement> element(
+ LayerAnimationElement::CreateOpacityElement(target, delta));
+
+ for (int i = 0; i < 2; ++i) {
+ delegate.SetOpacityFromAnimation(start);
+ element->Progress(0.0, &delegate);
+ EXPECT_FLOAT_EQ(start, delegate.GetOpacityForAnimation());
+ element->Progress(0.5, &delegate);
+ EXPECT_FLOAT_EQ(middle, delegate.GetOpacityForAnimation());
+ element->Progress(1.0, &delegate);
+ EXPECT_FLOAT_EQ(target, delegate.GetOpacityForAnimation());
+ }
+
+ EXPECT_EQ(delta, element->duration());
+}
+
+// Check that the pause element progresses the delegate as expected and
+// that the element can be reused after it completes.
+TEST(LayerAnimationElementTest, PauseElement) {
+ LayerAnimationElement::AnimatableProperties properties;
+ properties.insert(LayerAnimationElement::TRANSFORM);
+ properties.insert(LayerAnimationElement::BOUNDS);
+ properties.insert(LayerAnimationElement::OPACITY);
+ base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
+
+ scoped_ptr<LayerAnimationElement> element(
+ LayerAnimationElement::CreatePauseElement(properties, delta));
+
+ TestLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate copy = delegate;
+
+ element->Progress(1.0, &delegate);
+
+ // Nothing should have changed.
+ CheckApproximatelyEqual(delegate.GetBoundsForAnimation(),
+ copy.GetBoundsForAnimation());
+ CheckApproximatelyEqual(delegate.GetTransformForAnimation(),
+ copy.GetTransformForAnimation());
+ EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(),
+ copy.GetOpacityForAnimation());
+
+ // Pause should last for |delta|.
+ EXPECT_EQ(delta, element->duration());
+}
+
+} // namespace
+
+} // namespace ui
« no previous file with comments | « ui/gfx/compositor/layer_animation_element.cc ('k') | ui/gfx/compositor/layer_animation_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698