Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 "base/files/file_path.h" | |
| 6 #include "base/message_loop/message_loop.h" | |
| 7 #include "mojo/public/cpp/bindings/binding_set.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 #include "ui/events/devices/input_device.h" | |
| 10 #include "ui/events/devices/mojo/device_traits_test_service.mojom.h" | |
| 11 #include "ui/events/devices/touchscreen_device.h" | |
| 12 #include "ui/gfx/geometry/size.h" | |
| 13 | |
| 14 namespace ui { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 class DeviceStructTraitsTest : public testing::Test, | |
| 19 public mojom::DeviceTraitsTestService { | |
| 20 public: | |
| 21 DeviceStructTraitsTest() {} | |
| 22 | |
| 23 protected: | |
| 24 mojom::DeviceTraitsTestServicePtr GetTraitsTestProxy() { | |
| 25 return traits_test_bindings_.CreateInterfacePtrAndBind(this); | |
| 26 } | |
| 27 | |
| 28 private: | |
| 29 // DeviceTraitsTestService: | |
| 30 void EchoInputDevice(const InputDevice& in, | |
| 31 const EchoInputDeviceCallback& callback) override { | |
| 32 callback.Run(in); | |
| 33 } | |
| 34 | |
| 35 void EchoTouchscreenDevice( | |
| 36 const TouchscreenDevice& in, | |
| 37 const EchoTouchscreenDeviceCallback& callback) override { | |
| 38 callback.Run(in); | |
| 39 } | |
| 40 | |
| 41 base::MessageLoop loop_; // Needed otherwise DCHECK fails. | |
|
sadrul
2016/06/27 15:17:39
Which DCHECK? (I don't think the comment is all th
kylechar
2016/06/27 15:25:59
Done.
| |
| 42 mojo::BindingSet<DeviceTraitsTestService> traits_test_bindings_; | |
| 43 | |
| 44 DISALLOW_COPY_AND_ASSIGN(DeviceStructTraitsTest); | |
| 45 }; | |
| 46 | |
| 47 } // namespace | |
| 48 | |
| 49 TEST_F(DeviceStructTraitsTest, InputDevice) { | |
| 50 InputDevice input(15, // id | |
| 51 INPUT_DEVICE_INTERNAL, // type | |
| 52 "Input Device"); // name | |
| 53 input.sys_path = base::FilePath::FromUTF8Unsafe("/dev/input/event14"); | |
| 54 input.vendor_id = 1000; | |
| 55 input.product_id = 2000; | |
| 56 | |
| 57 mojom::DeviceTraitsTestServicePtr proxy = GetTraitsTestProxy(); | |
| 58 InputDevice output; | |
| 59 proxy->EchoInputDevice(input, &output); | |
| 60 | |
| 61 EXPECT_EQ(input.id, output.id); | |
| 62 EXPECT_EQ(input.type, output.type); | |
| 63 EXPECT_EQ(input.name, output.name); | |
| 64 EXPECT_EQ(input.sys_path, output.sys_path); | |
| 65 EXPECT_EQ(input.vendor_id, output.vendor_id); | |
| 66 EXPECT_EQ(input.product_id, output.product_id); | |
| 67 } | |
| 68 | |
| 69 TEST_F(DeviceStructTraitsTest, TouchscreenDevice) { | |
| 70 TouchscreenDevice input(10, // id | |
| 71 INPUT_DEVICE_UNKNOWN, // type | |
| 72 "Touchscreen Device", // name | |
| 73 gfx::Size(123, 456), // size | |
| 74 3); // touch_points | |
| 75 // Not setting sys_path intentionally. | |
| 76 input.vendor_id = 0; | |
| 77 input.product_id = 0; | |
|
sadrul
2016/06/27 15:17:39
Set some non-zero values here?
kylechar
2016/06/27 15:25:59
It seems like these often end up being zero in rea
| |
| 78 | |
| 79 mojom::DeviceTraitsTestServicePtr proxy = GetTraitsTestProxy(); | |
| 80 TouchscreenDevice output; | |
| 81 proxy->EchoTouchscreenDevice(input, &output); | |
| 82 | |
| 83 EXPECT_EQ(input.id, output.id); | |
| 84 EXPECT_EQ(input.type, output.type); | |
| 85 EXPECT_EQ(input.name, output.name); | |
| 86 EXPECT_EQ(input.sys_path, output.sys_path); | |
| 87 EXPECT_EQ(input.vendor_id, output.vendor_id); | |
| 88 EXPECT_EQ(input.product_id, output.product_id); | |
| 89 EXPECT_EQ(input.size, output.size); | |
| 90 EXPECT_EQ(input.touch_points, output.touch_points); | |
| 91 } | |
| 92 | |
| 93 } // namespace ui | |
| OLD | NEW |