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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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/events/x/device_data_manager_x11.h"
6
7 #include <vector>
8
9 // Generically-named #defines from Xlib that conflict with symbols in GTest.
10 #undef Bool
11 #undef None
12
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/events/device_hotplug_event_observer.h"
15 #include "ui/events/input_device.h"
16 #include "ui/events/input_device_event_observer.h"
17 #include "ui/events/keyboard_device.h"
18 #include "ui/events/touchscreen_device.h"
19
20 namespace ui {
21 namespace test {
22 namespace {
23
24 class TestInputDeviceObserver : public InputDeviceEventObserver {
25 public:
26 explicit TestInputDeviceObserver(DeviceDataManagerX11* manager)
27 : manager_(manager),
28 change_notified_(false) {
29 if (manager_)
30 manager_->AddObserver(this);
31 }
32
33 virtual ~TestInputDeviceObserver() {
34 if (manager_)
35 manager_->RemoveObserver(this);
36 }
37
38 // InputDeviceEventObserver implementation.
39 virtual void OnTouchscreenDeviceConfigurationChanged() override {}
40 virtual void OnKeyboardDeviceConfigurationChanged() override {
41 change_notified_ = true;
42 }
43
44 int change_notified() const { return change_notified_; }
45 void Reset() { change_notified_ = false; }
46
47 private:
48 DeviceDataManager* manager_;
49 bool change_notified_;
50
51 DISALLOW_COPY_AND_ASSIGN(TestInputDeviceObserver);
52 };
53
54 } // namespace
55
56 class DeviceDataManagerX11Test : public testing::Test {
57 public:
58 DeviceDataManagerX11Test() {}
59 virtual ~DeviceDataManagerX11Test() {}
60
61 void SetUp() override {
62 DeviceDataManagerX11::CreateInstance();
63 }
64
65 virtual void SetKeyboardDevices(const std::vector<KeyboardDevice>& devices) {
66 DeviceHotplugEventObserver* manager = DeviceDataManagerX11::GetInstance();
67 manager->OnKeyboardDevicesUpdated(devices);
68 }
69
70 private:
71 DISALLOW_COPY_AND_ASSIGN(DeviceDataManagerX11Test);
72 };
73
74 // Tests that the the device data manager notifies observers when a device is
75 // disabled and re-enabled.
76 TEST_F(DeviceDataManagerX11Test, NotifyOnDisable) {
77 DeviceDataManagerX11* manager = DeviceDataManagerX11::GetInstance();
78 TestInputDeviceObserver observer(manager);
79 std::vector<ui::KeyboardDevice> keyboards;
80 keyboards.push_back(ui::KeyboardDevice(1, ui::InputDeviceType::INTERNAL,
81 "Keyboard"));
82 keyboards.push_back(ui::KeyboardDevice(2, ui::InputDeviceType::INTERNAL,
83 "Keyboard"));
84 SetKeyboardDevices(keyboards);
85 EXPECT_TRUE(observer.change_notified());
86 std::vector<KeyboardDevice> devices = manager->keyboard_devices();
87 EXPECT_EQ(keyboards.size(), devices.size());
88 observer.Reset();
89
90 manager->DisableDevice(2);
91 EXPECT_TRUE(observer.change_notified());
92 devices = manager->keyboard_devices();
93 unsigned long expected_size = 1;
94 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.
95 KeyboardDevice device = devices.front();
96 EXPECT_EQ(1, device.id);
97 observer.Reset();
98
99 manager->EnableDevice(2);
100 EXPECT_TRUE(observer.change_notified());
101 devices = manager->keyboard_devices();
102 EXPECT_EQ(keyboards.size(), devices.size());
103 }
104
105 } // namespace test
106 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698