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