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