Upstream version 11.39.250.0
[platform/framework/web/crosswalk.git] / src / cc / trees / layer_tree_host_impl_unittest.cc
index 85e6a91..5315101 100644 (file)
@@ -13,6 +13,7 @@
 #include "cc/animation/scrollbar_animation_controller_thinning.h"
 #include "cc/base/latency_info_swap_promise.h"
 #include "cc/base/math_util.h"
+#include "cc/input/page_scale_animation.h"
 #include "cc/input/top_controls_manager.h"
 #include "cc/layers/append_quads_data.h"
 #include "cc/layers/delegated_renderer_layer_impl.h"
@@ -516,6 +517,20 @@ TEST_F(LayerTreeHostImplTest, ScrollRootCallsCommitAndRedraw) {
   EXPECT_TRUE(did_request_commit_);
 }
 
+TEST_F(LayerTreeHostImplTest, ScrollActiveOnlyAfterScrollMovement) {
+  SetupScrollAndContentsLayers(gfx::Size(100, 100));
+  host_impl_->SetViewportSize(gfx::Size(50, 50));
+  DrawFrame();
+
+  EXPECT_EQ(InputHandler::ScrollStarted,
+            host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel));
+  EXPECT_FALSE(host_impl_->IsActivelyScrolling());
+  host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10));
+  EXPECT_TRUE(host_impl_->IsActivelyScrolling());
+  host_impl_->ScrollEnd();
+  EXPECT_FALSE(host_impl_->IsActivelyScrolling());
+}
+
 TEST_F(LayerTreeHostImplTest, ScrollWithoutRootLayer) {
   // We should not crash when trying to scroll an empty layer tree.
   EXPECT_EQ(InputHandler::ScrollIgnored,
@@ -1159,7 +1174,9 @@ TEST_F(LayerTreeHostImplTest, PageScaleAnimation) {
 
     did_request_redraw_ = false;
     did_request_animate_ = false;
-    host_impl_->StartPageScaleAnimation(gfx::Vector2d(), false, 2.f, duration);
+    host_impl_->active_tree()->SetPageScaleAnimation(
+        gfx::Vector2d(), false, 2.f, duration);
+    host_impl_->ActivateSyncTree();
     EXPECT_FALSE(did_request_redraw_);
     EXPECT_TRUE(did_request_animate_);
 
@@ -1197,8 +1214,9 @@ TEST_F(LayerTreeHostImplTest, PageScaleAnimation) {
 
     did_request_redraw_ = false;
     did_request_animate_ = false;
-    host_impl_->StartPageScaleAnimation(
+    host_impl_->active_tree()->SetPageScaleAnimation(
         gfx::Vector2d(25, 25), true, min_page_scale, duration);
+    host_impl_->ActivateSyncTree();
     EXPECT_FALSE(did_request_redraw_);
     EXPECT_TRUE(did_request_animate_);
 
@@ -1247,7 +1265,9 @@ TEST_F(LayerTreeHostImplTest, PageScaleAnimationNoOp) {
                                                            max_page_scale);
     scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50));
 
-    host_impl_->StartPageScaleAnimation(gfx::Vector2d(), true, 1.f, duration);
+    host_impl_->active_tree()->SetPageScaleAnimation(
+        gfx::Vector2d(), true, 1.f, duration);
+    host_impl_->ActivateSyncTree();
     host_impl_->Animate(start_time);
     host_impl_->Animate(halfway_through_animation);
     EXPECT_TRUE(did_request_redraw_);
@@ -1261,6 +1281,92 @@ TEST_F(LayerTreeHostImplTest, PageScaleAnimationNoOp) {
   }
 }
 
+TEST_F(LayerTreeHostImplTest, PageScaleAnimationTransferedOnSyncTreeActivate) {
+  host_impl_->CreatePendingTree();
+  CreateScrollAndContentsLayers(host_impl_->pending_tree(),
+                                gfx::Size(100, 100));
+  host_impl_->ActivateSyncTree();
+  DrawFrame();
+
+  LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer();
+  DCHECK(scroll_layer);
+
+  float min_page_scale = 0.5f;
+  float max_page_scale = 4.f;
+  host_impl_->sync_tree()->SetPageScaleFactorAndLimits(
+      1.f, min_page_scale, max_page_scale);
+  host_impl_->ActivateSyncTree();
+
+  base::TimeTicks start_time =
+      base::TimeTicks() + base::TimeDelta::FromSeconds(1);
+  base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100);
+  base::TimeTicks third_through_animation = start_time + duration / 3;
+  base::TimeTicks halfway_through_animation = start_time + duration / 2;
+  base::TimeTicks end_time = start_time + duration;
+  float target_scale = 2.f;
+
+  scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50));
+
+  // Make sure TakePageScaleAnimation works properly.
+  host_impl_->sync_tree()->SetPageScaleAnimation(
+      gfx::Vector2d(), false, target_scale, duration);
+  scoped_ptr<PageScaleAnimation> psa =
+      host_impl_->sync_tree()->TakePageScaleAnimation();
+  EXPECT_EQ(target_scale, psa->target_page_scale_factor());
+  EXPECT_EQ(duration, psa->duration());
+  EXPECT_EQ(nullptr, host_impl_->sync_tree()->TakePageScaleAnimation());
+
+  // Recreate the PSA. Nothing should happen here since the tree containing the
+  // PSA hasn't been activated yet.
+  did_request_redraw_ = false;
+  did_request_animate_ = false;
+  host_impl_->sync_tree()->SetPageScaleAnimation(
+      gfx::Vector2d(), false, target_scale, duration);
+  host_impl_->Animate(halfway_through_animation);
+  EXPECT_FALSE(did_request_animate_);
+  EXPECT_FALSE(did_request_redraw_);
+
+  // Activate the sync tree. This should cause the animation to become enabled.
+  // It should also clear the pointer on the sync tree.
+  host_impl_->ActivateSyncTree();
+  EXPECT_EQ(nullptr, host_impl_->sync_tree()->TakePageScaleAnimation().get());
+  EXPECT_FALSE(did_request_redraw_);
+  EXPECT_TRUE(did_request_animate_);
+
+  // From here on, make sure the animation runs as normal.
+  did_request_redraw_ = false;
+  did_request_animate_ = false;
+  host_impl_->Animate(start_time);
+  EXPECT_TRUE(did_request_redraw_);
+  EXPECT_TRUE(did_request_animate_);
+
+  did_request_redraw_ = false;
+  did_request_animate_ = false;
+  host_impl_->Animate(third_through_animation);
+  EXPECT_TRUE(did_request_redraw_);
+  EXPECT_TRUE(did_request_animate_);
+
+  // Another activation shouldn't have any effect on the animation.
+  host_impl_->ActivateSyncTree();
+
+  did_request_redraw_ = false;
+  did_request_animate_ = false;
+  host_impl_->Animate(halfway_through_animation);
+  EXPECT_TRUE(did_request_redraw_);
+  EXPECT_TRUE(did_request_animate_);
+
+  did_request_redraw_ = false;
+  did_request_animate_ = false;
+  did_request_commit_ = false;
+  host_impl_->Animate(end_time);
+  EXPECT_TRUE(did_request_commit_);
+  EXPECT_FALSE(did_request_animate_);
+
+  scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas();
+  EXPECT_EQ(scroll_info->page_scale_delta, target_scale);
+  ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50));
+}
+
 class LayerTreeHostImplOverridePhysicalTime : public LayerTreeHostImpl {
  public:
   LayerTreeHostImplOverridePhysicalTime(
@@ -2156,8 +2262,6 @@ class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest {
   }
 
   void SetupTopControlsAndScrollLayer() {
-    CreateHostImpl(settings_, CreateOutputSurface());
-
     scoped_ptr<LayerImpl> root =
         LayerImpl::Create(host_impl_->active_tree(), 1);
     scoped_ptr<LayerImpl> root_clip =
@@ -2180,8 +2284,6 @@ class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest {
     host_impl_->SetViewportSize(viewport_size_);
     host_impl_->SetTopControlsLayoutHeight(
         settings_.top_controls_height);
-    LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer();
-    EXPECT_EQ(clip_size_, root_clip_ptr->bounds());
 
     host_impl_->CreatePendingTree();
     root =
@@ -2206,8 +2308,6 @@ class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest {
     host_impl_->SetViewportSize(viewport_size_);
     host_impl_->sync_tree()->set_top_controls_layout_height(
         settings_.top_controls_height);
-    root_clip_ptr = host_impl_->sync_tree()->root_layer();
-    EXPECT_EQ(clip_size_, root_clip_ptr->bounds());
   }
 
  protected:
@@ -2219,6 +2319,7 @@ class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest {
 };  // class LayerTreeHostImplTopControlsTest
 
 TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) {
+  CreateHostImpl(settings_, CreateOutputSurface());
   SetupTopControlsAndScrollLayer();
   DrawFrame();
 
@@ -2242,6 +2343,7 @@ TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) {
 }
 
 TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsWithPageScale) {
+  CreateHostImpl(settings_, CreateOutputSurface());
   SetupTopControlsAndScrollLayer();
   DrawFrame();
 
@@ -2275,6 +2377,7 @@ TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsWithPageScale) {
 // Ensure setting the top controls position explicitly using the setters on the
 // TreeImpl correctly affects the top controls manager and viewport bounds.
 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) {
+  CreateHostImpl(settings_, CreateOutputSurface());
   SetupTopControlsAndScrollLayer();
   DrawFrame();
 
@@ -2298,6 +2401,7 @@ TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) {
 // applied on sync tree activation. The total top controls offset shouldn't
 // change after the activation.
 TEST_F(LayerTreeHostImplTopControlsTest, ApplyDeltaOnTreeActivation) {
+  CreateHostImpl(settings_, CreateOutputSurface());
   SetupTopControlsAndScrollLayer();
   DrawFrame();
 
@@ -2332,6 +2436,7 @@ TEST_F(LayerTreeHostImplTopControlsTest, ApplyDeltaOnTreeActivation) {
 // height is the amount that the inner viewport container was shrunk outside
 // the compositor to accommodate the top controls.
 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) {
+  CreateHostImpl(settings_, CreateOutputSurface());
   SetupTopControlsAndScrollLayer();
   DrawFrame();
 
@@ -2373,6 +2478,7 @@ TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) {
 
 TEST_F(LayerTreeHostImplTopControlsTest,
        ScrollNonScrollableRootWithTopControls) {
+  CreateHostImpl(settings_, CreateOutputSurface());
   SetupTopControlsAndScrollLayer();
   DrawFrame();