OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 <linux/input.h> |
| 6 #include <wayland-server.h> |
| 7 |
| 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/events/event.h" |
| 11 #include "ui/ozone/platform/wayland/fake_server.h" |
| 12 #include "ui/ozone/platform/wayland/mock_platform_window_delegate.h" |
| 13 #include "ui/ozone/platform/wayland/wayland_test.h" |
| 14 #include "ui/ozone/platform/wayland/wayland_window.h" |
| 15 |
| 16 using ::testing::SaveArg; |
| 17 using ::testing::_; |
| 18 |
| 19 namespace ui { |
| 20 |
| 21 class WaylandKeyboardTest : public WaylandTest { |
| 22 public: |
| 23 WaylandKeyboardTest() {} |
| 24 |
| 25 void SetUp() override { |
| 26 WaylandTest::SetUp(); |
| 27 |
| 28 wl_seat_send_capabilities(server.seat()->resource(), |
| 29 WL_SEAT_CAPABILITY_KEYBOARD); |
| 30 |
| 31 Sync(); |
| 32 |
| 33 keyboard = server.seat()->keyboard.get(); |
| 34 ASSERT_TRUE(keyboard); |
| 35 } |
| 36 |
| 37 protected: |
| 38 wl::MockKeyboard* keyboard; |
| 39 |
| 40 private: |
| 41 DISALLOW_COPY_AND_ASSIGN(WaylandKeyboardTest); |
| 42 }; |
| 43 |
| 44 ACTION_P(CloneEvent, ptr) { |
| 45 *ptr = Event::Clone(*arg0); |
| 46 } |
| 47 |
| 48 TEST_F(WaylandKeyboardTest, Keypress) { |
| 49 struct wl_array empty; |
| 50 wl_array_init(&empty); |
| 51 wl_keyboard_send_enter(keyboard->resource(), 1, surface->resource(), &empty); |
| 52 wl_array_release(&empty); |
| 53 |
| 54 wl_keyboard_send_key(keyboard->resource(), 2, 0, 30 /* a */, |
| 55 WL_KEYBOARD_KEY_STATE_PRESSED); |
| 56 |
| 57 std::unique_ptr<Event> event; |
| 58 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 59 |
| 60 Sync(); |
| 61 ASSERT_TRUE(event); |
| 62 ASSERT_TRUE(event->IsKeyEvent()); |
| 63 |
| 64 auto key_event = event->AsKeyEvent(); |
| 65 EXPECT_EQ(ui::VKEY_A, key_event->key_code()); |
| 66 EXPECT_EQ(ET_KEY_PRESSED, key_event->type()); |
| 67 |
| 68 wl_keyboard_send_leave(keyboard->resource(), 3, surface->resource()); |
| 69 |
| 70 Sync(); |
| 71 |
| 72 wl_keyboard_send_key(keyboard->resource(), 3, 0, 30 /* a */, |
| 73 WL_KEYBOARD_KEY_STATE_PRESSED); |
| 74 EXPECT_CALL(delegate, DispatchEvent(_)).Times(0); |
| 75 } |
| 76 |
| 77 } // namespace ui |
OLD | NEW |