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

Unified Diff: ui/views/win/hwnd_message_handler_unittest.cc

Issue 988473002: 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/win/hwnd_message_handler_unittest.cc
diff --git a/ui/views/win/hwnd_message_handler_unittest.cc b/ui/views/win/hwnd_message_handler_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..88b07ceca401e11ef479a2c56252a693ebf1964b
--- /dev/null
+++ b/ui/views/win/hwnd_message_handler_unittest.cc
@@ -0,0 +1,215 @@
+// Copyright 2015 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 "ui/views/win/hwnd_message_handler.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace views {
+
+namespace {
+
+TOUCHINPUT GenerateTouchInput(int id, int x, int y, DWORD dwFlags) {
+ TOUCHINPUT input;
+ input.dwID = id;
+ input.x = x;
+ input.y = y;
+ input.dwFlags = dwFlags;
+ return input;
+}
+
+} // namespace
+
+TEST(HWNDMessageHandler, TestCorrectTouchInputList) {
+ HWNDMessageHandler messageHandler(NULL);
+ HWNDMessageHandler::TouchEvents touch_events1;
+
+ // One finger down.
+ scoped_ptr<TOUCHINPUT[]> input(new TOUCHINPUT[10]);
+ input[0] = GenerateTouchInput(1, 10, 10, TOUCHEVENTF_DOWN);
+
+ // Send out one touchpress event and set value to be
+ // InPreviousMessage at index 0 in touch_id_list.
+ messageHandler.PrepareTouchEventList(input.get(), 1, &touch_events1);
+ EXPECT_EQ(1, touch_events1.size());
+ EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events1[0].type());
+ EXPECT_EQ(0, touch_events1[0].touch_id());
+ EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list,
+ HWNDMessageHandler::InTouchList::InPreviousMessage);
+ EXPECT_EQ(touch_events1[0].location(),
+ messageHandler.touch_id_list()[0].location);
+
+ // One finger move and two fingers down.
+ HWNDMessageHandler::TouchEvents touch_events2;
+ input[0] = GenerateTouchInput(1, 20, 20, TOUCHEVENTF_MOVE);
+ input[1] = GenerateTouchInput(2, 30, 30, TOUCHEVENTF_DOWN);
+ input[2] = GenerateTouchInput(3, 40, 40, TOUCHEVENTF_DOWN);
+
+ // Send out touchmove and two touchpress events and touch_id_list has
+ // three InPreviousMessage at index 0, 1, 2.
+ messageHandler.PrepareTouchEventList(input.get(), 3, &touch_events2);
+ EXPECT_EQ(3, touch_events2.size());
+ EXPECT_EQ(ui::ET_TOUCH_MOVED, touch_events2[0].type());
+ EXPECT_EQ(0, touch_events2[0].touch_id());
+ EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list,
+ HWNDMessageHandler::InTouchList::InPreviousMessage);
+ EXPECT_EQ(messageHandler.touch_id_list()[1].in_touch_list,
+ HWNDMessageHandler::InTouchList::InPreviousMessage);
+ EXPECT_EQ(messageHandler.touch_id_list()[2].in_touch_list,
+ HWNDMessageHandler::InTouchList::InPreviousMessage);
+
+ // Release one finger and two finger moves.
+ HWNDMessageHandler::TouchEvents touch_events3;
+ input[0] = GenerateTouchInput(1, 22, 22, TOUCHEVENTF_UP);
+ input[1] = GenerateTouchInput(2, 33, 33, TOUCHEVENTF_MOVE);
+ input[2] = GenerateTouchInput(3, 44, 44, TOUCHEVENTF_MOVE);
+
+ // Send out one touchrelease, two touch move events and touch_id_list has
+ // two InPreviousMessage at index 1, 2 and one NotPresent at index 0.
+ messageHandler.PrepareTouchEventList(input.get(), 3, &touch_events3);
+ EXPECT_EQ(3, touch_events3.size());
+ EXPECT_EQ(ui::ET_TOUCH_RELEASED, touch_events3[0].type());
+ EXPECT_EQ(ui::ET_TOUCH_MOVED, touch_events3[1].type());
+ EXPECT_EQ(ui::ET_TOUCH_MOVED, touch_events3[2].type());
+ EXPECT_EQ(0, touch_events3[0].touch_id());
+ EXPECT_EQ(1, touch_events3[1].touch_id());
+ EXPECT_EQ(2, touch_events3[2].touch_id());
+ EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list,
+ HWNDMessageHandler::InTouchList::NotPresent);
+ EXPECT_EQ(messageHandler.touch_id_list()[1].in_touch_list,
+ HWNDMessageHandler::InTouchList::InPreviousMessage);
+ EXPECT_EQ(messageHandler.touch_id_list()[2].in_touch_list,
+ HWNDMessageHandler::InTouchList::InPreviousMessage);
+}
+
+TEST(HWNDMessageHandler, TestMissingTouchRelease) {
+ HWNDMessageHandler messageHandler(NULL);
+ HWNDMessageHandler::TouchEvents touch_events1;
+
+ // Two fingers down.
+ scoped_ptr<TOUCHINPUT[]> input(new TOUCHINPUT[10]);
+ input[0] = GenerateTouchInput(1, 10, 10, TOUCHEVENTF_DOWN);
+ input[1] = GenerateTouchInput(2, 20, 20, TOUCHEVENTF_DOWN);
+
+ // Send out two touchpress events and touch_id_list has two
+ // InPreviousMessage.
+ messageHandler.PrepareTouchEventList(input.get(), 2, &touch_events1);
+ EXPECT_EQ(2, touch_events1.size());
+ EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events1[0].type());
+ EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events1[1].type());
+ EXPECT_EQ(0, touch_events1[0].touch_id());
+ EXPECT_EQ(1, touch_events1[1].touch_id());
+ EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list,
+ HWNDMessageHandler::InTouchList::InPreviousMessage);
+ EXPECT_EQ(messageHandler.touch_id_list()[1].in_touch_list,
+ HWNDMessageHandler::InTouchList::InPreviousMessage);
+
+ // Only one finger down, so we miss two touchrelease.
+ HWNDMessageHandler::TouchEvents touch_events2;
+ input[0] = GenerateTouchInput(3, 30, 30, TOUCHEVENTF_DOWN);
+
+ // Send out one touchpress and two touchrelease events for the touch ids
+ // which are not in this input list, and touch_id_list has one
+ // InPreviousMessage at index 2.
+ messageHandler.PrepareTouchEventList(input.get(), 1, &touch_events2);
+ EXPECT_EQ(3, touch_events2.size());
+ EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events2[0].type());
+ EXPECT_EQ(ui::ET_TOUCH_RELEASED, touch_events2[1].type());
+ EXPECT_EQ(ui::ET_TOUCH_RELEASED, touch_events2[2].type());
+ EXPECT_EQ(2, touch_events2[0].touch_id());
+ EXPECT_EQ(0, touch_events2[1].touch_id());
+ EXPECT_EQ(1, touch_events2[2].touch_id());
+ EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list,
+ HWNDMessageHandler::InTouchList::NotPresent);
+ EXPECT_EQ(messageHandler.touch_id_list()[1].in_touch_list,
+ HWNDMessageHandler::InTouchList::NotPresent);
+ EXPECT_EQ(messageHandler.touch_id_list()[2].in_touch_list,
+ HWNDMessageHandler::InTouchList::InPreviousMessage);
+}
+
+TEST(HWNDMessageHandler, TestMissingTouchPress) {
+ HWNDMessageHandler messageHandler(NULL);
+ HWNDMessageHandler::TouchEvents touch_events1;
+
+ // One finger down.
+ scoped_ptr<TOUCHINPUT[]> input(new TOUCHINPUT[10]);
+ input[0] = GenerateTouchInput(1, 10, 10, TOUCHEVENTF_DOWN);
+
+ // Send out one touchpress event and touch_id_list has one
+ // InPreviousMessage.
+ messageHandler.PrepareTouchEventList(input.get(), 1, &touch_events1);
+ EXPECT_EQ(1, touch_events1.size());
+ EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events1[0].type());
+ EXPECT_EQ(0, touch_events1[0].touch_id());
+ EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list,
+ HWNDMessageHandler::InTouchList::InPreviousMessage);
+
+ // Two touch moves.
+ HWNDMessageHandler::TouchEvents touch_events2;
+ input[0] = GenerateTouchInput(1, 20, 20, TOUCHEVENTF_MOVE);
+ input[1] = GenerateTouchInput(2, 30, 30, TOUCHEVENTF_MOVE);
+
+ // From last time, there is only one finger pointer, now we have two touch
+ // moves, so we send out one touchmove event and one touchpress and one
+ // touchmove for the new touch pointer, and touch_id_list has two
+ // InPreviousMessage at index 0 and 1.
+ messageHandler.PrepareTouchEventList(input.get(), 2, &touch_events2);
+ EXPECT_EQ(3, touch_events2.size());
+ EXPECT_EQ(ui::ET_TOUCH_MOVED, touch_events2[0].type());
+ EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events2[1].type());
+ EXPECT_EQ(ui::ET_TOUCH_MOVED, touch_events2[2].type());
+ EXPECT_EQ(0, touch_events2[0].touch_id());
+ EXPECT_EQ(1, touch_events2[1].touch_id());
+ EXPECT_EQ(1, touch_events2[2].touch_id());
+ EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list,
+ HWNDMessageHandler::InTouchList::InPreviousMessage);
+ EXPECT_EQ(messageHandler.touch_id_list()[1].in_touch_list,
+ HWNDMessageHandler::InTouchList::InPreviousMessage);
+}
+
+TEST(HWNDMessageHandler, TestMissingTouchPressAndRelease) {
+ HWNDMessageHandler messageHandler(NULL);
+ HWNDMessageHandler::TouchEvents touch_events1;
+
+ // One finger down.
+ scoped_ptr<TOUCHINPUT[]> input(new TOUCHINPUT[10]);
+ input[0] = GenerateTouchInput(1, 10, 10, TOUCHEVENTF_DOWN);
+
+ // Send out one touchpress event and touch_id_list has one
+ // InPreviousMessage.
+ messageHandler.PrepareTouchEventList(input.get(), 1, &touch_events1);
+ EXPECT_EQ(1, touch_events1.size());
+ EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events1[0].type());
+ EXPECT_EQ(0, touch_events1[0].touch_id());
+ EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list,
+ HWNDMessageHandler::InTouchList::InPreviousMessage);
+
+ // One finger down and a new finger move, so we miss a touchrelease and
+ // touchpress.
+ HWNDMessageHandler::TouchEvents touch_events2;
+ input[0] = GenerateTouchInput(2, 20, 20, TOUCHEVENTF_DOWN);
+ input[1] = GenerateTouchInput(3, 30, 30, TOUCHEVENTF_MOVE);
+
+ // Send out one touchpress and one touchrelease events for the touch ids
+ // which are not in this input list, and touch_id_list has two
+ // InPreviousMessage at index 1 and 2 and NotPresent at index 0.
+ messageHandler.PrepareTouchEventList(input.get(), 2, &touch_events2);
+ EXPECT_EQ(4, touch_events2.size());
+ EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events2[0].type());
+ EXPECT_EQ(ui::ET_TOUCH_PRESSED, touch_events2[1].type());
+ EXPECT_EQ(ui::ET_TOUCH_MOVED, touch_events2[2].type());
+ EXPECT_EQ(ui::ET_TOUCH_RELEASED, touch_events2[3].type());
+ EXPECT_EQ(1, touch_events2[0].touch_id());
+ EXPECT_EQ(2, touch_events2[1].touch_id());
+ EXPECT_EQ(2, touch_events2[2].touch_id());
+ EXPECT_EQ(0, touch_events2[3].touch_id());
+ EXPECT_EQ(messageHandler.touch_id_list()[0].in_touch_list,
+ HWNDMessageHandler::InTouchList::NotPresent);
+ EXPECT_EQ(messageHandler.touch_id_list()[1].in_touch_list,
+ HWNDMessageHandler::InTouchList::InPreviousMessage);
+ EXPECT_EQ(messageHandler.touch_id_list()[2].in_touch_list,
+ HWNDMessageHandler::InTouchList::InPreviousMessage);
+}
+
+} // namespace views
« ui/views/win/hwnd_message_handler.cc ('K') | « 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