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

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

Issue 618283003: Adds special support to the device manager for keyboards devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix blocked devices not updating. Created 6 years, 2 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/events/x/device_data_manager_x11_unittest.cc
diff --git a/ui/events/x/device_data_manager_x11_unittest.cc b/ui/events/x/device_data_manager_x11_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8c349afb29d022d2c4cc9696bb7b30c745ab8379
--- /dev/null
+++ b/ui/events/x/device_data_manager_x11_unittest.cc
@@ -0,0 +1,106 @@
+// Copyright 2014 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/events/x/device_data_manager_x11.h"
+
+#include <vector>
+
+// Generically-named #defines from Xlib that conflict with symbols in GTest.
+#undef Bool
+#undef None
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/events/device_hotplug_event_observer.h"
+#include "ui/events/input_device.h"
+#include "ui/events/input_device_event_observer.h"
+#include "ui/events/keyboard_device.h"
+#include "ui/events/touchscreen_device.h"
+
+namespace ui {
+namespace test {
+namespace {
+
+class TestInputDeviceObserver : public InputDeviceEventObserver {
+ public:
+ explicit TestInputDeviceObserver(DeviceDataManagerX11* manager)
+ : manager_(manager),
+ change_notified_(false) {
+ if (manager_)
+ manager_->AddObserver(this);
+ }
+
+ virtual ~TestInputDeviceObserver() {
+ if (manager_)
+ manager_->RemoveObserver(this);
+ }
+
+ // InputDeviceEventObserver implementation.
+ virtual void OnTouchscreenDeviceConfigurationChanged() override {}
+ virtual void OnKeyboardDeviceConfigurationChanged() override {
+ change_notified_ = true;
+ }
+
+ int change_notified() const { return change_notified_; }
+ void Reset() { change_notified_ = false; }
+
+ private:
+ DeviceDataManager* manager_;
+ bool change_notified_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestInputDeviceObserver);
+};
+
+} // namespace
+
+class DeviceDataManagerX11Test : public testing::Test {
+ public:
+ DeviceDataManagerX11Test() {}
+ virtual ~DeviceDataManagerX11Test() {}
+
+ void SetUp() override {
+ DeviceDataManagerX11::CreateInstance();
+ }
+
+ virtual void SetKeyboardDevices(const std::vector<KeyboardDevice>& devices) {
+ DeviceHotplugEventObserver* manager = DeviceDataManagerX11::GetInstance();
+ manager->OnKeyboardDevicesUpdated(devices);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DeviceDataManagerX11Test);
+};
+
+// Tests that the the device data manager notifies observers when a device is
+// disabled and re-enabled.
+TEST_F(DeviceDataManagerX11Test, NotifyOnDisable) {
+ DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance();
+ TestInputDeviceObserver observer(manager);
+ std::vector<ui::KeyboardDevice> keyboards;
+ keyboards.push_back(ui::KeyboardDevice(1, ui::InputDeviceType::INTERNAL,
+ "Keyboard"));
+ keyboards.push_back(ui::KeyboardDevice(2, ui::InputDeviceType::INTERNAL,
+ "Keyboard"));
+ SetKeyboardDevices(keyboards);
+ EXPECT_TRUE(observer.change_notified());
+ std::vector<KeyboardDevice> devices = manager->keyboard_devices();
+ EXPECT_EQ(keyboards.size(), devices.size());
+ observer.Reset();
+
+ manager->DisableDevice(2);
+ EXPECT_TRUE(observer.change_notified());
+ devices = manager->keyboard_devices();
+ unsigned long expected_size = 1;
+ EXPECT_EQ(expected_size, devices.size());
flackr 2014/10/08 21:58:11 EXPECT_EQ(1u, devices.size());
rsadam 2014/10/09 05:19:03 Done.
+ KeyboardDevice device = devices.front();
+ EXPECT_EQ(1, device.id);
+ observer.Reset();
+
+ manager->EnableDevice(2);
+ EXPECT_TRUE(observer.change_notified());
+ devices = manager->keyboard_devices();
+ EXPECT_EQ(keyboards.size(), devices.size());
+}
+
+} // namespace test
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698