1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/memory/raw_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/ozone/platform/wayland/host/wayland_output.h"
#include "ui/ozone/platform/wayland/host/wayland_seat.h"
#include "ui/ozone/platform/wayland/test/mock_pointer.h"
#include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/ozone/platform/wayland/test/test_keyboard.h"
#include "ui/ozone/platform/wayland/test/wayland_test.h"
#include "ui/ozone/test/mock_platform_window_delegate.h"
namespace ui {
using ::testing::Values;
namespace {
constexpr gfx::Rect kDefaultBounds(0, 0, 100, 100);
} // namespace
class WaylandWindowManagerTest : public WaylandTest {
public:
WaylandWindowManagerTest() = default;
WaylandWindowManagerTest(const WaylandWindowManagerTest&) = delete;
WaylandWindowManagerTest& operator=(const WaylandWindowManagerTest&) = delete;
~WaylandWindowManagerTest() override = default;
void SetUp() override {
WaylandTest::SetUp();
manager_ = connection_->window_manager();
ASSERT_TRUE(manager_);
}
protected:
raw_ptr<WaylandWindowManager> manager_ = nullptr;
};
TEST_P(WaylandWindowManagerTest, GetWindow) {
MockWaylandPlatformWindowDelegate delegate;
auto window1 = CreateWaylandWindowWithParams(PlatformWindowType::kWindow,
kDefaultBounds, &delegate);
gfx::AcceleratedWidget window1_widget = window1->GetWidget();
auto window2 = CreateWaylandWindowWithParams(
PlatformWindowType::kWindow, gfx::Rect(0, 0, 300, 300), &delegate);
EXPECT_TRUE(window1.get() == manager_->GetWindow(window1->GetWidget()));
EXPECT_TRUE(window2.get() == manager_->GetWindow(window2->GetWidget()));
window1.reset();
EXPECT_FALSE(manager_->GetWindow(window1_widget));
}
TEST_P(WaylandWindowManagerTest, GetWindowWithLargestBounds) {
MockWaylandPlatformWindowDelegate delegate;
auto window1 = CreateWaylandWindowWithParams(PlatformWindowType::kWindow,
kDefaultBounds, &delegate);
// There is also default window create by the WaylandTest. Thus, make bounds
// of this window large enough.
auto window2 = CreateWaylandWindowWithParams(
PlatformWindowType::kWindow, gfx::Rect(0, 0, 3000, 3000), &delegate);
EXPECT_TRUE(window2.get() == manager_->GetWindowWithLargestBounds());
}
TEST_P(WaylandWindowManagerTest, GetCurrentFocusedWindow) {
MockWaylandPlatformWindowDelegate delegate;
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
wl_seat_send_capabilities(server->seat()->resource(),
WL_SEAT_CAPABILITY_POINTER);
});
ASSERT_TRUE(connection_->seat()->pointer());
auto window1 = CreateWaylandWindowWithParams(PlatformWindowType::kWindow,
kDefaultBounds, &delegate);
// When window is shown, it automatically gets keyboard focus. Reset it.
connection_->window_manager()->SetKeyboardFocusedWindow(nullptr);
WaylandTestBase::SyncDisplay();
EXPECT_FALSE(manager_->GetCurrentFocusedWindow());
EXPECT_FALSE(manager_->GetCurrentKeyboardFocusedWindow());
EXPECT_FALSE(manager_->GetCurrentPointerOrTouchFocusedWindow());
EXPECT_FALSE(manager_->GetCurrentPointerFocusedWindow());
PostToServerAndWait([surface_id = window1->root_surface()->get_surface_id()](
wl::TestWaylandServerThread* server) {
auto* const pointer = server->seat()->pointer()->resource();
auto* const surface =
server->GetObject<wl::MockSurface>(surface_id)->resource();
wl_pointer_send_enter(pointer, server->GetNextSerial(), surface, 0, 0);
wl_pointer_send_frame(pointer);
});
EXPECT_FALSE(manager_->GetCurrentKeyboardFocusedWindow());
EXPECT_EQ(window1.get(), manager_->GetCurrentFocusedWindow());
EXPECT_EQ(window1.get(), manager_->GetCurrentPointerOrTouchFocusedWindow());
EXPECT_EQ(window1.get(), manager_->GetCurrentPointerFocusedWindow());
PostToServerAndWait([surface_id = window1->root_surface()->get_surface_id()](
wl::TestWaylandServerThread* server) {
auto* const pointer = server->seat()->pointer()->resource();
auto* const surface =
server->GetObject<wl::MockSurface>(surface_id)->resource();
wl_pointer_send_leave(pointer, server->GetNextSerial(), surface);
wl_pointer_send_frame(pointer);
});
EXPECT_FALSE(manager_->GetCurrentFocusedWindow());
EXPECT_FALSE(manager_->GetCurrentPointerOrTouchFocusedWindow());
EXPECT_FALSE(manager_->GetCurrentPointerFocusedWindow());
}
TEST_P(WaylandWindowManagerTest, GetCurrentKeyboardFocusedWindow) {
MockWaylandPlatformWindowDelegate delegate;
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
wl_seat_send_capabilities(server->seat()->resource(),
WL_SEAT_CAPABILITY_KEYBOARD);
});
ASSERT_TRUE(connection_->seat()->keyboard());
auto window1 = CreateWaylandWindowWithParams(PlatformWindowType::kWindow,
kDefaultBounds, &delegate);
// When window is shown, it automatically gets keyboard focus. Reset it.
connection_->window_manager()->SetKeyboardFocusedWindow(nullptr);
WaylandTestBase::SyncDisplay();
EXPECT_FALSE(manager_->GetCurrentKeyboardFocusedWindow());
PostToServerAndWait([surface_id = window1->root_surface()->get_surface_id()](
wl::TestWaylandServerThread* server) {
auto* const keyboard = server->seat()->keyboard()->resource();
auto* const surface =
server->GetObject<wl::MockSurface>(surface_id)->resource();
wl::ScopedWlArray empty({});
wl_keyboard_send_enter(keyboard, server->GetNextSerial(), surface,
empty.get());
});
EXPECT_FALSE(manager_->GetCurrentPointerOrTouchFocusedWindow());
EXPECT_EQ(window1.get(), manager_->GetCurrentFocusedWindow());
EXPECT_EQ(window1.get(), manager_->GetCurrentKeyboardFocusedWindow());
PostToServerAndWait([surface_id = window1->root_surface()->get_surface_id()](
wl::TestWaylandServerThread* server) {
auto* const keyboard = server->seat()->keyboard()->resource();
auto* const surface =
server->GetObject<wl::MockSurface>(surface_id)->resource();
wl_keyboard_send_leave(keyboard, server->GetNextSerial(), surface);
});
EXPECT_FALSE(manager_->GetCurrentKeyboardFocusedWindow());
}
TEST_P(WaylandWindowManagerTest, GetAllWindows) {
MockWaylandPlatformWindowDelegate delegate;
// There is a default window created by WaylandTest.
auto windows = manager_->GetAllWindows();
EXPECT_EQ(1u, windows.size());
window_.reset();
auto window1 = CreateWaylandWindowWithParams(PlatformWindowType::kWindow,
kDefaultBounds, &delegate);
auto window2 = CreateWaylandWindowWithParams(PlatformWindowType::kWindow,
kDefaultBounds, &delegate);
windows = manager_->GetAllWindows();
EXPECT_EQ(2u, windows.size());
}
INSTANTIATE_TEST_SUITE_P(XdgVersionStableTest,
WaylandWindowManagerTest,
Values(wl::ServerConfig{}));
} // namespace ui
|