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

Unified Diff: ui/events/x/events_x_unittest.cc

Issue 313913004: Block internal PlatformEvents before they are dispatched in touchview. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix updating cursor on enter notify. Created 6 years, 6 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
« no previous file with comments | « ui/events/x/events_x.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/x/events_x_unittest.cc
diff --git a/ui/events/x/events_x_unittest.cc b/ui/events/x/events_x_unittest.cc
index 0078651d8b6e3f30ed0a20b19409358682dba46a..7517e408e17206e59b444b4fa7b2bfea6ca77f40 100644
--- a/ui/events/x/events_x_unittest.cc
+++ b/ui/events/x/events_x_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include <cstring>
+#include <set>
#include <X11/extensions/XInput2.h>
#include <X11/Xlib.h>
@@ -13,12 +14,14 @@
#undef Bool
#undef None
+#include "base/memory/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_utils.h"
#include "ui/events/test/events_test_utils_x11.h"
#include "ui/events/x/device_data_manager_x11.h"
+#include "ui/events/x/touch_factory_x11.h"
#include "ui/gfx/point.h"
namespace ui {
@@ -444,6 +447,66 @@ TEST_F(EventsXTest, FunctionKeyEvents) {
EXPECT_FALSE(HasFunctionKeyFlagSetIfSupported(display, XK_F35 + 1));
}
+// Verifies that the type of events from a disabled keyboard is ET_UNKNOWN, but
+// that an exception list of keys can still be processed.
+TEST_F(EventsXTest, DisableKeyboard) {
+ DeviceDataManagerX11* device_data_manager =
+ static_cast<DeviceDataManagerX11*>(
+ DeviceDataManager::GetInstance());
+ scoped_ptr<std::set<KeyboardCode> > excepted_keys(new std::set<KeyboardCode>);
+ excepted_keys->insert(VKEY_B);
+ device_data_manager->DisableKeyboard(excepted_keys.Pass());
+
+ Display* display = gfx::GetXDisplay();
+ XEvent event;
+
+ // A is not allowed on the blocked keyboard, and should return ET_UNKNOWN.
+ InitKeyEvent(display, &event, true, XKeysymToKeycode(display, XK_A), 0);
+ EXPECT_EQ(ui::ET_UNKNOWN, ui::EventTypeFromNative(&event));
+
+ // The B key is allowed as an exception, and should return KEY_PRESSED.
+ InitKeyEvent(display, &event, true, XKeysymToKeycode(display, XK_B), 0);
+ EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(&event));
+
+ device_data_manager->EnableKeyboard();
+
+ // A key returns KEY_PRESSED as per usual now that keyboard was re-enabled.
+ InitKeyEvent(display, &event, true, XKeysymToKeycode(display, XK_A), 0);
+ EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(&event));
+}
+
+#if defined(USE_XI2_MT)
+// Verifies that the type of events from a disabled mouse is ET_UNKNOWN.
+TEST_F(EventsXTest, DisableMouse) {
+ DeviceDataManagerX11* device_data_manager =
+ static_cast<DeviceDataManagerX11*>(
+ DeviceDataManager::GetInstance());
+ unsigned int blocked_device_id = 1;
+ unsigned int other_device_id = 2;
+ std::vector<unsigned int> device_list;
+ device_list.push_back(blocked_device_id);
+ device_list.push_back(other_device_id);
+ TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list);
+
+ device_data_manager->DisableDevice(blocked_device_id);
+
+ ScopedXI2Event xev;
+ xev.InitGenericButtonEvent(blocked_device_id, ET_MOUSE_PRESSED, gfx::Point(),
+ EF_LEFT_MOUSE_BUTTON);
+ EXPECT_EQ(ui::ET_UNKNOWN, ui::EventTypeFromNative(xev));
+
+ xev.InitGenericButtonEvent(other_device_id, ET_MOUSE_PRESSED, gfx::Point(),
+ EF_LEFT_MOUSE_BUTTON);
+ EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(xev));
+
+ device_data_manager->EnableDevice(blocked_device_id);
+
+ xev.InitGenericButtonEvent(blocked_device_id, ET_MOUSE_PRESSED, gfx::Point(),
+ EF_LEFT_MOUSE_BUTTON);
+ EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(xev));
+}
+#endif // defined(USE_XI2_MT)
+
#if !defined(OS_CHROMEOS)
TEST_F(EventsXTest, ImeFabricatedKeyEvents) {
Display* display = gfx::GetXDisplay();
« no previous file with comments | « ui/events/x/events_x.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698