chromium/ui/views/interaction/interaction_test_util_views.cc

// Copyright 2022 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/interaction/interaction_test_util_views.h"

#include <string>
#include <utility>

#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/i18n/rtl.h"
#include "base/run_loop.h"
#include "base/scoped_observation.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "ui/accessibility/ax_action_data.h"
#include "ui/accessibility/ax_enums.mojom-shared.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/base/interaction/interaction_test_util.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/events/gesture_event_details.h"
#include "ui/events/types/event_type.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/combobox/combobox.h"
#include "ui/views/controls/editable_combobox/editable_combobox.h"
#include "ui/views/controls/menu/menu_host.h"
#include "ui/views/controls/menu/menu_host_root_view.h"
#include "ui/views/controls/menu/menu_item_view.h"
#include "ui/views/controls/menu/submenu_view.h"
#include "ui/views/controls/tabbed_pane/tabbed_pane.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/interaction/element_tracker_views.h"
#include "ui/views/test/widget_activation_waiter.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/view.h"
#include "ui/views/view_observer.h"
#include "ui/views/view_tracker.h"
#include "ui/views/view_utils.h"
#include "ui/views/widget/any_widget_observer.h"
#include "ui/views/window/dialog_delegate.h"

#if BUILDFLAG(IS_OZONE)
#include "ui/ozone/public/ozone_platform.h"
#endif

#if BUILDFLAG(IS_LINUX) && BUILDFLAG(IS_OZONE) && \
    !BUILDFLAG(IS_CHROMEOS_ASH) && !BUILDFLAG(IS_CHROMEOS_LACROS)
#define HANDLE_WAYLAND_FAILURE
#else
#define HANDLE_WAYLAND_FAILURE
#endif

#if HANDLE_WAYLAND_FAILURE
#include "ui/views/widget/widget_observer.h"
#endif

namespace views::test {

namespace {

#if HANDLE_WAYLAND_FAILURE

// On Wayland on Linux, window activation isn't guaranteed to work (based on
// what compositor extensions are installed). So instead, make a best effort to
// wait for the widget to activate, and if it fails, skip the test as it cannot
// possibly pass.
class WidgetActivationWaiterWayland final : public WidgetObserver {};

#endif  // HANDLE_WAYLAND_FAILURE

// Waits for the dropdown pop-up and selects the specified item from the list.
class DropdownItemSelector {};

gfx::Point GetCenter(views::View* view) {}

bool SendDefaultAction(View* target) {}

// Sends a mouse click to the specified `target`.
// Views are EventHandlers but Widgets are not despite having the same API for
// event handling, so use a templated approach to support both cases.
template <class T>
void SendMouseClick(T* target, const gfx::Point& point) {}

// Sends a tap gesture to the specified `target`.
// Views are EventHandlers but Widgets are not despite having the same API for
// event handling, so use a templated approach to support both cases.
template <class T>
void SendTapGesture(T* target, const gfx::Point& point) {}

// Sends a key press to the specified `target`. Returns true if the view is
// still valid after processing the keypress.
bool SendKeyPress(View* view, ui::KeyboardCode code, int flags = ui::EF_NONE) {}

}  // namespace

InteractionTestUtilSimulatorViews::InteractionTestUtilSimulatorViews() =
    default;
InteractionTestUtilSimulatorViews::~InteractionTestUtilSimulatorViews() =
    default;

ui::test::ActionResult InteractionTestUtilSimulatorViews::PressButton(
    ui::TrackedElement* element,
    InputType input_type) {}

ui::test::ActionResult InteractionTestUtilSimulatorViews::SelectMenuItem(
    ui::TrackedElement* element,
    InputType input_type) {}

ui::test::ActionResult InteractionTestUtilSimulatorViews::DoDefaultAction(
    ui::TrackedElement* element,
    InputType input_type) {}

ui::test::ActionResult InteractionTestUtilSimulatorViews::SelectTab(
    ui::TrackedElement* tab_collection,
    size_t index,
    InputType input_type) {}

ui::test::ActionResult InteractionTestUtilSimulatorViews::SelectDropdownItem(
    ui::TrackedElement* dropdown,
    size_t index,
    InputType input_type) {}

ui::test::ActionResult InteractionTestUtilSimulatorViews::EnterText(
    ui::TrackedElement* element,
    std::u16string text,
    TextEntryMode mode) {}

ui::test::ActionResult InteractionTestUtilSimulatorViews::ActivateSurface(
    ui::TrackedElement* element) {}

ui::test::ActionResult InteractionTestUtilSimulatorViews::SendAccelerator(
    ui::TrackedElement* element,
    ui::Accelerator accelerator) {}

ui::test::ActionResult InteractionTestUtilSimulatorViews::Confirm(
    ui::TrackedElement* element) {}

// static
bool InteractionTestUtilSimulatorViews::IsWayland() {}

// static
ui::test::ActionResult InteractionTestUtilSimulatorViews::ActivateWidget(
    Widget* widget) {}

// static
bool InteractionTestUtilSimulatorViews::DoDefaultAction(View* view,
                                                        InputType input_type) {}

// static
void InteractionTestUtilSimulatorViews::PressButton(Button* button,
                                                    InputType input_type) {}

}  // namespace views::test