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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « ui/views/widget/native_widget_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
1171 // and reshowing a sheet on a window after the sheet was closed with -[NSWindow
1172 // close].
1173 TEST_F(NativeWidgetMacTest, CloseWithWindowModalSheet) {
1174 NSWindow* native_parent =
1175 MakeNativeParentWithStyle(NSClosableWindowMask | NSTitledWindowMask);
1176 {
1177 Widget* sheet_widget = ShowWindowModalWidget(native_parent);
1178 EXPECT_TRUE([sheet_widget->GetNativeWindow() isVisible]);
1179
1180 WidgetChangeObserver widget_observer(sheet_widget);
1181
1182 // Test synchronous close (asynchronous close is tested above).
1183 sheet_widget->CloseNow();
1184 EXPECT_TRUE(widget_observer.widget_closed());
1185
1186 // Spin the RunLoop to ensure the task that ends the modal session on
1187 // |native_parent| is executed. Otherwise |native_parent| will refuse to
1188 // show another sheet.
1189 base::RunLoop().RunUntilIdle();
1190 }
1191
1192 {
1193 Widget* sheet_widget = ShowWindowModalWidget(native_parent);
1194
1195 // Ensure the sheet wasn't blocked by a previous modal session.
1196 EXPECT_TRUE([sheet_widget->GetNativeWindow() isVisible]);
1197
1198 WidgetChangeObserver widget_observer(sheet_widget);
1199
1200 // Test native -[NSWindow close] on the sheet. Does not animate.
1201 [sheet_widget->GetNativeWindow() close];
1202 EXPECT_TRUE(widget_observer.widget_closed());
1203 base::RunLoop().RunUntilIdle();
1204 }
1205
1206 {
1207 Widget* sheet_widget = ShowWindowModalWidget(native_parent);
1208 EXPECT_TRUE([sheet_widget->GetNativeWindow() isVisible]);
1209 WidgetChangeObserver widget_observer(sheet_widget);
1210
1211 // Test -[NSWindow close] on the parent window.
1212 [native_parent close];
1213 EXPECT_TRUE(widget_observer.widget_closed());
1214 }
1215 }
1216
1160 // Test calls to Widget::ReparentNativeView() that result in a no-op on Mac. 1217 // Test calls to Widget::ReparentNativeView() that result in a no-op on Mac.
1161 // Tests with both native and non-native parents. 1218 // Tests with both native and non-native parents.
1162 TEST_F(NativeWidgetMacTest, NoopReparentNativeView) { 1219 TEST_F(NativeWidgetMacTest, NoopReparentNativeView) {
1163 NSWindow* parent = MakeNativeParent(); 1220 NSWindow* parent = MakeNativeParent();
1164 Widget* dialog = views::DialogDelegate::CreateDialogWidget( 1221 Widget* dialog = views::DialogDelegate::CreateDialogWidget(
1165 new DialogDelegateView, nullptr, [parent contentView]); 1222 new DialogDelegateView, nullptr, [parent contentView]);
1166 BridgedNativeWidget* bridge = 1223 BridgedNativeWidget* bridge =
1167 NativeWidgetMac::GetBridgeForNativeWindow(dialog->GetNativeWindow()); 1224 NativeWidgetMac::GetBridgeForNativeWindow(dialog->GetNativeWindow());
1168 1225
1169 EXPECT_EQ(bridge->parent()->GetNSWindow(), parent); 1226 EXPECT_EQ(bridge->parent()->GetNSWindow(), parent);
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
1862 1919
1863 - (void)dealloc { 1920 - (void)dealloc {
1864 if (deallocFlag_) { 1921 if (deallocFlag_) {
1865 DCHECK(!*deallocFlag_); 1922 DCHECK(!*deallocFlag_);
1866 *deallocFlag_ = true; 1923 *deallocFlag_ = true;
1867 } 1924 }
1868 [super dealloc]; 1925 [super dealloc];
1869 } 1926 }
1870 1927
1871 @end 1928 @end
OLDNEW
« 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