Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: ui/compositor/layer_animator_unittest.cc

Issue 1143433005: Remove gfx::FrameTime for a single clock source (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/compositor/layer_animator.h" 5 #include "ui/compositor/layer_animator.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/compositor/layer.h" 13 #include "ui/compositor/layer.h"
14 #include "ui/compositor/layer_animation_delegate.h" 14 #include "ui/compositor/layer_animation_delegate.h"
15 #include "ui/compositor/layer_animation_element.h" 15 #include "ui/compositor/layer_animation_element.h"
16 #include "ui/compositor/layer_animation_sequence.h" 16 #include "ui/compositor/layer_animation_sequence.h"
17 #include "ui/compositor/layer_animator_collection.h" 17 #include "ui/compositor/layer_animator_collection.h"
18 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 18 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
19 #include "ui/compositor/scoped_layer_animation_settings.h" 19 #include "ui/compositor/scoped_layer_animation_settings.h"
20 #include "ui/compositor/test/context_factories_for_test.h" 20 #include "ui/compositor/test/context_factories_for_test.h"
21 #include "ui/compositor/test/layer_animator_test_controller.h" 21 #include "ui/compositor/test/layer_animator_test_controller.h"
22 #include "ui/compositor/test/test_compositor_host.h" 22 #include "ui/compositor/test/test_compositor_host.h"
23 #include "ui/compositor/test/test_layer_animation_delegate.h" 23 #include "ui/compositor/test/test_layer_animation_delegate.h"
24 #include "ui/compositor/test/test_layer_animation_observer.h" 24 #include "ui/compositor/test/test_layer_animation_observer.h"
25 #include "ui/compositor/test/test_utils.h" 25 #include "ui/compositor/test/test_utils.h"
26 #include "ui/gfx/frame_time.h" 26
27 #include "ui/gfx/geometry/rect.h" 27 #include "ui/gfx/geometry/rect.h"
28 #include "ui/gfx/transform.h" 28 #include "ui/gfx/transform.h"
29 29
30 namespace ui { 30 namespace ui {
31 31
32 namespace { 32 namespace {
33 33
34 // Converts |color| to a string. Each component of the color is separated by a 34 // Converts |color| to a string. Each component of the color is separated by a
35 // space and the order if A R G B. 35 // space and the order if A R G B.
36 std::string ColorToString(SkColor color) { 36 std::string ColorToString(SkColor color) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } // namespace 187 } // namespace
188 188
189 // Checks that setting a property on an implicit animator causes an animation to 189 // Checks that setting a property on an implicit animator causes an animation to
190 // happen. 190 // happen.
191 TEST(LayerAnimatorTest, ImplicitAnimation) { 191 TEST(LayerAnimatorTest, ImplicitAnimation) {
192 scoped_refptr<LayerAnimator> animator( 192 scoped_refptr<LayerAnimator> animator(
193 LayerAnimator::CreateImplicitAnimator()); 193 LayerAnimator::CreateImplicitAnimator());
194 animator->set_disable_timer_for_test(true); 194 animator->set_disable_timer_for_test(true);
195 TestLayerAnimationDelegate delegate; 195 TestLayerAnimationDelegate delegate;
196 animator->SetDelegate(&delegate); 196 animator->SetDelegate(&delegate);
197 base::TimeTicks now = gfx::FrameTime::Now(); 197 base::TimeTicks now = base::TimeTicks::Now();
198 animator->SetBrightness(0.5); 198 animator->SetBrightness(0.5);
199 EXPECT_TRUE(animator->is_animating()); 199 EXPECT_TRUE(animator->is_animating());
200 animator->Step(now + base::TimeDelta::FromSeconds(1)); 200 animator->Step(now + base::TimeDelta::FromSeconds(1));
201 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5); 201 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5);
202 } 202 }
203 203
204 // Checks that if the animator is a default animator, that implicit animations 204 // Checks that if the animator is a default animator, that implicit animations
205 // are not started. 205 // are not started.
206 TEST(LayerAnimatorTest, NoImplicitAnimation) { 206 TEST(LayerAnimatorTest, NoImplicitAnimation) {
207 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 207 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, 1035 LayerAnimationElement::CreateGrayscaleElement(target_grayscale,
1036 delta), 1036 delta),
1037 LayerAnimationElement::CreateBrightnessElement(target_brightness, 1037 LayerAnimationElement::CreateBrightnessElement(target_brightness,
1038 delta) 1038 delta)
1039 )); 1039 ));
1040 1040
1041 // If last step time was not set correctly, the resulting delta should be 1041 // If last step time was not set correctly, the resulting delta should be
1042 // miniscule (fractions of a millisecond). If set correctly, then the delta 1042 // miniscule (fractions of a millisecond). If set correctly, then the delta
1043 // should be enormous. Arbitrarily choosing 1 minute as the threshold, 1043 // should be enormous. Arbitrarily choosing 1 minute as the threshold,
1044 // though a much smaller value would probably have sufficed. 1044 // though a much smaller value would probably have sufficed.
1045 delta = gfx::FrameTime::Now() - animator->last_step_time(); 1045 delta = base::TimeTicks::Now() - animator->last_step_time();
1046 EXPECT_GT(60.0, delta.InSecondsF()); 1046 EXPECT_GT(60.0, delta.InSecondsF());
1047 } 1047 }
1048 1048
1049 //------------------------------------------------------- 1049 //-------------------------------------------------------
1050 // Preempt by immediately setting new target. 1050 // Preempt by immediately setting new target.
1051 TEST(LayerAnimatorTest, MultiPreemptBySettingNewTarget) { 1051 TEST(LayerAnimatorTest, MultiPreemptBySettingNewTarget) {
1052 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1052 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1053 animator->set_disable_timer_for_test(true); 1053 animator->set_disable_timer_for_test(true);
1054 TestLayerAnimationDelegate delegate; 1054 TestLayerAnimationDelegate delegate;
1055 animator->SetDelegate(&delegate); 1055 animator->SetDelegate(&delegate);
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1635 TestLayerAnimator* animator = new TestLayerAnimator(); 1635 TestLayerAnimator* animator = new TestLayerAnimator();
1636 LayerAnimatorDestructionObserver destruction_observer; 1636 LayerAnimatorDestructionObserver destruction_observer;
1637 animator->SetDestructionObserver(&destruction_observer); 1637 animator->SetDestructionObserver(&destruction_observer);
1638 animator->set_disable_timer_for_test(true); 1638 animator->set_disable_timer_for_test(true);
1639 TestLayerAnimationDelegate delegate; 1639 TestLayerAnimationDelegate delegate;
1640 animator->SetDelegate(&delegate); 1640 animator->SetDelegate(&delegate);
1641 { 1641 {
1642 // ScopedLayerAnimationSettings should keep the Animator alive as long as 1642 // ScopedLayerAnimationSettings should keep the Animator alive as long as
1643 // it is alive, even beyond the end of the animation. 1643 // it is alive, even beyond the end of the animation.
1644 ScopedLayerAnimationSettings settings(animator); 1644 ScopedLayerAnimationSettings settings(animator);
1645 base::TimeTicks now = gfx::FrameTime::Now(); 1645 base::TimeTicks now = base::TimeTicks::Now();
1646 animator->SetBrightness(0.5); 1646 animator->SetBrightness(0.5);
1647 animator->Step(now + base::TimeDelta::FromSeconds(1)); 1647 animator->Step(now + base::TimeDelta::FromSeconds(1));
1648 EXPECT_FALSE(destruction_observer.IsAnimatorDeleted()); 1648 EXPECT_FALSE(destruction_observer.IsAnimatorDeleted());
1649 } 1649 }
1650 // ScopedLayerAnimationSettings was destroyed, so Animator should be deleted. 1650 // ScopedLayerAnimationSettings was destroyed, so Animator should be deleted.
1651 EXPECT_TRUE(destruction_observer.IsAnimatorDeleted()); 1651 EXPECT_TRUE(destruction_observer.IsAnimatorDeleted());
1652 } 1652 }
1653 1653
1654 // Tests that an observer added to a scoped settings object is not notified 1654 // Tests that an observer added to a scoped settings object is not notified
1655 // when the animator is destroyed unless explicitly requested. 1655 // when the animator is destroyed unless explicitly requested.
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
2644 EXPECT_TRUE(animator->is_animating()); 2644 EXPECT_TRUE(animator->is_animating());
2645 animator->Step(animator->last_step_time() + 2645 animator->Step(animator->last_step_time() +
2646 base::TimeDelta::FromMilliseconds(500)); 2646 base::TimeDelta::FromMilliseconds(500));
2647 animator->StopAnimating(); 2647 animator->StopAnimating();
2648 2648
2649 EXPECT_EQ(nullptr, observer.animator_layer()); 2649 EXPECT_EQ(nullptr, observer.animator_layer());
2650 EXPECT_TRUE(animator->is_animating()); 2650 EXPECT_TRUE(animator->is_animating());
2651 } 2651 }
2652 2652
2653 } // namespace ui 2653 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698