chromium/ui/ozone/platform/x11/test/x11_drag_drop_client_unittest.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/base/x/x11_drag_drop_client.h"

#include <map>
#include <memory>
#include <utility>
#include <vector>

#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkPath.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/mojom/drag_drop_types.mojom-shared.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/dragdrop/os_exchange_data_provider_factory_ozone.h"
#include "ui/base/x/x11_cursor.h"
#include "ui/base/x/x11_move_loop.h"
#include "ui/base/x/x11_move_loop_delegate.h"
#include "ui/base/x/x11_os_exchange_data_provider.h"
#include "ui/base/x/x11_util.h"
#include "ui/events/event_utils.h"
#include "ui/events/platform/x11/x11_event_source.h"
#include "ui/gfx/x/atom_cache.h"
#include "ui/gfx/x/connection.h"
#include "ui/gfx/x/xproto.h"
#include "ui/ozone/platform/x11/os_exchange_data_provider_x11.h"
#include "ui/ozone/platform/x11/x11_window.h"
#include "ui/platform_window/platform_window_init_properties.h"

namespace ui {
namespace {

DragOperation;

class TestDragDropClient;

// Collects messages which would otherwise be sent to |window_| via
// SendXClientEvent().
class ClientMessageEventCollector {};

// An implementation of X11MoveLoop where RunMoveLoop() always starts the
// move loop.
class TestMoveLoop : public X11MoveLoop {};

// Implementation of XDragDropClient which short circuits FindWindowFor().
class SimpleTestDragDropClient : public XDragDropClient,
                                 public XDragDropClient::Delegate,
                                 public X11MoveLoopDelegate {};

// Implementation of XDragDropClient which works with a fake
// |XDragDropClient::source_current_window_|.
class TestDragDropClient : public SimpleTestDragDropClient {};

///////////////////////////////////////////////////////////////////////////////
// ClientMessageEventCollector

ClientMessageEventCollector::ClientMessageEventCollector(
    x11::Window window,
    TestDragDropClient* client)
    :{}

ClientMessageEventCollector::~ClientMessageEventCollector() {}

std::vector<x11::ClientMessageEvent>
ClientMessageEventCollector::PopAllEvents() {}

void ClientMessageEventCollector::RecordEvent(
    const x11::ClientMessageEvent& event) {}

///////////////////////////////////////////////////////////////////////////////
// TestMoveLoop

TestMoveLoop::TestMoveLoop(X11MoveLoopDelegate* delegate)
    :{}

TestMoveLoop::~TestMoveLoop() = default;

bool TestMoveLoop::IsRunning() const {}

bool TestMoveLoop::RunMoveLoop(bool can_grab_pointer,
                               scoped_refptr<X11Cursor> old_cursor,
                               scoped_refptr<X11Cursor> new_cursor,
                               base::OnceClosure started_callback) {}

void TestMoveLoop::UpdateCursor(scoped_refptr<X11Cursor> cursor) {}

void TestMoveLoop::EndMoveLoop() {}

///////////////////////////////////////////////////////////////////////////////
// SimpleTestDragDropClient

SimpleTestDragDropClient::SimpleTestDragDropClient(X11Window* window)
    :{}

SimpleTestDragDropClient::~SimpleTestDragDropClient() = default;

void SimpleTestDragDropClient::SetTopmostXWindow(x11::Window window) {}

bool SimpleTestDragDropClient::IsMoveLoopRunning() {}

DragOperation SimpleTestDragDropClient::StartDragAndDrop(
    std::unique_ptr<OSExchangeData> data,
    X11Window* source_window,
    int allowed_operations,
    mojom::DragEventSource source) {}

std::optional<gfx::AcceleratedWidget>
SimpleTestDragDropClient::GetDragWidget() {}

int SimpleTestDragDropClient::UpdateDrag(const gfx::Point& screen_point) {}

void SimpleTestDragDropClient::UpdateCursor(
    DragOperation negotiated_operation) {}
void SimpleTestDragDropClient::OnBeginForeignDrag(x11::Window window) {}
void SimpleTestDragDropClient::OnEndForeignDrag() {}
void SimpleTestDragDropClient::OnBeforeDragLeave() {}
DragOperation SimpleTestDragDropClient::PerformDrop() {}
void SimpleTestDragDropClient::EndDragLoop() {}

x11::Window SimpleTestDragDropClient::FindWindowFor(
    const gfx::Point& screen_point) {}

void SimpleTestDragDropClient::OnMouseMovement(const gfx::Point& screen_point,
                                               int flags,
                                               base::TimeTicks event_time) {}

void SimpleTestDragDropClient::OnMouseReleased() {}

void SimpleTestDragDropClient::OnMoveLoopEnded() {}

///////////////////////////////////////////////////////////////////////////////
// TestDragDropClient

TestDragDropClient::TestDragDropClient(X11Window* window)
    :{}

TestDragDropClient::~TestDragDropClient() = default;

x11::Atom TestDragDropClient::GetAtom(const char* name) {}

bool TestDragDropClient::MessageHasType(const x11::ClientMessageEvent& event,
                                        const char* type) {}

void TestDragDropClient::SetEventCollectorFor(
    x11::Window window,
    ClientMessageEventCollector* collector) {}

void TestDragDropClient::OnStatus(x11::Window target_window,
                                  bool will_accept_drop,
                                  x11::Atom accepted_action) {}

void TestDragDropClient::OnFinished(x11::Window target_window,
                                    bool accepted_drop,
                                    x11::Atom performed_action) {}

void TestDragDropClient::SetTopmostXWindowAndMoveMouse(x11::Window window) {}

void TestDragDropClient::SendXClientEvent(
    x11::Window window,
    const x11::ClientMessageEvent& event) {}

class TestPlatformWindowDelegate : public PlatformWindowDelegate {};

class TestOSExchangeDataProvideFactory
    : public OSExchangeDataProviderFactoryOzone {};

}  // namespace

class X11DragDropClientTest : public testing::Test {};

namespace {

void BasicStep2(TestDragDropClient* client, x11::Window toplevel) {}

void BasicStep3(TestDragDropClient* client, x11::Window toplevel) {}

}  // namespace

TEST_F(X11DragDropClientTest, Basic) {}

namespace {

void TargetDoesNotRespondStep2(TestDragDropClient* client) {}

}  // namespace

// Test that we do not wait for the target to send XdndStatus if we have not
// received any XdndStatus messages at all from the target. The Unity
// DNDCollectionWindow is an example of an XdndAware target which does not
// respond to XdndPosition messages at all.
TEST_F(X11DragDropClientTest, TargetDoesNotRespond) {}

namespace {

void QueuePositionStep2(TestDragDropClient* client) {}

}  // namespace

// Test that XdndPosition messages are queued till the pending XdndPosition
// message is acked via an XdndStatus message.
TEST_F(X11DragDropClientTest, QueuePosition) {}

namespace {

void TargetChangesStep2(TestDragDropClient* client) {}

}  // namespace

// Test the behavior when the target changes during a drag.
TEST_F(X11DragDropClientTest, TargetChanges) {}

namespace {

void RejectAfterMouseReleaseStep2(TestDragDropClient* client) {}

void RejectAfterMouseReleaseStep3(TestDragDropClient* client) {}

}  // namespace

// Test that the source sends XdndLeave instead of XdndDrop if the drag
// operation is rejected after the mouse is released.
TEST_F(X11DragDropClientTest, RejectAfterMouseRelease) {}

}  // namespace ui