#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
#include <memory>
#include <utility>
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/cursor_client.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/client/window_parenting_client.h"
#include "ui/aura/env.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/window_occlusion_tracker_test_api.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
#include "ui/base/mojom/ui_base_types.mojom-shared.h"
#include "ui/display/screen.h"
#include "ui/events/event_processor.h"
#include "ui/events/event_utils.h"
#include "ui/events/test/event_generator.h"
#include "ui/views/test/native_widget_factory.h"
#include "ui/views/test/test_views.h"
#include "ui/views/test/test_views_delegate.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/view_constants_aura.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_delegate.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include "ui/base/view_prop.h"
#include "ui/base/win/window_event_target.h"
#include "ui/views/win/hwnd_util.h"
#endif
namespace views::test {
DesktopNativeWidgetAuraTest;
TEST_F(DesktopNativeWidgetAuraTest, CreateWithParentNotInRootWindow) { … }
TEST_F(DesktopNativeWidgetAuraTest, DesktopAuraWindowSizeTest) { … }
TEST_F(DesktopNativeWidgetAuraTest, NativeViewInitiallyHidden) { … }
TEST_F(DesktopNativeWidgetAuraTest, NativeViewNoActivate) { … }
#if BUILDFLAG(IS_WIN)
TEST_F(DesktopNativeWidgetAuraTest, WidgetNotVisibleOnlyWindowTreeHostShown) {
Widget widget;
Widget::InitParams init_params = CreateParams(
Widget::InitParams::CLIENT_OWNS_WIDGET, Widget::InitParams::TYPE_WINDOW);
widget.Init(std::move(init_params));
ShowWindow(widget.GetNativeView()->GetHost()->GetAcceleratedWidget(),
SW_SHOWNORMAL);
EXPECT_FALSE(widget.IsVisible());
}
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
#define MAYBE_GlobalCursorState …
#else
#define MAYBE_GlobalCursorState …
#endif
TEST_F(DesktopNativeWidgetAuraTest, MAYBE_GlobalCursorState) { … }
TEST_F(DesktopNativeWidgetAuraTest, DontAccessContentWindowDuringDestruction) { … }
namespace {
std::unique_ptr<Widget> CreateAndShowControlWidget(aura::Window* parent) { … }
}
#if BUILDFLAG(IS_CHROMEOS_ASH)
#define MAYBE_ReorderDoesntRecomputeOcclusion …
#else
#define MAYBE_ReorderDoesntRecomputeOcclusion …
#endif
TEST_F(DesktopNativeWidgetAuraTest, MAYBE_ReorderDoesntRecomputeOcclusion) { … }
void QuitNestedLoopAndCloseWidget(std::unique_ptr<Widget> widget,
base::OnceClosure quit_runloop) { … }
TEST_F(DesktopNativeWidgetAuraTest, WidgetCanBeDestroyedFromNestedLoop) { … }
class TestDesktopNativeWidgetAura : public DesktopNativeWidgetAura { … };
class DesktopNativeWidgetAuraWithNoDelegateTest
: public DesktopNativeWidgetAuraTest { … };
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, GetHitTestMaskTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, GetMaximumSizeTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, GetMinimumSizeTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, GetNonClientComponentTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, GetWidgetTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, HasHitTestMaskTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, OnCaptureLostTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, OnGestureEventTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, OnHostMovedInPixelsTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, OnHostResizedTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, OnHostWorkspaceChangedTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, OnKeyEventTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, OnMouseEventTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, OnPaintTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, OnScrollEventTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, OnWindowActivatedTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, OnWindowFocusedTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, ShouldActivateTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest,
ShouldDescendIntoChildForEventHandlingTest) { … }
TEST_F(DesktopNativeWidgetAuraWithNoDelegateTest, UpdateVisualStateTest) { … }
#if !BUILDFLAG(IS_FUCHSIA)
class DesktopAuraTopLevelWindowTest : public aura::WindowObserver { … };
TEST_F(DesktopNativeWidgetAuraTest, FullscreenWindowDestroyedBeforeOwnerTest) { … }
TEST_F(DesktopNativeWidgetAuraTest, FullscreenWindowOwnerDestroyed) { … }
TEST_F(DesktopNativeWidgetAuraTest, TopLevelOwnedPopupTest) { … }
TEST_F(DesktopNativeWidgetAuraTest, TopLevelOwnedPopupResizeTest) { … }
TEST_F(DesktopNativeWidgetAuraTest, TopLevelOwnedPopupRepositionTest) { … }
#endif
void GenerateMouseEvents(Widget* widget, ui::EventType last_event_type) { … }
void RunCloseWidgetDuringDispatchTest(WidgetTest* test,
ui::EventType last_event_type) { … }
TEST_F(DesktopNativeWidgetAuraTest, CloseWidgetDuringMousePress) { … }
TEST_F(DesktopNativeWidgetAuraTest, CloseWidgetDuringMouseReleased) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
#define MAYBE_WindowMouseModalityTest …
#else
#define MAYBE_WindowMouseModalityTest …
#endif
TEST_F(DesktopNativeWidgetAuraTest, MAYBE_WindowMouseModalityTest) { … }
#if BUILDFLAG(IS_WIN)
TEST_F(DesktopNativeWidgetAuraTest, WindowModalityActivationTest) {
TestDesktopWidgetDelegate widget_delegate;
widget_delegate.InitWidget(
CreateParams(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET,
Widget::InitParams::TYPE_WINDOW));
Widget* top_level_widget = widget_delegate.GetWidget();
top_level_widget->Show();
EXPECT_TRUE(top_level_widget->IsVisible());
HWND win32_window = views::HWNDForWidget(top_level_widget);
EXPECT_TRUE(::IsWindow(win32_window));
widget_delegate.SetCanActivate(false);
auto dialog_delegate = std::make_unique<DialogDelegateView>();
dialog_delegate->SetModalType(ui::mojom::ModalType::kWindow);
Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget(
dialog_delegate.release(), nullptr, top_level_widget->GetNativeView());
modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200));
modal_dialog_widget->Show();
EXPECT_TRUE(modal_dialog_widget->IsVisible());
LRESULT activate_result = ::SendMessage(
win32_window, WM_MOUSEACTIVATE, reinterpret_cast<WPARAM>(win32_window),
MAKELPARAM(WM_LBUTTONDOWN, HTCLIENT));
EXPECT_EQ(activate_result, MA_ACTIVATE);
modal_dialog_widget->CloseNow();
}
TEST_F(DesktopNativeWidgetAuraTest,
CharMessagesAsKeyboardMessagesDoesNotCrash) {
Widget widget;
Widget::InitParams params = CreateParams(
Widget::InitParams::CLIENT_OWNS_WIDGET, Widget::InitParams::TYPE_WINDOW);
widget.Init(std::move(params));
widget.Show();
ui::WindowEventTarget* target =
reinterpret_cast<ui::WindowEventTarget*>(ui::ViewProp::GetValue(
widget.GetNativeWindow()->GetHost()->GetAcceleratedWidget(),
ui::WindowEventTarget::kWin32InputEventTarget));
ASSERT_NE(nullptr, target);
bool handled = false;
target->HandleKeyboardMessage(WM_CHAR, 0, 0, &handled);
target->HandleKeyboardMessage(WM_SYSCHAR, 0, 0, &handled);
target->HandleKeyboardMessage(WM_SYSDEADCHAR, 0, 0, &handled);
widget.CloseNow();
}
#endif
TEST_F(DesktopNativeWidgetAuraTest, Reparent) { … }
}