This source file includes following definitions.
- SetUp
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "cc/animation/scrollbar_animation_controller_thinning.h"
#include "cc/layers/solid_color_scrollbar_layer_impl.h"
#include "cc/test/fake_impl_proxy.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/test_shared_bitmap_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
namespace {
class ScrollbarAnimationControllerThinningTest : public testing::Test {
public:
ScrollbarAnimationControllerThinningTest()
: host_impl_(&proxy_, &shared_bitmap_manager_) {}
protected:
virtual void SetUp() {
scoped_ptr<LayerImpl> scroll_layer =
LayerImpl::Create(host_impl_.active_tree(), 1);
clip_layer_ = LayerImpl::Create(host_impl_.active_tree(), 3);
scroll_layer->SetScrollClipLayer(clip_layer_->id());
LayerImpl* scroll_layer_ptr = scroll_layer.get();
clip_layer_->AddChild(scroll_layer.Pass());
const int kId = 2;
const int kThumbThickness = 10;
const bool kIsLeftSideVerticalScrollbar = false;
const bool kIsOverlayScrollbar = true;
scrollbar_layer_ =
SolidColorScrollbarLayerImpl::Create(host_impl_.active_tree(),
kId,
HORIZONTAL,
kThumbThickness,
kIsLeftSideVerticalScrollbar,
kIsOverlayScrollbar);
scrollbar_layer_->SetClipLayerById(clip_layer_->id());
scrollbar_layer_->SetScrollLayerById(scroll_layer_ptr->id());
clip_layer_->SetBounds(gfx::Size(100, 100));
scroll_layer_ptr->SetBounds(gfx::Size(50, 50));
scrollbar_controller_ = ScrollbarAnimationControllerThinning::CreateForTest(
scroll_layer_ptr,
base::TimeDelta::FromSeconds(2),
base::TimeDelta::FromSeconds(3));
}
FakeImplProxy proxy_;
TestSharedBitmapManager shared_bitmap_manager_;
FakeLayerTreeHostImpl host_impl_;
scoped_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_;
scoped_ptr<LayerImpl> clip_layer_;
scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar_layer_;
};
TEST_F(ScrollbarAnimationControllerThinningTest, Idle) {
scrollbar_controller_->Animate(base::TimeTicks());
EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
}
TEST_F(ScrollbarAnimationControllerThinningTest, AwakenByProgrammaticScroll) {
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
EXPECT_TRUE(scrollbar_controller_->DidScrollUpdate(time));
EXPECT_TRUE(scrollbar_controller_->IsAnimating());
EXPECT_EQ(2, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
EXPECT_EQ(1, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
EXPECT_TRUE(scrollbar_controller_->DidScrollUpdate(time));
EXPECT_EQ(2, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
time += base::TimeDelta::FromSeconds(1);
EXPECT_EQ(1, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
EXPECT_EQ(0, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
EXPECT_FALSE(scrollbar_controller_->IsAnimating());
}
TEST_F(ScrollbarAnimationControllerThinningTest, ScrollWithMouseNear) {
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->DidMouseMoveNear(time, 1);
time += base::TimeDelta::FromSeconds(3);
scrollbar_controller_->Animate(time);
EXPECT_FALSE(scrollbar_controller_->IsAnimating());
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
EXPECT_TRUE(scrollbar_controller_->DidScrollUpdate(time));
EXPECT_TRUE(scrollbar_controller_->IsAnimating());
EXPECT_EQ(2, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(5);
scrollbar_controller_->Animate(time);
EXPECT_FALSE(scrollbar_controller_->IsAnimating());
EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
}
TEST_F(ScrollbarAnimationControllerThinningTest, MouseNear) {
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->DidMouseMoveNear(time, 1);
EXPECT_TRUE(scrollbar_controller_->IsAnimating());
EXPECT_EQ(0, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.6f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
EXPECT_FALSE(scrollbar_controller_->IsAnimating());
scrollbar_controller_->DidMouseMoveNear(time, 1);
EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
EXPECT_FALSE(scrollbar_controller_->IsAnimating());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->DidMouseMoveNear(time, 26);
EXPECT_TRUE(scrollbar_controller_->IsAnimating());
EXPECT_EQ(0, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.6f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
EXPECT_FALSE(scrollbar_controller_->IsAnimating());
}
TEST_F(ScrollbarAnimationControllerThinningTest, MouseOver) {
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->DidMouseMoveNear(time, 0);
EXPECT_TRUE(scrollbar_controller_->IsAnimating());
EXPECT_EQ(0, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.6f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
EXPECT_FALSE(scrollbar_controller_->IsAnimating());
scrollbar_controller_->DidMouseMoveNear(time, 0);
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
EXPECT_FALSE(scrollbar_controller_->IsAnimating());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->DidMouseMoveNear(time, 26);
EXPECT_TRUE(scrollbar_controller_->IsAnimating());
EXPECT_EQ(0, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.6f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
EXPECT_FALSE(scrollbar_controller_->IsAnimating());
}
TEST_F(ScrollbarAnimationControllerThinningTest, MouseNearThenOver) {
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->DidMouseMoveNear(time, 1);
EXPECT_TRUE(scrollbar_controller_->IsAnimating());
EXPECT_EQ(0, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(3);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
EXPECT_FALSE(scrollbar_controller_->IsAnimating());
scrollbar_controller_->DidMouseMoveNear(time, 0);
EXPECT_TRUE(scrollbar_controller_->IsAnimating());
EXPECT_EQ(0, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
EXPECT_FALSE(scrollbar_controller_->IsAnimating());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->DidMouseMoveOffScrollbar(time);
EXPECT_TRUE(scrollbar_controller_->IsAnimating());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor());
scrollbar_controller_->DidMouseMoveNear(time, 1);
EXPECT_TRUE(scrollbar_controller_->IsAnimating());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor());
time += base::TimeDelta::FromSeconds(1);
scrollbar_controller_->Animate(time);
EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
}
}
}