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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <linux/input-event-codes.h>
#include <wayland-client-core.h>
#include "ash/drag_drop/drag_drop_controller.h"
#include "ash/shell.h"
#include "base/containers/contains.h"
#include "base/containers/flat_map.h"
#include "base/test/bind.h"
#include "components/exo/wayland/test/client_util.h"
#include "components/exo/wayland/test/server_util.h"
#include "components/exo/wayland/test/shell_client_data.h"
#include "components/exo/wayland/test/test_client.h"
#include "components/exo/wayland/test/wayland_server_test.h"
#include "ui/aura/client/drag_drop_client.h"
namespace exo::wayland {
using DataDeviceManagerTest = test::WaylandServerTest;
namespace {
class InputListenerImpl : public test::InputListener {
public:
// test::InputListener:
void OnButtonPressed(uint32_t serial, uint32_t button) override {
button_serial_map[button] = serial;
}
void OnTouchDown(uint32_t serial,
wl_surface* surface,
int32_t id,
const gfx::PointF& point) override {
touch_serial_map[id] = serial;
}
base::flat_map<uint32_t, uint32_t> button_serial_map;
base::flat_map<int32_t, uint32_t> touch_serial_map;
};
} // namespace
// TODO(crbug.com/41494812): enable the flaky test.
#if defined(MEMORY_SANITIZER)
#define MAYBE_Mouse DISABLED_Mouse
#else
#define MAYBE_Mouse Mouse
#endif
TEST_F(DataDeviceManagerTest, MAYBE_Mouse) {
test::ResourceKey surface_key;
InputListenerImpl* input_listener = nullptr;
PostToClientAndWait([&](test::TestClient* client) {
ASSERT_TRUE(client->InitShmBufferFactory(256 * 256 * 4));
auto* data_ptr =
client->set_data(std::make_unique<test::ShellClientData>(client));
auto input_listener_impl = std::make_unique<InputListenerImpl>();
input_listener = input_listener_impl.get();
data_ptr->set_input_listener(std::move(input_listener_impl));
data_ptr->CreateXdgToplevel();
data_ptr->CreateAndAttachBuffer({256, 256});
data_ptr->Commit();
surface_key = data_ptr->GetSurfaceResourceKey();
});
Surface* surface = test::server_util::GetUserDataForResource<Surface>(
server_.get(), surface_key);
auto* drag_drop_controller = static_cast<ash::DragDropController*>(
aura::client::GetDragDropClient(ash::Shell::GetPrimaryRootWindow()));
auto* generator = GetEventGenerator();
{
generator->MoveMouseToCenterOf(surface->window());
generator->PressLeftButton();
generator->ReleaseLeftButton();
// process events on client side. This should not start D&D, (thus it will
// not start nested loop) because the button has already been released
PostToClientAndWait([&](test::TestClient* client) {
EXPECT_TRUE(base::Contains(input_listener->button_serial_map, BTN_LEFT));
auto* shell_client_data = client->GetDataAs<test::ShellClientData>();
uint32_t serial = input_listener->button_serial_map[BTN_LEFT];
shell_client_data->StartDrag(serial);
});
}
{
generator->PressLeftButton();
generator->PressButton(ui::EF_MIDDLE_MOUSE_BUTTON);
bool nested_loop_started;
auto* nested_loop_started_ptr = &nested_loop_started;
// This scenario will start D&D, which will run nested loop, so use
// the nested loop closure to drive the test.
drag_drop_controller->SetLoopClosureForTesting(
base::BindLambdaForTesting([generator, nested_loop_started_ptr]() {
generator->ReleaseLeftButton();
*nested_loop_started_ptr = true;
}),
base::DoNothing());
PostToClientAndWait([&](test::TestClient* client) {
EXPECT_TRUE(base::Contains(input_listener->button_serial_map, BTN_LEFT));
auto* shell_client_data = client->GetDataAs<test::ShellClientData>();
uint32_t serial = input_listener->button_serial_map[BTN_LEFT];
shell_client_data->StartDrag(serial);
});
EXPECT_TRUE(nested_loop_started);
}
{
generator->PressLeftButton();
generator->PressButton(ui::EF_MIDDLE_MOUSE_BUTTON);
generator->ReleaseButton(ui::EF_MIDDLE_MOUSE_BUTTON);
bool nested_loop_started = false;
auto* nested_loop_started_ptr = &nested_loop_started;
// This scenario will start D&D, which will run nested loop, so use
// the nested loop closure to drive the test.
drag_drop_controller->SetLoopClosureForTesting(
base::BindLambdaForTesting([generator, nested_loop_started_ptr]() {
generator->ReleaseLeftButton();
*nested_loop_started_ptr = true;
}),
base::DoNothing());
PostToClientAndWait([&](test::TestClient* client) {
EXPECT_TRUE(base::Contains(input_listener->button_serial_map, BTN_LEFT));
auto* shell_client_data = client->GetDataAs<test::ShellClientData>();
uint32_t serial = input_listener->button_serial_map[BTN_LEFT];
shell_client_data->StartDrag(serial);
});
EXPECT_TRUE(nested_loop_started);
}
}
// TODO(crbug.com/41494812): enable the flaky test.
#if defined(MEMORY_SANITIZER)
#define MAYBE_Touch DISABLED_Touch
#else
#define MAYBE_Touch Touch
#endif
TEST_F(DataDeviceManagerTest, MAYBE_Touch) {
test::ResourceKey surface_key;
InputListenerImpl* input_listener = nullptr;
PostToClientAndWait([&](test::TestClient* client) {
ASSERT_TRUE(client->InitShmBufferFactory(256 * 256 * 4));
auto* data_ptr =
client->set_data(std::make_unique<test::ShellClientData>(client));
data_ptr->CreateXdgToplevel();
data_ptr->CreateAndAttachBuffer({256, 256});
data_ptr->Commit();
auto input_listener_impl = std::make_unique<InputListenerImpl>();
input_listener = input_listener_impl.get();
data_ptr->set_input_listener(std::move(input_listener_impl));
surface_key = data_ptr->GetSurfaceResourceKey();
});
Surface* surface = test::server_util::GetUserDataForResource<Surface>(
server_.get(), surface_key);
auto* drag_drop_controller = static_cast<ash::DragDropController*>(
aura::client::GetDragDropClient(ash::Shell::GetPrimaryRootWindow()));
drag_drop_controller->enable_no_image_touch_drag_for_test();
auto* generator = GetEventGenerator();
{
generator->PressTouch(
generator->delegate()->CenterOfWindow(surface->window()));
generator->ReleaseTouch();
// process events on client side. This should not start D&D, (thus it will
// not start nested loop) because the button has already been released
PostToClientAndWait([&](test::TestClient* client) {
EXPECT_TRUE(base::Contains(input_listener->touch_serial_map, 0));
auto* shell_client_data = client->GetDataAs<test::ShellClientData>();
uint32_t serial = input_listener->touch_serial_map[0];
shell_client_data->StartDrag(serial);
});
}
{
generator->PressTouch();
enum Step {
Started,
Moved,
Released,
};
Step step = Step::Started;
auto* step_ptr = &step;
// This scenario will start D&D, which will run nested loop, so use
// the nested loop closure to drive the test.
drag_drop_controller->SetLoopClosureForTesting(
base::BindLambdaForTesting([generator, step_ptr]() {
switch (*step_ptr) {
case Started:
generator->MoveTouchBy(5, 5);
*step_ptr = Moved;
break;
case Moved:
generator->ReleaseTouch();
*step_ptr = Released;
break;
case Released:
break;
}
}),
base::DoNothing());
PostToClientAndWait([&](test::TestClient* client) {
EXPECT_TRUE(base::Contains(input_listener->touch_serial_map, 0));
auto* shell_client_data = client->GetDataAs<test::ShellClientData>();
uint32_t serial = input_listener->touch_serial_map[0];
shell_client_data->StartDrag(serial);
});
EXPECT_EQ(step, Released);
}
}
} // namespace exo::wayland
|