Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/basictypes.h" | |
| 6 #include "base/compiler_specific.h" | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "base/time.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #include "ui/gfx/rect.h" | |
| 11 #include "ui/gfx/transform.h" | |
| 12 #include "ui/gfx/compositor/layer_animation_delegate.h" | |
| 13 #include "ui/gfx/compositor/layer_animation_element.h" | |
|
sky
2011/10/20 16:33:03
Tests should include the .h first, as you would in
| |
| 14 #include "ui/gfx/compositor/test_utils.h" | |
| 15 #include "ui/gfx/compositor/test_layer_animation_delegate.h" | |
| 16 | |
| 17 namespace ui { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 // Check that the transformation element progresses the delegate as expected and | |
| 22 // that the element can be reused after it completes. | |
| 23 TEST(LayerAnimationElementTest, TransformElement) { | |
| 24 TestLayerAnimationDelegate delegate; | |
| 25 Transform start_transform, target_transform, middle_transform; | |
| 26 start_transform.SetRotate(-90); | |
| 27 target_transform.SetRotate(90); | |
| 28 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | |
| 29 | |
| 30 scoped_ptr<LayerAnimationElement> element( | |
| 31 LayerAnimationElement::CreateTransformElement(target_transform, delta)); | |
| 32 | |
| 33 for (int i = 0; i < 2; ++i) { | |
| 34 delegate.SetTransformFromAnimation(start_transform); | |
| 35 element->Progress(0.0, &delegate); | |
| 36 CheckApproximatelyEqual(start_transform, | |
| 37 delegate.GetTransformForAnimation()); | |
| 38 element->Progress(0.5, &delegate); | |
| 39 CheckApproximatelyEqual(middle_transform, | |
| 40 delegate.GetTransformForAnimation()); | |
| 41 element->Progress(1.0, &delegate); | |
| 42 CheckApproximatelyEqual(target_transform, | |
| 43 delegate.GetTransformForAnimation()); | |
| 44 } | |
| 45 | |
| 46 EXPECT_EQ(delta, element->duration()); | |
| 47 } | |
| 48 | |
| 49 // Check that the bounds element progresses the delegate as expected and | |
| 50 // that the element can be reused after it completes. | |
| 51 TEST(LayerAnimationElementTest, BoundsElement) { | |
| 52 TestLayerAnimationDelegate delegate; | |
| 53 gfx::Rect start, target, middle; | |
| 54 start = target = middle = gfx::Rect(0, 0, 50, 50); | |
| 55 start.set_x(-90); | |
| 56 target.set_x(90); | |
| 57 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | |
| 58 | |
| 59 scoped_ptr<LayerAnimationElement> element( | |
| 60 LayerAnimationElement::CreateBoundsElement(target, delta)); | |
| 61 | |
| 62 for (int i = 0; i < 2; ++i) { | |
| 63 delegate.SetBoundsFromAnimation(start); | |
| 64 element->Progress(0.0, &delegate); | |
| 65 CheckApproximatelyEqual(start, delegate.GetBoundsForAnimation()); | |
| 66 element->Progress(0.5, &delegate); | |
| 67 CheckApproximatelyEqual(middle, delegate.GetBoundsForAnimation()); | |
| 68 element->Progress(1.0, &delegate); | |
| 69 CheckApproximatelyEqual(target, delegate.GetBoundsForAnimation()); | |
| 70 } | |
| 71 | |
| 72 EXPECT_EQ(delta, element->duration()); | |
| 73 } | |
| 74 | |
| 75 // Check that the opacity element progresses the delegate as expected and | |
| 76 // that the element can be reused after it completes. | |
| 77 TEST(LayerAnimationElementTest, OpacityElement) { | |
| 78 TestLayerAnimationDelegate delegate; | |
| 79 float start = 0.0; | |
| 80 float middle = 0.5; | |
| 81 float target = 1.0; | |
| 82 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | |
| 83 scoped_ptr<LayerAnimationElement> element( | |
| 84 LayerAnimationElement::CreateOpacityElement(target, delta)); | |
| 85 | |
| 86 for (int i = 0; i < 2; ++i) { | |
| 87 delegate.SetOpacityFromAnimation(start); | |
| 88 element->Progress(0.0, &delegate); | |
| 89 EXPECT_FLOAT_EQ(start, delegate.GetOpacityForAnimation()); | |
| 90 element->Progress(0.5, &delegate); | |
| 91 EXPECT_FLOAT_EQ(middle, delegate.GetOpacityForAnimation()); | |
| 92 element->Progress(1.0, &delegate); | |
| 93 EXPECT_FLOAT_EQ(target, delegate.GetOpacityForAnimation()); | |
| 94 } | |
| 95 | |
| 96 EXPECT_EQ(delta, element->duration()); | |
| 97 } | |
| 98 | |
| 99 // Check that the pause element progresses the delegate as expected and | |
| 100 // that the element can be reused after it completes. | |
| 101 TEST(LayerAnimationElementTest, PauseElement) { | |
| 102 LayerAnimationElement::AnimatableProperties properties; | |
| 103 properties.insert(LayerAnimationElement::TRANSFORM); | |
| 104 properties.insert(LayerAnimationElement::BOUNDS); | |
| 105 properties.insert(LayerAnimationElement::OPACITY); | |
| 106 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | |
| 107 | |
| 108 scoped_ptr<LayerAnimationElement> element( | |
| 109 LayerAnimationElement::CreatePauseElement(properties, delta)); | |
| 110 | |
| 111 TestLayerAnimationDelegate delegate; | |
| 112 TestLayerAnimationDelegate copy = delegate; | |
| 113 | |
| 114 element->Progress(1.0, &delegate); | |
| 115 | |
| 116 // Nothing should have changed. | |
| 117 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), | |
| 118 copy.GetBoundsForAnimation()); | |
| 119 CheckApproximatelyEqual(delegate.GetTransformForAnimation(), | |
| 120 copy.GetTransformForAnimation()); | |
| 121 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), | |
| 122 copy.GetOpacityForAnimation()); | |
| 123 | |
| 124 // Pause should last for |delta|. | |
| 125 EXPECT_EQ(delta, element->duration()); | |
| 126 } | |
| 127 | |
| 128 } // namespace | |
| 129 | |
| 130 } // namespace ui | |
| OLD | NEW |