chromium/ui/views/test/widget_test.h

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_VIEWS_TEST_WIDGET_TEST_H_
#define UI_VIEWS_TEST_WIDGET_TEST_H_

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

#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/scoped_observation.h"
#include "base/test/bind.h"
#include "build/build_config.h"
#include "build/chromecast_buildflags.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/views/widget/widget_observer.h"

#if (BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CASTOS)) || \
    BUILDFLAG(IS_CHROMEOS_LACROS) || BUILDFLAG(IS_WIN)

#include "ui/display/screen.h"
#endif

namespace ui {
class EventSink;
class ImeKeyEventDispatcher;
}  // namespace ui

namespace views {

class View;
namespace internal {

class RootView;

}  // namespace internal

namespace test {

// These functions return an arbitrary view v such that:
//
// 1) v is a descendant of the root view of the provided widget, and
// 2) predicate.Run(v) returned true
//
// They are *not* guaranteed to return first child matching the predicate for
// any specific ordering of the children. In fact, these methods deliberately
// randomly choose a child to return, so make sure your predicate matches
// *only* the view you want!
ViewPredicate;
View* AnyViewMatchingPredicate(View* root, const ViewPredicate& predicate);
template <typename Pred>
View* AnyViewMatchingPredicate(View* root, Pred predicate) {}
View* AnyViewMatchingPredicate(Widget* widget, const ViewPredicate& predicate);
template <typename Pred>
View* AnyViewMatchingPredicate(Widget* widget, Pred predicate) {}

View* AnyViewWithClassName(Widget* widget, const std::string& classname);

class WidgetTest : public ViewsTestBase {};

class DesktopWidgetTest : public WidgetTest {};

class DesktopWidgetTestInteractive : public DesktopWidgetTest {};

// A helper WidgetDelegate for tests that require hooks into WidgetDelegate
// calls, and removes some of the boilerplate for initializing a Widget. Calls
// Widget::CloseNow() when destroyed if it hasn't already been done.
class TestDesktopWidgetDelegate : public WidgetDelegate {};

// Testing widget delegate that creates a widget with a single view, which is
// the initially focused view.
class TestInitialFocusWidgetDelegate : public TestDesktopWidgetDelegate {};

// Use in tests to wait for a widget to be destroyed.
class WidgetDestroyedWaiter : public WidgetObserver {};

// Helper class to wait for a Widget to become visible. This will add a failure
// to the currently-running test if the widget is destroyed before becoming
// visible.
class WidgetVisibleWaiter : public WidgetObserver {};

}  // namespace test
}  // namespace views

#endif  // UI_VIEWS_TEST_WIDGET_TEST_H_