chromium/chrome/browser/ui/views/menu_view_drag_and_drop_test.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 "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/ui/views/menu_test_base.h"
#include "chrome/test/base/interactive_test_utils.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/metadata/metadata_header_macros.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/ozone_buildflags.h"
#include "ui/compositor/layer_tree_owner.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/controls/menu/menu_controller.h"
#include "ui/views/controls/menu/menu_item_view.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/controls/menu/submenu_view.h"
#include "ui/views/view.h"
#include "ui/views/widget/drop_helper.h"

namespace {

DragOperation;

const char16_t kTestNestedDragData[] =;
const char16_t kTestTopLevelDragData[] =;

// A simple view which can be dragged.
class TestDragView : public views::View {};

TestDragView::TestDragView() {}

TestDragView::~TestDragView() {}

int TestDragView::GetDragOperations(const gfx::Point& point) {}

void TestDragView::WriteDragData(const gfx::Point& point,
                                 ui::OSExchangeData* data) {}

BEGIN_METADATA()

// A simple view to serve as a drop target.
class TestTargetView : public views::View {};

void TestTargetView::Init() {}

bool TestTargetView::GetDropFormats(
    int* formats,
    std::set<ui::ClipboardFormatType>* format_types) {}

bool TestTargetView::AreDropTypesRequired() {}

bool TestTargetView::CanDrop(const OSExchangeData& data) {}

void TestTargetView::OnDragEntered(const ui::DropTargetEvent& event) {}

int TestTargetView::OnDragUpdated(const ui::DropTargetEvent& event) {}

views::View::DropCallback TestTargetView::GetDropCallback(
    const ui::DropTargetEvent& event) {}

void TestTargetView::OnDragExited() {}

void TestTargetView::PerformDrop(
    const ui::DropTargetEvent& event,
    ui::mojom::DragOperation& output_drag_op,
    std::unique_ptr<ui::LayerTreeOwner> drag_image_layer_owner) {}

BEGIN_METADATA()

}  // namespace

class MenuViewDragAndDropTest : public MenuTestBase,
                                public views::WidgetObserver {};

void MenuViewDragAndDropTest::BuildMenu(views::MenuItemView* menu) {}

void MenuViewDragAndDropTest::DoTestWithMenuOpen() {}

void MenuViewDragAndDropTest::TearDown() {}

void MenuViewDragAndDropTest::OnDragEntered() {}

bool MenuViewDragAndDropTest::GetDropFormats(
    views::MenuItemView* menu,
    int* formats,
    std::set<ui::ClipboardFormatType>* format_types) {}

bool MenuViewDragAndDropTest::AreDropTypesRequired(views::MenuItemView* menu) {}

bool MenuViewDragAndDropTest::CanDrop(views::MenuItemView* menu,
                                      const ui::OSExchangeData& data) {}

DragOperation MenuViewDragAndDropTest::GetDropOperation(
    views::MenuItemView* item,
    const ui::DropTargetEvent& event,
    DropPosition* position) {}

views::View::DropCallback MenuViewDragAndDropTest::GetDropCallback(
    views::MenuItemView* menu,
    DropPosition position,
    const ui::DropTargetEvent& event) {}

bool MenuViewDragAndDropTest::CanDrag(views::MenuItemView* menu) {}

void MenuViewDragAndDropTest::WriteDragData(
    views::MenuItemView* sender, ui::OSExchangeData* data) {}

int MenuViewDragAndDropTest::GetDragOperations(views::MenuItemView* sender) {}

bool MenuViewDragAndDropTest::ShouldCloseOnDragComplete() {}

void MenuViewDragAndDropTest::PerformDrop(
    const ui::DropTargetEvent& event,
    ui::mojom::DragOperation& output_drag_op,
    std::unique_ptr<ui::LayerTreeOwner> drag_image_layer_owner) {}

class MenuViewDragAndDropTestTestInMenuDrag : public MenuViewDragAndDropTest {};

void MenuViewDragAndDropTestTestInMenuDrag::OnWidgetDragWillStart(
    views::Widget* widget) {}

void MenuViewDragAndDropTestTestInMenuDrag::OnWidgetDragComplete(
    views::Widget* widget) {}

void MenuViewDragAndDropTestTestInMenuDrag::DoTestWithMenuOpen() {}

void MenuViewDragAndDropTestTestInMenuDrag::StartDrag() {}

// Test that an in-menu (i.e., entirely implemented in the menu code) closes the
// menu automatically once the drag is complete, and does not ask the delegate
// to stay open.
// TODO(pkasting): https://crbug.com/939621 Fails on Mac.
// TODO(crbug.com/40911016): Re-enable this test for linux.
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
#define MAYBE_TestInMenuDrag
#else
#define MAYBE_TestInMenuDrag
#endif
VIEW_TEST(MenuViewDragAndDropTestTestInMenuDrag, MAYBE_TestInMenuDrag)

class MenuViewDragAndDropTestNestedDrag : public MenuViewDragAndDropTest {};

void MenuViewDragAndDropTestNestedDrag::OnWidgetDragWillStart(
    views::Widget* widget) {}

void MenuViewDragAndDropTestNestedDrag::OnWidgetDragComplete(
    views::Widget* widget) {}

void MenuViewDragAndDropTestNestedDrag::DoTestWithMenuOpen() {}

void MenuViewDragAndDropTestNestedDrag::OnDragEntered() {}

void MenuViewDragAndDropTestNestedDrag::StartDrag() {}

// Test that a nested drag (i.e. one via a child view, and not entirely
// implemented in menu code) will consult the delegate before closing the view
// after the drag.
// TODO(pkasting): https://crbug.com/939621 Fails on Mac.
// TODO(crbug.com/41496561): Test is failing under ChromeRefresh2023 on wayland.
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_OZONE_WAYLAND)
#define MAYBE_MenuViewDragAndDropNestedDrag
#else
#define MAYBE_MenuViewDragAndDropNestedDrag
#endif
VIEW_TEST(MenuViewDragAndDropTestNestedDrag,
          MAYBE_MenuViewDragAndDropNestedDrag)

class MenuViewDragAndDropForDropStayOpen : public MenuViewDragAndDropTest {};

int MenuViewDragAndDropForDropStayOpen::GetMenuRunnerFlags() {}

void MenuViewDragAndDropForDropStayOpen::DoTestWithMenuOpen() {}

// Test that if a menu is opened for a drop which is handled by a child view
// that the menu does not immediately try to close.
// If this flakes, disable and log details in http://crbug.com/523255.
// Flaky on Lacros. https://crbug.com/1281104
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_MenuViewStaysOpenForNestedDrag
#else
#define MAYBE_MenuViewStaysOpenForNestedDrag
#endif
VIEW_TEST(MenuViewDragAndDropForDropStayOpen,
          MAYBE_MenuViewStaysOpenForNestedDrag)

class MenuViewDragAndDropForDropCancel : public MenuViewDragAndDropTest {};

int MenuViewDragAndDropForDropCancel::GetMenuRunnerFlags() {}

void MenuViewDragAndDropForDropCancel::DoTestWithMenuOpen() {}

// Test that if a menu is opened for a drop handled entirely by menu code, the
// menu will try to close if it does not receive any drag updates.
// Flaky on Lacros. https://crbug.com/1281103
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_MenuViewCancelsForOwnDrag
#else
#define MAYBE_MenuViewCancelsForOwnDrag
#endif
VIEW_TEST(MenuViewDragAndDropForDropCancel, MAYBE_MenuViewCancelsForOwnDrag)