1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/input/scroll_state.h"
7 #include "cc/layers/layer_impl.h"
8 #include "cc/test/fake_impl_proxy.h"
9 #include "cc/test/fake_layer_tree_host_impl.h"
10 #include "cc/test/test_shared_bitmap_manager.h"
11 #include "cc/test/test_task_graph_runner.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
17 class ScrollStateTest
: public testing::Test
{};
19 TEST_F(ScrollStateTest
, ConsumeDeltaNative
) {
20 const float delta_x
= 12.3f
;
21 const float delta_y
= 3.9f
;
23 const float delta_x_to_consume
= 1.2f
;
24 const float delta_y_to_consume
= 2.3f
;
26 ScrollState
scrollState(delta_x
, delta_y
, 0, 0, false /* should_propagate */,
27 false /* delta_consumed_for_scroll_sequence */,
28 false /* is_direct_manipulation */);
29 EXPECT_FLOAT_EQ(delta_x
, scrollState
.delta_x());
30 EXPECT_FLOAT_EQ(delta_y
, scrollState
.delta_y());
31 EXPECT_FALSE(scrollState
.delta_consumed_for_scroll_sequence());
32 EXPECT_FALSE(scrollState
.FullyConsumed());
34 scrollState
.ConsumeDelta(0, 0);
35 EXPECT_FLOAT_EQ(delta_x
, scrollState
.delta_x());
36 EXPECT_FLOAT_EQ(delta_y
, scrollState
.delta_y());
37 EXPECT_FALSE(scrollState
.delta_consumed_for_scroll_sequence());
38 EXPECT_FALSE(scrollState
.FullyConsumed());
40 scrollState
.ConsumeDelta(delta_x_to_consume
, 0);
41 EXPECT_FLOAT_EQ(delta_x
- delta_x_to_consume
, scrollState
.delta_x());
42 EXPECT_FLOAT_EQ(delta_y
, scrollState
.delta_y());
43 EXPECT_TRUE(scrollState
.delta_consumed_for_scroll_sequence());
44 EXPECT_FALSE(scrollState
.FullyConsumed());
46 scrollState
.ConsumeDelta(0, delta_y_to_consume
);
47 EXPECT_FLOAT_EQ(delta_x
- delta_x_to_consume
, scrollState
.delta_x());
48 EXPECT_FLOAT_EQ(delta_y
- delta_y_to_consume
, scrollState
.delta_y());
49 EXPECT_TRUE(scrollState
.delta_consumed_for_scroll_sequence());
50 EXPECT_FALSE(scrollState
.FullyConsumed());
52 scrollState
.ConsumeDelta(scrollState
.delta_x(), scrollState
.delta_y());
53 EXPECT_TRUE(scrollState
.delta_consumed_for_scroll_sequence());
54 EXPECT_TRUE(scrollState
.FullyConsumed());
57 TEST_F(ScrollStateTest
, CurrentNativeScrollingScrollable
) {
58 ScrollState
scrollState(0, 0, 0, 0, false, false, false);
61 TestSharedBitmapManager shared_bitmap_manager
;
62 TestTaskGraphRunner task_graph_runner
;
63 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
66 scoped_ptr
<LayerImpl
> layer_impl
=
67 LayerImpl::Create(host_impl
.active_tree(), 1);
68 scrollState
.set_current_native_scrolling_layer(layer_impl
.get());
69 EXPECT_EQ(layer_impl
, scrollState
.current_native_scrolling_layer());
72 TEST_F(ScrollStateTest
, FullyConsumed
) {
73 ScrollState
scrollState(1, 3, 0, 0, 0, false, false);
74 EXPECT_FALSE(scrollState
.FullyConsumed());
76 scrollState
.ConsumeDelta(1, 3);
77 EXPECT_TRUE(scrollState
.FullyConsumed());