Chromium Code Reviews| Index: ui/views/widget/native_widget_mac_unittest.mm |
| diff --git a/ui/views/widget/native_widget_mac_unittest.mm b/ui/views/widget/native_widget_mac_unittest.mm |
| index 96f7f7bd425edd1affcf41b79e1fad202e3a66fa..e85aa064caa572451334954497933e2f17f828f8 100644 |
| --- a/ui/views/widget/native_widget_mac_unittest.mm |
| +++ b/ui/views/widget/native_widget_mac_unittest.mm |
| @@ -998,6 +998,16 @@ Widget* ShowChildModalWidgetAndWait(NSWindow* native_parent) { |
| return modal_dialog_widget; |
| } |
| +// Shows a window-modal Widget (as a sheet). No need to wait since the native |
| +// sheet animation is blocking. |
| +Widget* ShowWindowModalWidget(NSWindow* native_parent) { |
| + Widget* sheet_widget = views::DialogDelegate::CreateDialogWidget( |
| + new ModalDialogDelegate(ui::MODAL_TYPE_WINDOW), nullptr, |
| + [native_parent contentView]); |
| + sheet_widget->Show(); |
| + return sheet_widget; |
| +} |
| + |
| } // namespace |
| // Tests object lifetime for the show/hide animations used for child-modal |
| @@ -1157,6 +1167,43 @@ TEST_F(NativeWidgetMacTest, WindowModalSheet) { |
| EXPECT_TRUE([parent_close_button isEnabled]); |
| } |
| +// Tests behavior when closing a window that is a sheet, or that hosts a sheet. |
|
Robert Sesek
2017/01/13 20:02:47
Also worth testing re-showing a sheet on a window
tapted
2017/01/13 20:52:51
Done.
|
| +TEST_F(NativeWidgetMacTest, CloseWithWindowModalSheet) { |
| + NSWindow* native_parent = |
| + MakeNativeParentWithStyle(NSClosableWindowMask | NSTitledWindowMask); |
| + { |
| + Widget* sheet_widget = ShowWindowModalWidget(native_parent); |
| + WidgetChangeObserver widget_observer(sheet_widget); |
| + |
| + // Test synchronous close (asynchronous close is tested above). |
| + sheet_widget->CloseNow(); |
| + EXPECT_TRUE(widget_observer.widget_closed()); |
| + |
| + // Spin the RunLoop to ensure the task that ends the modal session on |
| + // |native_parent| is executed. Otherwise |native_parent| will refuse to |
| + // show another sheet. |
| + base::RunLoop().RunUntilIdle(); |
| + } |
| + { |
| + Widget* sheet_widget = ShowWindowModalWidget(native_parent); |
| + WidgetChangeObserver widget_observer(sheet_widget); |
| + |
| + // Test native -[NSWindow close] on the sheet. Does not animate. |
| + [sheet_widget->GetNativeWindow() close]; |
| + EXPECT_TRUE(widget_observer.widget_closed()); |
| + base::RunLoop().RunUntilIdle(); |
| + } |
| + |
| + { |
| + Widget* sheet_widget = ShowWindowModalWidget(native_parent); |
| + WidgetChangeObserver widget_observer(sheet_widget); |
| + |
| + // Test -[NSWindow close] on the parent window. |
| + [native_parent close]; |
| + EXPECT_TRUE(widget_observer.widget_closed()); |
| + } |
| +} |
| + |
| // Test calls to Widget::ReparentNativeView() that result in a no-op on Mac. |
| // Tests with both native and non-native parents. |
| TEST_F(NativeWidgetMacTest, NoopReparentNativeView) { |