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

Unified Diff: cc/trees/layer_tree_host_impl_unittest.cc

Issue 16925007: Fix scrollbar fade animation scheduling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mock out physical time Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: cc/trees/layer_tree_host_impl_unittest.cc
diff --git a/cc/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc
index 097244c2a980fda58114932a747aacdb276f16ed..a0bc3d90898a4677361e733bbf2e3408d9b79b75 100644
--- a/cc/trees/layer_tree_host_impl_unittest.cc
+++ b/cc/trees/layer_tree_host_impl_unittest.cc
@@ -129,7 +129,7 @@ class LayerTreeHostImplTest : public testing::Test,
virtual bool IsInsideDraw() OVERRIDE { return false; }
virtual void RenewTreePriority() OVERRIDE {}
virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay)
- OVERRIDE {}
+ OVERRIDE { requested_scrollbar_animation_delay_ = delay; }
virtual void DidActivatePendingTree() OVERRIDE {}
void set_reduce_memory_result(bool reduce_memory_result) {
@@ -284,6 +284,7 @@ class LayerTreeHostImplTest : public testing::Test,
bool did_request_redraw_;
bool did_upload_visible_tile_;
bool reduce_memory_result_;
+ base::TimeDelta requested_scrollbar_animation_delay_;
};
class TestWebGraphicsContext3DMakeCurrentFails
@@ -989,6 +990,106 @@ TEST_F(LayerTreeHostImplTest, PageScaleAnimationNoOp) {
}
}
+TEST_F(LayerTreeHostImplTest, ScrollbarLinearFadeScheduling) {
+ LayerTreeSettings settings;
+ settings.use_linear_fade_scrollbar_animator = true;
+ settings.scrollbar_linear_fade_delay_ms = 20;
+ settings.scrollbar_linear_fade_length_ms = 20;
+
+ host_impl_ = LayerTreeHostImpl::Create(settings,
+ this,
+ &proxy_,
+ &stats_instrumentation_);
+ host_impl_->InitializeRenderer(CreateOutputSurface());
+ host_impl_->SetViewportSize(gfx::Size(10, 10));
+
+ gfx::Size content_size(100, 100);
+ scoped_ptr<LayerImpl> root =
+ LayerImpl::Create(host_impl_->active_tree(), 1);
+ root->SetBounds(content_size);
+ root->SetContentBounds(content_size);
+
+ scoped_ptr<LayerImpl> scroll =
+ LayerImpl::Create(host_impl_->active_tree(), 2);
+ scroll->SetScrollable(true);
+ scroll->SetScrollOffset(gfx::Vector2d());
+ scroll->SetMaxScrollOffset(gfx::Vector2d(content_size.width(),
+ content_size.height()));
+ scroll->SetBounds(content_size);
+ scroll->SetContentBounds(content_size);
+
+ scoped_ptr<LayerImpl> contents =
+ LayerImpl::Create(host_impl_->active_tree(), 3);
+ contents->SetDrawsContent(true);
+ contents->SetBounds(content_size);
+ contents->SetContentBounds(content_size);
+
+ scoped_ptr<ScrollbarLayerImpl> scrollbar = ScrollbarLayerImpl::Create(
+ host_impl_->active_tree(),
+ 4,
+ VERTICAL);
+ scroll->SetVerticalScrollbarLayer(scrollbar.get());
+
+ scroll->AddChild(contents.Pass());
+ root->AddChild(scroll.Pass());
+ root->AddChild(scrollbar.PassAs<LayerImpl>());
+
+ host_impl_->active_tree()->SetRootLayer(root.Pass());
+ host_impl_->active_tree()->DidBecomeActive();
+ InitializeRendererAndDrawFrame();
+
+ base::TimeTicks fake_time = base::TimeTicks::Now();
danakj 2013/06/14 18:36:43 nit: fake_now ?
+ host_impl_->SetCurrentPhysicalTimeTicksForTest(fake_time);
+
+ // If no scroll happened recently, StartScrollbarAnimation should have no
+ // effect.
+ host_impl_->StartScrollbarAnimation();
+ EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
+ EXPECT_FALSE(did_request_redraw_);
+
+ // After a scroll, a fade animation should be scheduled about 20ms from now
+ // (check greater than 10ms to avoid flakiness).
danakj 2013/06/14 18:36:43 this comment out of date
+ host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel);
+ host_impl_->ScrollEnd();
+ host_impl_->StartScrollbarAnimation();
+ EXPECT_LT(base::TimeDelta::FromMilliseconds(19),
+ requested_scrollbar_animation_delay_);
+ EXPECT_FALSE(did_request_redraw_);
+ requested_scrollbar_animation_delay_ = base::TimeDelta();
+
+ // After the fade begins, we should start getting redraws instead of a
+ // scheduled animation.
+ fake_time += base::TimeDelta::FromMilliseconds(25);
+ host_impl_->SetCurrentPhysicalTimeTicksForTest(fake_time);
+ host_impl_->StartScrollbarAnimation();
+ EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
+ EXPECT_TRUE(did_request_redraw_);
+ did_request_redraw_ = false;
+
+ // If no scroll happened recently, StartScrollbarAnimation should have no
+ // effect.
+ fake_time += base::TimeDelta::FromMilliseconds(25);
+ host_impl_->SetCurrentPhysicalTimeTicksForTest(fake_time);
+ host_impl_->StartScrollbarAnimation();
+ EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
+ EXPECT_FALSE(did_request_redraw_);
+
+ // Setting the scroll offset outside a scroll should also cause the scrollbar
+ // to appear and to schedule a fade.
+ host_impl_->RootScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5));
+ host_impl_->StartScrollbarAnimation();
+ EXPECT_LT(base::TimeDelta::FromMilliseconds(19),
+ requested_scrollbar_animation_delay_);
+ EXPECT_FALSE(did_request_redraw_);
+ requested_scrollbar_animation_delay_ = base::TimeDelta();
+
+ // None of the above should have called CurrentFrameTimeTicks, so if we call
+ // it now we should get the current time.
+ fake_time += base::TimeDelta::FromMilliseconds(10);
+ host_impl_->SetCurrentPhysicalTimeTicksForTest(fake_time);
+ EXPECT_EQ(fake_time, host_impl_->CurrentFrameTimeTicks());
+}
+
TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) {
SetupScrollAndContentsLayers(gfx::Size(100, 100));
host_impl_->SetViewportSize(gfx::Size(50, 50));

Powered by Google App Engine
This is Rietveld 408576698