OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 "mojo/services/view_manager/scheduled_animation_group.h" |
| 6 |
| 7 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 8 #include "mojo/converters/transform/transform_type_converters.h" |
| 9 #include "mojo/services/view_manager/server_view.h" |
| 10 #include "mojo/services/view_manager/test_server_view_delegate.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "third_party/mojo_services/src/view_manager/public/interfaces/animation
s.mojom.h" |
| 13 |
| 14 using mojo::ANIMATION_PROPERTY_NONE; |
| 15 using mojo::ANIMATION_PROPERTY_OPACITY; |
| 16 using mojo::ANIMATION_PROPERTY_TRANSFORM; |
| 17 using mojo::ANIMATION_TWEEN_TYPE_LINEAR; |
| 18 using mojo::AnimationGroup; |
| 19 using mojo::AnimationSequence; |
| 20 using mojo::AnimationElement; |
| 21 using mojo::AnimationValue; |
| 22 |
| 23 namespace view_manager { |
| 24 namespace { |
| 25 |
| 26 bool IsAnimationGroupValid(const AnimationGroup& transport_group) { |
| 27 TestServerViewDelegate view_delegate; |
| 28 ServerView view(&view_delegate, ViewId()); |
| 29 scoped_ptr<ScheduledAnimationGroup> group(ScheduledAnimationGroup::Create( |
| 30 &view, base::TimeTicks::Now(), 1, transport_group)); |
| 31 return group.get() != nullptr; |
| 32 } |
| 33 |
| 34 } // namespace |
| 35 |
| 36 TEST(ScheduledAnimationGroupTest, IsAnimationGroupValid) { |
| 37 AnimationGroup group; |
| 38 |
| 39 // AnimationGroup with no sequences is not valid. |
| 40 EXPECT_FALSE(IsAnimationGroupValid(group)); |
| 41 |
| 42 group.sequences.push_back(AnimationSequence::New()); |
| 43 |
| 44 // Sequence with no elements is not valid. |
| 45 EXPECT_FALSE(IsAnimationGroupValid(group)); |
| 46 |
| 47 AnimationSequence& sequence = *(group.sequences[0]); |
| 48 sequence.elements.push_back(AnimationElement::New()); |
| 49 AnimationElement& element = *(sequence.elements[0]); |
| 50 element.property = ANIMATION_PROPERTY_OPACITY; |
| 51 element.tween_type = ANIMATION_TWEEN_TYPE_LINEAR; |
| 52 |
| 53 // Element with no target_value is not valid. |
| 54 EXPECT_FALSE(IsAnimationGroupValid(group)); |
| 55 |
| 56 // Opacity must be between 0 and 1. |
| 57 element.target_value = AnimationValue::New(); |
| 58 element.target_value->float_value = 2.5f; |
| 59 EXPECT_FALSE(IsAnimationGroupValid(group)); |
| 60 |
| 61 element.target_value->float_value = .5f; |
| 62 EXPECT_TRUE(IsAnimationGroupValid(group)); |
| 63 |
| 64 // Bogus start value. |
| 65 element.start_value = AnimationValue::New(); |
| 66 element.start_value->float_value = 2.5f; |
| 67 EXPECT_FALSE(IsAnimationGroupValid(group)); |
| 68 |
| 69 element.start_value->float_value = .5f; |
| 70 EXPECT_TRUE(IsAnimationGroupValid(group)); |
| 71 |
| 72 // Bogus transform. |
| 73 element.property = ANIMATION_PROPERTY_TRANSFORM; |
| 74 EXPECT_FALSE(IsAnimationGroupValid(group)); |
| 75 element.start_value->transform = mojo::Transform::From(gfx::Transform()); |
| 76 EXPECT_FALSE(IsAnimationGroupValid(group)); |
| 77 element.target_value->transform = mojo::Transform::From(gfx::Transform()); |
| 78 EXPECT_TRUE(IsAnimationGroupValid(group)); |
| 79 |
| 80 // Add another empty sequence, should be invalid again. |
| 81 group.sequences.push_back(AnimationSequence::New()); |
| 82 EXPECT_FALSE(IsAnimationGroupValid(group)); |
| 83 |
| 84 AnimationSequence& sequence2 = *(group.sequences[1]); |
| 85 sequence2.elements.push_back(AnimationElement::New()); |
| 86 AnimationElement& element2 = *(sequence2.elements[0]); |
| 87 element2.property = ANIMATION_PROPERTY_OPACITY; |
| 88 element2.tween_type = ANIMATION_TWEEN_TYPE_LINEAR; |
| 89 |
| 90 // Element with no target_value is not valid. |
| 91 EXPECT_FALSE(IsAnimationGroupValid(group)); |
| 92 |
| 93 element2.property = ANIMATION_PROPERTY_NONE; |
| 94 EXPECT_TRUE(IsAnimationGroupValid(group)); |
| 95 } |
| 96 |
| 97 } // namespace view_manager |
OLD | NEW |