Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / cc / animation / scrollbar_animation_controller_thinning_unittest.cc
index 383ce22..c0ab515 100644 (file)
 namespace cc {
 namespace {
 
-class ScrollbarAnimationControllerThinningTest : public testing::Test {
+class ScrollbarAnimationControllerThinningTest
+    : public testing::Test,
+      public ScrollbarAnimationControllerClient {
  public:
   ScrollbarAnimationControllerThinningTest()
       : host_impl_(&proxy_, &shared_bitmap_manager_) {}
 
+  virtual void PostDelayedScrollbarFade(const base::Closure& start_fade,
+                                        base::TimeDelta delay) OVERRIDE {
+    start_fade_ = start_fade;
+  }
+  virtual void SetNeedsScrollbarAnimationFrame() OVERRIDE {}
+
  protected:
   virtual void SetUp() {
     scoped_ptr<LayerImpl> scroll_layer =
@@ -29,6 +37,7 @@ class ScrollbarAnimationControllerThinningTest : public testing::Test {
 
     const int kId = 2;
     const int kThumbThickness = 10;
+    const int kTrackStart = 0;
     const bool kIsLeftSideVerticalScrollbar = false;
     const bool kIsOverlayScrollbar = true;
     scrollbar_layer_ =
@@ -36,6 +45,7 @@ class ScrollbarAnimationControllerThinningTest : public testing::Test {
                                              kId,
                                              HORIZONTAL,
                                              kThumbThickness,
+                                             kTrackStart,
                                              kIsLeftSideVerticalScrollbar,
                                              kIsOverlayScrollbar);
 
@@ -44,8 +54,9 @@ class ScrollbarAnimationControllerThinningTest : public testing::Test {
     clip_layer_->SetBounds(gfx::Size(100, 100));
     scroll_layer_ptr->SetBounds(gfx::Size(50, 50));
 
-    scrollbar_controller_ = ScrollbarAnimationControllerThinning::CreateForTest(
+    scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create(
         scroll_layer_ptr,
+        this,
         base::TimeDelta::FromSeconds(2),
         base::TimeDelta::FromSeconds(3));
   }
@@ -56,6 +67,8 @@ class ScrollbarAnimationControllerThinningTest : public testing::Test {
   scoped_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_;
   scoped_ptr<LayerImpl> clip_layer_;
   scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar_layer_;
+
+  base::Closure start_fade_;
 };
 
 // Check initialization of scrollbar.
@@ -70,31 +83,24 @@ TEST_F(ScrollbarAnimationControllerThinningTest, Idle) {
 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());
+  scrollbar_controller_->DidScrollUpdate();
   EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
   // Scrollbar doesn't change size if triggered by scroll.
   EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
 
+  start_fade_.Run();
+
   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());
 
   // Subsequent scroll restarts animation.
-  EXPECT_TRUE(scrollbar_controller_->DidScrollUpdate(time));
-  EXPECT_EQ(2, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
+  scrollbar_controller_->DidScrollUpdate();
 
-  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());
+  start_fade_.Run();
 
-  time += base::TimeDelta::FromSeconds(1);
-  EXPECT_EQ(0, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
+  time += base::TimeDelta::FromSeconds(2);
   scrollbar_controller_->Animate(time);
   EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
   EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
@@ -113,8 +119,6 @@ TEST_F(ScrollbarAnimationControllerThinningTest, AwakenByProgrammaticScroll) {
   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());
 }
 
 // Initiate a scroll when the pointer is already near the scrollbar. It should
@@ -123,22 +127,22 @@ TEST_F(ScrollbarAnimationControllerThinningTest, ScrollWithMouseNear) {
   base::TimeTicks time;
   time += base::TimeDelta::FromSeconds(1);
 
-  scrollbar_controller_->DidMouseMoveNear(time, 1);
+  scrollbar_controller_->DidMouseMoveNear(1);
+  scrollbar_controller_->Animate(time);
   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());
+  scrollbar_controller_->DidScrollUpdate();
+  start_fade_.Run();
+  scrollbar_controller_->Animate(time);
   EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
   // Scrollbar should still be thick.
   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());
 }
@@ -148,9 +152,8 @@ TEST_F(ScrollbarAnimationControllerThinningTest, ScrollWithMouseNear) {
 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());
+  scrollbar_controller_->DidMouseMoveNear(1);
+  scrollbar_controller_->Animate(time);
   EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
   EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
 
@@ -169,19 +172,17 @@ TEST_F(ScrollbarAnimationControllerThinningTest, MouseNear) {
   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());
 
   // Subsequent moves should not change anything.
-  scrollbar_controller_->DidMouseMoveNear(time, 1);
+  scrollbar_controller_->DidMouseMoveNear(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());
 
   // Now move away from bar.
   time += base::TimeDelta::FromSeconds(1);
-  scrollbar_controller_->DidMouseMoveNear(time, 26);
-  EXPECT_TRUE(scrollbar_controller_->IsAnimating());
-  EXPECT_EQ(0, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
+  scrollbar_controller_->DidMouseMoveNear(26);
+  scrollbar_controller_->Animate(time);
   EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
   EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
 
@@ -200,7 +201,6 @@ TEST_F(ScrollbarAnimationControllerThinningTest, MouseNear) {
   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());
 }
 
 // Move the pointer over the scrollbar. Make sure it gets thick and dark
@@ -208,9 +208,8 @@ TEST_F(ScrollbarAnimationControllerThinningTest, MouseNear) {
 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());
+  scrollbar_controller_->DidMouseMoveNear(0);
+  scrollbar_controller_->Animate(time);
   EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
   EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
 
@@ -229,19 +228,17 @@ TEST_F(ScrollbarAnimationControllerThinningTest, MouseOver) {
   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());
 
   // Subsequent moves should not change anything.
-  scrollbar_controller_->DidMouseMoveNear(time, 0);
+  scrollbar_controller_->DidMouseMoveNear(0);
+  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());
 
   // Now move away from bar.
   time += base::TimeDelta::FromSeconds(1);
-  scrollbar_controller_->DidMouseMoveNear(time, 26);
-  EXPECT_TRUE(scrollbar_controller_->IsAnimating());
-  EXPECT_EQ(0, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
+  scrollbar_controller_->DidMouseMoveNear(26);
+  scrollbar_controller_->Animate(time);
   EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
   EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
 
@@ -260,7 +257,6 @@ TEST_F(ScrollbarAnimationControllerThinningTest, MouseOver) {
   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());
 }
 
 // First move the pointer near the scrollbar, then over it, then back near
@@ -269,9 +265,8 @@ TEST_F(ScrollbarAnimationControllerThinningTest, MouseOver) {
 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());
+  scrollbar_controller_->DidMouseMoveNear(1);
+  scrollbar_controller_->Animate(time);
   EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity());
   EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
 
@@ -280,12 +275,10 @@ TEST_F(ScrollbarAnimationControllerThinningTest, MouseNearThenOver) {
   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());
 
   // Now move over.
-  scrollbar_controller_->DidMouseMoveNear(time, 0);
-  EXPECT_TRUE(scrollbar_controller_->IsAnimating());
-  EXPECT_EQ(0, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
+  scrollbar_controller_->DidMouseMoveNear(0);
+  scrollbar_controller_->Animate(time);
 
   // Should animate to darkened.
   time += base::TimeDelta::FromSeconds(1);
@@ -302,24 +295,23 @@ TEST_F(ScrollbarAnimationControllerThinningTest, MouseNearThenOver) {
   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());
 
   // This is tricky. The DidMouseMoveOffScrollbar() is sent before the
   // subsequent DidMouseMoveNear(), if the mouse moves in that direction.
   // This results in the thumb thinning. We want to make sure that when the
   // thumb starts expanding it doesn't first narrow to the idle thinness.
   time += base::TimeDelta::FromSeconds(1);
-  scrollbar_controller_->DidMouseMoveOffScrollbar(time);
-  EXPECT_TRUE(scrollbar_controller_->IsAnimating());
+  scrollbar_controller_->DidMouseMoveOffScrollbar();
+  scrollbar_controller_->Animate(time);
 
   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);
+  scrollbar_controller_->DidMouseMoveNear(1);
+  scrollbar_controller_->Animate(time);
   // A new animation is kicked off.
-  EXPECT_TRUE(scrollbar_controller_->IsAnimating());
 
   time += base::TimeDelta::FromSeconds(1);
   scrollbar_controller_->Animate(time);