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

Side by Side Diff: ui/views/win/hwnd_message_handler_unittest.cc

Issue 1143333002: Revert "Correctly release the touch events on Lenovo Horizon device." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « ui/views/win/hwnd_message_handler.cc ('k') | no next file » | 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 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.
4
5 #include "ui/views/win/hwnd_message_handler.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace views {
10
11 namespace {
12
13 TOUCHINPUT GenerateTouchInput(int id, int x, int y, DWORD dwFlags) {
14 TOUCHINPUT input;
15 input.dwID = id;
16 input.x = x;
17 input.y = y;
18 input.dwFlags = dwFlags;
19 return input;
20 }
21
22 } // namespace
23
24 TEST(HWNDMessageHandler, TestCorrectTouchInputList) {
25 HWNDMessageHandler messageHandler(NULL);
26 HWNDMessageHandler::TouchEvents touch_events1;
27
28 // One finger down.
29 scoped_ptr<TOUCHINPUT[]> input(new TOUCHINPUT[10]);
30 input[0] = GenerateTouchInput(1, 10, 10, TOUCHEVENTF_DOWN);
31
32 // Send out one touchpress event and set value to be
33 // InPreviousMessage at index 0 in touch_id_list.
34 messageHandler.PrepareTouchEventList(input.get(), 1, &touch_events1);
35 EXPECT_EQ(1, touch_events1.size());
36 EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events1[0].type());
37 EXPECT_EQ(0, touch_events1[0].touch_id());
38 EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list,
39 HWNDMessageHandler::InTouchList::InPreviousMessage);
40 EXPECT_EQ(touch_events1[0].location(),
41 messageHandler.touch_id_list()[0].location);
42
43 // One finger move and two fingers down.
44 HWNDMessageHandler::TouchEvents touch_events2;
45 input[0] = GenerateTouchInput(1, 20, 20, TOUCHEVENTF_MOVE);
46 input[1] = GenerateTouchInput(2, 30, 30, TOUCHEVENTF_DOWN);
47 input[2] = GenerateTouchInput(3, 40, 40, TOUCHEVENTF_DOWN);
48
49 // Send out touchmove and two touchpress events and touch_id_list has
50 // three InPreviousMessage at index 0, 1, 2.
51 messageHandler.PrepareTouchEventList(input.get(), 3, &touch_events2);
52 EXPECT_EQ(3, touch_events2.size());
53 EXPECT_EQ(ui::ET_TOUCH_MOVED, touch_events2[0].type());
54 EXPECT_EQ(0, touch_events2[0].touch_id());
55 EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list,
56 HWNDMessageHandler::InTouchList::InPreviousMessage);
57 EXPECT_EQ(messageHandler.touch_id_list()[1].in_touch_list,
58 HWNDMessageHandler::InTouchList::InPreviousMessage);
59 EXPECT_EQ(messageHandler.touch_id_list()[2].in_touch_list,
60 HWNDMessageHandler::InTouchList::InPreviousMessage);
61
62 // Release one finger and two finger moves.
63 HWNDMessageHandler::TouchEvents touch_events3;
64 input[0] = GenerateTouchInput(1, 22, 22, TOUCHEVENTF_UP);
65 input[1] = GenerateTouchInput(2, 33, 33, TOUCHEVENTF_MOVE);
66 input[2] = GenerateTouchInput(3, 44, 44, TOUCHEVENTF_MOVE);
67
68 // Send out one touchrelease, two touch move events and touch_id_list has
69 // two InPreviousMessage at index 1, 2 and one NotPresent at index 0.
70 messageHandler.PrepareTouchEventList(input.get(), 3, &touch_events3);
71 EXPECT_EQ(3, touch_events3.size());
72 EXPECT_EQ(ui::ET_TOUCH_RELEASED, touch_events3[0].type());
73 EXPECT_EQ(ui::ET_TOUCH_MOVED, touch_events3[1].type());
74 EXPECT_EQ(ui::ET_TOUCH_MOVED, touch_events3[2].type());
75 EXPECT_EQ(0, touch_events3[0].touch_id());
76 EXPECT_EQ(1, touch_events3[1].touch_id());
77 EXPECT_EQ(2, touch_events3[2].touch_id());
78 EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list,
79 HWNDMessageHandler::InTouchList::NotPresent);
80 EXPECT_EQ(messageHandler.touch_id_list()[1].in_touch_list,
81 HWNDMessageHandler::InTouchList::InPreviousMessage);
82 EXPECT_EQ(messageHandler.touch_id_list()[2].in_touch_list,
83 HWNDMessageHandler::InTouchList::InPreviousMessage);
84 }
85
86 TEST(HWNDMessageHandler, TestCombineTouchMoveAndUp) {
87 HWNDMessageHandler messageHandler(NULL);
88 HWNDMessageHandler::TouchEvents touch_events1;
89
90 // Two fingers down.
91 scoped_ptr<TOUCHINPUT[]> input(new TOUCHINPUT[10]);
92 input[0] = GenerateTouchInput(1, 10, 10, TOUCHEVENTF_DOWN);
93 input[1] = GenerateTouchInput(2, 20, 20, TOUCHEVENTF_DOWN);
94
95 // Send out two touchpress events and touch_id_list has two
96 // InPreviousMessage.
97 messageHandler.PrepareTouchEventList(input.get(), 2, &touch_events1);
98 EXPECT_EQ(2, touch_events1.size());
99 EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events1[0].type());
100 EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events1[1].type());
101 EXPECT_EQ(0, touch_events1[0].touch_id());
102 EXPECT_EQ(1, touch_events1[1].touch_id());
103 EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list,
104 HWNDMessageHandler::InTouchList::InPreviousMessage);
105 EXPECT_EQ(messageHandler.touch_id_list()[1].in_touch_list,
106 HWNDMessageHandler::InTouchList::InPreviousMessage);
107
108 // One finger move and up and one fingers move.
109 HWNDMessageHandler::TouchEvents touch_events2;
110 input[0] = GenerateTouchInput(1, 20, 20,
111 TOUCHEVENTF_MOVE | TOUCHEVENTF_UP);
112 input[1] = GenerateTouchInput(2, 30, 30, TOUCHEVENTF_MOVE);
113
114 // Send out a touchmove, touchrelease and a touchmove events and
115 // touch_id_list has one InPreviousMessage at index 1 and one NotPresent
116 // at index 0.
117 messageHandler.PrepareTouchEventList(input.get(), 2, &touch_events2);
118 EXPECT_EQ(3, touch_events2.size());
119 EXPECT_EQ(ui::ET_TOUCH_MOVED, touch_events2[0].type());
120 EXPECT_EQ(ui::ET_TOUCH_RELEASED, touch_events2[1].type());
121 EXPECT_EQ(ui::ET_TOUCH_MOVED, touch_events2[2].type());
122 EXPECT_EQ(0, touch_events2[0].touch_id());
123 EXPECT_EQ(0, touch_events2[1].touch_id());
124 EXPECT_EQ(1, touch_events2[2].touch_id());
125 EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list,
126 HWNDMessageHandler::InTouchList::NotPresent);
127 EXPECT_EQ(messageHandler.touch_id_list()[1].in_touch_list,
128 HWNDMessageHandler::InTouchList::InPreviousMessage);
129 }
130
131 TEST(HWNDMessageHandler, TestMissingTouchRelease) {
132 HWNDMessageHandler messageHandler(NULL);
133 HWNDMessageHandler::TouchEvents touch_events1;
134
135 // Two fingers down.
136 scoped_ptr<TOUCHINPUT[]> input(new TOUCHINPUT[10]);
137 input[0] = GenerateTouchInput(1, 10, 10, TOUCHEVENTF_DOWN);
138 input[1] = GenerateTouchInput(2, 20, 20, TOUCHEVENTF_DOWN);
139
140 // Send out two touchpress events and touch_id_list has two
141 // InPreviousMessage.
142 messageHandler.PrepareTouchEventList(input.get(), 2, &touch_events1);
143 EXPECT_EQ(2, touch_events1.size());
144 EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events1[0].type());
145 EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events1[1].type());
146 EXPECT_EQ(0, touch_events1[0].touch_id());
147 EXPECT_EQ(1, touch_events1[1].touch_id());
148 EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list,
149 HWNDMessageHandler::InTouchList::InPreviousMessage);
150 EXPECT_EQ(messageHandler.touch_id_list()[1].in_touch_list,
151 HWNDMessageHandler::InTouchList::InPreviousMessage);
152
153 // Only one finger down, so we miss two touchrelease.
154 HWNDMessageHandler::TouchEvents touch_events2;
155 input[0] = GenerateTouchInput(3, 30, 30, TOUCHEVENTF_DOWN);
156
157 // Send out one touchpress and two touchrelease events for the touch ids
158 // which are not in this input list, and touch_id_list has one
159 // InPreviousMessage at index 2.
160 messageHandler.PrepareTouchEventList(input.get(), 1, &touch_events2);
161 EXPECT_EQ(3, touch_events2.size());
162 EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events2[0].type());
163 EXPECT_EQ(ui::ET_TOUCH_RELEASED, touch_events2[1].type());
164 EXPECT_EQ(ui::ET_TOUCH_RELEASED, touch_events2[2].type());
165 EXPECT_EQ(2, touch_events2[0].touch_id());
166 EXPECT_EQ(0, touch_events2[1].touch_id());
167 EXPECT_EQ(1, touch_events2[2].touch_id());
168 EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list,
169 HWNDMessageHandler::InTouchList::NotPresent);
170 EXPECT_EQ(messageHandler.touch_id_list()[1].in_touch_list,
171 HWNDMessageHandler::InTouchList::NotPresent);
172 EXPECT_EQ(messageHandler.touch_id_list()[2].in_touch_list,
173 HWNDMessageHandler::InTouchList::InPreviousMessage);
174 }
175
176 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/win/hwnd_message_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698