chromium/ui/ozone/platform/wayland/host/wayland_data_drag_controller_unittest.cc

// Copyright 2018 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/test/mock_callback.h"
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "ui/ozone/platform/wayland/host/wayland_data_drag_controller.h"

#include <linux/input.h>
#include <wayland-server.h>

#include <memory>
#include <string>
#include <vector>

#include "base/containers/contains.h"
#include "base/containers/flat_set.h"
#include "base/functional/bind.h"
#include "base/pickle.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/test/bind.h"
#include "build/chromeos_buildflags.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/clipboard/clipboard_constants.h"
#include "ui/base/clipboard/clipboard_format_type.h"
#include "ui/base/clipboard/file_info.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/dragdrop/os_exchange_data_provider_factory.h"
#include "ui/events/base_event_utils.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/ozone/platform/wayland/host/wayland_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_cursor_position.h"
#include "ui/ozone/platform/wayland/host/wayland_data_device.h"
#include "ui/ozone/platform/wayland/host/wayland_data_device_manager.h"
#include "ui/ozone/platform/wayland/host/wayland_data_offer.h"
#include "ui/ozone/platform/wayland/host/wayland_data_source.h"
#include "ui/ozone/platform/wayland/host/wayland_serial_tracker.h"
#include "ui/ozone/platform/wayland/host/wayland_window.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/scoped_wl_array.h"
#include "ui/ozone/platform/wayland/test/test_data_device.h"
#include "ui/ozone/platform/wayland/test/test_data_device_manager.h"
#include "ui/ozone/platform/wayland/test/test_data_offer.h"
#include "ui/ozone/platform/wayland/test/test_data_source.h"
#include "ui/ozone/platform/wayland/test/test_keyboard.h"
#include "ui/ozone/platform/wayland/test/test_wayland_server_thread.h"
#include "ui/ozone/platform/wayland/test/wayland_drag_drop_test.h"
#include "ui/ozone/platform/wayland/test/wayland_test.h"
#include "ui/ozone/public/platform_clipboard.h"
#include "ui/platform_window/platform_window_init_properties.h"
#include "ui/platform_window/wm/wm_drag_handler.h"
#include "ui/platform_window/wm/wm_drop_handler.h"
#include "url/gurl.h"

_;
AtMost;
Eq;
Mock;
Values;
DragEventSource;
DragOperation;

namespace ui {
namespace {

constexpr char kSampleTextForDragAndDrop[] =;
constexpr char16_t kSampleTextForDragAndDrop16[] =;

constexpr FilenameToURLPolicy kFilenameToURLPolicy =;

template <typename StringType>
PlatformClipboard::Data ToClipboardData(const StringType& data_string) {}

}  // namespace

class MockDropHandler : public WmDropHandler {};

class WaylandDataDragControllerTest : public WaylandDragDropTest {};

TEST_P(WaylandDataDragControllerTest, StartDrag) {}

TEST_P(WaylandDataDragControllerTest, StartDragWithWrongMimeType) {}

// Ensures data drag controller properly offers dragged data with custom
// formats. Regression test for a bunch of bugs, such as:
//  - https://crbug.com/1236708
//  - https://crbug.com/1207607
//  - https://crbug.com/1247063
TEST_P(WaylandDataDragControllerTest, StartDragWithCustomFormats) {}

TEST_P(WaylandDataDragControllerTest, StartDragWithFileContents) {}

// Cancels a DnD session that we initiated while the cursor is over our window.
TEST_P(WaylandDataDragControllerTest, CancelOutgoingDrag) {}

// Cancels a DnD session that we initiated while the cursor is outside of our
// window.
TEST_P(WaylandDataDragControllerTest, CancelOutgoingDragOutsideWindow) {}

// Cancels an incoming DnD session on the client-side.
// Regression test for https://crbug.com/336706549.
TEST_P(WaylandDataDragControllerTest, CancelIncomingDrag) {}

MATCHER_P(PointFNear, n, "") {}

TEST_P(WaylandDataDragControllerTest, ReceiveDrag) {}

TEST_P(WaylandDataDragControllerTest, ReceiveDragPixelSurface) {}

// Emulating an incoming DnD session, ensures that data drag controller
// fetches all the data for the mime-types offered by the source client.
TEST_P(WaylandDataDragControllerTest, DropSeveralMimeTypes) {}

// Tests URI validation for text/uri-list MIME type.  Log warnings rendered in
// the console when this test is running are the expected and valid side effect.
TEST_P(WaylandDataDragControllerTest, ValidateDroppedUriList) {}

// Tests URI validation for text/x-moz-url MIME type.  Log warnings rendered in
// the console when this test is running are the expected and valid side effect.
TEST_P(WaylandDataDragControllerTest, ValidateDroppedXMozUrl) {}

// Verifies the correct delegate functions are called when a drag session is
// started and cancelled within the same surface.
TEST_P(WaylandDataDragControllerTest, StartAndCancel) {}

TEST_P(WaylandDataDragControllerTest, ForeignDragHandleAskAction) {}

// Verifies entered surface destruction is properly handled.
// Regression test for https://crbug.com/1143707.
TEST_P(WaylandDataDragControllerTest, DestroyEnteredSurface) {}

// Verifies that early origin surface destruction is properly handled.
// Regression test for https://crbug.com/1143707.
TEST_P(WaylandDataDragControllerTest, DestroyOriginSurface) {}

// Ensures drag/drop events are properly propagated to non-toplevel windows.
TEST_P(WaylandDataDragControllerTest, DragToNonToplevelWindows) {}

// Ensures that requests to create a |PlatformWindowType::kPopup| during drag
// sessions return wl_subsurface-backed windows.
TEST_P(WaylandDataDragControllerTest, PopupRequestCreatesPopupWindow) {}

// Ensures that requests to create a |PlatformWindowType::kMenu| during drag
// sessions return xdg_popup-backed windows.
TEST_P(WaylandDataDragControllerTest, MenuRequestCreatesPopupWindow) {}

// Regression test for https://crbug.com/1209269.
//
// Emulates "quick" wl_pointer.button release events being sent by the
// compositor, and processed by the ozone/wayland either (1) before or (2) just
// after WaylandWindow::StartDrag is called. The drag start happens in
// response to sequence of input events. Such event processing may take some
// time, for example, when they happen in web contents, which involves async
// browser <=> renderer IPC, etc. In both cases, drag controller is expected to
// gracefully reset state and quit drag loop as if the drag session was
// cancelled as usual.
TEST_P(WaylandDataDragControllerTest, AsyncNoopStartDrag) {}

TEST_P(WaylandDataDragControllerTest, SuppressPointerButtonReleasesAfterEnter) {}

// Regression test for https://crbug.com/1175083.
TEST_P(WaylandDataDragControllerTest, StartDragWithCorrectSerial) {}

// Check drag session is correctly started when there are both mouse button and
// a touch point pressed.
TEST_P(WaylandDataDragControllerTest, StartDragWithCorrectSerialForDragSource) {}

// With an incoming DnD session, this ensures that data drag controller
// gracefully handles drop events received while the data fetching is still
// unfinished. Regression test for https://crbug.com/1400872.
TEST_P(WaylandDataDragControllerTest, DropWhileFetchingData) {}

// Regression test for https://crbug.com/1405176.
TEST_P(WaylandDataDragControllerTest, DndActionsToDragOperations) {}

// Emulate an incoming DnD session, testing that data drag controller gracefully
// handles entered window destruction happening while the data fetching is still
// unfinished. Regression test for https://crbug.com/1400872.
// TODO(b/324541578): Fix threading-related flakiness and re-enabled.
TEST_P(WaylandDataDragControllerTest,
       DISABLED_DestroyWindowWhileFetchingForeignData) {}

// Emulate an incoming DnD session and verifies that data drag controller aborts
// data fetching, if needed, upon wl_data_device.leave.
TEST_P(WaylandDataDragControllerTest, LeaveWindowWhileFetchingData) {}

// Cursor position should be updated during a (outgoing) drag with mouse.
TEST_P(WaylandDataDragControllerTest,
       CursorPositionShouldBeUpdatedDuringMouseDrag) {}

// Cursor position should not be updated during a (outgoing) drag with touch.
TEST_P(WaylandDataDragControllerTest,
       CursorPositionShouldNotBeUpdatedDuringTouchDrag) {}

// Regression test for https://crbug.com/336449364.
TEST_P(WaylandDataDragControllerTest, OutgoingSessionWithoutDndFinished) {}

#if !BUILDFLAG(IS_CHROMEOS_LACROS)
INSTANTIATE_TEST_SUITE_P();

#else
INSTANTIATE_TEST_SUITE_P(
    XdgVersionStableTestWithAuraShell,
    WaylandDataDragControllerTest,
    Values(wl::ServerConfig{.enable_aura_shell =
                                wl::EnableAuraShellProtocol::kEnabled},
           wl::ServerConfig{
               .enable_aura_shell = wl::EnableAuraShellProtocol::kEnabled}));
#endif

}  // namespace ui