summaryrefslogtreecommitdiffstats
path: root/cc/layer_tree_host_unittest_animation.cc
diff options
context:
space:
mode:
authordanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-19 07:26:40 +0000
committerdanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-19 07:26:40 +0000
commitf91a75e00c853bcab5ab23175b97b022055bc9bb (patch)
tree61439bba56532da0f768f70b2de8c2f9633881fc /cc/layer_tree_host_unittest_animation.cc
parent25c6cfe167bfab66ae1b63970737642940a54a0c (diff)
downloadchromium_src-f91a75e00c853bcab5ab23175b97b022055bc9bb.zip
chromium_src-f91a75e00c853bcab5ab23175b97b022055bc9bb.tar.gz
chromium_src-f91a75e00c853bcab5ab23175b97b022055bc9bb.tar.bz2
cc: Move more animation tests to layer_tree_host_unittests_animation.cc
Created FakeContentLayer to replace ContentLayerWithUpdateTracking. R=enne,jamesr Review URL: https://codereview.chromium.org/11640006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173873 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/layer_tree_host_unittest_animation.cc')
-rw-r--r--cc/layer_tree_host_unittest_animation.cc335
1 files changed, 331 insertions, 4 deletions
diff --git a/cc/layer_tree_host_unittest_animation.cc b/cc/layer_tree_host_unittest_animation.cc
index e49e825..d4e80c0 100644
--- a/cc/layer_tree_host_unittest_animation.cc
+++ b/cc/layer_tree_host_unittest_animation.cc
@@ -4,7 +4,12 @@
#include "cc/layer_tree_host.h"
+#include "cc/animation_curve.h"
#include "cc/layer.h"
+#include "cc/layer_animation_controller.h"
+#include "cc/layer_impl.h"
+#include "cc/test/fake_content_layer.h"
+#include "cc/test/fake_content_layer_client.h"
#include "cc/test/layer_tree_test_common.h"
namespace cc {
@@ -64,10 +69,332 @@ class LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested
int num_commits_;
};
-TEST_F(LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested,
- runMultiThread) {
- runTest(true);
-}
+MULTI_THREAD_TEST_F(
+ LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested)
+
+// Trigger a frame with setNeedsCommit. Then, inside the resulting animate
+// callback, requet another frame using setNeedsAnimate. End the test when
+// animate gets called yet-again, indicating that the proxy is correctly
+// handling the case where setNeedsAnimate() is called inside the begin frame
+// flow.
+class LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback :
+ public LayerTreeHostAnimationTest {
+ public:
+ LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback()
+ : num_animates_(0) {
+ }
+
+ virtual void beginTest() OVERRIDE {
+ postSetNeedsAnimateToMainThread();
+ }
+
+ virtual void animate(base::TimeTicks) OVERRIDE {
+ if (!num_animates_) {
+ m_layerTreeHost->setNeedsAnimate();
+ num_animates_++;
+ return;
+ }
+ endTest();
+ }
+
+ virtual void afterTest() OVERRIDE {}
+
+ private:
+ int num_animates_;
+};
+
+MULTI_THREAD_TEST_F(
+ LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback)
+
+// Add a layer animation and confirm that LayerTreeHostImpl::animateLayers does
+// get called and continues to get called.
+class LayerTreeHostAnimationTestAddAnimation :
+ public LayerTreeHostAnimationTest {
+ public:
+ LayerTreeHostAnimationTestAddAnimation()
+ : num_animates_(0)
+ , received_animation_started_notification_(false)
+ , start_time_(0) {
+ }
+
+ virtual void beginTest() OVERRIDE {
+ postAddInstantAnimationToMainThread();
+ }
+
+ virtual void animateLayers(
+ LayerTreeHostImpl* impl_host,
+ base::TimeTicks monotonic_time) OVERRIDE {
+ if (!num_animates_) {
+ // The animation had zero duration so layerTreeHostImpl should no
+ // longer need to animate its layers.
+ EXPECT_FALSE(impl_host->needsAnimateLayers());
+ num_animates_++;
+ first_monotonic_time_ = monotonic_time;
+ return;
+ }
+ EXPECT_LT(0, start_time_);
+ EXPECT_TRUE(received_animation_started_notification_);
+ endTest();
+ }
+
+ virtual void notifyAnimationStarted(double wall_clock_time) OVERRIDE {
+ received_animation_started_notification_ = true;
+ start_time_ = wall_clock_time;
+ }
+
+ virtual void afterTest() OVERRIDE {}
+
+private:
+ int num_animates_;
+ bool received_animation_started_notification_;
+ double start_time_;
+ base::TimeTicks first_monotonic_time_;
+};
+
+MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAddAnimation)
+
+// Add a layer animation to a layer, but continually fail to draw. Confirm that
+// after a while, we do eventually force a draw.
+class LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws :
+ public LayerTreeHostAnimationTest {
+ public:
+ LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws()
+ : started_animating_(false) {
+ }
+
+ virtual void beginTest() OVERRIDE {
+ postAddAnimationToMainThread(m_layerTreeHost->rootLayer());
+ }
+
+ virtual void animateLayers(
+ LayerTreeHostImpl* host_impl,
+ base::TimeTicks monotonicTime) OVERRIDE {
+ started_animating_ = true;
+ }
+
+ virtual void drawLayersOnThread(LayerTreeHostImpl*) OVERRIDE {
+ if (started_animating_)
+ endTest();
+ }
+
+ virtual bool prepareToDrawOnThread(LayerTreeHostImpl*) OVERRIDE {
+ return false;
+ }
+
+ virtual void afterTest() OVERRIDE {}
+
+ private:
+ bool started_animating_;
+};
+
+// Starvation can only be an issue with the MT compositor.
+MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws)
+
+// Ensures that animations continue to be ticked when we are backgrounded.
+class LayerTreeHostAnimationTestTickAnimationWhileBackgrounded :
+ public LayerTreeHostAnimationTest {
+ public:
+ LayerTreeHostAnimationTestTickAnimationWhileBackgrounded()
+ : num_animates_(0) {
+ }
+
+ virtual void beginTest() OVERRIDE {
+ postAddAnimationToMainThread(m_layerTreeHost->rootLayer());
+ }
+
+ // Use willAnimateLayers to set visible false before the animation runs and
+ // causes a commit, so we block the second visible animate in single-thread
+ // mode.
+ virtual void willAnimateLayers(
+ LayerTreeHostImpl* host_impl,
+ base::TimeTicks monotonicTime) OVERRIDE {
+ if (num_animates_ < 2) {
+ if (!num_animates_) {
+ // We have a long animation running. It should continue to tick even
+ // if we are not visible.
+ postSetVisibleToMainThread(false);
+ }
+ num_animates_++;
+ return;
+ }
+ endTest();
+ }
+
+ virtual void afterTest() OVERRIDE {}
+
+ private:
+ int num_animates_;
+};
+
+SINGLE_AND_MULTI_THREAD_TEST_F(
+ LayerTreeHostAnimationTestTickAnimationWhileBackgrounded)
+
+// Ensures that animations continue to be ticked when we are backgrounded.
+class LayerTreeHostAnimationTestAddAnimationWithTimingFunction :
+ public LayerTreeHostAnimationTest {
+public:
+ LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {}
+
+ virtual void beginTest() OVERRIDE {
+ postAddAnimationToMainThread(m_layerTreeHost->rootLayer());
+ }
+
+ virtual void animateLayers(
+ LayerTreeHostImpl* host_impl,
+ base::TimeTicks monotonicTime) OVERRIDE {
+ LayerAnimationController* controller =
+ m_layerTreeHost->rootLayer()->layerAnimationController();
+ ActiveAnimation* animation =
+ controller->getActiveAnimation(0, ActiveAnimation::Opacity);
+ if (!animation)
+ return;
+
+ const FloatAnimationCurve* curve =
+ animation->curve()->toFloatAnimationCurve();
+ float startOpacity = curve->getValue(0);
+ float endOpacity = curve->getValue(curve->duration());
+ float linearly_interpolated_opacity =
+ 0.25 * endOpacity + 0.75 * startOpacity;
+ double time = curve->duration() * 0.25;
+ // If the linear timing function associated with this animation was not
+ // picked up, then the linearly interpolated opacity would be different
+ // because of the default ease timing function.
+ EXPECT_FLOAT_EQ(linearly_interpolated_opacity, curve->getValue(time));
+
+ LayerAnimationController* controller_impl =
+ host_impl->rootLayer()->layerAnimationController();
+ ActiveAnimation* animation_impl =
+ controller_impl->getActiveAnimation(0, ActiveAnimation::Opacity);
+
+ controller->removeAnimation(animation->id());
+ controller_impl->removeAnimation(animation_impl->id());
+ endTest();
+ }
+
+ virtual void afterTest() OVERRIDE {}
+};
+
+SINGLE_AND_MULTI_THREAD_TEST_F(
+ LayerTreeHostAnimationTestAddAnimationWithTimingFunction)
+
+// Ensures that main thread animations have their start times synchronized with
+// impl thread animations.
+class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes :
+ public LayerTreeHostAnimationTest {
+ public:
+ LayerTreeHostAnimationTestSynchronizeAnimationStartTimes()
+ : main_start_time_(-1),
+ impl_start_time_(-1) {
+ }
+
+ virtual void beginTest() OVERRIDE {
+ postAddAnimationToMainThread(m_layerTreeHost->rootLayer());
+ }
+
+ virtual void notifyAnimationStarted(double time) OVERRIDE {
+ LayerAnimationController* controller =
+ m_layerTreeHost->rootLayer()->layerAnimationController();
+ ActiveAnimation* animation =
+ controller->getActiveAnimation(0, ActiveAnimation::Opacity);
+ main_start_time_ = animation->startTime();
+ controller->removeAnimation(animation->id());
+
+ if (impl_start_time_ > 0)
+ endTest();
+ }
+
+ virtual void animateLayers(
+ LayerTreeHostImpl* impl_host,
+ base::TimeTicks monotonicTime) OVERRIDE {
+ LayerAnimationController* controller =
+ impl_host->rootLayer()->layerAnimationController();
+ ActiveAnimation* animation =
+ controller->getActiveAnimation(0, ActiveAnimation::Opacity);
+ if (!animation)
+ return;
+
+ impl_start_time_ = animation->startTime();
+ controller->removeAnimation(animation->id());
+
+ if (main_start_time_ > 0)
+ endTest();
+ }
+
+ virtual void afterTest() OVERRIDE {
+ EXPECT_FLOAT_EQ(impl_start_time_, main_start_time_);
+ }
+
+ private:
+ double main_start_time_;
+ double impl_start_time_;
+};
+
+SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestSynchronizeAnimationStartTimes)
+
+// Ensures that notifyAnimationFinished is called.
+class LayerTreeHostAnimationTestAnimationFinishedEvents :
+ public LayerTreeHostAnimationTest {
+ public:
+ LayerTreeHostAnimationTestAnimationFinishedEvents() {}
+
+ virtual void beginTest() OVERRIDE {
+ postAddInstantAnimationToMainThread();
+ }
+
+ virtual void notifyAnimationFinished(double time) OVERRIDE {
+ LayerAnimationController* controller =
+ m_layerTreeHost->rootLayer()->layerAnimationController();
+ ActiveAnimation* animation =
+ controller->getActiveAnimation(0, ActiveAnimation::Opacity);
+ controller->removeAnimation(animation->id());
+ endTest();
+ }
+
+ virtual void afterTest() OVERRIDE {}
+};
+
+SINGLE_AND_MULTI_THREAD_TEST_F(
+ LayerTreeHostAnimationTestAnimationFinishedEvents)
+
+// Ensures that when opacity is being animated, this value does not cause the
+// subtree to be skipped.
+class LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity :
+ public LayerTreeHostAnimationTest {
+ public:
+ LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity()
+ : update_check_layer_(FakeContentLayer::Create(&client_)) {
+ }
+
+ virtual void setupTree() OVERRIDE {
+ update_check_layer_->setOpacity(0);
+ m_layerTreeHost->setRootLayer(update_check_layer_);
+ LayerTreeHostAnimationTest::setupTree();
+ }
+
+ virtual void beginTest() OVERRIDE {
+ postAddAnimationToMainThread(update_check_layer_.get());
+ }
+
+ virtual void commitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE {
+ endTest();
+ }
+
+ virtual void afterTest() OVERRIDE {
+ // update() should have been called once, proving that the layer was not
+ // skipped.
+ EXPECT_EQ(1, update_check_layer_->update_count());
+
+ // clear update_check_layer_ so LayerTreeHost dies.
+ update_check_layer_ = NULL;
+ }
+
+ private:
+ FakeContentLayerClient client_;
+ scoped_refptr<FakeContentLayer> update_check_layer_;
+};
+
+MULTI_THREAD_TEST_F(
+ LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity)
} // namespace
} // namespace cc