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

Side by Side Diff: ui/views/widget/native_widget_mac_unittest.mm

Issue 2629593005: MacViews: Support -[NSWindow close] on sheets. (Closed)
Patch Set: Fix lifetime 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ui/views/widget/native_widget_mac.h" 5 #import "ui/views/widget/native_widget_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #import "base/mac/foundation_util.h" 9 #import "base/mac/foundation_util.h"
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 // Visible immediately (although it animates from transparent). 991 // Visible immediately (although it animates from transparent).
992 EXPECT_TRUE(modal_dialog_widget->IsVisible()); 992 EXPECT_TRUE(modal_dialog_widget->IsVisible());
993 993
994 // Run the animation. 994 // Run the animation.
995 show_waiter.WaitForMethod(); 995 show_waiter.WaitForMethod();
996 EXPECT_TRUE(modal_dialog_widget->IsVisible()); 996 EXPECT_TRUE(modal_dialog_widget->IsVisible());
997 EXPECT_TRUE(show_waiter.method_called()); 997 EXPECT_TRUE(show_waiter.method_called());
998 return modal_dialog_widget; 998 return modal_dialog_widget;
999 } 999 }
1000 1000
1001 // Shows a window-modal Widget (as a sheet). No need to wait since the native
1002 // sheet animation is blocking.
1003 Widget* ShowWindowModalWidget(NSWindow* native_parent) {
1004 Widget* sheet_widget = views::DialogDelegate::CreateDialogWidget(
1005 new ModalDialogDelegate(ui::MODAL_TYPE_WINDOW), nullptr,
1006 [native_parent contentView]);
1007 sheet_widget->Show();
1008 return sheet_widget;
1009 }
1010
1001 } // namespace 1011 } // namespace
1002 1012
1003 // Tests object lifetime for the show/hide animations used for child-modal 1013 // Tests object lifetime for the show/hide animations used for child-modal
1004 // windows. Parents the dialog off a native parent window (not a views::Widget). 1014 // windows. Parents the dialog off a native parent window (not a views::Widget).
1005 TEST_F(NativeWidgetMacTest, NativeWindowChildModalShowHide) { 1015 TEST_F(NativeWidgetMacTest, NativeWindowChildModalShowHide) {
1006 NSWindow* native_parent = MakeNativeParent(); 1016 NSWindow* native_parent = MakeNativeParent();
1007 { 1017 {
1008 Widget* modal_dialog_widget = ShowChildModalWidgetAndWait(native_parent); 1018 Widget* modal_dialog_widget = ShowChildModalWidgetAndWait(native_parent);
1009 TestWidgetObserver widget_observer(modal_dialog_widget); 1019 TestWidgetObserver widget_observer(modal_dialog_widget);
1010 1020
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 base::RunLoop().RunUntilIdle(); 1160 base::RunLoop().RunUntilIdle();
1151 EXPECT_FALSE([sheet_window delegate]); 1161 EXPECT_FALSE([sheet_window delegate]);
1152 1162
1153 EXPECT_TRUE(did_observe); // Also ensures the Close() actually uses sheets. 1163 EXPECT_TRUE(did_observe); // Also ensures the Close() actually uses sheets.
1154 [[NSNotificationCenter defaultCenter] removeObserver:observer]; 1164 [[NSNotificationCenter defaultCenter] removeObserver:observer];
1155 1165
1156 EXPECT_TRUE(widget_observer.widget_closed()); 1166 EXPECT_TRUE(widget_observer.widget_closed());
1157 EXPECT_TRUE([parent_close_button isEnabled]); 1167 EXPECT_TRUE([parent_close_button isEnabled]);
1158 } 1168 }
1159 1169
1170 // 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.
1171 TEST_F(NativeWidgetMacTest, CloseWithWindowModalSheet) {
1172 NSWindow* native_parent =
1173 MakeNativeParentWithStyle(NSClosableWindowMask | NSTitledWindowMask);
1174 {
1175 Widget* sheet_widget = ShowWindowModalWidget(native_parent);
1176 WidgetChangeObserver widget_observer(sheet_widget);
1177
1178 // Test synchronous close (asynchronous close is tested above).
1179 sheet_widget->CloseNow();
1180 EXPECT_TRUE(widget_observer.widget_closed());
1181
1182 // Spin the RunLoop to ensure the task that ends the modal session on
1183 // |native_parent| is executed. Otherwise |native_parent| will refuse to
1184 // show another sheet.
1185 base::RunLoop().RunUntilIdle();
1186 }
1187 {
1188 Widget* sheet_widget = ShowWindowModalWidget(native_parent);
1189 WidgetChangeObserver widget_observer(sheet_widget);
1190
1191 // Test native -[NSWindow close] on the sheet. Does not animate.
1192 [sheet_widget->GetNativeWindow() close];
1193 EXPECT_TRUE(widget_observer.widget_closed());
1194 base::RunLoop().RunUntilIdle();
1195 }
1196
1197 {
1198 Widget* sheet_widget = ShowWindowModalWidget(native_parent);
1199 WidgetChangeObserver widget_observer(sheet_widget);
1200
1201 // Test -[NSWindow close] on the parent window.
1202 [native_parent close];
1203 EXPECT_TRUE(widget_observer.widget_closed());
1204 }
1205 }
1206
1160 // Test calls to Widget::ReparentNativeView() that result in a no-op on Mac. 1207 // Test calls to Widget::ReparentNativeView() that result in a no-op on Mac.
1161 // Tests with both native and non-native parents. 1208 // Tests with both native and non-native parents.
1162 TEST_F(NativeWidgetMacTest, NoopReparentNativeView) { 1209 TEST_F(NativeWidgetMacTest, NoopReparentNativeView) {
1163 NSWindow* parent = MakeNativeParent(); 1210 NSWindow* parent = MakeNativeParent();
1164 Widget* dialog = views::DialogDelegate::CreateDialogWidget( 1211 Widget* dialog = views::DialogDelegate::CreateDialogWidget(
1165 new DialogDelegateView, nullptr, [parent contentView]); 1212 new DialogDelegateView, nullptr, [parent contentView]);
1166 BridgedNativeWidget* bridge = 1213 BridgedNativeWidget* bridge =
1167 NativeWidgetMac::GetBridgeForNativeWindow(dialog->GetNativeWindow()); 1214 NativeWidgetMac::GetBridgeForNativeWindow(dialog->GetNativeWindow());
1168 1215
1169 EXPECT_EQ(bridge->parent()->GetNSWindow(), parent); 1216 EXPECT_EQ(bridge->parent()->GetNSWindow(), parent);
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
1862 1909
1863 - (void)dealloc { 1910 - (void)dealloc {
1864 if (deallocFlag_) { 1911 if (deallocFlag_) {
1865 DCHECK(!*deallocFlag_); 1912 DCHECK(!*deallocFlag_);
1866 *deallocFlag_ = true; 1913 *deallocFlag_ = true;
1867 } 1914 }
1868 [super dealloc]; 1915 [super dealloc];
1869 } 1916 }
1870 1917
1871 @end 1918 @end
OLDNEW
« ui/views/widget/native_widget_mac.mm ('K') | « 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