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
cc / layers / touch_action_region_unittest.cc [blame]
// Copyright 2017 The Chromium Authors
// 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(TouchAction::kPanLeft, gfx::Rect(0, 0, 50, 50));
touch_action_region.Union(TouchAction::kPanRight, gfx::Rect(25, 25, 25, 25));
// The point is only in PanLeft, so the result is PanLeft.
EXPECT_EQ(TouchAction::kPanLeft,
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(TouchAction::kNone,
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(TouchAction::kAuto,
touch_action_region.GetAllowedTouchAction(gfx::Point(60, 60)));
}
TEST(TouchActionRegionTest, GetAllowedTouchActionMapOverlapToNonZero) {
TouchActionRegion touch_action_region;
touch_action_region.Union(TouchAction::kPanX, gfx::Rect(0, 0, 50, 50));
touch_action_region.Union(TouchAction::kPanRight, gfx::Rect(25, 25, 25, 25));
// The point is only in PanX, so the result is PanX.
EXPECT_EQ(TouchAction::kPanX,
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(TouchAction::kPanRight,
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(TouchAction::kAuto,
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(TouchAction::kAuto,
touch_action_region.GetAllowedTouchAction(gfx::Point(10, 10)));
}
TEST(TouchActionRegionTest, GetAllowedTouchActionSingleMapEntry) {
TouchActionRegion touch_action_region;
touch_action_region.Union(TouchAction::kPanUp, gfx::Rect(0, 0, 50, 50));
// The point is only in PanUp, so the result is PanUp.
EXPECT_EQ(TouchAction::kPanUp,
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(TouchAction::kAuto,
touch_action_region.GetAllowedTouchAction(gfx::Point(60, 60)));
}
} // namespace
} // namespace cc