Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: ui/events/gestures/touch_point_state_unittest.cc

Issue 101933004: Eager Gesture Recognizer (WIP) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Starting work on Android. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/events/gestures/touch_point_state.cc ('k') | ui/views/controls/menu/menu_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 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.
4
5 #include "testing/gtest/include/gtest/gtest-spi.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/events/event.h"
8 #include "ui/events/gestures/test/eager_gesture_recognition_test_base.h"
9 #include "ui/events/gestures/touch_point_state.h"
10
11 namespace ui {
12
13 // Printing helper to allow gtest to give helpful error output.
14 static std::ostream& operator<<(std::ostream& os,
15 const ui::TouchPointState& tps) {
16 return os << "TouchPointState(" << tps.touch_id()
17 << ", " << (tps.has_press() ? "true" : "false")
18 << ", " << (tps.has_release() ? "true" : "false")
19 << ", " << tps.move_count()
20 << ", " << tps.timer_count()
21 << ")";
22 }
23
24 namespace test {
25
26 class TouchPointStateTest : public EagerGestureRecognitionTestBase {
27 public:
28 TouchPointStateTest() {}
29
30 private:
31 DISALLOW_COPY_AND_ASSIGN(TouchPointStateTest);
32 };
33
34 TEST_F(TouchPointStateTest, InitializeTouchPointState) {
35 TouchPointState tps(0);
36 EXPECT_EQ(TouchPointState(0, false, false, 0, 0), tps);
37 tps.Update(Press(0));
38 EXPECT_EQ(TouchPointState(0, true, false, 0, 0), tps);
39 }
40
41 TEST_F(TouchPointStateTest, UpdateTouchPointState) {
42 TouchPointState tps(0);
43 EXPECT_EQ(TouchPointState(0, false, false, 0, 0), tps);
44 tps.Update(Press(0));
45 EXPECT_EQ(TouchPointState(0, true, false, 0, 0), tps);
46
47 tps.Update(Move(0));
48 EXPECT_EQ(TouchPointState(0, true, false, 1, 0), tps);
49 tps.Update(Move(0));
50 EXPECT_EQ(TouchPointState(0, true, false, 2, 0), tps);
51 tps.Update(Move(0));
52 EXPECT_EQ(TouchPointState(0, true, false, 3, 0), tps);
53
54 tps.Update(Release(0));
55 EXPECT_EQ(TouchPointState(0, true, true, 3, 0), tps);
56 }
57
58 TEST_F(TouchPointStateTest, Contains) {
59 EXPECT_TRUE(TouchPointState(0, false, false, 0, 0).
60 Contains(TouchPointState(0, false, false, 0, 0)));
61 EXPECT_TRUE(TouchPointState(0, false, false, 1, 0).
62 Contains(TouchPointState(0, false, false, 0, 0)));
63 EXPECT_FALSE(TouchPointState(0, false, false, 0, 0).
64 Contains(TouchPointState(0, true, false, 0, 0)));
65 EXPECT_FALSE(TouchPointState(0, false, false, 0, 0).
66 Contains(TouchPointState(0, false, false, 5, 0)));
67 }
68
69 TEST_F(TouchPointStateTest, EmptyIntersection) {
70 EXPECT_TRUE(TouchPointState(0, false, false, 0, 0).
71 HasEmptyIntersection(TouchPointState(0, false, false, 0, 0)));
72 EXPECT_TRUE(TouchPointState(0, false, false, 1, 0).
73 HasEmptyIntersection(TouchPointState(0, true, false, 0, 0)));
74 EXPECT_FALSE(TouchPointState(0, false, false, 1, 0).
75 HasEmptyIntersection(TouchPointState(0, false, false, 1, 0)));
76 EXPECT_FALSE(TouchPointState(0, true, false, 0, 0).
77 HasEmptyIntersection(TouchPointState(0, true, false, 5, 0)));
78 }
79
80 TEST_F(TouchPointStateTest, CopyForGestureType) {
81 TouchPointState tps1(0, true, true, 1, 1);
82 scoped_ptr<TouchPointState> tps1_filtered(
83 tps1.CopyForGestureType(ET_GESTURE_SCROLL_BEGIN,
84 TouchPointState::WAIT_FOR_ACK));
85 EXPECT_EQ(TouchPointState(0, true, false, 1, 0), *tps1_filtered.get());
86
87 TouchPointState tps2(0, true, true, 1, 0);
88 scoped_ptr<TouchPointState> tps2_filtered(
89 tps1.CopyForGestureType(ET_GESTURE_TAP,
90 TouchPointState::WAIT_FOR_ACK));
91 EXPECT_EQ(tps2, *tps2_filtered.get());
92
93 TouchPointState tps3(0, true, true, 1, 0);
94 scoped_ptr<TouchPointState> tps3_filtered(
95 tps1.CopyForGestureType(ET_GESTURE_TAP_DOWN,
96 TouchPointState::WAIT_FOR_ACK));
97 EXPECT_EQ(TouchPointState(0, true, false, 0, 0), *tps3_filtered.get());
98
99 TouchPointState tps4(0, true, true, 1, 1);
100 scoped_ptr<TouchPointState> tps4_filtered(
101 tps1.CopyForGestureType(ET_GESTURE_BEGIN,
102 TouchPointState::WAIT_FOR_ACK));
103 EXPECT_EQ(TouchPointState(0, true, false, 0, 0), *tps4_filtered.get());
104
105 TouchPointState tps5(0, true, true, 1, 2);
106 scoped_ptr<TouchPointState> tps5_filtered(
107 tps1.CopyForGestureType(ET_GESTURE_LONG_PRESS,
108 TouchPointState::WAIT_FOR_ACK));
109 EXPECT_EQ(TouchPointState(0, true, false, 0, 2), *tps5_filtered.get());
110
111 TouchPointState tps6(0, true, true, 1, 2);
112 scoped_ptr<TouchPointState> tps6_filtered(
113 tps1.CopyForGestureType(ET_GESTURE_SHOW_PRESS,
114 TouchPointState::WAIT_FOR_ACK));
115 EXPECT_EQ(TouchPointState(0, true, false, 0, 1), *tps6_filtered.get());
116 }
117
118 } // namespace test
119 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gestures/touch_point_state.cc ('k') | ui/views/controls/menu/menu_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698