Commit 9346d615 authored by Thomas Lukaszewicz's avatar Thomas Lukaszewicz Committed by Commit Bot

Updated interactive Widget tests to use WidgetAutoclosePtr

Interactive Widget tests now use WidgetAutoclosePtr where
applicable.

Bug: None
Change-Id: Ibf3e904585b1f25817e5e51a7a5d9e743679193a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2148123
Commit-Queue: Thomas Lukaszewicz <tluk@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758852}
parent f7e8f449
...@@ -307,10 +307,10 @@ TEST_F(DesktopWidgetTestInteractive, ...@@ -307,10 +307,10 @@ TEST_F(DesktopWidgetTestInteractive,
// Create widget 1 and expect the active window to be its window. // Create widget 1 and expect the active window to be its window.
View* focusable_view1 = new View; View* focusable_view1 = new View;
focusable_view1->SetFocusBehavior(View::FocusBehavior::ALWAYS); focusable_view1->SetFocusBehavior(View::FocusBehavior::ALWAYS);
Widget* widget1 = CreateTopLevelNativeWidget(); WidgetAutoclosePtr widget1(CreateTopLevelNativeWidget());
widget1->GetContentsView()->AddChildView(focusable_view1); widget1->GetContentsView()->AddChildView(focusable_view1);
widget1->Show(); widget1->Show();
aura::Window* root_window1 = GetRootWindow(widget1); aura::Window* root_window1 = GetRootWindow(widget1.get());
focusable_view1->RequestFocus(); focusable_view1->RequestFocus();
EXPECT_TRUE(root_window1 != nullptr); EXPECT_TRUE(root_window1 != nullptr);
...@@ -321,12 +321,12 @@ TEST_F(DesktopWidgetTestInteractive, ...@@ -321,12 +321,12 @@ TEST_F(DesktopWidgetTestInteractive,
// Create widget 2 and expect the active window to be its window. // Create widget 2 and expect the active window to be its window.
View* focusable_view2 = new View; View* focusable_view2 = new View;
Widget* widget2 = CreateTopLevelNativeWidget(); WidgetAutoclosePtr widget2(CreateTopLevelNativeWidget());
widget1->GetContentsView()->AddChildView(focusable_view2); widget1->GetContentsView()->AddChildView(focusable_view2);
widget2->Show(); widget2->Show();
aura::Window* root_window2 = GetRootWindow(widget2); aura::Window* root_window2 = GetRootWindow(widget2.get());
focusable_view2->RequestFocus(); focusable_view2->RequestFocus();
ActivatePlatformWindow(widget2); ActivatePlatformWindow(widget2.get());
wm::ActivationClient* activation_client2 = wm::ActivationClient* activation_client2 =
wm::GetActivationClient(root_window2); wm::GetActivationClient(root_window2);
...@@ -338,18 +338,15 @@ TEST_F(DesktopWidgetTestInteractive, ...@@ -338,18 +338,15 @@ TEST_F(DesktopWidgetTestInteractive,
// Now set focus back to widget 1 and expect the active window to be its // Now set focus back to widget 1 and expect the active window to be its
// window. // window.
focusable_view1->RequestFocus(); focusable_view1->RequestFocus();
ActivatePlatformWindow(widget1); ActivatePlatformWindow(widget1.get());
EXPECT_EQ(activation_client2->GetActiveWindow(), EXPECT_EQ(activation_client2->GetActiveWindow(),
reinterpret_cast<aura::Window*>(NULL)); reinterpret_cast<aura::Window*>(NULL));
EXPECT_EQ(activation_client1->GetActiveWindow(), widget1->GetNativeView()); EXPECT_EQ(activation_client1->GetActiveWindow(), widget1->GetNativeView());
widget2->CloseNow();
widget1->CloseNow();
} }
// Verifies bubbles result in a focus lost when shown. // Verifies bubbles result in a focus lost when shown.
TEST_F(DesktopWidgetTestInteractive, FocusChangesOnBubble) { TEST_F(DesktopWidgetTestInteractive, FocusChangesOnBubble) {
Widget* widget = CreateTopLevelNativeWidget(); WidgetAutoclosePtr widget(CreateTopLevelNativeWidget());
View* focusable_view = View* focusable_view =
widget->GetContentsView()->AddChildView(std::make_unique<View>()); widget->GetContentsView()->AddChildView(std::make_unique<View>());
focusable_view->SetFocusBehavior(View::FocusBehavior::ALWAYS); focusable_view->SetFocusBehavior(View::FocusBehavior::ALWAYS);
...@@ -376,8 +373,6 @@ TEST_F(DesktopWidgetTestInteractive, FocusChangesOnBubble) { ...@@ -376,8 +373,6 @@ TEST_F(DesktopWidgetTestInteractive, FocusChangesOnBubble) {
// Closing the bubble should result in focus going back to the contents view. // Closing the bubble should result in focus going back to the contents view.
EXPECT_TRUE(focusable_view->HasFocus()); EXPECT_TRUE(focusable_view->HasFocus());
widget->CloseNow();
} }
class TouchEventHandler : public ui::EventHandler { class TouchEventHandler : public ui::EventHandler {
...@@ -433,23 +428,21 @@ TEST_F(DesktopWidgetTestInteractive, DISABLED_TouchNoActivateWindow) { ...@@ -433,23 +428,21 @@ TEST_F(DesktopWidgetTestInteractive, DISABLED_TouchNoActivateWindow) {
View* focusable_view = new View; View* focusable_view = new View;
focusable_view->SetFocusBehavior(View::FocusBehavior::ALWAYS); focusable_view->SetFocusBehavior(View::FocusBehavior::ALWAYS);
Widget* widget = CreateTopLevelNativeWidget(); WidgetAutoclosePtr widget(CreateTopLevelNativeWidget());
widget->GetContentsView()->AddChildView(focusable_view); widget->GetContentsView()->AddChildView(focusable_view);
widget->Show(); widget->Show();
{ {
TouchEventHandler touch_event_handler(widget); TouchEventHandler touch_event_handler(widget.get());
ASSERT_TRUE(ui_controls::SendTouchEvents(ui_controls::PRESS, 1, 100, 100)); ASSERT_TRUE(ui_controls::SendTouchEvents(ui_controls::PRESS, 1, 100, 100));
touch_event_handler.WaitForEvents(); touch_event_handler.WaitForEvents();
} }
widget->CloseNow();
} }
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
TEST_F(WidgetTestInteractive, CaptureAutoReset) { TEST_F(WidgetTestInteractive, CaptureAutoReset) {
Widget* toplevel = CreateTopLevelFramelessPlatformWidget(); WidgetAutoclosePtr toplevel(CreateTopLevelFramelessPlatformWidget());
View* container = new View; View* container = new View;
toplevel->SetContentsView(container); toplevel->SetContentsView(container);
...@@ -473,13 +466,10 @@ TEST_F(WidgetTestInteractive, CaptureAutoReset) { ...@@ -473,13 +466,10 @@ TEST_F(WidgetTestInteractive, CaptureAutoReset) {
EXPECT_TRUE(toplevel->HasCapture()); EXPECT_TRUE(toplevel->HasCapture());
toplevel->ReleaseCapture(); toplevel->ReleaseCapture();
EXPECT_FALSE(toplevel->HasCapture()); EXPECT_FALSE(toplevel->HasCapture());
toplevel->Close();
RunPendingMessages();
} }
TEST_F(WidgetTestInteractive, ResetCaptureOnGestureEnd) { TEST_F(WidgetTestInteractive, ResetCaptureOnGestureEnd) {
Widget* toplevel = CreateTopLevelFramelessPlatformWidget(); WidgetAutoclosePtr toplevel(CreateTopLevelFramelessPlatformWidget());
View* container = new View; View* container = new View;
toplevel->SetContentsView(container); toplevel->SetContentsView(container);
...@@ -526,9 +516,6 @@ TEST_F(WidgetTestInteractive, ResetCaptureOnGestureEnd) { ...@@ -526,9 +516,6 @@ TEST_F(WidgetTestInteractive, ResetCaptureOnGestureEnd) {
toplevel->OnMouseEvent(&press); toplevel->OnMouseEvent(&press);
toplevel->OnMouseEvent(&release); toplevel->OnMouseEvent(&release);
EXPECT_EQ(1, mouse->pressed()); EXPECT_EQ(1, mouse->pressed());
toplevel->Close();
RunPendingMessages();
} }
// Checks that if a mouse-press triggers a capture on a different widget (which // Checks that if a mouse-press triggers a capture on a different widget (which
...@@ -543,7 +530,7 @@ TEST_F(WidgetTestInteractive, DisableCaptureWidgetFromMousePress) { ...@@ -543,7 +530,7 @@ TEST_F(WidgetTestInteractive, DisableCaptureWidgetFromMousePress) {
// release event to |second|, to make sure that the release event is // release event to |second|, to make sure that the release event is
// dispatched after the nested loop starts. // dispatched after the nested loop starts.
Widget* first = CreateTopLevelFramelessPlatformWidget(); WidgetAutoclosePtr first(CreateTopLevelFramelessPlatformWidget());
Widget* second = CreateTopLevelFramelessPlatformWidget(); Widget* second = CreateTopLevelFramelessPlatformWidget();
NestedLoopCaptureView* container = new NestedLoopCaptureView(second); NestedLoopCaptureView* container = new NestedLoopCaptureView(second);
...@@ -567,16 +554,14 @@ TEST_F(WidgetTestInteractive, DisableCaptureWidgetFromMousePress) { ...@@ -567,16 +554,14 @@ TEST_F(WidgetTestInteractive, DisableCaptureWidgetFromMousePress) {
ui::EF_LEFT_MOUSE_BUTTON); ui::EF_LEFT_MOUSE_BUTTON);
first->OnMouseEvent(&press); first->OnMouseEvent(&press);
EXPECT_FALSE(first->HasCapture()); EXPECT_FALSE(first->HasCapture());
first->Close();
RunPendingMessages();
} }
// Tests some grab/ungrab events. // Tests some grab/ungrab events.
// TODO(estade): can this be enabled now that this is an interactive ui test? // TODO(estade): can this be enabled now that this is an interactive ui test?
TEST_F(WidgetTestInteractive, DISABLED_GrabUngrab) { TEST_F(WidgetTestInteractive, DISABLED_GrabUngrab) {
Widget* toplevel = CreateTopLevelPlatformWidget(); WidgetAutoclosePtr toplevel(CreateTopLevelPlatformWidget());
Widget* child1 = CreateChildNativeWidgetWithParent(toplevel); Widget* child1 = CreateChildNativeWidgetWithParent(toplevel.get());
Widget* child2 = CreateChildNativeWidgetWithParent(toplevel); Widget* child2 = CreateChildNativeWidgetWithParent(toplevel.get());
toplevel->SetBounds(gfx::Rect(0, 0, 500, 500)); toplevel->SetBounds(gfx::Rect(0, 0, 500, 500));
...@@ -629,14 +614,12 @@ TEST_F(WidgetTestInteractive, DISABLED_GrabUngrab) { ...@@ -629,14 +614,12 @@ TEST_F(WidgetTestInteractive, DISABLED_GrabUngrab) {
EXPECT_FALSE(toplevel->HasCapture()); EXPECT_FALSE(toplevel->HasCapture());
EXPECT_FALSE(child1->HasCapture()); EXPECT_FALSE(child1->HasCapture());
EXPECT_FALSE(child2->HasCapture()); EXPECT_FALSE(child2->HasCapture());
toplevel->CloseNow();
} }
// Tests mouse move outside of the window into the "resize controller" and back // Tests mouse move outside of the window into the "resize controller" and back
// will still generate an OnMouseEntered and OnMouseExited event.. // will still generate an OnMouseEntered and OnMouseExited event..
TEST_F(WidgetTestInteractive, CheckResizeControllerEvents) { TEST_F(WidgetTestInteractive, CheckResizeControllerEvents) {
Widget* toplevel = CreateTopLevelFramelessPlatformWidget(); WidgetAutoclosePtr toplevel(CreateTopLevelFramelessPlatformWidget());
toplevel->SetBounds(gfx::Rect(0, 0, 100, 100)); toplevel->SetBounds(gfx::Rect(0, 0, 100, 100));
...@@ -678,20 +661,16 @@ TEST_F(WidgetTestInteractive, CheckResizeControllerEvents) { ...@@ -678,20 +661,16 @@ TEST_F(WidgetTestInteractive, CheckResizeControllerEvents) {
toplevel->OnMouseEvent(&moved_over); toplevel->OnMouseEvent(&moved_over);
EXPECT_EQ(1, view->EnteredCalls()); EXPECT_EQ(1, view->EnteredCalls());
EXPECT_EQ(0, view->ExitedCalls()); EXPECT_EQ(0, view->ExitedCalls());
RunPendingMessages();
toplevel->CloseNow();
} }
// Test view focus restoration when a widget is deactivated and re-activated. // Test view focus restoration when a widget is deactivated and re-activated.
TEST_F(WidgetTestInteractive, ViewFocusOnWidgetActivationChanges) { TEST_F(WidgetTestInteractive, ViewFocusOnWidgetActivationChanges) {
Widget* widget1 = CreateTopLevelPlatformWidget(); WidgetAutoclosePtr widget1(CreateTopLevelPlatformWidget());
View* view1 = new View; View* view1 = new View;
view1->SetFocusBehavior(View::FocusBehavior::ALWAYS); view1->SetFocusBehavior(View::FocusBehavior::ALWAYS);
widget1->GetContentsView()->AddChildView(view1); widget1->GetContentsView()->AddChildView(view1);
Widget* widget2 = CreateTopLevelPlatformWidget(); WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget());
View* view2a = new View; View* view2a = new View;
View* view2b = new View; View* view2b = new View;
view2a->SetFocusBehavior(View::FocusBehavior::ALWAYS); view2a->SetFocusBehavior(View::FocusBehavior::ALWAYS);
...@@ -699,12 +678,12 @@ TEST_F(WidgetTestInteractive, ViewFocusOnWidgetActivationChanges) { ...@@ -699,12 +678,12 @@ TEST_F(WidgetTestInteractive, ViewFocusOnWidgetActivationChanges) {
widget2->GetContentsView()->AddChildView(view2a); widget2->GetContentsView()->AddChildView(view2a);
widget2->GetContentsView()->AddChildView(view2b); widget2->GetContentsView()->AddChildView(view2b);
ShowSync(widget1); ShowSync(widget1.get());
EXPECT_TRUE(widget1->IsActive()); EXPECT_TRUE(widget1->IsActive());
view1->RequestFocus(); view1->RequestFocus();
EXPECT_EQ(view1, widget1->GetFocusManager()->GetFocusedView()); EXPECT_EQ(view1, widget1->GetFocusManager()->GetFocusedView());
ShowSync(widget2); ShowSync(widget2.get());
EXPECT_TRUE(widget2->IsActive()); EXPECT_TRUE(widget2->IsActive());
EXPECT_FALSE(widget1->IsActive()); EXPECT_FALSE(widget1->IsActive());
EXPECT_EQ(nullptr, widget1->GetFocusManager()->GetFocusedView()); EXPECT_EQ(nullptr, widget1->GetFocusManager()->GetFocusedView());
...@@ -713,20 +692,17 @@ TEST_F(WidgetTestInteractive, ViewFocusOnWidgetActivationChanges) { ...@@ -713,20 +692,17 @@ TEST_F(WidgetTestInteractive, ViewFocusOnWidgetActivationChanges) {
view2b->RequestFocus(); view2b->RequestFocus();
EXPECT_EQ(view2b, widget2->GetFocusManager()->GetFocusedView()); EXPECT_EQ(view2b, widget2->GetFocusManager()->GetFocusedView());
ActivateSync(widget1); ActivateSync(widget1.get());
EXPECT_TRUE(widget1->IsActive()); EXPECT_TRUE(widget1->IsActive());
EXPECT_EQ(view1, widget1->GetFocusManager()->GetFocusedView()); EXPECT_EQ(view1, widget1->GetFocusManager()->GetFocusedView());
EXPECT_FALSE(widget2->IsActive()); EXPECT_FALSE(widget2->IsActive());
EXPECT_EQ(nullptr, widget2->GetFocusManager()->GetFocusedView()); EXPECT_EQ(nullptr, widget2->GetFocusManager()->GetFocusedView());
ActivateSync(widget2); ActivateSync(widget2.get());
EXPECT_TRUE(widget2->IsActive()); EXPECT_TRUE(widget2->IsActive());
EXPECT_EQ(view2b, widget2->GetFocusManager()->GetFocusedView()); EXPECT_EQ(view2b, widget2->GetFocusManager()->GetFocusedView());
EXPECT_FALSE(widget1->IsActive()); EXPECT_FALSE(widget1->IsActive());
EXPECT_EQ(nullptr, widget1->GetFocusManager()->GetFocusedView()); EXPECT_EQ(nullptr, widget1->GetFocusManager()->GetFocusedView());
widget1->CloseNow();
widget2->CloseNow();
} }
// Test z-order of child widgets relative to their parent. // Test z-order of child widgets relative to their parent.
...@@ -801,7 +777,7 @@ TEST_F(WidgetTestInteractive, ChildStackedRelativeToParent) { ...@@ -801,7 +777,7 @@ TEST_F(WidgetTestInteractive, ChildStackedRelativeToParent) {
// Test view focus retention when a widget's HWND is disabled and re-enabled. // Test view focus retention when a widget's HWND is disabled and re-enabled.
TEST_F(WidgetTestInteractive, ViewFocusOnHWNDEnabledChanges) { TEST_F(WidgetTestInteractive, ViewFocusOnHWNDEnabledChanges) {
Widget* widget = CreateTopLevelFramelessPlatformWidget(); WidgetAutoclosePtr widget(CreateTopLevelFramelessPlatformWidget());
widget->SetContentsView(new View); widget->SetContentsView(new View);
for (size_t i = 0; i < 2; ++i) { for (size_t i = 0; i < 2; ++i) {
auto child = std::make_unique<View>(); auto child = std::make_unique<View>();
...@@ -811,7 +787,7 @@ TEST_F(WidgetTestInteractive, ViewFocusOnHWNDEnabledChanges) { ...@@ -811,7 +787,7 @@ TEST_F(WidgetTestInteractive, ViewFocusOnHWNDEnabledChanges) {
widget->Show(); widget->Show();
widget->GetNativeWindow()->GetHost()->Show(); widget->GetNativeWindow()->GetHost()->Show();
const HWND hwnd = HWNDForWidget(widget); const HWND hwnd = HWNDForWidget(widget.get());
EXPECT_TRUE(::IsWindow(hwnd)); EXPECT_TRUE(::IsWindow(hwnd));
EXPECT_TRUE(::IsWindowEnabled(hwnd)); EXPECT_TRUE(::IsWindowEnabled(hwnd));
EXPECT_EQ(hwnd, ::GetActiveWindow()); EXPECT_EQ(hwnd, ::GetActiveWindow());
...@@ -836,8 +812,6 @@ TEST_F(WidgetTestInteractive, ViewFocusOnHWNDEnabledChanges) { ...@@ -836,8 +812,6 @@ TEST_F(WidgetTestInteractive, ViewFocusOnHWNDEnabledChanges) {
EXPECT_TRUE(widget->IsActive()); EXPECT_TRUE(widget->IsActive());
EXPECT_EQ(view, widget->GetFocusManager()->GetFocusedView()); EXPECT_EQ(view, widget->GetFocusManager()->GetFocusedView());
} }
widget->CloseNow();
} }
// This class subclasses the Widget class to listen for activation change // This class subclasses the Widget class to listen for activation change
...@@ -1171,7 +1145,7 @@ TEST_F(DesktopWidgetTestInteractive, CanActivateFlagIsHonored) { ...@@ -1171,7 +1145,7 @@ TEST_F(DesktopWidgetTestInteractive, CanActivateFlagIsHonored) {
// Test that touch selection quick menu is not activated when opened. // Test that touch selection quick menu is not activated when opened.
TEST_F(DesktopWidgetTestInteractive, TEST_F(DesktopWidgetTestInteractive,
MAYBE_TouchSelectionQuickMenuIsNotActivated) { MAYBE_TouchSelectionQuickMenuIsNotActivated) {
Widget* widget = CreateTopLevelNativeWidget(); WidgetAutoclosePtr widget(CreateTopLevelNativeWidget());
widget->SetBounds(gfx::Rect(0, 0, 200, 200)); widget->SetBounds(gfx::Rect(0, 0, 200, 200));
Textfield* textfield = new Textfield; Textfield* textfield = new Textfield;
...@@ -1186,7 +1160,7 @@ TEST_F(DesktopWidgetTestInteractive, ...@@ -1186,7 +1160,7 @@ TEST_F(DesktopWidgetTestInteractive,
RunPendingMessages(); RunPendingMessages();
ui::test::EventGenerator generator(GetRootWindow(widget)); ui::test::EventGenerator generator(GetRootWindow(widget.get()));
generator.GestureTapAt(textfield->GetBoundsInScreen().origin() + generator.GestureTapAt(textfield->GetBoundsInScreen().origin() +
gfx::Vector2d(10, 10)); gfx::Vector2d(10, 10));
static_cast<TouchSelectionControllerImpl*>( static_cast<TouchSelectionControllerImpl*>(
...@@ -1196,7 +1170,6 @@ TEST_F(DesktopWidgetTestInteractive, ...@@ -1196,7 +1170,6 @@ TEST_F(DesktopWidgetTestInteractive,
EXPECT_TRUE(textfield->HasFocus()); EXPECT_TRUE(textfield->HasFocus());
EXPECT_TRUE(widget->IsActive()); EXPECT_TRUE(widget->IsActive());
EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
widget->CloseNow();
} }
#endif // defined(USE_AURA) #endif // defined(USE_AURA)
...@@ -1255,90 +1228,76 @@ TEST_F(WidgetTestInteractive, DisableViewDoesNotActivateWidget) { ...@@ -1255,90 +1228,76 @@ TEST_F(WidgetTestInteractive, DisableViewDoesNotActivateWidget) {
} // namespace test } // namespace test
TEST_F(WidgetTestInteractive, ShowCreatesActiveWindow) { TEST_F(WidgetTestInteractive, ShowCreatesActiveWindow) {
Widget* widget = CreateTopLevelPlatformWidget(); WidgetAutoclosePtr widget(CreateTopLevelPlatformWidget());
ShowSync(widget);
EXPECT_EQ(GetWidgetShowState(widget), ui::SHOW_STATE_NORMAL);
widget->CloseNow(); ShowSync(widget.get());
EXPECT_EQ(GetWidgetShowState(widget.get()), ui::SHOW_STATE_NORMAL);
} }
TEST_F(WidgetTestInteractive, ShowInactive) { TEST_F(WidgetTestInteractive, ShowInactive) {
WidgetTest::WaitForSystemAppActivation(); WidgetTest::WaitForSystemAppActivation();
Widget* widget = CreateTopLevelPlatformWidget(); WidgetAutoclosePtr widget(CreateTopLevelPlatformWidget());
ShowInactiveSync(widget); ShowInactiveSync(widget.get());
EXPECT_EQ(GetWidgetShowState(widget), ui::SHOW_STATE_INACTIVE); EXPECT_EQ(GetWidgetShowState(widget.get()), ui::SHOW_STATE_INACTIVE);
widget->CloseNow();
} }
TEST_F(WidgetTestInteractive, InactiveBeforeShow) { TEST_F(WidgetTestInteractive, InactiveBeforeShow) {
Widget* widget = CreateTopLevelPlatformWidget(); WidgetAutoclosePtr widget(CreateTopLevelPlatformWidget());
EXPECT_FALSE(widget->IsActive()); EXPECT_FALSE(widget->IsActive());
EXPECT_FALSE(widget->IsVisible()); EXPECT_FALSE(widget->IsVisible());
ShowSync(widget); ShowSync(widget.get());
EXPECT_TRUE(widget->IsActive()); EXPECT_TRUE(widget->IsActive());
EXPECT_TRUE(widget->IsVisible()); EXPECT_TRUE(widget->IsVisible());
widget->CloseNow();
} }
TEST_F(WidgetTestInteractive, ShowInactiveAfterShow) { TEST_F(WidgetTestInteractive, ShowInactiveAfterShow) {
// Create 2 widgets to ensure window layering does not change. // Create 2 widgets to ensure window layering does not change.
Widget* widget = CreateTopLevelPlatformWidget(); WidgetAutoclosePtr widget(CreateTopLevelPlatformWidget());
Widget* widget2 = CreateTopLevelPlatformWidget(); WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget());
ShowSync(widget2); ShowSync(widget2.get());
EXPECT_FALSE(widget->IsActive()); EXPECT_FALSE(widget->IsActive());
EXPECT_TRUE(widget2->IsVisible()); EXPECT_TRUE(widget2->IsVisible());
EXPECT_TRUE(widget2->IsActive()); EXPECT_TRUE(widget2->IsActive());
ShowSync(widget); ShowSync(widget.get());
EXPECT_TRUE(widget->IsActive()); EXPECT_TRUE(widget->IsActive());
EXPECT_FALSE(widget2->IsActive()); EXPECT_FALSE(widget2->IsActive());
ShowInactiveSync(widget); ShowInactiveSync(widget.get());
EXPECT_TRUE(widget->IsActive()); EXPECT_TRUE(widget->IsActive());
EXPECT_FALSE(widget2->IsActive()); EXPECT_FALSE(widget2->IsActive());
EXPECT_EQ(GetWidgetShowState(widget), ui::SHOW_STATE_NORMAL); EXPECT_EQ(GetWidgetShowState(widget.get()), ui::SHOW_STATE_NORMAL);
widget2->CloseNow();
widget->CloseNow();
} }
TEST_F(WidgetTestInteractive, ShowAfterShowInactive) { TEST_F(WidgetTestInteractive, ShowAfterShowInactive) {
Widget* widget = CreateTopLevelPlatformWidget(); WidgetAutoclosePtr widget(CreateTopLevelPlatformWidget());
widget->SetBounds(gfx::Rect(100, 100, 100, 100)); widget->SetBounds(gfx::Rect(100, 100, 100, 100));
ShowInactiveSync(widget); ShowInactiveSync(widget.get());
ShowSync(widget); ShowSync(widget.get());
EXPECT_EQ(GetWidgetShowState(widget), ui::SHOW_STATE_NORMAL); EXPECT_EQ(GetWidgetShowState(widget.get()), ui::SHOW_STATE_NORMAL);
widget->CloseNow();
} }
#if BUILDFLAG(ENABLE_DESKTOP_AURA) || defined(OS_MACOSX) #if BUILDFLAG(ENABLE_DESKTOP_AURA) || defined(OS_MACOSX)
TEST_F(WidgetTestInteractive, InactiveWidgetDoesNotGrabActivation) { TEST_F(WidgetTestInteractive, InactiveWidgetDoesNotGrabActivation) {
Widget* widget = CreateTopLevelPlatformWidget(); WidgetAutoclosePtr widget(CreateTopLevelPlatformWidget());
ShowSync(widget); ShowSync(widget.get());
EXPECT_EQ(GetWidgetShowState(widget), ui::SHOW_STATE_NORMAL); EXPECT_EQ(GetWidgetShowState(widget.get()), ui::SHOW_STATE_NORMAL);
Widget widget2; WidgetAutoclosePtr widget2(new Widget());
Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
widget2.Init(std::move(params)); widget2->Init(std::move(params));
widget2.Show(); widget2->Show();
RunPendingMessagesForActiveStatusChange(); RunPendingMessagesForActiveStatusChange();
EXPECT_EQ(GetWidgetShowState(&widget2), ui::SHOW_STATE_INACTIVE); EXPECT_EQ(GetWidgetShowState(widget2.get()), ui::SHOW_STATE_INACTIVE);
EXPECT_EQ(GetWidgetShowState(widget), ui::SHOW_STATE_NORMAL); EXPECT_EQ(GetWidgetShowState(widget.get()), ui::SHOW_STATE_NORMAL);
widget->CloseNow();
widget2.CloseNow();
} }
#endif // BUILDFLAG(ENABLE_DESKTOP_AURA) || defined(OS_MACOSX) #endif // BUILDFLAG(ENABLE_DESKTOP_AURA) || defined(OS_MACOSX)
...@@ -1354,37 +1313,33 @@ TEST_F(WidgetTestInteractive, InactiveWidgetDoesNotGrabActivation) { ...@@ -1354,37 +1313,33 @@ TEST_F(WidgetTestInteractive, InactiveWidgetDoesNotGrabActivation) {
// Test that window state is not changed after getting out of full screen. // Test that window state is not changed after getting out of full screen.
TEST_F(WidgetTestInteractive, MAYBE_ExitFullscreenRestoreState) { TEST_F(WidgetTestInteractive, MAYBE_ExitFullscreenRestoreState) {
Widget* toplevel = CreateTopLevelPlatformWidget(); WidgetAutoclosePtr toplevel(CreateTopLevelPlatformWidget());
toplevel->Show(); toplevel->Show();
RunPendingMessages(); RunPendingMessages();
// This should be a normal state window. // This should be a normal state window.
EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetWidgetShowState(toplevel)); EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetWidgetShowState(toplevel.get()));
toplevel->SetFullscreen(true); toplevel->SetFullscreen(true);
EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetWidgetShowState(toplevel)); EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetWidgetShowState(toplevel.get()));
toplevel->SetFullscreen(false); toplevel->SetFullscreen(false);
EXPECT_NE(ui::SHOW_STATE_FULLSCREEN, GetWidgetShowState(toplevel)); EXPECT_NE(ui::SHOW_STATE_FULLSCREEN, GetWidgetShowState(toplevel.get()));
// And it should still be in normal state after getting out of full screen. // And it should still be in normal state after getting out of full screen.
EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetWidgetShowState(toplevel)); EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetWidgetShowState(toplevel.get()));
// Now, make it maximized. // Now, make it maximized.
toplevel->Maximize(); toplevel->Maximize();
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetWidgetShowState(toplevel)); EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetWidgetShowState(toplevel.get()));
toplevel->SetFullscreen(true); toplevel->SetFullscreen(true);
EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetWidgetShowState(toplevel)); EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetWidgetShowState(toplevel.get()));
toplevel->SetFullscreen(false); toplevel->SetFullscreen(false);
EXPECT_NE(ui::SHOW_STATE_FULLSCREEN, GetWidgetShowState(toplevel)); EXPECT_NE(ui::SHOW_STATE_FULLSCREEN, GetWidgetShowState(toplevel.get()));
// And it stays maximized after getting out of full screen. // And it stays maximized after getting out of full screen.
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetWidgetShowState(toplevel)); EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetWidgetShowState(toplevel.get()));
// Clean up.
toplevel->Close();
RunPendingMessages();
} }
// Testing initial focus is assigned properly for normal top-level widgets, // Testing initial focus is assigned properly for normal top-level widgets,
...@@ -1414,23 +1369,21 @@ TEST_F(WidgetTestInteractive, InitialFocus) { ...@@ -1414,23 +1369,21 @@ TEST_F(WidgetTestInteractive, InitialFocus) {
} }
TEST_F(DesktopWidgetTestInteractive, RestoreAfterMinimize) { TEST_F(DesktopWidgetTestInteractive, RestoreAfterMinimize) {
Widget* widget = CreateTopLevelNativeWidget(); WidgetAutoclosePtr widget(CreateTopLevelNativeWidget());
ShowSync(widget); ShowSync(widget.get());
ASSERT_FALSE(widget->IsMinimized()); ASSERT_FALSE(widget->IsMinimized());
PropertyWaiter minimize_waiter( PropertyWaiter minimize_waiter(
base::BindRepeating(&Widget::IsMinimized, base::Unretained(widget)), base::BindRepeating(&Widget::IsMinimized, base::Unretained(widget.get())),
true); true);
widget->Minimize(); widget->Minimize();
EXPECT_TRUE(minimize_waiter.Wait()); EXPECT_TRUE(minimize_waiter.Wait());
PropertyWaiter restore_waiter( PropertyWaiter restore_waiter(
base::BindRepeating(&Widget::IsMinimized, base::Unretained(widget)), base::BindRepeating(&Widget::IsMinimized, base::Unretained(widget.get())),
false); false);
widget->Restore(); widget->Restore();
EXPECT_TRUE(restore_waiter.Wait()); EXPECT_TRUE(restore_waiter.Wait());
widget->CloseNow();
} }
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -1439,14 +1392,14 @@ TEST_F(DesktopWidgetTestInteractive, RestoreAfterMinimize) { ...@@ -1439,14 +1392,14 @@ TEST_F(DesktopWidgetTestInteractive, RestoreAfterMinimize) {
// Tests that root window visibility toggles correctly when the desktop widget // Tests that root window visibility toggles correctly when the desktop widget
// is minimized and maximized on Windows, and the Widget remains visible. // is minimized and maximized on Windows, and the Widget remains visible.
TEST_F(DesktopWidgetTestInteractive, RestoreAndMinimizeVisibility) { TEST_F(DesktopWidgetTestInteractive, RestoreAndMinimizeVisibility) {
Widget* widget = CreateTopLevelNativeWidget(); WidgetAutoclosePtr widget(CreateTopLevelNativeWidget());
aura::Window* root_window = GetRootWindow(widget); aura::Window* root_window = GetRootWindow(widget.get());
ShowSync(widget); ShowSync(widget.get());
ASSERT_FALSE(widget->IsMinimized()); ASSERT_FALSE(widget->IsMinimized());
EXPECT_TRUE(root_window->IsVisible()); EXPECT_TRUE(root_window->IsVisible());
PropertyWaiter minimize_widget_waiter( PropertyWaiter minimize_widget_waiter(
base::BindRepeating(&Widget::IsMinimized, base::Unretained(widget)), base::BindRepeating(&Widget::IsMinimized, base::Unretained(widget.get())),
true); true);
widget->Minimize(); widget->Minimize();
EXPECT_TRUE(minimize_widget_waiter.Wait()); EXPECT_TRUE(minimize_widget_waiter.Wait());
...@@ -1454,22 +1407,21 @@ TEST_F(DesktopWidgetTestInteractive, RestoreAndMinimizeVisibility) { ...@@ -1454,22 +1407,21 @@ TEST_F(DesktopWidgetTestInteractive, RestoreAndMinimizeVisibility) {
EXPECT_FALSE(root_window->IsVisible()); EXPECT_FALSE(root_window->IsVisible());
PropertyWaiter restore_widget_waiter( PropertyWaiter restore_widget_waiter(
base::BindRepeating(&Widget::IsMinimized, base::Unretained(widget)), base::BindRepeating(&Widget::IsMinimized, base::Unretained(widget.get())),
false); false);
widget->Restore(); widget->Restore();
EXPECT_TRUE(restore_widget_waiter.Wait()); EXPECT_TRUE(restore_widget_waiter.Wait());
EXPECT_TRUE(widget->IsVisible()); EXPECT_TRUE(widget->IsVisible());
EXPECT_TRUE(root_window->IsVisible()); EXPECT_TRUE(root_window->IsVisible());
widget->CloseNow();
} }
// Test that focus is restored to the widget after a minimized window // Test that focus is restored to the widget after a minimized window
// is activated. // is activated.
TEST_F(DesktopWidgetTestInteractive, MinimizeAndActivateFocus) { TEST_F(DesktopWidgetTestInteractive, MinimizeAndActivateFocus) {
Widget* widget = CreateTopLevelNativeWidget(); WidgetAutoclosePtr widget(CreateTopLevelNativeWidget());
aura::Window* root_window = GetRootWindow(widget); aura::Window* root_window = GetRootWindow(widget.get());
auto* widget_window = widget->GetNativeWindow(); auto* widget_window = widget->GetNativeWindow();
ShowSync(widget); ShowSync(widget.get());
ASSERT_FALSE(widget->IsMinimized()); ASSERT_FALSE(widget->IsMinimized());
EXPECT_TRUE(root_window->IsVisible()); EXPECT_TRUE(root_window->IsVisible());
widget_window->Focus(); widget_window->Focus();
...@@ -1479,7 +1431,7 @@ TEST_F(DesktopWidgetTestInteractive, MinimizeAndActivateFocus) { ...@@ -1479,7 +1431,7 @@ TEST_F(DesktopWidgetTestInteractive, MinimizeAndActivateFocus) {
EXPECT_TRUE(widget->GetContentsView()->HasFocus()); EXPECT_TRUE(widget->GetContentsView()->HasFocus());
PropertyWaiter minimize_widget_waiter( PropertyWaiter minimize_widget_waiter(
base::BindRepeating(&Widget::IsMinimized, base::Unretained(widget)), base::BindRepeating(&Widget::IsMinimized, base::Unretained(widget.get())),
true); true);
widget->Minimize(); widget->Minimize();
EXPECT_TRUE(minimize_widget_waiter.Wait()); EXPECT_TRUE(minimize_widget_waiter.Wait());
...@@ -1487,7 +1439,7 @@ TEST_F(DesktopWidgetTestInteractive, MinimizeAndActivateFocus) { ...@@ -1487,7 +1439,7 @@ TEST_F(DesktopWidgetTestInteractive, MinimizeAndActivateFocus) {
EXPECT_FALSE(root_window->IsVisible()); EXPECT_FALSE(root_window->IsVisible());
PropertyWaiter restore_widget_waiter( PropertyWaiter restore_widget_waiter(
base::BindRepeating(&Widget::IsMinimized, base::Unretained(widget)), base::BindRepeating(&Widget::IsMinimized, base::Unretained(widget.get())),
false); false);
widget->Activate(); widget->Activate();
EXPECT_TRUE(widget->GetContentsView()->HasFocus()); EXPECT_TRUE(widget->GetContentsView()->HasFocus());
...@@ -1495,7 +1447,6 @@ TEST_F(DesktopWidgetTestInteractive, MinimizeAndActivateFocus) { ...@@ -1495,7 +1447,6 @@ TEST_F(DesktopWidgetTestInteractive, MinimizeAndActivateFocus) {
EXPECT_TRUE(widget->IsVisible()); EXPECT_TRUE(widget->IsVisible());
EXPECT_TRUE(root_window->IsVisible()); EXPECT_TRUE(root_window->IsVisible());
EXPECT_TRUE(widget_window->CanFocus()); EXPECT_TRUE(widget_window->CanFocus());
widget->CloseNow();
} }
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
...@@ -1504,8 +1455,8 @@ TEST_F(DesktopWidgetTestInteractive, MinimizeAndActivateFocus) { ...@@ -1504,8 +1455,8 @@ TEST_F(DesktopWidgetTestInteractive, MinimizeAndActivateFocus) {
// Tests that minimizing a widget causes the gesture_handler // Tests that minimizing a widget causes the gesture_handler
// to be cleared when the widget is minimized. // to be cleared when the widget is minimized.
TEST_F(DesktopWidgetTestInteractive, EventHandlersClearedOnWidgetMinimize) { TEST_F(DesktopWidgetTestInteractive, EventHandlersClearedOnWidgetMinimize) {
Widget* widget = CreateTopLevelNativeWidget(); WidgetAutoclosePtr widget(CreateTopLevelNativeWidget());
ShowSync(widget); ShowSync(widget.get());
ASSERT_FALSE(widget->IsMinimized()); ASSERT_FALSE(widget->IsMinimized());
View mouse_handler_view; View mouse_handler_view;
internal::RootView* root_view = internal::RootView* root_view =
...@@ -1517,8 +1468,6 @@ TEST_F(DesktopWidgetTestInteractive, EventHandlersClearedOnWidgetMinimize) { ...@@ -1517,8 +1468,6 @@ TEST_F(DesktopWidgetTestInteractive, EventHandlersClearedOnWidgetMinimize) {
widget->Minimize(); widget->Minimize();
EXPECT_FALSE(GetGestureHandler(root_view)); EXPECT_FALSE(GetGestureHandler(root_view));
widget->CloseNow();
} }
#endif #endif
...@@ -1529,16 +1478,16 @@ TEST_F(DesktopWidgetTestInteractive, EventHandlersClearedOnWidgetMinimize) { ...@@ -1529,16 +1478,16 @@ TEST_F(DesktopWidgetTestInteractive, EventHandlersClearedOnWidgetMinimize) {
TEST_F(DesktopWidgetTestInteractive, TEST_F(DesktopWidgetTestInteractive,
DesktopNativeWidgetWithModalTransientChild) { DesktopNativeWidgetWithModalTransientChild) {
// Create a desktop native Widget for Widget::Deactivate(). // Create a desktop native Widget for Widget::Deactivate().
Widget* deactivate_widget = CreateTopLevelNativeWidget(); WidgetAutoclosePtr deactivate_widget(CreateTopLevelNativeWidget());
ShowSync(deactivate_widget); ShowSync(deactivate_widget.get());
// Create a top level desktop native widget. // Create a top level desktop native widget.
Widget* top_level = CreateTopLevelNativeWidget(); WidgetAutoclosePtr top_level(CreateTopLevelNativeWidget());
Textfield* textfield = new Textfield; Textfield* textfield = new Textfield;
textfield->SetBounds(0, 0, 200, 20); textfield->SetBounds(0, 0, 200, 20);
top_level->GetRootView()->AddChildView(textfield); top_level->GetRootView()->AddChildView(textfield);
ShowSync(top_level); ShowSync(top_level.get());
textfield->RequestFocus(); textfield->RequestFocus();
EXPECT_TRUE(textfield->HasFocus()); EXPECT_TRUE(textfield->HasFocus());
...@@ -1559,18 +1508,15 @@ TEST_F(DesktopWidgetTestInteractive, ...@@ -1559,18 +1508,15 @@ TEST_F(DesktopWidgetTestInteractive,
EXPECT_TRUE(dialog_textfield->HasFocus()); EXPECT_TRUE(dialog_textfield->HasFocus());
EXPECT_FALSE(textfield->HasFocus()); EXPECT_FALSE(textfield->HasFocus());
DeactivateSync(top_level); DeactivateSync(top_level.get());
EXPECT_FALSE(dialog_textfield->HasFocus()); EXPECT_FALSE(dialog_textfield->HasFocus());
EXPECT_FALSE(textfield->HasFocus()); EXPECT_FALSE(textfield->HasFocus());
// After deactivation and activation of top level widget, only modal dialog // After deactivation and activation of top level widget, only modal dialog
// should restore focused view. // should restore focused view.
ActivateSync(top_level); ActivateSync(top_level.get());
EXPECT_TRUE(dialog_textfield->HasFocus()); EXPECT_TRUE(dialog_textfield->HasFocus());
EXPECT_FALSE(textfield->HasFocus()); EXPECT_FALSE(textfield->HasFocus());
top_level->CloseNow();
deactivate_widget->CloseNow();
} }
#endif // defined(OS_LINUX) && BUILDFLAG(ENABLE_DESKTOP_AURA) #endif // defined(OS_LINUX) && BUILDFLAG(ENABLE_DESKTOP_AURA)
...@@ -1971,33 +1917,32 @@ class WidgetInputMethodInteractiveTest : public DesktopWidgetTestInteractive { ...@@ -1971,33 +1917,32 @@ class WidgetInputMethodInteractiveTest : public DesktopWidgetTestInteractive {
#endif #endif
// Test input method focus changes affected by top window activaction. // Test input method focus changes affected by top window activaction.
TEST_F(WidgetInputMethodInteractiveTest, MAYBE_Activation) { TEST_F(WidgetInputMethodInteractiveTest, MAYBE_Activation) {
Widget* widget = CreateTopLevelNativeWidget(); WidgetAutoclosePtr widget(CreateTopLevelNativeWidget());
Textfield* textfield = new Textfield; Textfield* textfield = new Textfield;
widget->GetRootView()->AddChildView(textfield); widget->GetRootView()->AddChildView(textfield);
textfield->RequestFocus(); textfield->RequestFocus();
ShowSync(widget); ShowSync(widget.get());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT,
widget->GetInputMethod()->GetTextInputType()); widget->GetInputMethod()->GetTextInputType());
DeactivateSync(widget); DeactivateSync(widget.get());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
widget->GetInputMethod()->GetTextInputType()); widget->GetInputMethod()->GetTextInputType());
widget->CloseNow();
} }
// Test input method focus changes affected by focus changes within 1 window. // Test input method focus changes affected by focus changes within 1 window.
TEST_F(WidgetInputMethodInteractiveTest, OneWindow) { TEST_F(WidgetInputMethodInteractiveTest, OneWindow) {
Widget* widget = CreateTopLevelNativeWidget(); WidgetAutoclosePtr widget(CreateTopLevelNativeWidget());
Textfield* textfield1 = new Textfield; Textfield* textfield1 = new Textfield;
Textfield* textfield2 = new Textfield; Textfield* textfield2 = new Textfield;
textfield2->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); textfield2->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
widget->GetRootView()->AddChildView(textfield1); widget->GetRootView()->AddChildView(textfield1);
widget->GetRootView()->AddChildView(textfield2); widget->GetRootView()->AddChildView(textfield2);
ShowSync(widget); ShowSync(widget.get());
textfield1->RequestFocus(); textfield1->RequestFocus();
EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT,
...@@ -2011,31 +1956,30 @@ TEST_F(WidgetInputMethodInteractiveTest, OneWindow) { ...@@ -2011,31 +1956,30 @@ TEST_F(WidgetInputMethodInteractiveTest, OneWindow) {
// DNWA (which just activates the last active window) and involves the // DNWA (which just activates the last active window) and involves the
// AuraTestHelper which sets the input method as DummyInputMethod. // AuraTestHelper which sets the input method as DummyInputMethod.
#if BUILDFLAG(ENABLE_DESKTOP_AURA) || defined(OS_MACOSX) #if BUILDFLAG(ENABLE_DESKTOP_AURA) || defined(OS_MACOSX)
DeactivateSync(widget); DeactivateSync(widget.get());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
widget->GetInputMethod()->GetTextInputType()); widget->GetInputMethod()->GetTextInputType());
ActivateSync(widget); ActivateSync(widget.get());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD,
widget->GetInputMethod()->GetTextInputType()); widget->GetInputMethod()->GetTextInputType());
DeactivateSync(widget); DeactivateSync(widget.get());
textfield1->RequestFocus(); textfield1->RequestFocus();
ActivateSync(widget); ActivateSync(widget.get());
EXPECT_TRUE(widget->IsActive()); EXPECT_TRUE(widget->IsActive());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT,
widget->GetInputMethod()->GetTextInputType()); widget->GetInputMethod()->GetTextInputType());
#endif #endif
widget->CloseNow();
} }
// Test input method focus changes affected by focus changes cross 2 windows // Test input method focus changes affected by focus changes cross 2 windows
// which shares the same top window. // which shares the same top window.
TEST_F(WidgetInputMethodInteractiveTest, TwoWindows) { TEST_F(WidgetInputMethodInteractiveTest, TwoWindows) {
Widget* parent = CreateTopLevelNativeWidget(); WidgetAutoclosePtr parent(CreateTopLevelNativeWidget());
parent->SetBounds(gfx::Rect(100, 100, 100, 100)); parent->SetBounds(gfx::Rect(100, 100, 100, 100));
Widget* child = CreateChildNativeWidgetWithParent(parent); Widget* child = CreateChildNativeWidgetWithParent(parent.get());
child->SetBounds(gfx::Rect(0, 0, 50, 50)); child->SetBounds(gfx::Rect(0, 0, 50, 50));
child->Show(); child->Show();
...@@ -2044,7 +1988,7 @@ TEST_F(WidgetInputMethodInteractiveTest, TwoWindows) { ...@@ -2044,7 +1988,7 @@ TEST_F(WidgetInputMethodInteractiveTest, TwoWindows) {
textfield_parent->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); textfield_parent->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
parent->GetRootView()->AddChildView(textfield_parent); parent->GetRootView()->AddChildView(textfield_parent);
child->GetRootView()->AddChildView(textfield_child); child->GetRootView()->AddChildView(textfield_child);
ShowSync(parent); ShowSync(parent.get());
EXPECT_EQ(parent->GetInputMethod(), child->GetInputMethod()); EXPECT_EQ(parent->GetInputMethod(), child->GetInputMethod());
...@@ -2060,33 +2004,31 @@ TEST_F(WidgetInputMethodInteractiveTest, TwoWindows) { ...@@ -2060,33 +2004,31 @@ TEST_F(WidgetInputMethodInteractiveTest, TwoWindows) {
// DNWA (which just activates the last active window) and involves the // DNWA (which just activates the last active window) and involves the
// AuraTestHelper which sets the input method as DummyInputMethod. // AuraTestHelper which sets the input method as DummyInputMethod.
#if BUILDFLAG(ENABLE_DESKTOP_AURA) || defined(OS_MACOSX) #if BUILDFLAG(ENABLE_DESKTOP_AURA) || defined(OS_MACOSX)
DeactivateSync(parent); DeactivateSync(parent.get());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
parent->GetInputMethod()->GetTextInputType()); parent->GetInputMethod()->GetTextInputType());
ActivateSync(parent); ActivateSync(parent.get());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT,
parent->GetInputMethod()->GetTextInputType()); parent->GetInputMethod()->GetTextInputType());
textfield_parent->RequestFocus(); textfield_parent->RequestFocus();
DeactivateSync(parent); DeactivateSync(parent.get());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
parent->GetInputMethod()->GetTextInputType()); parent->GetInputMethod()->GetTextInputType());
ActivateSync(parent); ActivateSync(parent.get());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD,
parent->GetInputMethod()->GetTextInputType()); parent->GetInputMethod()->GetTextInputType());
#endif #endif
parent->CloseNow();
} }
// Test input method focus changes affected by textfield's state changes. // Test input method focus changes affected by textfield's state changes.
TEST_F(WidgetInputMethodInteractiveTest, TextField) { TEST_F(WidgetInputMethodInteractiveTest, TextField) {
Widget* widget = CreateTopLevelNativeWidget(); WidgetAutoclosePtr widget(CreateTopLevelNativeWidget());
Textfield* textfield = new Textfield; Textfield* textfield = new Textfield;
widget->GetRootView()->AddChildView(textfield); widget->GetRootView()->AddChildView(textfield);
ShowSync(widget); ShowSync(widget.get());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
widget->GetInputMethod()->GetTextInputType()); widget->GetInputMethod()->GetTextInputType());
...@@ -2105,15 +2047,14 @@ TEST_F(WidgetInputMethodInteractiveTest, TextField) { ...@@ -2105,15 +2047,14 @@ TEST_F(WidgetInputMethodInteractiveTest, TextField) {
textfield->SetReadOnly(true); textfield->SetReadOnly(true);
EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
widget->GetInputMethod()->GetTextInputType()); widget->GetInputMethod()->GetTextInputType());
widget->CloseNow();
} }
// Test input method should not work for accelerator. // Test input method should not work for accelerator.
TEST_F(WidgetInputMethodInteractiveTest, AcceleratorInTextfield) { TEST_F(WidgetInputMethodInteractiveTest, AcceleratorInTextfield) {
Widget* widget = CreateTopLevelNativeWidget(); WidgetAutoclosePtr widget(CreateTopLevelNativeWidget());
Textfield* textfield = new Textfield; Textfield* textfield = new Textfield;
widget->GetRootView()->AddChildView(textfield); widget->GetRootView()->AddChildView(textfield);
ShowSync(widget); ShowSync(widget.get());
textfield->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT); textfield->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT);
textfield->RequestFocus(); textfield->RequestFocus();
...@@ -2130,8 +2071,6 @@ TEST_F(WidgetInputMethodInteractiveTest, AcceleratorInTextfield) { ...@@ -2130,8 +2071,6 @@ TEST_F(WidgetInputMethodInteractiveTest, AcceleratorInTextfield) {
ui::KeyEvent key_event2(key_event); ui::KeyEvent key_event2(key_event);
widget->OnKeyEvent(&key_event2); widget->OnKeyEvent(&key_event2);
EXPECT_FALSE(key_event2.stopped_propagation()); EXPECT_FALSE(key_event2.stopped_propagation());
widget->CloseNow();
} }
} // namespace test } // namespace test
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment