Chromium Code Reviews| Index: ui/events/devices/mojo/device_struct_traits_unittest.cc |
| diff --git a/ui/events/devices/mojo/device_struct_traits_unittest.cc b/ui/events/devices/mojo/device_struct_traits_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0f18d9ea7053521fa14da2b418d7c06907f65dc9 |
| --- /dev/null |
| +++ b/ui/events/devices/mojo/device_struct_traits_unittest.cc |
| @@ -0,0 +1,93 @@ |
| +// Copyright 2016 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 "base/files/file_path.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "mojo/public/cpp/bindings/binding_set.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/events/devices/input_device.h" |
| +#include "ui/events/devices/mojo/device_traits_test_service.mojom.h" |
| +#include "ui/events/devices/touchscreen_device.h" |
| +#include "ui/gfx/geometry/size.h" |
| + |
| +namespace ui { |
| + |
| +namespace { |
| + |
| +class DeviceStructTraitsTest : public testing::Test, |
| + public mojom::DeviceTraitsTestService { |
| + public: |
| + DeviceStructTraitsTest() {} |
| + |
| + protected: |
| + mojom::DeviceTraitsTestServicePtr GetTraitsTestProxy() { |
| + return traits_test_bindings_.CreateInterfacePtrAndBind(this); |
| + } |
| + |
| + private: |
| + // DeviceTraitsTestService: |
| + void EchoInputDevice(const InputDevice& in, |
| + const EchoInputDeviceCallback& callback) override { |
| + callback.Run(in); |
| + } |
| + |
| + void EchoTouchscreenDevice( |
| + const TouchscreenDevice& in, |
| + const EchoTouchscreenDeviceCallback& callback) override { |
| + callback.Run(in); |
| + } |
| + |
| + 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.
|
| + mojo::BindingSet<DeviceTraitsTestService> traits_test_bindings_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DeviceStructTraitsTest); |
| +}; |
| + |
| +} // namespace |
| + |
| +TEST_F(DeviceStructTraitsTest, InputDevice) { |
| + InputDevice input(15, // id |
| + INPUT_DEVICE_INTERNAL, // type |
| + "Input Device"); // name |
| + input.sys_path = base::FilePath::FromUTF8Unsafe("/dev/input/event14"); |
| + input.vendor_id = 1000; |
| + input.product_id = 2000; |
| + |
| + mojom::DeviceTraitsTestServicePtr proxy = GetTraitsTestProxy(); |
| + InputDevice output; |
| + proxy->EchoInputDevice(input, &output); |
| + |
| + EXPECT_EQ(input.id, output.id); |
| + EXPECT_EQ(input.type, output.type); |
| + EXPECT_EQ(input.name, output.name); |
| + EXPECT_EQ(input.sys_path, output.sys_path); |
| + EXPECT_EQ(input.vendor_id, output.vendor_id); |
| + EXPECT_EQ(input.product_id, output.product_id); |
| +} |
| + |
| +TEST_F(DeviceStructTraitsTest, TouchscreenDevice) { |
| + TouchscreenDevice input(10, // id |
| + INPUT_DEVICE_UNKNOWN, // type |
| + "Touchscreen Device", // name |
| + gfx::Size(123, 456), // size |
| + 3); // touch_points |
| + // Not setting sys_path intentionally. |
| + input.vendor_id = 0; |
| + 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
|
| + |
| + mojom::DeviceTraitsTestServicePtr proxy = GetTraitsTestProxy(); |
| + TouchscreenDevice output; |
| + proxy->EchoTouchscreenDevice(input, &output); |
| + |
| + EXPECT_EQ(input.id, output.id); |
| + EXPECT_EQ(input.type, output.type); |
| + EXPECT_EQ(input.name, output.name); |
| + EXPECT_EQ(input.sys_path, output.sys_path); |
| + EXPECT_EQ(input.vendor_id, output.vendor_id); |
| + EXPECT_EQ(input.product_id, output.product_id); |
| + EXPECT_EQ(input.size, output.size); |
| + EXPECT_EQ(input.touch_points, output.touch_points); |
| +} |
| + |
| +} // namespace ui |