chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_ozone_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 "ui/views/widget/desktop_aura/desktop_drag_drop_client_ozone.h"

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

#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/scoped_refptr.h"
#include "base/notreached.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "ui/aura/client/drag_drop_delegate.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/cursor/platform_cursor.h"
#include "ui/base/data_transfer_policy/data_transfer_endpoint.h"
#include "ui/base/data_transfer_policy/data_transfer_policy_controller.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/platform_window/platform_window.h"
#include "ui/platform_window/wm/wm_drag_handler.h"
#include "ui/platform_window/wm/wm_drop_handler.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/views_delegate.h"
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_platform.h"

namespace views {
namespace {

DragEventSource;
DragOperation;

// Platforms have different approaches to handling window coordinates.  For
// instance, Wayland doesn't use window origin (it is always zero) and treats
// coordinates of pointer events as local ones (always within the window), but
// X11 1) uses the origin and may adjust it so that a window gets non-zero
// origin, see X11Window::OnConfigureEvent(), and 2) treats mouse coordinates as
// global ones, so that the event may be considered being 'outside the window'
// and discarded, which will make some tests in this suite failing.
//
// To ensure the drag to be always started within the drag widget, we choose
// size of the drag widget and location so that the location stays within the
// widget, even if the platform adjusts its position.
//
// See crbug.com/1119787
constexpr gfx::Rect kDragWidgetBounds{};
constexpr gfx::PointF kStartDragLocation{};

class FakePlatformWindow : public ui::PlatformWindow, public ui::WmDragHandler {};

// DragDropDelegate which counts the number of each type of drag-drop event.
class FakeDragDropDelegate : public aura::client::DragDropDelegate {};

}  // namespace

class DesktopDragDropClientOzoneTest : public ViewsTestBase {};

TEST_F(DesktopDragDropClientOzoneTest, StartDrag) {}

TEST_F(DesktopDragDropClientOzoneTest, StartDragCtrlPressed) {}

TEST_F(DesktopDragDropClientOzoneTest, ReceiveDrag) {}

TEST_F(DesktopDragDropClientOzoneTest, TargetDestroyedDuringDrag) {}

// crbug.com/1151836 was null dereference during drag and drop.
//
// A possible reason was invalid sequence of events, so here we just drop data
// without any notifications that should come before (like drag enter or drag
// motion).  Before this change, that would hit some DCHECKS in the debug build
// or cause crash in the release one, now it is handled properly.  Methods of
// FakeDragDropDelegate ensure that data in the event is always valid.
//
// The error message rendered in the console when this test is running is the
// expected and valid side effect.
//
// See more information in the bug.
TEST_F(DesktopDragDropClientOzoneTest, Bug1151836) {}

namespace {

class MockDataTransferPolicyController
    : public ui::DataTransferPolicyController {};

}  // namespace

TEST_F(DesktopDragDropClientOzoneTest, DataLeakPreventionAllowDrop) {}

TEST_F(DesktopDragDropClientOzoneTest, DataLeakPreventionBlockDrop) {}

}  // namespace views