chromium/ui/views/bubble/bubble_dialog_delegate_view_unittest.cc

// Copyright 2016 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/bubble/bubble_dialog_delegate_view.h"

#include <stddef.h>

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

#include "base/i18n/rtl.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "ui/base/hit_test.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/mojom/dialog_button.mojom.h"
#include "ui/base/ui_base_features.h"
#include "ui/compositor/compositor.h"
#include "ui/display/test/test_screen.h"
#include "ui/events/event_utils.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/animation/test/ink_drop_host_test_api.h"
#include "ui/views/animation/test/test_ink_drop.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/styled_label.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/test_views.h"
#include "ui/views/test/test_widget_observer.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/test/views_test_utils.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"

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

namespace views {

TestInkDrop;

namespace {

constexpr gfx::Size kContentSize =;

class TestBubbleDialogDelegateView : public BubbleDialogDelegateView {};

BEGIN_METADATA()

class TestAlertBubbleDialogDelegateView : public TestBubbleDialogDelegateView {};

BEGIN_METADATA()

// A Widget that returns something other than null as its ThemeProvider.  This
// allows us to see whether the theme provider returned by some object came from
// this widget.
class WidgetWithNonNullThemeProvider : public Widget {};

class BubbleDialogDelegateViewTest : public ViewsTestBase {};

class BubbleUmaLoggerTest : public ViewsTestBase {};

}  // namespace

TEST_F(BubbleDialogDelegateViewTest, CreateDelegate) {}

TEST_F(BubbleDialogDelegateViewTest, CloseAnchorWidget) {}

// This test checks that the bubble delegate is capable to handle an early
// destruction of the used anchor view. (Animations and delayed closure of the
// bubble will call upon the anchor view to get its location).
TEST_F(BubbleDialogDelegateViewTest, CloseAnchorViewTest) {}

// Testing that a move of the anchor view will lead to new bubble locations.
TEST_F(BubbleDialogDelegateViewTest, TestAnchorRectMovesWithViewTest) {}

TEST_F(BubbleDialogDelegateViewTest, ResetAnchorWidget) {}

TEST_F(BubbleDialogDelegateViewTest, MultipleBubbleAnchorHighlightTestInOrder) {}

TEST_F(BubbleDialogDelegateViewTest,
       MultipleBubbleAnchorHighlightTestOutOfOrder) {}

TEST_F(BubbleDialogDelegateViewTest, NoParentWidget) {}

TEST_F(BubbleDialogDelegateViewTest, InitiallyFocusedView) {}

TEST_F(BubbleDialogDelegateViewTest, NonClientHitTest) {}

TEST_F(BubbleDialogDelegateViewTest, VisibleWhenAnchorWidgetBoundsChanged) {}

TEST_F(BubbleDialogDelegateViewTest, GetPrimaryWindowWidget) {}

// Test that setting WidgetDelegate::SetCanActivate() to false makes the
// widget created via BubbleDialogDelegateView::CreateBubble() not activatable.
TEST_F(BubbleDialogDelegateViewTest, NotActivatable) {}

TEST_F(BubbleDialogDelegateViewTest, CloseMethods) {}

TEST_F(BubbleDialogDelegateViewTest, PinBlocksCloseOnDeactivate) {}

TEST_F(BubbleDialogDelegateViewTest, CloseOnDeactivatePinCanOutliveBubble) {}

TEST_F(BubbleDialogDelegateViewTest, MultipleCloseOnDeactivatePins) {}

TEST_F(BubbleDialogDelegateViewTest, CustomTitle) {}

// Ensure the BubbleFrameView correctly resizes when the title is provided by a
// StyledLabel.
TEST_F(BubbleDialogDelegateViewTest, StyledLabelTitle) {}

// Ensure associated buttons are highlighted or unhighlighted when the bubble
// widget is shown or hidden respectively.
TEST_F(BubbleDialogDelegateViewTest, AttachedWidgetShowsInkDropWhenVisible) {}

// Ensure associated buttons are highlighted or unhighlighted when the bubble
// widget is shown or hidden respectively when highlighted button is set after
// widget is shown.
TEST_F(BubbleDialogDelegateViewTest, VisibleWidgetShowsInkDropOnAttaching) {}

TEST_F(BubbleDialogDelegateViewTest, VisibleAnchorChanges) {}

TEST_F(BubbleDialogDelegateViewTest, GetThemeProvider_FromAnchorWidget) {}

const int kScreenWidth =;
const int kScreenHeight =;

struct ArrowTestParameters {};

class BubbleDialogDelegateViewArrowTest
    : public BubbleDialogDelegateViewTest,
      public testing::WithParamInterface<ArrowTestParameters> {};

TEST_P(BubbleDialogDelegateViewArrowTest, AvailableScreenSpaceTest) {}

const int kAnchorFarRightX =;
const int kAnchorFarLeftX =;
const int kAnchorFarTopY =;
const int kAnchorFarBottomY =;
const int kAnchorLength =;

// When the anchor rect is positioned at different places Rect(x, y,
// kAnchorLength, kAnchorLength) with (x,y) set to far corners of the screen,
// available space to position the bubble should vary acc. to
// |adjust_if_offscreen_|.
const ArrowTestParameters kAnchorAtFarScreenCornersParams[] =;

INSTANTIATE_TEST_SUITE_P();

// Tests whether the BubbleDialogDelegateView will create a layer backed
// ClientView when SetPaintClientToLayer is set to true.
TEST_F(BubbleDialogDelegateViewTest, WithClientLayerTest) {}

// Tests to ensure BubbleDialogDelegateView does not create a layer backed
// ClientView when SetPaintClientToLayer is set to false.
TEST_F(BubbleDialogDelegateViewTest, WithoutClientLayerTest) {}

TEST_F(BubbleDialogDelegateViewTest, AlertAccessibleEvent) {}

// Anchoring Tests -------------------------------------------------------------

namespace {

class AnchorTestBubbleDialogDelegateView : public BubbleDialogDelegateView {};

// Provides functionality for testing bubble anchoring logic.
// Deriving from widget test provides some nice out-of-the-box functionality for
// creating and managing widgets.
class BubbleDialogDelegateViewAnchorTest : public test::WidgetTest {};

}  // namespace

TEST_F(BubbleDialogDelegateViewAnchorTest,
       AnchoredToWidgetShouldPaintAsActive) {}

TEST_F(BubbleDialogDelegateViewAnchorTest,
       AnchoredToWidgetBecomesActiveWhenBubbleIsShown) {}

TEST_F(BubbleDialogDelegateViewAnchorTest,
       ActiveStatePersistsAcrossAnchorWidgetAndBubbleActivation) {}

TEST_F(BubbleDialogDelegateViewAnchorTest,
       AnchoringAlreadyActiveBubbleChangesAnchorWidgetState) {}

TEST_F(BubbleDialogDelegateViewAnchorTest,
       ActivationPassesToRemainingWidgetOnBubbleClose) {}

TEST_F(BubbleDialogDelegateViewAnchorTest,
       ActivationPassesToOtherWidgetOnReanchor) {}

TEST_F(BubbleDialogDelegateViewAnchorTest,
       ActivationPassesAcrossChainOfAnchoredBubbles) {}

TEST_F(BubbleDialogDelegateViewAnchorTest,
       DestroyingAnchoredToWidgetDoesNotCrash) {}

TEST_F(BubbleDialogDelegateViewAnchorTest,
       DestroyingMiddleWidgetOfAnchorChainDoesNotCrash) {}

// Tests that if the anchor view has kWidgetForAnchoringKey property,
// uses that widget for anchoring.
TEST_F(BubbleDialogDelegateViewAnchorTest, WidgetForAnchoring) {}

TEST_F(BubbleDialogDelegateViewTest, BubbleMetrics) {}

class TestBubbleUmaLogger : public BubbleDialogDelegate::BubbleUmaLogger {};

TEST_F(BubbleUmaLoggerTest, LogMetricFromView) {}

TEST_F(BubbleUmaLoggerTest, LogMetricFromDelegate) {}

TEST_F(BubbleUmaLoggerTest, DoNotLogMetricNotFromAllowedClasses) {}

}  // namespace views