Index: services/view_manager/scheduled_animation_group_unittest.cc |
diff --git a/services/view_manager/scheduled_animation_group_unittest.cc b/services/view_manager/scheduled_animation_group_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..06a2c6e5492c3e86b7ae69c6dc5fe9332c87c913 |
--- /dev/null |
+++ b/services/view_manager/scheduled_animation_group_unittest.cc |
@@ -0,0 +1,89 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "services/view_manager/scheduled_animation_group.h" |
+ |
+#include "mojo/converters/geometry/geometry_type_converters.h" |
+#include "mojo/services/public/interfaces/view_manager/animations.mojom.h" |
+#include "services/view_manager/server_view.h" |
+#include "services/view_manager/test_server_view_delegate.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace mojo { |
+namespace service { |
+namespace { |
+ |
+bool IsAnimationGroupValid(const AnimationGroup& transport_group) { |
+ TestServerViewDelegate view_delegate; |
+ ServerView view(&view_delegate, ViewId()); |
+ scoped_ptr<ScheduledAnimationGroup> group(ScheduledAnimationGroup::Create( |
+ &view, base::TimeTicks::Now(), 1, transport_group)); |
+ return group.get() != nullptr; |
+} |
+ |
+} // namespace |
+ |
+TEST(ScheduledAnimationGroupTest, IsAnimationGroupValid) { |
+ AnimationGroup group; |
+ |
+ // AnimationGroup with no sequences is not valid. |
+ EXPECT_FALSE(IsAnimationGroupValid(group)); |
+ |
+ group.sequences.push_back(AnimationSequence::New()); |
+ |
+ // Sequence with no elements is not valid. |
+ EXPECT_FALSE(IsAnimationGroupValid(group)); |
+ |
+ AnimationSequence& sequence = *(group.sequences[0]); |
+ sequence.elements.push_back(AnimationElement::New()); |
+ AnimationElement& element = *(sequence.elements[0]); |
+ element.property = ANIMATION_PROPERTY_OPACITY; |
+ element.tween_type = ANIMATION_TWEEN_TYPE_LINEAR; |
+ |
+ // Element with no target_value is not valid. |
+ EXPECT_FALSE(IsAnimationGroupValid(group)); |
+ |
+ // Opacity must be between 0 and 1. |
+ element.target_value = AnimationValue::New(); |
+ element.target_value->float_value = 2.5f; |
+ EXPECT_FALSE(IsAnimationGroupValid(group)); |
+ |
+ element.target_value->float_value = .5f; |
+ EXPECT_TRUE(IsAnimationGroupValid(group)); |
+ |
+ // Bogus start value. |
+ element.start_value = AnimationValue::New(); |
+ element.start_value->float_value = 2.5f; |
+ EXPECT_FALSE(IsAnimationGroupValid(group)); |
+ |
+ element.start_value->float_value = .5f; |
+ EXPECT_TRUE(IsAnimationGroupValid(group)); |
+ |
+ // Bogus transform. |
+ element.property = ANIMATION_PROPERTY_TRANSFORM; |
+ EXPECT_FALSE(IsAnimationGroupValid(group)); |
+ element.start_value->transform = Transform::From(gfx::Transform()); |
+ EXPECT_FALSE(IsAnimationGroupValid(group)); |
+ element.target_value->transform = Transform::From(gfx::Transform()); |
+ EXPECT_TRUE(IsAnimationGroupValid(group)); |
+ |
+ // Add another empty sequence, should be invalid again. |
+ group.sequences.push_back(AnimationSequence::New()); |
+ EXPECT_FALSE(IsAnimationGroupValid(group)); |
+ |
+ AnimationSequence& sequence2 = *(group.sequences[1]); |
+ sequence2.elements.push_back(AnimationElement::New()); |
+ AnimationElement& element2 = *(sequence2.elements[0]); |
+ element2.property = ANIMATION_PROPERTY_OPACITY; |
+ element2.tween_type = ANIMATION_TWEEN_TYPE_LINEAR; |
+ |
+ // Element with no target_value is not valid. |
+ EXPECT_FALSE(IsAnimationGroupValid(group)); |
+ |
+ element2.property = ANIMATION_PROPERTY_NONE; |
+ EXPECT_TRUE(IsAnimationGroupValid(group)); |
+} |
+ |
+} // namespace service |
+} // namespace mojo |