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.
5 #include "mojo/services/view_manager/scheduled_animation_group.h"
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/animations.mojom.h"
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
;
23 namespace view_manager
{
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;
36 TEST(ScheduledAnimationGroupTest
, IsAnimationGroupValid
) {
39 // AnimationGroup with no sequences is not valid.
40 EXPECT_FALSE(IsAnimationGroupValid(group
));
42 group
.sequences
.push_back(AnimationSequence::New());
44 // Sequence with no elements is not valid.
45 EXPECT_FALSE(IsAnimationGroupValid(group
));
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
;
53 // Element with no target_value is not valid.
54 EXPECT_FALSE(IsAnimationGroupValid(group
));
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
));
61 element
.target_value
->float_value
= .5f
;
62 EXPECT_TRUE(IsAnimationGroupValid(group
));
65 element
.start_value
= AnimationValue::New();
66 element
.start_value
->float_value
= 2.5f
;
67 EXPECT_FALSE(IsAnimationGroupValid(group
));
69 element
.start_value
->float_value
= .5f
;
70 EXPECT_TRUE(IsAnimationGroupValid(group
));
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
));
80 // Add another empty sequence, should be invalid again.
81 group
.sequences
.push_back(AnimationSequence::New());
82 EXPECT_FALSE(IsAnimationGroupValid(group
));
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
;
90 // Element with no target_value is not valid.
91 EXPECT_FALSE(IsAnimationGroupValid(group
));
93 element2
.property
= ANIMATION_PROPERTY_NONE
;
94 EXPECT_TRUE(IsAnimationGroupValid(group
));
97 } // namespace view_manager