OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <wayland-server-core.h> | 5 #include <wayland-server-core.h> |
6 #include <xdg-shell-unstable-v5-server-protocol.h> | 6 #include <xdg-shell-unstable-v5-server-protocol.h> |
7 | 7 |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/events/event.h" |
12 #include "ui/ozone/platform/wayland/fake_server.h" | 13 #include "ui/ozone/platform/wayland/fake_server.h" |
13 #include "ui/ozone/platform/wayland/mock_platform_window_delegate.h" | 14 #include "ui/ozone/platform/wayland/mock_platform_window_delegate.h" |
14 #include "ui/ozone/platform/wayland/wayland_test.h" | 15 #include "ui/ozone/platform/wayland/wayland_test.h" |
15 #include "ui/ozone/platform/wayland/wayland_window.h" | 16 #include "ui/ozone/platform/wayland/wayland_window.h" |
16 | 17 |
17 using ::testing::Eq; | 18 using ::testing::Eq; |
18 using ::testing::Mock; | 19 using ::testing::Mock; |
19 using ::testing::SaveArg; | 20 using ::testing::SaveArg; |
20 using ::testing::StrEq; | 21 using ::testing::StrEq; |
21 using ::testing::_; | 22 using ::testing::_; |
22 | 23 |
23 namespace ui { | 24 namespace ui { |
24 | 25 |
25 class WaylandWindowTest : public WaylandTest { | 26 class WaylandWindowTest : public WaylandTest { |
26 public: | 27 public: |
27 WaylandWindowTest() {} | 28 WaylandWindowTest() |
| 29 : test_mouse_event(ET_MOUSE_PRESSED, |
| 30 gfx::Point(10, 15), |
| 31 gfx::Point(10, 15), |
| 32 base::TimeDelta::FromSeconds(123456), |
| 33 EF_LEFT_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON, |
| 34 EF_LEFT_MOUSE_BUTTON) {} |
28 | 35 |
29 void SetUp() override { | 36 void SetUp() override { |
30 WaylandTest::SetUp(); | 37 WaylandTest::SetUp(); |
31 | 38 |
32 xdg_surface = surface->xdg_surface.get(); | 39 xdg_surface = surface->xdg_surface.get(); |
33 ASSERT_TRUE(xdg_surface); | 40 ASSERT_TRUE(xdg_surface); |
34 } | 41 } |
35 | 42 |
36 protected: | 43 protected: |
37 wl::MockXdgSurface* xdg_surface; | 44 wl::MockXdgSurface* xdg_surface; |
38 | 45 |
| 46 MouseEvent test_mouse_event; |
| 47 |
39 private: | 48 private: |
40 DISALLOW_COPY_AND_ASSIGN(WaylandWindowTest); | 49 DISALLOW_COPY_AND_ASSIGN(WaylandWindowTest); |
41 }; | 50 }; |
42 | 51 |
43 TEST_F(WaylandWindowTest, SetTitle) { | 52 TEST_F(WaylandWindowTest, SetTitle) { |
44 EXPECT_CALL(*xdg_surface, SetTitle(StrEq("hello"))); | 53 EXPECT_CALL(*xdg_surface, SetTitle(StrEq("hello"))); |
45 window.SetTitle(base::ASCIIToUTF16("hello")); | 54 window.SetTitle(base::ASCIIToUTF16("hello")); |
46 } | 55 } |
47 | 56 |
48 TEST_F(WaylandWindowTest, Maximize) { | 57 TEST_F(WaylandWindowTest, Maximize) { |
49 EXPECT_CALL(*xdg_surface, SetMaximized()); | 58 EXPECT_CALL(*xdg_surface, SetMaximized()); |
50 window.Maximize(); | 59 window.Maximize(); |
51 } | 60 } |
52 | 61 |
53 TEST_F(WaylandWindowTest, Minimize) { | 62 TEST_F(WaylandWindowTest, Minimize) { |
54 EXPECT_CALL(*xdg_surface, SetMinimized()); | 63 EXPECT_CALL(*xdg_surface, SetMinimized()); |
55 window.Minimize(); | 64 window.Minimize(); |
56 } | 65 } |
57 | 66 |
58 TEST_F(WaylandWindowTest, Restore) { | 67 TEST_F(WaylandWindowTest, Restore) { |
59 EXPECT_CALL(*xdg_surface, UnsetMaximized()); | 68 EXPECT_CALL(*xdg_surface, UnsetMaximized()); |
60 window.Restore(); | 69 window.Restore(); |
61 } | 70 } |
62 | 71 |
| 72 TEST_F(WaylandWindowTest, CanDispatchMouseEventDefault) { |
| 73 EXPECT_FALSE(window.CanDispatchEvent(&test_mouse_event)); |
| 74 } |
| 75 |
| 76 TEST_F(WaylandWindowTest, CanDispatchMouseEventFocus) { |
| 77 window.set_pointer_focus(true); |
| 78 EXPECT_TRUE(window.CanDispatchEvent(&test_mouse_event)); |
| 79 } |
| 80 |
| 81 TEST_F(WaylandWindowTest, CanDispatchMouseEventUnfocus) { |
| 82 window.set_pointer_focus(false); |
| 83 EXPECT_FALSE(window.CanDispatchEvent(&test_mouse_event)); |
| 84 } |
| 85 |
| 86 ACTION_P(CloneEvent, ptr) { |
| 87 *ptr = Event::Clone(*arg0); |
| 88 } |
| 89 |
| 90 TEST_F(WaylandWindowTest, DispatchEvent) { |
| 91 scoped_ptr<Event> event; |
| 92 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 93 window.DispatchEvent(&test_mouse_event); |
| 94 ASSERT_TRUE(event); |
| 95 ASSERT_TRUE(event->IsMouseEvent()); |
| 96 auto mouse_event = static_cast<MouseEvent*>(event.get()); |
| 97 EXPECT_EQ(mouse_event->location_f(), test_mouse_event.location_f()); |
| 98 EXPECT_EQ(mouse_event->root_location_f(), test_mouse_event.root_location_f()); |
| 99 EXPECT_EQ(mouse_event->time_stamp(), test_mouse_event.time_stamp()); |
| 100 EXPECT_EQ(mouse_event->button_flags(), test_mouse_event.button_flags()); |
| 101 EXPECT_EQ(mouse_event->changed_button_flags(), |
| 102 test_mouse_event.changed_button_flags()); |
| 103 } |
| 104 |
63 TEST_F(WaylandWindowTest, ConfigureEvent) { | 105 TEST_F(WaylandWindowTest, ConfigureEvent) { |
64 wl_array states; | 106 wl_array states; |
65 wl_array_init(&states); | 107 wl_array_init(&states); |
66 xdg_surface_send_configure(xdg_surface->resource(), 1000, 1000, &states, 12); | 108 xdg_surface_send_configure(xdg_surface->resource(), 1000, 1000, &states, 12); |
67 xdg_surface_send_configure(xdg_surface->resource(), 1500, 1000, &states, 13); | 109 xdg_surface_send_configure(xdg_surface->resource(), 1500, 1000, &states, 13); |
68 | 110 |
69 // Make sure that the implementation does not call OnBoundsChanged for each | 111 // Make sure that the implementation does not call OnBoundsChanged for each |
70 // configure event if it receives multiple in a row. | 112 // configure event if it receives multiple in a row. |
71 EXPECT_CALL(delegate, OnBoundsChanged(Eq(gfx::Rect(0, 0, 1500, 1000)))); | 113 EXPECT_CALL(delegate, OnBoundsChanged(Eq(gfx::Rect(0, 0, 1500, 1000)))); |
72 EXPECT_CALL(*xdg_surface, AckConfigure(13)); | 114 EXPECT_CALL(*xdg_surface, AckConfigure(13)); |
73 } | 115 } |
74 | 116 |
75 } // namespace ui | 117 } // namespace ui |
OLD | NEW |