summaryrefslogtreecommitdiffstats
path: root/cc/input/scroll_state_unittest.cc
blob: a996a1c021e00ebd741d95b4b0507f3dc584a286 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/input/scroll_state.h"

#include "cc/layers/layer_impl.h"
#include "cc/test/fake_impl_task_runner_provider.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/test_shared_bitmap_manager.h"
#include "cc/test/test_task_graph_runner.h"
#include "cc/trees/layer_tree_impl.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace cc {

class ScrollStateTest : public testing::Test {};

TEST_F(ScrollStateTest, ConsumeDeltaNative) {
  const float delta_x = 12.3f;
  const float delta_y = 3.9f;

  const float delta_x_to_consume = 1.2f;
  const float delta_y_to_consume = 2.3f;

  ScrollStateData scroll_state_data;
  scroll_state_data.delta_x = delta_x;
  scroll_state_data.delta_y = delta_y;
  ScrollState scroll_state(scroll_state_data);

  EXPECT_FLOAT_EQ(delta_x, scroll_state.delta_x());
  EXPECT_FLOAT_EQ(delta_y, scroll_state.delta_y());
  EXPECT_FALSE(scroll_state.delta_consumed_for_scroll_sequence());
  EXPECT_FALSE(scroll_state.FullyConsumed());

  scroll_state.ConsumeDelta(0, 0);
  EXPECT_FLOAT_EQ(delta_x, scroll_state.delta_x());
  EXPECT_FLOAT_EQ(delta_y, scroll_state.delta_y());
  EXPECT_FALSE(scroll_state.delta_consumed_for_scroll_sequence());
  EXPECT_FALSE(scroll_state.FullyConsumed());

  scroll_state.ConsumeDelta(delta_x_to_consume, 0);
  EXPECT_FLOAT_EQ(delta_x - delta_x_to_consume, scroll_state.delta_x());
  EXPECT_FLOAT_EQ(delta_y, scroll_state.delta_y());
  EXPECT_TRUE(scroll_state.delta_consumed_for_scroll_sequence());
  EXPECT_FALSE(scroll_state.FullyConsumed());

  scroll_state.ConsumeDelta(0, delta_y_to_consume);
  EXPECT_FLOAT_EQ(delta_x - delta_x_to_consume, scroll_state.delta_x());
  EXPECT_FLOAT_EQ(delta_y - delta_y_to_consume, scroll_state.delta_y());
  EXPECT_TRUE(scroll_state.delta_consumed_for_scroll_sequence());
  EXPECT_FALSE(scroll_state.FullyConsumed());

  scroll_state.ConsumeDelta(scroll_state.delta_x(), scroll_state.delta_y());
  EXPECT_TRUE(scroll_state.delta_consumed_for_scroll_sequence());
  EXPECT_TRUE(scroll_state.FullyConsumed());
}

TEST_F(ScrollStateTest, CurrentNativeScrollingScrollable) {
  ScrollStateData scroll_state_data;
  ScrollState scroll_state(scroll_state_data);

  FakeImplTaskRunnerProvider task_runner_provider;
  TestSharedBitmapManager shared_bitmap_manager;
  TestTaskGraphRunner task_graph_runner;
  FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
                                  &task_graph_runner);

  scoped_ptr<LayerImpl> layer_impl =
      LayerImpl::Create(host_impl.active_tree(), 1);
  ScrollNode* scroll_node =
      host_impl.active_tree()->property_trees()->scroll_tree.Node(
          layer_impl->scroll_tree_index());
  scroll_state.set_current_native_scrolling_node(scroll_node);
  EXPECT_EQ(scroll_node, scroll_state.current_native_scrolling_node());
}

TEST_F(ScrollStateTest, FullyConsumed) {
  ScrollStateData scroll_state_data;
  scroll_state_data.delta_x = 1;
  scroll_state_data.delta_y = 3;
  ScrollState scroll_state(scroll_state_data);

  EXPECT_FALSE(scroll_state.FullyConsumed());
  scroll_state.ConsumeDelta(1, 3);
  EXPECT_TRUE(scroll_state.FullyConsumed());
}
}  // namespace cc