| 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/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/events/event.h" |
| 11 #include "ui/ozone/platform/wayland/fake_server.h" | 12 #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/mock_platform_window_delegate.h" |
| 13 #include "ui/ozone/platform/wayland/wayland_display.h" | 14 #include "ui/ozone/platform/wayland/wayland_display.h" |
| 14 #include "ui/ozone/platform/wayland/wayland_window.h" | 15 #include "ui/ozone/platform/wayland/wayland_window.h" |
| 15 | 16 |
| 16 using ::testing::Eq; | 17 using ::testing::Eq; |
| 17 using ::testing::Mock; | 18 using ::testing::Mock; |
| 18 using ::testing::SaveArg; | 19 using ::testing::SaveArg; |
| 19 using ::testing::StrEq; | 20 using ::testing::StrEq; |
| 20 using ::testing::_; | 21 using ::testing::_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 37 | 38 |
| 38 server.Pause(); | 39 server.Pause(); |
| 39 | 40 |
| 40 EXPECT_TRUE(server.GetObject<wl::MockSurface>(window.GetWidget())); | 41 EXPECT_TRUE(server.GetObject<wl::MockSurface>(window.GetWidget())); |
| 41 server.Resume(); | 42 server.Resume(); |
| 42 } | 43 } |
| 43 | 44 |
| 44 class WaylandWindowTest : public testing::Test { | 45 class WaylandWindowTest : public testing::Test { |
| 45 public: | 46 public: |
| 46 WaylandWindowTest() | 47 WaylandWindowTest() |
| 47 : window(&delegate, &display, gfx::Rect(0, 0, 800, 600)) {} | 48 : window(&delegate, &display, gfx::Rect(0, 0, 800, 600)), |
| 49 test_mouse_event(ET_MOUSE_PRESSED, |
| 50 gfx::Point(10, 15), |
| 51 gfx::Point(10, 15), |
| 52 base::TimeDelta::FromSeconds(123456), |
| 53 EF_LEFT_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON, |
| 54 EF_LEFT_MOUSE_BUTTON) {} |
| 48 | 55 |
| 49 void SetUp() override { | 56 void SetUp() override { |
| 50 ASSERT_TRUE(server.Start()); | 57 ASSERT_TRUE(server.Start()); |
| 51 ASSERT_TRUE(display.Initialize()); | 58 ASSERT_TRUE(display.Initialize()); |
| 52 ASSERT_TRUE(window.Initialize()); | 59 ASSERT_TRUE(window.Initialize()); |
| 53 wl_display_roundtrip(display.display()); | 60 wl_display_roundtrip(display.display()); |
| 54 | 61 |
| 55 server.Pause(); | 62 server.Pause(); |
| 56 | 63 |
| 57 auto surface = server.GetObject<wl::MockSurface>(window.GetWidget()); | 64 auto surface = server.GetObject<wl::MockSurface>(window.GetWidget()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 72 wl_display_roundtrip(display.display()); | 79 wl_display_roundtrip(display.display()); |
| 73 server.Pause(); | 80 server.Pause(); |
| 74 } | 81 } |
| 75 | 82 |
| 76 private: | 83 private: |
| 77 wl::FakeServer server; | 84 wl::FakeServer server; |
| 78 bool initialized = false; | 85 bool initialized = false; |
| 79 | 86 |
| 80 protected: | 87 protected: |
| 81 WaylandDisplay display; | 88 WaylandDisplay display; |
| 82 | |
| 83 MockPlatformWindowDelegate delegate; | 89 MockPlatformWindowDelegate delegate; |
| 84 WaylandWindow window; | 90 WaylandWindow window; |
| 85 | 91 |
| 86 wl::MockXdgSurface* xdg_surface; | 92 wl::MockXdgSurface* xdg_surface; |
| 87 | 93 |
| 94 MouseEvent test_mouse_event; |
| 95 |
| 88 private: | 96 private: |
| 89 DISALLOW_COPY_AND_ASSIGN(WaylandWindowTest); | 97 DISALLOW_COPY_AND_ASSIGN(WaylandWindowTest); |
| 90 }; | 98 }; |
| 91 | 99 |
| 92 TEST_F(WaylandWindowTest, SetTitle) { | 100 TEST_F(WaylandWindowTest, SetTitle) { |
| 93 EXPECT_CALL(*xdg_surface, SetTitle(StrEq("hello"))); | 101 EXPECT_CALL(*xdg_surface, SetTitle(StrEq("hello"))); |
| 94 window.SetTitle(base::ASCIIToUTF16("hello")); | 102 window.SetTitle(base::ASCIIToUTF16("hello")); |
| 95 } | 103 } |
| 96 | 104 |
| 97 TEST_F(WaylandWindowTest, Maximize) { | 105 TEST_F(WaylandWindowTest, Maximize) { |
| 98 EXPECT_CALL(*xdg_surface, SetMaximized()); | 106 EXPECT_CALL(*xdg_surface, SetMaximized()); |
| 99 window.Maximize(); | 107 window.Maximize(); |
| 100 } | 108 } |
| 101 | 109 |
| 102 TEST_F(WaylandWindowTest, Minimize) { | 110 TEST_F(WaylandWindowTest, Minimize) { |
| 103 EXPECT_CALL(*xdg_surface, SetMinimized()); | 111 EXPECT_CALL(*xdg_surface, SetMinimized()); |
| 104 window.Minimize(); | 112 window.Minimize(); |
| 105 } | 113 } |
| 106 | 114 |
| 107 TEST_F(WaylandWindowTest, Restore) { | 115 TEST_F(WaylandWindowTest, Restore) { |
| 108 EXPECT_CALL(*xdg_surface, UnsetMaximized()); | 116 EXPECT_CALL(*xdg_surface, UnsetMaximized()); |
| 109 window.Restore(); | 117 window.Restore(); |
| 110 } | 118 } |
| 111 | 119 |
| 120 TEST_F(WaylandWindowTest, CanDispatchMouseEventDefault) { |
| 121 EXPECT_FALSE(window.CanDispatchEvent(&test_mouse_event)); |
| 122 } |
| 123 |
| 124 TEST_F(WaylandWindowTest, CanDispatchMouseEventFocus) { |
| 125 window.set_pointer_focus(true); |
| 126 EXPECT_TRUE(window.CanDispatchEvent(&test_mouse_event)); |
| 127 } |
| 128 |
| 129 TEST_F(WaylandWindowTest, CanDispatchMouseEventUnfocus) { |
| 130 window.set_pointer_focus(false); |
| 131 EXPECT_FALSE(window.CanDispatchEvent(&test_mouse_event)); |
| 132 } |
| 133 |
| 134 ACTION_P(CloneEvent, ptr) { |
| 135 *ptr = Event::Clone(*arg0); |
| 136 } |
| 137 |
| 138 TEST_F(WaylandWindowTest, DispatchEvent) { |
| 139 scoped_ptr<Event> event; |
| 140 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 141 window.DispatchEvent(&test_mouse_event); |
| 142 ASSERT_TRUE(event); |
| 143 ASSERT_TRUE(event->IsMouseEvent()); |
| 144 auto mouse_event = static_cast<MouseEvent*>(event.get()); |
| 145 EXPECT_EQ(mouse_event->location_f(), test_mouse_event.location_f()); |
| 146 EXPECT_EQ(mouse_event->root_location_f(), test_mouse_event.root_location_f()); |
| 147 EXPECT_EQ(mouse_event->time_stamp(), test_mouse_event.time_stamp()); |
| 148 EXPECT_EQ(mouse_event->button_flags(), test_mouse_event.button_flags()); |
| 149 EXPECT_EQ(mouse_event->changed_button_flags(), |
| 150 test_mouse_event.changed_button_flags()); |
| 151 } |
| 152 |
| 112 TEST_F(WaylandWindowTest, ConfigureEvent) { | 153 TEST_F(WaylandWindowTest, ConfigureEvent) { |
| 113 wl_array states; | 154 wl_array states; |
| 114 wl_array_init(&states); | 155 wl_array_init(&states); |
| 115 xdg_surface_send_configure(xdg_surface->resource(), 1000, 1000, &states, 12); | 156 xdg_surface_send_configure(xdg_surface->resource(), 1000, 1000, &states, 12); |
| 116 xdg_surface_send_configure(xdg_surface->resource(), 1500, 1000, &states, 13); | 157 xdg_surface_send_configure(xdg_surface->resource(), 1500, 1000, &states, 13); |
| 117 | 158 |
| 118 // Make sure that the implementation does not call OnBoundsChanged for each | 159 // Make sure that the implementation does not call OnBoundsChanged for each |
| 119 // configure event if it receives multiple in a row. | 160 // configure event if it receives multiple in a row. |
| 120 EXPECT_CALL(delegate, OnBoundsChanged(_)).Times(0); | 161 EXPECT_CALL(delegate, OnBoundsChanged(_)).Times(0); |
| 121 Sync(); | 162 Sync(); |
| 122 Mock::VerifyAndClearExpectations(&delegate); | 163 Mock::VerifyAndClearExpectations(&delegate); |
| 123 | 164 |
| 124 EXPECT_CALL(delegate, OnBoundsChanged(Eq(gfx::Rect(0, 0, 1500, 1000)))); | 165 EXPECT_CALL(delegate, OnBoundsChanged(Eq(gfx::Rect(0, 0, 1500, 1000)))); |
| 125 EXPECT_CALL(*xdg_surface, AckConfigure(13)); | 166 EXPECT_CALL(*xdg_surface, AckConfigure(13)); |
| 126 window.ApplyPendingBounds(); | 167 window.ApplyPendingBounds(); |
| 127 } | 168 } |
| 128 | 169 |
| 129 } // namespace ui | 170 } // namespace ui |
| OLD | NEW |