Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: ui/views/widget/native_widget_mac_unittest.mm

Issue 2629593005: MacViews: Support -[NSWindow close] on sheets. (Closed)
Patch Set: no doNothing Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/widget/native_widget_mac.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..17b543f5f1a1c6b1be153a183c231c6a4b6d2b25 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,53 @@ 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,
+// and reshowing a sheet on a window after the sheet was closed with -[NSWindow
+// close].
+TEST_F(NativeWidgetMacTest, CloseWithWindowModalSheet) {
+ NSWindow* native_parent =
+ MakeNativeParentWithStyle(NSClosableWindowMask | NSTitledWindowMask);
+ {
+ Widget* sheet_widget = ShowWindowModalWidget(native_parent);
+ EXPECT_TRUE([sheet_widget->GetNativeWindow() isVisible]);
+
+ 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);
+
+ // Ensure the sheet wasn't blocked by a previous modal session.
+ EXPECT_TRUE([sheet_widget->GetNativeWindow() isVisible]);
+
+ 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);
+ EXPECT_TRUE([sheet_widget->GetNativeWindow() isVisible]);
+ 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) {
« no previous file with comments | « ui/views/widget/native_widget_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698