summaryrefslogtreecommitdiffstats
path: root/chromium/cc/layers/touch_action_region_unittest.cc
blob: e41631901e3c4992dea354088d54cd744738dace (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
// Copyright 2017 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/layers/touch_action_region.h"

#include "testing/gtest/include/gtest/gtest.h"

namespace cc {
namespace {

TEST(TouchActionRegionTest, GetAllowedTouchActionMapOverlapToZero) {
  TouchActionRegion touch_action_region;
  touch_action_region.Union(kTouchActionPanLeft, gfx::Rect(0, 0, 50, 50));
  touch_action_region.Union(kTouchActionPanRight, gfx::Rect(25, 25, 25, 25));
  // The point is only in PanLeft, so the result is PanLeft.
  EXPECT_EQ(kTouchActionPanLeft,
            touch_action_region.GetAllowedTouchAction(gfx::Point(10, 10)));
  // The point is in both PanLeft and PanRight, and those actions have no
  // common components, so the result is None.
  EXPECT_EQ(kTouchActionNone,
            touch_action_region.GetAllowedTouchAction(gfx::Point(30, 30)));
  // The point is in neither PanLeft nor PanRight, so the result is Auto since
  // the default touch action is auto.
  EXPECT_EQ(kTouchActionAuto,
            touch_action_region.GetAllowedTouchAction(gfx::Point(60, 60)));
}

TEST(TouchActionRegionTest, GetAllowedTouchActionMapOverlapToNonZero) {
  TouchActionRegion touch_action_region;
  touch_action_region.Union(kTouchActionPanX, gfx::Rect(0, 0, 50, 50));
  touch_action_region.Union(kTouchActionPanRight, gfx::Rect(25, 25, 25, 25));
  // The point is only in PanX, so the result is PanX.
  EXPECT_EQ(kTouchActionPanX,
            touch_action_region.GetAllowedTouchAction(gfx::Point(10, 10)));
  // The point is in both PanX and PanRight, and PanRight is a common component,
  // so the result is PanRight.
  EXPECT_EQ(kTouchActionPanRight,
            touch_action_region.GetAllowedTouchAction(gfx::Point(30, 30)));
  // The point is neither PanX nor PanRight, so the result is Auto since the
  // default touch action is auto.
  EXPECT_EQ(kTouchActionAuto,
            touch_action_region.GetAllowedTouchAction(gfx::Point(60, 60)));
}

TEST(TouchActionRegionTest, GetAllowedTouchActionEmptyMap) {
  TouchActionRegion touch_action_region;
  // The result is Auto since the map is empty and the default touch
  // action is auto.
  EXPECT_EQ(kTouchActionAuto,
            touch_action_region.GetAllowedTouchAction(gfx::Point(10, 10)));
}

TEST(TouchActionRegionTest, GetAllowedTouchActionSingleMapEntry) {
  TouchActionRegion touch_action_region;
  touch_action_region.Union(kTouchActionPanUp, gfx::Rect(0, 0, 50, 50));
  // The point is only in PanUp, so the result is PanUp.
  EXPECT_EQ(kTouchActionPanUp,
            touch_action_region.GetAllowedTouchAction(gfx::Point(10, 10)));
  // The point is not in PanUp, so the result is Auto since the default touch
  // action is auto.
  EXPECT_EQ(kTouchActionAuto,
            touch_action_region.GetAllowedTouchAction(gfx::Point(60, 60)));
}

}  // namespace
}  // namespace cc