| OLD | NEW |
| (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, TestMissingTouchRelease) { |
| 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 // Only one finger down, so we miss two touchrelease. |
| 109 HWNDMessageHandler::TouchEvents touch_events2; |
| 110 input[0] = GenerateTouchInput(3, 30, 30, TOUCHEVENTF_DOWN); |
| 111 |
| 112 // Send out one touchpress and two touchrelease events for the touch ids |
| 113 // which are not in this input list, and touch_id_list has one |
| 114 // InPreviousMessage at index 2. |
| 115 messageHandler.PrepareTouchEventList(input.get(), 1, &touch_events2); |
| 116 EXPECT_EQ(3, touch_events2.size()); |
| 117 EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events2[0].type()); |
| 118 EXPECT_EQ(ui::ET_TOUCH_RELEASED, touch_events2[1].type()); |
| 119 EXPECT_EQ(ui::ET_TOUCH_RELEASED, touch_events2[2].type()); |
| 120 EXPECT_EQ(2, touch_events2[0].touch_id()); |
| 121 EXPECT_EQ(0, touch_events2[1].touch_id()); |
| 122 EXPECT_EQ(1, touch_events2[2].touch_id()); |
| 123 EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list, |
| 124 HWNDMessageHandler::InTouchList::NotPresent); |
| 125 EXPECT_EQ(messageHandler.touch_id_list()[1].in_touch_list, |
| 126 HWNDMessageHandler::InTouchList::NotPresent); |
| 127 EXPECT_EQ(messageHandler.touch_id_list()[2].in_touch_list, |
| 128 HWNDMessageHandler::InTouchList::InPreviousMessage); |
| 129 } |
| 130 |
| 131 TEST(HWNDMessageHandler, TestMissingTouchPress) { |
| 132 HWNDMessageHandler messageHandler(NULL); |
| 133 HWNDMessageHandler::TouchEvents touch_events1; |
| 134 |
| 135 // One finger down. |
| 136 scoped_ptr<TOUCHINPUT[]> input(new TOUCHINPUT[10]); |
| 137 input[0] = GenerateTouchInput(1, 10, 10, TOUCHEVENTF_DOWN); |
| 138 |
| 139 // Send out one touchpress event and touch_id_list has one |
| 140 // InPreviousMessage. |
| 141 messageHandler.PrepareTouchEventList(input.get(), 1, &touch_events1); |
| 142 EXPECT_EQ(1, touch_events1.size()); |
| 143 EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events1[0].type()); |
| 144 EXPECT_EQ(0, touch_events1[0].touch_id()); |
| 145 EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list, |
| 146 HWNDMessageHandler::InTouchList::InPreviousMessage); |
| 147 |
| 148 // Two touch moves. |
| 149 HWNDMessageHandler::TouchEvents touch_events2; |
| 150 input[0] = GenerateTouchInput(1, 20, 20, TOUCHEVENTF_MOVE); |
| 151 input[1] = GenerateTouchInput(2, 30, 30, TOUCHEVENTF_MOVE); |
| 152 |
| 153 // From last time, there is only one finger pointer, now we have two touch |
| 154 // moves, so we send out one touchmove event and one touchpress and one |
| 155 // touchmove for the new touch pointer, and touch_id_list has two |
| 156 // InPreviousMessage at index 0 and 1. |
| 157 messageHandler.PrepareTouchEventList(input.get(), 2, &touch_events2); |
| 158 EXPECT_EQ(3, touch_events2.size()); |
| 159 EXPECT_EQ(ui::ET_TOUCH_MOVED, touch_events2[0].type()); |
| 160 EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events2[1].type()); |
| 161 EXPECT_EQ(ui::ET_TOUCH_MOVED, touch_events2[2].type()); |
| 162 EXPECT_EQ(0, touch_events2[0].touch_id()); |
| 163 EXPECT_EQ(1, touch_events2[1].touch_id()); |
| 164 EXPECT_EQ(1, touch_events2[2].touch_id()); |
| 165 EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list, |
| 166 HWNDMessageHandler::InTouchList::InPreviousMessage); |
| 167 EXPECT_EQ(messageHandler.touch_id_list()[1].in_touch_list, |
| 168 HWNDMessageHandler::InTouchList::InPreviousMessage); |
| 169 } |
| 170 |
| 171 TEST(HWNDMessageHandler, TestMissingTouchPressAndRelease) { |
| 172 HWNDMessageHandler messageHandler(NULL); |
| 173 HWNDMessageHandler::TouchEvents touch_events1; |
| 174 |
| 175 // One finger down. |
| 176 scoped_ptr<TOUCHINPUT[]> input(new TOUCHINPUT[10]); |
| 177 input[0] = GenerateTouchInput(1, 10, 10, TOUCHEVENTF_DOWN); |
| 178 |
| 179 // Send out one touchpress event and touch_id_list has one |
| 180 // InPreviousMessage. |
| 181 messageHandler.PrepareTouchEventList(input.get(), 1, &touch_events1); |
| 182 EXPECT_EQ(1, touch_events1.size()); |
| 183 EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events1[0].type()); |
| 184 EXPECT_EQ(0, touch_events1[0].touch_id()); |
| 185 EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list, |
| 186 HWNDMessageHandler::InTouchList::InPreviousMessage); |
| 187 |
| 188 // One finger down and a new finger move, so we miss a touchrelease and |
| 189 // touchpress. |
| 190 HWNDMessageHandler::TouchEvents touch_events2; |
| 191 input[0] = GenerateTouchInput(2, 20, 20, TOUCHEVENTF_DOWN); |
| 192 input[1] = GenerateTouchInput(3, 30, 30, TOUCHEVENTF_MOVE); |
| 193 |
| 194 // Send out one touchpress and one touchrelease events for the touch ids |
| 195 // which are not in this input list, and touch_id_list has two |
| 196 // InPreviousMessage at index 1 and 2 and NotPresent at index 0. |
| 197 messageHandler.PrepareTouchEventList(input.get(), 2, &touch_events2); |
| 198 EXPECT_EQ(4, touch_events2.size()); |
| 199 EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events2[0].type()); |
| 200 EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events2[1].type()); |
| 201 EXPECT_EQ(ui::ET_TOUCH_MOVED, touch_events2[2].type()); |
| 202 EXPECT_EQ(ui::ET_TOUCH_RELEASED, touch_events2[3].type()); |
| 203 EXPECT_EQ(1, touch_events2[0].touch_id()); |
| 204 EXPECT_EQ(2, touch_events2[1].touch_id()); |
| 205 EXPECT_EQ(2, touch_events2[2].touch_id()); |
| 206 EXPECT_EQ(0, touch_events2[3].touch_id()); |
| 207 EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list, |
| 208 HWNDMessageHandler::InTouchList::NotPresent); |
| 209 EXPECT_EQ(messageHandler.touch_id_list()[1].in_touch_list, |
| 210 HWNDMessageHandler::InTouchList::InPreviousMessage); |
| 211 EXPECT_EQ(messageHandler.touch_id_list()[2].in_touch_list, |
| 212 HWNDMessageHandler::InTouchList::InPreviousMessage); |
| 213 } |
| 214 |
| 215 } // namespace views |
| OLD | NEW |