Chromium Code Reviews| 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..4a467c8c149b589d6f1a14149225bab920a3d1c9 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,131 @@ TEST_F(LayerTreeHostImplTest, PageScaleAnimationNoOp) { |
| } |
| } |
| +class LayerTreeHostImplOverridePhysicalTime : public LayerTreeHostImpl { |
| + public: |
| + LayerTreeHostImplOverridePhysicalTime( |
| + const LayerTreeSettings& settings, |
| + LayerTreeHostImplClient* client, |
| + Proxy* proxy, |
| + RenderingStatsInstrumentation* rendering_stats_instrumentation) |
| + : LayerTreeHostImpl(settings, |
| + client, |
| + proxy, |
| + rendering_stats_instrumentation) {} |
| + |
| + |
| + virtual base::TimeTicks CurrentPhysicalTimeTicks() const OVERRIDE { |
| + return fake_current_physical_time_; |
| + } |
| + |
| + void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) { |
| + fake_current_physical_time_ = fake_now; |
| + } |
| + |
| + private: |
| + base::TimeTicks fake_current_physical_time_; |
| +}; |
| + |
| +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_ = make_scoped_ptr(new LayerTreeHostImplOverridePhysicalTime( |
| + settings, this, &proxy_, &stats_instrumentation_)) |
| + .PassAs<LayerTreeHostImpl>(); |
| + LayerTreeHostImplOverridePhysicalTime* host_impl_override_time = |
|
danakj
2013/06/14 21:25:23
nit: you could save the raw pointer before making
aelias_OOO_until_Jul13
2013/06/14 22:19:02
Done.
|
| + static_cast<LayerTreeHostImplOverridePhysicalTime*>(host_impl_.get()); |
| + 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(); |
| + host_impl_override_time->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. |
| + 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_override_time->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_override_time->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_override_time->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)); |