summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-13 00:54:55 +0000
committerjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-13 00:54:55 +0000
commit31a8245f6712529bf88040fbab28e050cde4582c (patch)
treefe365005fe7900298e10e9c1d00c7435fc655fc3 /ui
parentddcfbbd24b2c140117b6dc886b6453cc350d859e (diff)
downloadchromium_src-31a8245f6712529bf88040fbab28e050cde4582c.zip
chromium_src-31a8245f6712529bf88040fbab28e050cde4582c.tar.gz
chromium_src-31a8245f6712529bf88040fbab28e050cde4582c.tar.bz2
Set default frame rate for SlideAnimation to 60 Hz
After discussion with Glen and some digging into svn history we don't know why this was set to 50 Hz and not 60 Hz. In testing on Chromebooks and Linux hardware we can easily animate at 60 Hz for most animations. We're going to try setting it to 60 Hz and see how things behave. Also added some unit tests around SlideAnimation. BUG=136910 TEST=SlideAnimationTest in ui_unittests Review URL: https://chromiumcodereview.appspot.com/10703153 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146490 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/base/animation/slide_animation.cc10
-rw-r--r--ui/base/animation/slide_animation.h4
-rw-r--r--ui/base/animation/slide_animation_unittest.cc72
3 files changed, 79 insertions, 7 deletions
diff --git a/ui/base/animation/slide_animation.cc b/ui/base/animation/slide_animation.cc
index ec08334..e73474c 100644
--- a/ui/base/animation/slide_animation.cc
+++ b/ui/base/animation/slide_animation.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -9,13 +9,13 @@
namespace ui {
// How many frames per second to target.
-static const int kDefaultFramerateHz = 50;
+static const int kDefaultFrameRateHz = 60;
// How long animations should take by default.
static const int kDefaultDurationMs = 120;
SlideAnimation::SlideAnimation(AnimationDelegate* target)
- : LinearAnimation(kDefaultFramerateHz, target),
+ : LinearAnimation(kDefaultFrameRateHz, target),
target_(target),
tween_type_(Tween::EASE_OUT),
showing_(false),
@@ -55,7 +55,7 @@ void SlideAnimation::Show() {
return;
}
- // This will also reset the currently-occuring animation.
+ // This will also reset the currently-occurring animation.
SetDuration(static_cast<int>(slide_duration_ * (1 - value_current_)));
Start();
}
@@ -77,7 +77,7 @@ void SlideAnimation::Hide() {
return;
}
- // This will also reset the currently-occuring animation.
+ // This will also reset the currently-occurring animation.
SetDuration(static_cast<int>(slide_duration_ * value_current_));
Start();
}
diff --git a/ui/base/animation/slide_animation.h b/ui/base/animation/slide_animation.h
index a5eed76..709633b 100644
--- a/ui/base/animation/slide_animation.h
+++ b/ui/base/animation/slide_animation.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -70,6 +70,8 @@ class UI_EXPORT SlideAnimation : public LinearAnimation {
bool IsShowing() const { return showing_; }
bool IsClosing() const { return !showing_ && value_end_ < value_current_; }
+ class TestApi;
+
private:
// Overridden from Animation.
virtual void AnimateToState(double state) OVERRIDE;
diff --git a/ui/base/animation/slide_animation_unittest.cc b/ui/base/animation/slide_animation_unittest.cc
index 35227ac..7a8dbb8 100644
--- a/ui/base/animation/slide_animation_unittest.cc
+++ b/ui/base/animation/slide_animation_unittest.cc
@@ -1,19 +1,89 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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 "base/memory/scoped_ptr.h"
+#include "base/time.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/animation/slide_animation.h"
#include "ui/base/animation/test_animation_delegate.h"
namespace ui {
+// Class to provide access to SlideAnimation internals for testing.
+class SlideAnimation::TestApi {
+ public:
+ explicit TestApi(SlideAnimation* animation) : animation_(animation) {}
+
+ void SetStartTime(base::TimeTicks ticks) {
+ animation_->SetStartTime(ticks);
+ }
+
+ void Step(base::TimeTicks ticks) {
+ animation_->Step(ticks);
+ }
+
+ private:
+ SlideAnimation* animation_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestApi);
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// SlideAnimationTest
class SlideAnimationTest: public testing::Test {
private:
MessageLoopForUI message_loop_;
};
+// Tests animation construction.
+TEST_F(SlideAnimationTest, InitialState) {
+ SlideAnimation animation(NULL);
+ // By default, slide animations are 60 Hz, so the timer interval should be
+ // 1/60th of a second.
+ EXPECT_EQ(1000 / 60, animation.timer_interval().InMilliseconds());
+ // Duration defaults to 120 ms.
+ EXPECT_EQ(120, animation.GetSlideDuration());
+ // Slide is neither showing nor closing.
+ EXPECT_FALSE(animation.IsShowing());
+ EXPECT_FALSE(animation.IsClosing());
+ // Starts at 0.
+ EXPECT_EQ(0.0, animation.GetCurrentValue());
+}
+
+TEST_F(SlideAnimationTest, Basics) {
+ SlideAnimation animation(NULL);
+ SlideAnimation::TestApi test_api(&animation);
+
+ // Use linear tweening to make the math easier below.
+ animation.SetTweenType(Tween::LINEAR);
+
+ // Duration can be set after construction.
+ animation.SetSlideDuration(100);
+ EXPECT_EQ(100, animation.GetSlideDuration());
+
+ // Show toggles the appropriate state.
+ animation.Show();
+ EXPECT_TRUE(animation.IsShowing());
+ EXPECT_FALSE(animation.IsClosing());
+
+ // Simulate running the animation.
+ test_api.SetStartTime(base::TimeTicks());
+ test_api.Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(50));
+ EXPECT_EQ(0.5, animation.GetCurrentValue());
+
+ // We can start hiding mid-way through the animation.
+ animation.Hide();
+ EXPECT_FALSE(animation.IsShowing());
+ EXPECT_TRUE(animation.IsClosing());
+
+ // Reset stops the animation.
+ animation.Reset();
+ EXPECT_EQ(0.0, animation.GetCurrentValue());
+ EXPECT_FALSE(animation.IsShowing());
+ EXPECT_FALSE(animation.IsClosing());
+}
+
// Tests that delegate is not notified when animation is running and is deleted.
// (Such a scenario would cause problems for BoundsAnimator).
TEST_F(SlideAnimationTest, DontNotifyOnDelete) {