chromium/ui/views/controls/button/button_unittest.cc

// Copyright 2012 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/controls/button/button.h"

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

#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/actions/actions.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/display/screen.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
#include "ui/events/test/event_generator.h"
#include "ui/events/types/event_type.h"
#include "ui/gfx/geometry/point.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/animation/ink_drop_host.h"
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/test/ink_drop_host_test_api.h"
#include "ui/views/animation/test/test_ink_drop.h"
#include "ui/views/animation/test/test_ink_drop_host.h"
#include "ui/views/context_menu_controller.h"
#include "ui/views/controls/button/button_controller.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/menu_button.h"
#include "ui/views/controls/button/radio_button.h"
#include "ui/views/controls/button/toggle_button.h"
#include "ui/views/controls/link.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/style/platform_style.h"
#include "ui/views/test/ax_event_counter.h"
#include "ui/views/test/button_test_api.h"
#include "ui/views/test/view_metadata_test_utils.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/widget/widget_utils.h"

#if defined(USE_AURA)
#include "ui/aura/test/test_cursor_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#endif

namespace views {

InkDropHostTestApi;
TestInkDrop;

namespace {

// No-op test double of a ContextMenuController.
class TestContextMenuController : public ContextMenuController {};

class TestButton : public Button {};

BEGIN_METADATA()

class TestButtonObserver {};

TestInkDrop* AddTestInkDrop(TestButton* button) {}

}  // namespace

class ButtonTest : public ViewsTestBase {};

// Iterate through the metadata for Button to ensure it all works.
TEST_F(ButtonTest, MetadataTest) {}

// Tests that hover state changes correctly when visibility/enableness changes.
TEST_F(ButtonTest, HoverStateOnVisibilityChange) {}

// Tests that the hover state is preserved during a view hierarchy update of a
// button's child View.
TEST_F(ButtonTest, HoverStatePreservedOnDescendantViewHierarchyChange) {}

TEST_F(ButtonTest, AccessibleHoveredStateUpdatesCorrectly) {}

// Tests the different types of NotifyActions.
TEST_F(ButtonTest, NotifyAction) {}

// Tests that OnClickCanceled gets called when NotifyClick is not expected
// anymore.
TEST_F(ButtonTest, NotifyActionNoClick) {}

TEST_F(ButtonTest, ButtonControllerNotifyClick) {}

// No touch on desktop Mac. Tracked in http://crbug.com/445520.
#if !BUILDFLAG(IS_MAC) || defined(USE_AURA)

namespace {

void PerformGesture(Button* button, ui::EventType event_type) {}

}  // namespace

// Tests that gesture events correctly change the button state.
TEST_F(ButtonTest, GestureEventsSetState) {}

// Tests that if the button was disabled in its button press handler, gesture
// events will not revert the disabled state back to normal.
// https://crbug.com/1084241.
TEST_F(ButtonTest, GestureEventsRespectDisabledState) {}

#endif  // !BUILDFLAG(IS_MAC) || defined(USE_AURA)

// Ensure subclasses of Button are correctly recognized as Button.
TEST_F(ButtonTest, AsButton) {}

// Tests that pressing a button shows the ink drop and releasing the button
// does not hide the ink drop.
// Note: Ink drop is not hidden upon release because Button descendants
// may enter a different ink drop state.
TEST_F(ButtonTest, ButtonClickTogglesInkDrop) {}

// Tests that pressing a button shows and releasing capture hides ink drop.
// Releasing capture should also reset PRESSED button state to NORMAL.
TEST_F(ButtonTest, CaptureLossHidesInkDrop) {}

TEST_F(ButtonTest, HideInkDropWhenShowingContextMenu) {}

TEST_F(ButtonTest, DontHideInkDropWhenShowingContextMenu) {}

TEST_F(ButtonTest, HideInkDropOnBlur) {}

TEST_F(ButtonTest, HideInkDropHighlightOnDisable) {}

TEST_F(ButtonTest, InkDropAfterTryingToShowContextMenu) {}

TEST_F(ButtonTest, HideInkDropHighlightWhenRemoved) {}

// Tests that when button is set to notify on release, dragging mouse out and
// back transitions ink drop states correctly.
TEST_F(ButtonTest, InkDropShowHideOnMouseDraggedNotifyOnRelease) {}

// Tests that when button is set to notify on press, dragging mouse out and back
// does not change the ink drop state.
TEST_F(ButtonTest, InkDropShowHideOnMouseDraggedNotifyOnPress) {}

TEST_F(ButtonTest, InkDropStaysHiddenWhileDragging) {}

// Ensure PressedCallback is dynamically settable.
TEST_F(ButtonTest, SetCallback) {}

// VisibilityTestButton tests to see if an ink drop or a layer has been added to
// the button at any point during the visibility state changes of its Widget.
class VisibilityTestButton : public TestButton {};

// Test that hiding or closing a Widget doesn't attempt to add a layer due to
// changed visibility states.
TEST_F(ButtonTest, NoLayerAddedForWidgetVisibilityChanges) {}

// Verify that the Space key clicks the button on key-press on Mac, and
// key-release on other platforms.
TEST_F(ButtonTest, ActionOnSpace) {}

// Verify that the Return key clicks the button on key-press on all platforms
// except Mac. On Mac, the Return key performs the default action associated
// with a dialog, even if a button has focus.
TEST_F(ButtonTest, ActionOnReturn) {}

// Verify that a subclass may customize the action for a key pressed event.
TEST_F(ButtonTest, CustomActionOnKeyPressedEvent) {}

// Verifies that button activation highlight state changes trigger property
// change callbacks.
TEST_F(ButtonTest, ChangingHighlightStateNotifiesCallback) {}

// Verifies that button state changes trigger property change callbacks.
TEST_F(ButtonTest, ClickingButtonNotifiesObserverOfStateChanges) {}

// Verifies that direct calls to Button::SetState() trigger property change
// callbacks.
TEST_F(ButtonTest, SetStateNotifiesObserver) {}

// Verifies setting the tooltip text will call NotifyAccessibilityEvent.
TEST_F(ButtonTest, SetTooltipTextNotifiesAccessibilityEvent) {}

TEST_F(ButtonTest, AccessibleRole) {}

TEST_F(ButtonTest, AccessibleDefaultActionVerb) {}

TEST_F(ButtonTest, AnchorHighlightSetsHiglight) {}

TEST_F(ButtonTest, AnchorHighlightDestructionClearsHighlight) {}

TEST_F(ButtonTest, NestedAnchorHighlights) {}

TEST_F(ButtonTest, OverlappingAnchorHighlights) {}

TEST_F(ButtonTest, AnchorHighlightsCanOutliveButton) {}

ButtonActionViewInterfaceTest;

TEST_F(ButtonActionViewInterfaceTest, TestActionChanged) {}

TEST_F(ButtonActionViewInterfaceTest, TestActionTriggered) {}

}  // namespace views