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

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: Handling patch for mac files 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"
27 #include "ui/gfx/geometry/rect.h" 26 #include "ui/gfx/geometry/rect.h"
28 #include "ui/gfx/transform.h" 27 #include "ui/gfx/transform.h"
29 28
30 namespace ui { 29 namespace ui {
31 30
32 namespace { 31 namespace {
33 32
34 // Converts |color| to a string. Each component of the color is separated by a 33 // Converts |color| to a string. Each component of the color is separated by a
35 // space and the order if A R G B. 34 // space and the order if A R G B.
36 std::string ColorToString(SkColor color) { 35 std::string ColorToString(SkColor color) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } // namespace 186 } // namespace
188 187
189 // Checks that setting a property on an implicit animator causes an animation to 188 // Checks that setting a property on an implicit animator causes an animation to
190 // happen. 189 // happen.
191 TEST(LayerAnimatorTest, ImplicitAnimation) { 190 TEST(LayerAnimatorTest, ImplicitAnimation) {
192 scoped_refptr<LayerAnimator> animator( 191 scoped_refptr<LayerAnimator> animator(
193 LayerAnimator::CreateImplicitAnimator()); 192 LayerAnimator::CreateImplicitAnimator());
194 animator->set_disable_timer_for_test(true); 193 animator->set_disable_timer_for_test(true);
195 TestLayerAnimationDelegate delegate; 194 TestLayerAnimationDelegate delegate;
196 animator->SetDelegate(&delegate); 195 animator->SetDelegate(&delegate);
197 base::TimeTicks now = gfx::FrameTime::Now(); 196 base::TimeTicks now = base::TimeTicks::Now();
198 animator->SetBrightness(0.5); 197 animator->SetBrightness(0.5);
199 EXPECT_TRUE(animator->is_animating()); 198 EXPECT_TRUE(animator->is_animating());
200 animator->Step(now + base::TimeDelta::FromSeconds(1)); 199 animator->Step(now + base::TimeDelta::FromSeconds(1));
201 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5); 200 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5);
202 } 201 }
203 202
204 // Checks that if the animator is a default animator, that implicit animations 203 // Checks that if the animator is a default animator, that implicit animations
205 // are not started. 204 // are not started.
206 TEST(LayerAnimatorTest, NoImplicitAnimation) { 205 TEST(LayerAnimatorTest, NoImplicitAnimation) {
207 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 206 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, 1034 LayerAnimationElement::CreateGrayscaleElement(target_grayscale,
1036 delta), 1035 delta),
1037 LayerAnimationElement::CreateBrightnessElement(target_brightness, 1036 LayerAnimationElement::CreateBrightnessElement(target_brightness,
1038 delta) 1037 delta)
1039 )); 1038 ));
1040 1039
1041 // If last step time was not set correctly, the resulting delta should be 1040 // 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 1041 // miniscule (fractions of a millisecond). If set correctly, then the delta
1043 // should be enormous. Arbitrarily choosing 1 minute as the threshold, 1042 // should be enormous. Arbitrarily choosing 1 minute as the threshold,
1044 // though a much smaller value would probably have sufficed. 1043 // though a much smaller value would probably have sufficed.
1045 delta = gfx::FrameTime::Now() - animator->last_step_time(); 1044 delta = base::TimeTicks::Now() - animator->last_step_time();
1046 EXPECT_GT(60.0, delta.InSecondsF()); 1045 EXPECT_GT(60.0, delta.InSecondsF());
1047 } 1046 }
1048 1047
1049 //------------------------------------------------------- 1048 //-------------------------------------------------------
1050 // Preempt by immediately setting new target. 1049 // Preempt by immediately setting new target.
1051 TEST(LayerAnimatorTest, MultiPreemptBySettingNewTarget) { 1050 TEST(LayerAnimatorTest, MultiPreemptBySettingNewTarget) {
1052 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1051 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1053 animator->set_disable_timer_for_test(true); 1052 animator->set_disable_timer_for_test(true);
1054 TestLayerAnimationDelegate delegate; 1053 TestLayerAnimationDelegate delegate;
1055 animator->SetDelegate(&delegate); 1054 animator->SetDelegate(&delegate);
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1635 TestLayerAnimator* animator = new TestLayerAnimator(); 1634 TestLayerAnimator* animator = new TestLayerAnimator();
1636 LayerAnimatorDestructionObserver destruction_observer; 1635 LayerAnimatorDestructionObserver destruction_observer;
1637 animator->SetDestructionObserver(&destruction_observer); 1636 animator->SetDestructionObserver(&destruction_observer);
1638 animator->set_disable_timer_for_test(true); 1637 animator->set_disable_timer_for_test(true);
1639 TestLayerAnimationDelegate delegate; 1638 TestLayerAnimationDelegate delegate;
1640 animator->SetDelegate(&delegate); 1639 animator->SetDelegate(&delegate);
1641 { 1640 {
1642 // ScopedLayerAnimationSettings should keep the Animator alive as long as 1641 // ScopedLayerAnimationSettings should keep the Animator alive as long as
1643 // it is alive, even beyond the end of the animation. 1642 // it is alive, even beyond the end of the animation.
1644 ScopedLayerAnimationSettings settings(animator); 1643 ScopedLayerAnimationSettings settings(animator);
1645 base::TimeTicks now = gfx::FrameTime::Now(); 1644 base::TimeTicks now = base::TimeTicks::Now();
1646 animator->SetBrightness(0.5); 1645 animator->SetBrightness(0.5);
1647 animator->Step(now + base::TimeDelta::FromSeconds(1)); 1646 animator->Step(now + base::TimeDelta::FromSeconds(1));
1648 EXPECT_FALSE(destruction_observer.IsAnimatorDeleted()); 1647 EXPECT_FALSE(destruction_observer.IsAnimatorDeleted());
1649 } 1648 }
1650 // ScopedLayerAnimationSettings was destroyed, so Animator should be deleted. 1649 // ScopedLayerAnimationSettings was destroyed, so Animator should be deleted.
1651 EXPECT_TRUE(destruction_observer.IsAnimatorDeleted()); 1650 EXPECT_TRUE(destruction_observer.IsAnimatorDeleted());
1652 } 1651 }
1653 1652
1654 // Tests that an observer added to a scoped settings object is not notified 1653 // Tests that an observer added to a scoped settings object is not notified
1655 // when the animator is destroyed unless explicitly requested. 1654 // 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()); 2643 EXPECT_TRUE(animator->is_animating());
2645 animator->Step(animator->last_step_time() + 2644 animator->Step(animator->last_step_time() +
2646 base::TimeDelta::FromMilliseconds(500)); 2645 base::TimeDelta::FromMilliseconds(500));
2647 animator->StopAnimating(); 2646 animator->StopAnimating();
2648 2647
2649 EXPECT_EQ(nullptr, observer.animator_layer()); 2648 EXPECT_EQ(nullptr, observer.animator_layer());
2650 EXPECT_TRUE(animator->is_animating()); 2649 EXPECT_TRUE(animator->is_animating());
2651 } 2650 }
2652 2651
2653 } // namespace ui 2652 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698