| 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 110bee999392e7e66db813e375deca2ff781de9b..1e8595c8727c411d2db26928952b98ff2aa219b4 100644
|
| --- a/cc/trees/layer_tree_host_impl_unittest.cc
|
| +++ b/cc/trees/layer_tree_host_impl_unittest.cc
|
| @@ -1563,192 +1563,160 @@ class LayerTreeHostImplOverridePhysicalTime : public LayerTreeHostImpl {
|
| base::TimeTicks fake_current_physical_time_;
|
| };
|
|
|
| -#define SETUP_LAYERS_FOR_SCROLLBAR_ANIMATION_TEST() \
|
| - gfx::Size viewport_size(10, 10); \
|
| - gfx::Size content_size(100, 100); \
|
| - \
|
| - LayerTreeHostImplOverridePhysicalTime* host_impl_override_time = \
|
| - new LayerTreeHostImplOverridePhysicalTime(settings, this, &proxy_, \
|
| - shared_bitmap_manager_.get(), \
|
| - &stats_instrumentation_); \
|
| - host_impl_ = make_scoped_ptr(host_impl_override_time); \
|
| - host_impl_->InitializeRenderer(CreateOutputSurface()); \
|
| - host_impl_->SetViewportSize(viewport_size); \
|
| - \
|
| - scoped_ptr<LayerImpl> root = \
|
| - LayerImpl::Create(host_impl_->active_tree(), 1); \
|
| - root->SetBounds(viewport_size); \
|
| - \
|
| - scoped_ptr<LayerImpl> scroll = \
|
| - LayerImpl::Create(host_impl_->active_tree(), 2); \
|
| - scroll->SetScrollClipLayer(root->id()); \
|
| - scroll->PushScrollOffsetFromMainThread(gfx::ScrollOffset()); \
|
| - root->SetBounds(viewport_size); \
|
| - scroll->SetBounds(content_size); \
|
| - scroll->SetContentBounds(content_size); \
|
| - scroll->SetIsContainerForFixedPositionLayers(true); \
|
| - \
|
| - scoped_ptr<LayerImpl> contents = \
|
| - LayerImpl::Create(host_impl_->active_tree(), 3); \
|
| - contents->SetDrawsContent(true); \
|
| - contents->SetBounds(content_size); \
|
| - contents->SetContentBounds(content_size); \
|
| - \
|
| - scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar = \
|
| - SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 4, \
|
| - VERTICAL, 10, 0, false, true); \
|
| - EXPECT_FLOAT_EQ(0.f, scrollbar->opacity()); \
|
| - \
|
| - scroll->AddChild(contents.Pass()); \
|
| - root->AddChild(scroll.Pass()); \
|
| - root->SetHasRenderSurface(true); \
|
| - scrollbar->SetScrollLayerAndClipLayerByIds(2, 1); \
|
| - root->AddChild(scrollbar.Pass()); \
|
| - \
|
| - host_impl_->active_tree()->SetRootLayer(root.Pass()); \
|
| - host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 2, \
|
| - Layer::INVALID_ID); \
|
| - host_impl_->active_tree()->DidBecomeActive(); \
|
| - DrawFrame();
|
| -
|
| -TEST_F(LayerTreeHostImplTest, ScrollbarLinearFadeScheduling) {
|
| - LayerTreeSettings settings;
|
| - settings.scrollbar_animator = LayerTreeSettings::LINEAR_FADE;
|
| - settings.scrollbar_fade_delay_ms = 20;
|
| - settings.scrollbar_fade_duration_ms = 20;
|
| -
|
| - SETUP_LAYERS_FOR_SCROLLBAR_ANIMATION_TEST();
|
| -
|
| - base::TimeTicks fake_now = gfx::FrameTime::Now();
|
| +class LayerTreeHostImplTestScrollbarAnimation : public LayerTreeHostImplTest {
|
| + protected:
|
| + void SetupLayers(LayerTreeSettings settings) {
|
| + gfx::Size viewport_size(10, 10);
|
| + gfx::Size content_size(100, 100);
|
| +
|
| + LayerTreeHostImplOverridePhysicalTime* host_impl_override_time =
|
| + new LayerTreeHostImplOverridePhysicalTime(settings, this, &proxy_,
|
| + shared_bitmap_manager_.get(),
|
| + &stats_instrumentation_);
|
| + host_impl_ = make_scoped_ptr(host_impl_override_time);
|
| + host_impl_->InitializeRenderer(CreateOutputSurface());
|
| + host_impl_->SetViewportSize(viewport_size);
|
|
|
| - EXPECT_FALSE(did_request_animate_);
|
| - EXPECT_FALSE(did_request_redraw_);
|
| - EXPECT_EQ(base::TimeDelta(), requested_animation_delay_);
|
| - EXPECT_TRUE(animation_task_.Equals(base::Closure()));
|
| + scoped_ptr<LayerImpl> root =
|
| + LayerImpl::Create(host_impl_->active_tree(), 1);
|
| + root->SetBounds(viewport_size);
|
|
|
| - // If no scroll happened during a scroll gesture, it should have no effect.
|
| - host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL);
|
| - host_impl_->ScrollEnd();
|
| - EXPECT_FALSE(did_request_animate_);
|
| - EXPECT_FALSE(did_request_redraw_);
|
| - EXPECT_EQ(base::TimeDelta(), requested_animation_delay_);
|
| - EXPECT_TRUE(animation_task_.Equals(base::Closure()));
|
| + scoped_ptr<LayerImpl> scroll =
|
| + LayerImpl::Create(host_impl_->active_tree(), 2);
|
| + scroll->SetScrollClipLayer(root->id());
|
| + scroll->PushScrollOffsetFromMainThread(gfx::ScrollOffset());
|
| + root->SetBounds(viewport_size);
|
| + scroll->SetBounds(content_size);
|
| + scroll->SetContentBounds(content_size);
|
| + scroll->SetIsContainerForFixedPositionLayers(true);
|
|
|
| - // After a scroll, a fade animation should be scheduled about 20ms from now.
|
| - host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL);
|
| - host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0, 5));
|
| - EXPECT_FALSE(did_request_animate_);
|
| - EXPECT_TRUE(did_request_redraw_);
|
| - did_request_redraw_ = false;
|
| - EXPECT_EQ(base::TimeDelta(), requested_animation_delay_);
|
| - EXPECT_TRUE(animation_task_.Equals(base::Closure()));
|
| + scoped_ptr<LayerImpl> contents =
|
| + LayerImpl::Create(host_impl_->active_tree(), 3);
|
| + contents->SetDrawsContent(true);
|
| + contents->SetBounds(content_size);
|
| + contents->SetContentBounds(content_size);
|
|
|
| - host_impl_->ScrollEnd();
|
| - EXPECT_FALSE(did_request_animate_);
|
| - EXPECT_FALSE(did_request_redraw_);
|
| - EXPECT_EQ(base::TimeDelta::FromMilliseconds(20), requested_animation_delay_);
|
| - EXPECT_FALSE(animation_task_.Equals(base::Closure()));
|
| + scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar =
|
| + SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 4,
|
| + VERTICAL, 10, 0, false, true);
|
| + EXPECT_FLOAT_EQ(0.f, scrollbar->opacity());
|
|
|
| - fake_now += requested_animation_delay_;
|
| - requested_animation_delay_ = base::TimeDelta();
|
| - animation_task_.Run();
|
| - animation_task_ = base::Closure();
|
| - EXPECT_TRUE(did_request_animate_);
|
| - did_request_animate_ = false;
|
| - EXPECT_FALSE(did_request_redraw_);
|
| + scroll->AddChild(contents.Pass());
|
| + root->AddChild(scroll.Pass());
|
| + root->SetHasRenderSurface(true);
|
| + scrollbar->SetScrollLayerAndClipLayerByIds(2, 1);
|
| + root->AddChild(scrollbar.Pass());
|
|
|
| - // After the fade begins, we should start getting redraws instead of a
|
| - // scheduled animation.
|
| - host_impl_->Animate(fake_now);
|
| - EXPECT_TRUE(did_request_animate_);
|
| - did_request_animate_ = false;
|
| - EXPECT_TRUE(did_request_redraw_);
|
| - did_request_redraw_ = false;
|
| - EXPECT_EQ(base::TimeDelta(), requested_animation_delay_);
|
| - EXPECT_TRUE(animation_task_.Equals(base::Closure()));
|
| + host_impl_->active_tree()->SetRootLayer(root.Pass());
|
| + host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 2,
|
| + Layer::INVALID_ID);
|
| + host_impl_->active_tree()->DidBecomeActive();
|
| + DrawFrame();
|
| + }
|
|
|
| - // Setting the scroll offset outside a scroll should also cause the scrollbar
|
| - // to appear and to schedule a fade.
|
| - host_impl_->InnerViewportScrollLayer()->PushScrollOffsetFromMainThread(
|
| - gfx::ScrollOffset(5, 5));
|
| - EXPECT_FALSE(did_request_animate_);
|
| - EXPECT_FALSE(did_request_redraw_);
|
| - EXPECT_EQ(base::TimeDelta::FromMilliseconds(20), requested_animation_delay_);
|
| - EXPECT_FALSE(animation_task_.Equals(base::Closure()));
|
| - requested_animation_delay_ = base::TimeDelta();
|
| - animation_task_ = base::Closure();
|
| -
|
| - // Unnecessarily Fade animation of solid color scrollbar is not triggered.
|
| - host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL);
|
| - host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0));
|
| - EXPECT_FALSE(did_request_animate_);
|
| - EXPECT_TRUE(did_request_redraw_);
|
| - did_request_redraw_ = false;
|
| - EXPECT_EQ(base::TimeDelta(), requested_animation_delay_);
|
| - EXPECT_TRUE(animation_task_.Equals(base::Closure()));
|
| + void RunTest(LayerTreeSettings::ScrollbarAnimator animator) {
|
| + LayerTreeSettings settings;
|
| + settings.scrollbar_animator = animator;
|
| + settings.scrollbar_fade_delay_ms = 20;
|
| + settings.scrollbar_fade_duration_ms = 20;
|
|
|
| - host_impl_->ScrollEnd();
|
| - EXPECT_FALSE(did_request_animate_);
|
| - EXPECT_FALSE(did_request_redraw_);
|
| - EXPECT_EQ(base::TimeDelta(), requested_animation_delay_);
|
| - EXPECT_TRUE(animation_task_.Equals(base::Closure()));
|
| -}
|
| + SetupLayers(settings);
|
|
|
| -TEST_F(LayerTreeHostImplTest, ScrollbarFadePinchZoomScrollbars) {
|
| - LayerTreeSettings settings;
|
| - settings.scrollbar_animator = LayerTreeSettings::LINEAR_FADE;
|
| - settings.scrollbar_fade_delay_ms = 20;
|
| - settings.scrollbar_fade_duration_ms = 20;
|
| - settings.use_pinch_zoom_scrollbars = true;
|
| + base::TimeTicks fake_now = gfx::FrameTime::Now();
|
|
|
| - SETUP_LAYERS_FOR_SCROLLBAR_ANIMATION_TEST();
|
| + EXPECT_FALSE(did_request_animate_);
|
| + EXPECT_FALSE(did_request_redraw_);
|
| + EXPECT_EQ(base::TimeDelta(), requested_animation_delay_);
|
| + EXPECT_TRUE(animation_task_.Equals(base::Closure()));
|
|
|
| - base::TimeTicks fake_now = gfx::FrameTime::Now();
|
| + // If no scroll happened during a scroll gesture, it should have no effect.
|
| + host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL);
|
| + host_impl_->ScrollEnd();
|
| + EXPECT_FALSE(did_request_animate_);
|
| + EXPECT_FALSE(did_request_redraw_);
|
| + EXPECT_EQ(base::TimeDelta(), requested_animation_delay_);
|
| + EXPECT_TRUE(animation_task_.Equals(base::Closure()));
|
|
|
| - host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 4.f);
|
| + // After a scroll, a scrollbar animation should be scheduled about 20ms from
|
| + // now.
|
| + host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL);
|
| + host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0, 5));
|
| + EXPECT_FALSE(did_request_animate_);
|
| + EXPECT_TRUE(did_request_redraw_);
|
| + did_request_redraw_ = false;
|
| + EXPECT_EQ(base::TimeDelta(), requested_animation_delay_);
|
| + EXPECT_TRUE(animation_task_.Equals(base::Closure()));
|
|
|
| - EXPECT_EQ(base::TimeDelta(), requested_animation_delay_);
|
| - EXPECT_FALSE(did_request_animate_);
|
| + host_impl_->ScrollEnd();
|
| + EXPECT_FALSE(did_request_animate_);
|
| + EXPECT_FALSE(did_request_redraw_);
|
| + EXPECT_EQ(base::TimeDelta::FromMilliseconds(20),
|
| + requested_animation_delay_);
|
| + EXPECT_FALSE(animation_task_.Equals(base::Closure()));
|
| +
|
| + fake_now += requested_animation_delay_;
|
| + requested_animation_delay_ = base::TimeDelta();
|
| + animation_task_.Run();
|
| + animation_task_ = base::Closure();
|
| + EXPECT_TRUE(did_request_animate_);
|
| + did_request_animate_ = false;
|
| + EXPECT_FALSE(did_request_redraw_);
|
|
|
| - // If no scroll happened during a scroll gesture, it should have no effect.
|
| - host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL);
|
| - host_impl_->ScrollEnd();
|
| - EXPECT_EQ(base::TimeDelta(), requested_animation_delay_);
|
| - EXPECT_FALSE(did_request_animate_);
|
| - EXPECT_TRUE(animation_task_.Equals(base::Closure()));
|
| + // After the scrollbar animation begins, we should start getting redraws.
|
| + host_impl_->Animate(fake_now);
|
| + EXPECT_TRUE(did_request_animate_);
|
| + did_request_animate_ = false;
|
| + EXPECT_TRUE(did_request_redraw_);
|
| + did_request_redraw_ = false;
|
| + EXPECT_EQ(base::TimeDelta(), requested_animation_delay_);
|
| + EXPECT_TRUE(animation_task_.Equals(base::Closure()));
|
|
|
| - // After a scroll, no fade animation should be scheduled.
|
| - host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL);
|
| - host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0));
|
| - host_impl_->ScrollEnd();
|
| - did_request_redraw_ = false;
|
| - EXPECT_EQ(base::TimeDelta(), requested_animation_delay_);
|
| - EXPECT_FALSE(did_request_animate_);
|
| - requested_animation_delay_ = base::TimeDelta();
|
| + // Setting the scroll offset outside a scroll should also cause the
|
| + // scrollbar to appear and to schedule a scrollbar animation.
|
| + host_impl_->InnerViewportScrollLayer()->PushScrollOffsetFromMainThread(
|
| + gfx::ScrollOffset(5, 5));
|
| + EXPECT_FALSE(did_request_animate_);
|
| + EXPECT_FALSE(did_request_redraw_);
|
| + EXPECT_EQ(base::TimeDelta::FromMilliseconds(20),
|
| + requested_animation_delay_);
|
| + EXPECT_FALSE(animation_task_.Equals(base::Closure()));
|
| + requested_animation_delay_ = base::TimeDelta();
|
| + animation_task_ = base::Closure();
|
| +
|
| + // Scrollbar animation is not triggered unnecessarily.
|
| + host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL);
|
| + host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0));
|
| + EXPECT_FALSE(did_request_animate_);
|
| + EXPECT_TRUE(did_request_redraw_);
|
| + did_request_redraw_ = false;
|
| + EXPECT_EQ(base::TimeDelta(), requested_animation_delay_);
|
| + EXPECT_TRUE(animation_task_.Equals(base::Closure()));
|
|
|
| - // We should not see any draw requests.
|
| - fake_now += base::TimeDelta::FromMilliseconds(25);
|
| - EXPECT_EQ(base::TimeDelta(), requested_animation_delay_);
|
| - EXPECT_FALSE(did_request_animate_);
|
| + host_impl_->ScrollEnd();
|
| + EXPECT_FALSE(did_request_animate_);
|
| + EXPECT_FALSE(did_request_redraw_);
|
| + EXPECT_EQ(base::TimeDelta(), requested_animation_delay_);
|
| + EXPECT_TRUE(animation_task_.Equals(base::Closure()));
|
|
|
| - // Make page scale > min so that subsequent scrolls will trigger fades.
|
| - host_impl_->SetPageScaleOnActiveTree(1.1f);
|
| + // Changing page scale triggers scrollbar animation.
|
| + host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 4.f);
|
| + host_impl_->SetPageScaleOnActiveTree(1.1f);
|
| + EXPECT_FALSE(did_request_animate_);
|
| + EXPECT_FALSE(did_request_redraw_);
|
| + EXPECT_EQ(base::TimeDelta::FromMilliseconds(20),
|
| + requested_animation_delay_);
|
| + EXPECT_FALSE(animation_task_.Equals(base::Closure()));
|
| + requested_animation_delay_ = base::TimeDelta();
|
| + animation_task_ = base::Closure();
|
| + }
|
| +};
|
|
|
| - // After a scroll, a fade animation should be scheduled about 20ms from now.
|
| - host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL);
|
| - host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0));
|
| - host_impl_->ScrollEnd();
|
| - did_request_redraw_ = false;
|
| - EXPECT_LT(base::TimeDelta::FromMilliseconds(19), requested_animation_delay_);
|
| - EXPECT_FALSE(did_request_animate_);
|
| - requested_animation_delay_ = base::TimeDelta();
|
| - animation_task_.Run();
|
| +TEST_F(LayerTreeHostImplTestScrollbarAnimation, LinearFade) {
|
| + RunTest(LayerTreeSettings::LINEAR_FADE);
|
| +}
|
|
|
| - // After the fade begins, we should start getting redraws instead of a
|
| - // scheduled animation.
|
| - fake_now += base::TimeDelta::FromMilliseconds(25);
|
| - host_impl_->Animate(fake_now);
|
| - EXPECT_TRUE(did_request_animate_);
|
| +TEST_F(LayerTreeHostImplTestScrollbarAnimation, Thinning) {
|
| + RunTest(LayerTreeSettings::THINNING);
|
| }
|
|
|
| void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale(
|
|
|