chromium/ui/views/interaction/element_tracker_views_unittest.cc

// Copyright 2021 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/element_tracker_views.h"

#include <iterator>
#include <memory>
#include <utility>

#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/ranges/algorithm.h"
#include "base/test/bind.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/element_test_util.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/types/event_type.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/menu_button.h"
#include "ui/views/interaction/interaction_test_util_views.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/widget/widget.h"

namespace views {

DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE();
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE();
DECLARE_CUSTOM_ELEMENT_EVENT_TYPE();
DEFINE_CUSTOM_ELEMENT_EVENT_TYPE(kCustomEventType);

namespace {

enum ElementEventType {};

View* ElementToView(ui::TrackedElement* element) {}

// A subclass of View that has metadata.
class TypedView : public View {};

BEGIN_METADATA()

// Watches events on the ElementTracker and converts the resulting values back
// into Views from the original ui::TrackedElement objects. Monitoring
// callbacks in this way could be done with gmock but the boilerplate would be
// unfortunately complicated (for some events, the correct parameters are not
// known until after the call is made, since the call itself might create the
// element in question). So instead we use this helper class.
class ElementEventWatcher {};

ElementTrackerViews::ViewList ElementsToViews(
    ui::ElementTracker::ElementList elements) {}

}  // namespace

class ElementTrackerViewsTest : public ViewsTestBase {};

TEST_F(ElementTrackerViewsTest, ViewShownByAddingToWidgetSendsNotification) {}

TEST_F(ElementTrackerViewsTest,
       ViewHiddenByRemovingFromWidgetSendsNotification) {}

TEST_F(ElementTrackerViewsTest, ViewShownAfterAddingToWidgetSendsNotification) {}

TEST_F(ElementTrackerViewsTest,
       ViewHiddenAfterAddingToWidgetSendsNotification) {}

TEST_F(ElementTrackerViewsTest, SettingIDOnVisibleViewSendsNotification) {}

TEST_F(ElementTrackerViewsTest, ClearingIDOnVisibleViewSendsNotification) {}

TEST_F(ElementTrackerViewsTest, ChangingIDOnVisibleViewSendsNotification) {}

TEST_F(ElementTrackerViewsTest, ButtonPressedSendsActivatedSignal) {}

TEST_F(ElementTrackerViewsTest, MenuButtonPressedSendsActivatedSignal) {}

TEST_F(ElementTrackerViewsTest, SendCustomEventWithNamedElement) {}

TEST_F(ElementTrackerViewsTest, SendCustomEventWithUnnamedElement) {}

TEST_F(ElementTrackerViewsTest, HandlesCreateWithTheSameIDMultipleTimes) {}

TEST_F(ElementTrackerViewsTest, HandlesReshowingTheSameView) {}

TEST_F(ElementTrackerViewsTest, CanLookupViewByIdentifier) {}

TEST_F(ElementTrackerViewsTest, CanLookUpElementByIdentifier) {}

TEST_F(ElementTrackerViewsTest, CanGetFirstViewByIdentifier) {}

TEST_F(ElementTrackerViewsTest, CanGetFirstElementByIdentifier) {}

TEST_F(ElementTrackerViewsTest, CanGetAllViewsByIdentifier) {}

TEST_F(ElementTrackerViewsTest, CanGetAllElementsByIdentifier) {}

TEST_F(ElementTrackerViewsTest, CanGetVisibilityByIdentifier) {}

TEST_F(ElementTrackerViewsTest, CanLookupElementByView) {}

TEST_F(ElementTrackerViewsTest, AssignTemporaryId) {}

// The following tests ensure conformity with the different platforms' Views
// implementation to ensure that Views are reported as visible to the user at
// the correct times, including during Widget close/delete.

TEST_F(ElementTrackerViewsTest, ParentNotVisibleWhenAddedToWidget) {}

TEST_F(ElementTrackerViewsTest, WidgetNotVisibleWhenAddedToWidget) {}

TEST_F(ElementTrackerViewsTest, ParentHidden) {}

TEST_F(ElementTrackerViewsTest, WidgetHidden) {}

TEST_F(ElementTrackerViewsTest, WidgetClosed) {}

TEST_F(ElementTrackerViewsTest, WidgetDestroyed) {}

TEST_F(ElementTrackerViewsTest, WidgetShownAfterAdd) {}

// This is a gross corner case where a Widget might not report IsVisible()
// during show, but we're still showing views and could conceivably add another
// view as part of a callback.
TEST_F(ElementTrackerViewsTest, AddedDuringWidgetShow) {}

TEST_F(ElementTrackerViewsTest, CleansUpWidgetTrackers) {}

TEST_F(ElementTrackerViewsTest, GetUniqueView) {}

TEST_F(ElementTrackerViewsTest, GetUniqueViewAs) {}

TEST_F(ElementTrackerViewsTest, GetFirstMatchingViewWithSingleView) {}

TEST_F(ElementTrackerViewsTest, GetFirstMatchingViewAs) {}

TEST_F(ElementTrackerViewsTest, GetFirstMatchingViewWithMultipleViews) {}

TEST_F(ElementTrackerViewsTest, GetFirstMatchingViewWithNonViewsElements) {}

TEST_F(ElementTrackerViewsTest, GetAllMatchingViewsWithSingleView) {}

TEST_F(ElementTrackerViewsTest, GetAllMatchingViewsWithMultipleViews) {}

TEST_F(ElementTrackerViewsTest, GetAllMatchingViewsWithNonViewsElements) {}

TEST_F(ElementTrackerViewsTest, GetAllViewsInAnyContextWithSingleView) {}

TEST_F(ElementTrackerViewsTest, GetAllViewsInAnyContextWithMultipleViews) {}

TEST_F(ElementTrackerViewsTest, GetAllViewsInAnyContextWithNonViewsElements) {}

// Verifies that Views on different Widgets are differentiated by the system.
class ElementTrackerTwoWidgetTest : public ElementTrackerViewsTest {};

TEST_F(ElementTrackerTwoWidgetTest, ViewMovedToDifferentWidgetGeneratesEvents) {}

TEST_F(ElementTrackerTwoWidgetTest, CanLookUpViewsOnMultipleWidgets) {}

TEST_F(ElementTrackerTwoWidgetTest,
       MakingViewsVisibleSendsNotificationsToCorrectListeners) {}

TEST_F(ElementTrackerTwoWidgetTest,
       ButtonPressedSendsNotificationsToCorrectListeners) {}

// The following are variations on the "view's context changes when it moves
// between widgets" test, but with an override context callback modifying
// what context is returned for one or both widgets.

TEST_F(ElementTrackerTwoWidgetTest, OverrideContextCallbackCollapsesContexts) {}

TEST_F(ElementTrackerTwoWidgetTest,
       OverrideContextCallbackOverridesContextSelectively) {}

}  // namespace views