| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 5954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5965 EXPECT_EQ(0, set_needs_commit_count); | 5965 EXPECT_EQ(0, set_needs_commit_count); |
| 5966 EXPECT_EQ(2, set_needs_redraw_count); | 5966 EXPECT_EQ(2, set_needs_redraw_count); |
| 5967 } | 5967 } |
| 5968 } | 5968 } |
| 5969 | 5969 |
| 5970 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { | 5970 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { |
| 5971 public: | 5971 public: |
| 5972 virtual void SetUp() OVERRIDE { | 5972 virtual void SetUp() OVERRIDE { |
| 5973 LayerTreeSettings settings = DefaultSettings(); | 5973 LayerTreeSettings settings = DefaultSettings(); |
| 5974 settings.calculate_top_controls_position = true; | 5974 settings.calculate_top_controls_position = true; |
| 5975 settings.top_controls_height = top_controls_height_; |
| 5975 CreateHostImpl(settings, CreateOutputSurface()); | 5976 CreateHostImpl(settings, CreateOutputSurface()); |
| 5976 } | 5977 } |
| 5978 |
| 5979 protected: |
| 5980 static const int top_controls_height_; |
| 5977 }; | 5981 }; |
| 5978 | 5982 |
| 5983 const int LayerTreeHostImplWithTopControlsTest::top_controls_height_ = 50; |
| 5984 |
| 5979 TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) { | 5985 TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) { |
| 5980 SetupScrollAndContentsLayers(gfx::Size(100, 100)) | 5986 SetupScrollAndContentsLayers(gfx::Size(100, 100)) |
| 5981 ->SetScrollOffset(gfx::Vector2d(0, 10)); | 5987 ->SetScrollOffset(gfx::Vector2d(0, 10)); |
| 5982 host_impl_->Animate(base::TimeTicks(), base::Time()); | 5988 host_impl_->Animate(base::TimeTicks(), base::Time()); |
| 5983 EXPECT_FALSE(did_request_redraw_); | 5989 EXPECT_FALSE(did_request_redraw_); |
| 5984 } | 5990 } |
| 5985 | 5991 |
| 5992 TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) { |
| 5993 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
| 5994 host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 5995 DrawFrame(); |
| 5996 |
| 5997 EXPECT_EQ(InputHandler::ScrollStarted, |
| 5998 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 5999 EXPECT_EQ(0, host_impl_->top_controls_manager()->controls_top_offset()); |
| 6000 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 6001 scroll_layer->TotalScrollOffset().ToString()); |
| 6002 |
| 6003 // Scroll just the top controls and verify that the scroll succeeds. |
| 6004 const float residue = 10; |
| 6005 float offset = top_controls_height_ - residue; |
| 6006 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); |
| 6007 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->controls_top_offset()); |
| 6008 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 6009 scroll_layer->TotalScrollOffset().ToString()); |
| 6010 |
| 6011 // Scroll across the boundary |
| 6012 const float content_scroll = 20; |
| 6013 offset = residue + content_scroll; |
| 6014 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); |
| 6015 EXPECT_EQ(-top_controls_height_, |
| 6016 host_impl_->top_controls_manager()->controls_top_offset()); |
| 6017 EXPECT_EQ(gfx::Vector2dF(0, content_scroll).ToString(), |
| 6018 scroll_layer->TotalScrollOffset().ToString()); |
| 6019 |
| 6020 // Now scroll back to the top of the content |
| 6021 offset = -content_scroll; |
| 6022 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); |
| 6023 EXPECT_EQ(-top_controls_height_, |
| 6024 host_impl_->top_controls_manager()->controls_top_offset()); |
| 6025 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 6026 scroll_layer->TotalScrollOffset().ToString()); |
| 6027 |
| 6028 // And scroll the top controls completely into view |
| 6029 offset = -top_controls_height_; |
| 6030 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); |
| 6031 EXPECT_EQ(0, host_impl_->top_controls_manager()->controls_top_offset()); |
| 6032 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 6033 scroll_layer->TotalScrollOffset().ToString()); |
| 6034 |
| 6035 // And attempt to scroll past the end |
| 6036 EXPECT_FALSE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); |
| 6037 EXPECT_EQ(0, host_impl_->top_controls_manager()->controls_top_offset()); |
| 6038 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 6039 scroll_layer->TotalScrollOffset().ToString()); |
| 6040 |
| 6041 host_impl_->ScrollEnd(); |
| 6042 } |
| 6043 |
| 5986 class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest { | 6044 class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest { |
| 5987 public: | 6045 public: |
| 5988 void SetupVirtualViewportLayers(const gfx::Size& content_size, | 6046 void SetupVirtualViewportLayers(const gfx::Size& content_size, |
| 5989 const gfx::Size& outer_viewport, | 6047 const gfx::Size& outer_viewport, |
| 5990 const gfx::Size& inner_viewport) { | 6048 const gfx::Size& inner_viewport) { |
| 5991 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); | 6049 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); |
| 5992 const int kOuterViewportClipLayerId = 6; | 6050 const int kOuterViewportClipLayerId = 6; |
| 5993 const int kOuterViewportScrollLayerId = 7; | 6051 const int kOuterViewportScrollLayerId = 7; |
| 5994 const int kInnerViewportScrollLayerId = 2; | 6052 const int kInnerViewportScrollLayerId = 2; |
| 5995 const int kInnerViewportClipLayerId = 4; | 6053 const int kInnerViewportClipLayerId = 4; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6117 EXPECT_EQ(host_impl_->global_tile_state().hard_memory_limit_in_bytes, | 6175 EXPECT_EQ(host_impl_->global_tile_state().hard_memory_limit_in_bytes, |
| 6118 300u * 1024u * 1024u); | 6176 300u * 1024u * 1024u); |
| 6119 EXPECT_EQ(host_impl_->global_tile_state().soft_memory_limit_in_bytes, | 6177 EXPECT_EQ(host_impl_->global_tile_state().soft_memory_limit_in_bytes, |
| 6120 150u * 1024u * 1024u); | 6178 150u * 1024u * 1024u); |
| 6121 EXPECT_EQ(host_impl_->global_tile_state().unused_memory_limit_in_bytes, | 6179 EXPECT_EQ(host_impl_->global_tile_state().unused_memory_limit_in_bytes, |
| 6122 75u * 1024u * 1024u); | 6180 75u * 1024u * 1024u); |
| 6123 } | 6181 } |
| 6124 | 6182 |
| 6125 } // namespace | 6183 } // namespace |
| 6126 } // namespace cc | 6184 } // namespace cc |
| OLD | NEW |