OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" | 5 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" |
6 | 6 |
7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
8 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" | 8 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" |
9 #import "testing/gtest_mac.h" | 9 #import "testing/gtest_mac.h" |
10 | 10 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 virtual void SetUp() OVERRIDE { | 72 virtual void SetUp() OVERRIDE { |
73 CocoaTest::SetUp(); | 73 CocoaTest::SetUp(); |
74 | 74 |
75 // Center the window so that the sheet doesn't go offscreen. | 75 // Center the window so that the sheet doesn't go offscreen. |
76 [test_window() center]; | 76 [test_window() center]; |
77 | 77 |
78 // Create two dummy tabs and make the first one active. | 78 // Create two dummy tabs and make the first one active. |
79 NSRect dummyRect = NSMakeRect(0, 0, 50, 50); | 79 NSRect dummyRect = NSMakeRect(0, 0, 50, 50); |
80 tab_views_.reset([[NSMutableArray alloc] init]); | 80 tab_views_.reset([[NSMutableArray alloc] init]); |
81 for (int i = 0; i < 2; ++i) { | 81 for (int i = 0; i < 2; ++i) { |
82 scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:dummyRect]); | 82 base::scoped_nsobject<NSView> view( |
| 83 [[NSView alloc] initWithFrame:dummyRect]); |
83 [tab_views_ addObject:view]; | 84 [tab_views_ addObject:view]; |
84 } | 85 } |
85 tab0_.reset([[tab_views_ objectAtIndex:0] retain]); | 86 tab0_.reset([[tab_views_ objectAtIndex:0] retain]); |
86 tab1_.reset([[tab_views_ objectAtIndex:1] retain]); | 87 tab1_.reset([[tab_views_ objectAtIndex:1] retain]); |
87 ActivateTabView(tab0_); | 88 ActivateTabView(tab0_); |
88 | 89 |
89 // Create a test sheet. | 90 // Create a test sheet. |
90 sheet_window_.reset([[NSWindow alloc] | 91 sheet_window_.reset([[NSWindow alloc] |
91 initWithContentRect:dummyRect | 92 initWithContentRect:dummyRect |
92 styleMask:NSTitledWindowMask | 93 styleMask:NSTitledWindowMask |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 return rect; | 129 return rect; |
129 } | 130 } |
130 | 131 |
131 void VerifySheetXPosition(NSRect sheet_frame, NSView* parent_view) { | 132 void VerifySheetXPosition(NSRect sheet_frame, NSView* parent_view) { |
132 NSRect parent_frame = GetViewFrameInScreenCoordinates(parent_view); | 133 NSRect parent_frame = GetViewFrameInScreenCoordinates(parent_view); |
133 CGFloat expected_x = NSMinX(parent_frame) + | 134 CGFloat expected_x = NSMinX(parent_frame) + |
134 (NSWidth(parent_frame) - NSWidth(sheet_frame)) / 2.0; | 135 (NSWidth(parent_frame) - NSWidth(sheet_frame)) / 2.0; |
135 EXPECT_EQ(expected_x, NSMinX(sheet_frame)); | 136 EXPECT_EQ(expected_x, NSMinX(sheet_frame)); |
136 } | 137 } |
137 | 138 |
138 scoped_nsobject<NSWindow> sheet_window_; | 139 base::scoped_nsobject<NSWindow> sheet_window_; |
139 scoped_nsobject<CustomConstrainedWindowSheet> sheet_; | 140 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet_; |
140 scoped_nsobject<ConstrainedWindowSheetController> controller_; | 141 base::scoped_nsobject<ConstrainedWindowSheetController> controller_; |
141 scoped_nsobject<NSMutableArray> tab_views_; | 142 base::scoped_nsobject<NSMutableArray> tab_views_; |
142 scoped_nsobject<NSView> active_tab_view_; | 143 base::scoped_nsobject<NSView> active_tab_view_; |
143 scoped_nsobject<NSView> tab0_; | 144 base::scoped_nsobject<NSView> tab0_; |
144 scoped_nsobject<NSView> tab1_; | 145 base::scoped_nsobject<NSView> tab1_; |
145 }; | 146 }; |
146 | 147 |
147 // Test showing then hiding the sheet. | 148 // Test showing then hiding the sheet. |
148 TEST_F(ConstrainedWindowSheetControllerTest, ShowHide) { | 149 TEST_F(ConstrainedWindowSheetControllerTest, ShowHide) { |
149 EXPECT_FALSE([sheet_window_ isVisible]); | 150 EXPECT_FALSE([sheet_window_ isVisible]); |
150 [controller_ showSheet:sheet_ forParentView:active_tab_view_]; | 151 [controller_ showSheet:sheet_ forParentView:active_tab_view_]; |
151 EXPECT_TRUE([ConstrainedWindowSheetController controllerForSheet:sheet_]); | 152 EXPECT_TRUE([ConstrainedWindowSheetController controllerForSheet:sheet_]); |
152 EXPECT_TRUE([sheet_window_ isVisible]); | 153 EXPECT_TRUE([sheet_window_ isVisible]); |
153 | 154 |
154 [controller_ closeSheet:sheet_]; | 155 [controller_ closeSheet:sheet_]; |
(...skipping 21 matching lines...) Expand all Loading... |
176 [controller_ showSheet:sheet_ forParentView:tab1_]; | 177 [controller_ showSheet:sheet_ forParentView:tab1_]; |
177 EXPECT_EQ(0.0, [sheet_window_ alphaValue]); | 178 EXPECT_EQ(0.0, [sheet_window_ alphaValue]); |
178 | 179 |
179 ActivateTabView(tab1_); | 180 ActivateTabView(tab1_); |
180 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); | 181 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); |
181 VerifySheetXPosition([sheet_window_ frame], tab1_); | 182 VerifySheetXPosition([sheet_window_ frame], tab1_); |
182 } | 183 } |
183 | 184 |
184 // Test that two parent windows with two sheet controllers don't conflict. | 185 // Test that two parent windows with two sheet controllers don't conflict. |
185 TEST_F(ConstrainedWindowSheetControllerTest, TwoParentWindows) { | 186 TEST_F(ConstrainedWindowSheetControllerTest, TwoParentWindows) { |
186 scoped_nsobject<NSWindow> parent_window2([[NSWindow alloc] | 187 base::scoped_nsobject<NSWindow> parent_window2( |
187 initWithContentRect:NSMakeRect(0, 0, 30, 30) | 188 [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 30, 30) |
188 styleMask:NSTitledWindowMask | 189 styleMask:NSTitledWindowMask |
189 backing:NSBackingStoreBuffered | 190 backing:NSBackingStoreBuffered |
190 defer:NO]); | 191 defer:NO]); |
191 [parent_window2 setReleasedWhenClosed:NO]; | 192 [parent_window2 setReleasedWhenClosed:NO]; |
192 | 193 |
193 ConstrainedWindowSheetController* controller2 = | 194 ConstrainedWindowSheetController* controller2 = |
194 [ConstrainedWindowSheetController | 195 [ConstrainedWindowSheetController |
195 controllerForParentWindow:parent_window2]; | 196 controllerForParentWindow:parent_window2]; |
196 EXPECT_TRUE(controller2); | 197 EXPECT_TRUE(controller2); |
197 EXPECT_NSNE(controller_, controller2); | 198 EXPECT_NSNE(controller_, controller2); |
198 | 199 |
199 [controller2 showSheet:sheet_ forParentView:[parent_window2 contentView]]; | 200 [controller2 showSheet:sheet_ forParentView:[parent_window2 contentView]]; |
200 EXPECT_NSEQ(controller2, | 201 EXPECT_NSEQ(controller2, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 ActivateTabView(tab0_); | 249 ActivateTabView(tab0_); |
249 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); | 250 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); |
250 | 251 |
251 NSRect new_active_frame = [sheet_window_ frame]; | 252 NSRect new_active_frame = [sheet_window_ frame]; |
252 EXPECT_EQ(NSWidth(new_inactive_frame), NSWidth(new_active_frame)); | 253 EXPECT_EQ(NSWidth(new_inactive_frame), NSWidth(new_active_frame)); |
253 EXPECT_EQ(NSHeight(new_inactive_frame), NSHeight(new_active_frame)); | 254 EXPECT_EQ(NSHeight(new_inactive_frame), NSHeight(new_active_frame)); |
254 } | 255 } |
255 | 256 |
256 // Test system sheets. | 257 // Test system sheets. |
257 TEST_F(ConstrainedWindowSheetControllerTest, SystemSheet) { | 258 TEST_F(ConstrainedWindowSheetControllerTest, SystemSheet) { |
258 scoped_nsobject<ConstrainedWindowSystemSheetTest> system_sheet( | 259 base::scoped_nsobject<ConstrainedWindowSystemSheetTest> system_sheet( |
259 [[ConstrainedWindowSystemSheetTest alloc] init]); | 260 [[ConstrainedWindowSystemSheetTest alloc] init]); |
260 scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); | 261 base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); |
261 [system_sheet setAlert:alert]; | 262 [system_sheet setAlert:alert]; |
262 | 263 |
263 EXPECT_FALSE([[alert window] isVisible]); | 264 EXPECT_FALSE([[alert window] isVisible]); |
264 [controller_ showSheet:system_sheet | 265 [controller_ showSheet:system_sheet |
265 forParentView:active_tab_view_]; | 266 forParentView:active_tab_view_]; |
266 EXPECT_TRUE([[alert window] isVisible]); | 267 EXPECT_TRUE([[alert window] isVisible]); |
267 | 268 |
268 [controller_ closeSheet:system_sheet]; | 269 [controller_ closeSheet:system_sheet]; |
269 EXPECT_FALSE([[alert window] isVisible]); | 270 EXPECT_FALSE([[alert window] isVisible]); |
270 EXPECT_EQ(kSystemSheetReturnCode, [system_sheet returnCode]); | 271 EXPECT_EQ(kSystemSheetReturnCode, [system_sheet returnCode]); |
271 } | 272 } |
272 | 273 |
273 // Test showing a system sheet on an inactive tab. | 274 // Test showing a system sheet on an inactive tab. |
274 TEST_F(ConstrainedWindowSheetControllerTest, SystemSheetAddToInactiveTab) { | 275 TEST_F(ConstrainedWindowSheetControllerTest, SystemSheetAddToInactiveTab) { |
275 scoped_nsobject<ConstrainedWindowSystemSheetTest> system_sheet( | 276 base::scoped_nsobject<ConstrainedWindowSystemSheetTest> system_sheet( |
276 [[ConstrainedWindowSystemSheetTest alloc] init]); | 277 [[ConstrainedWindowSystemSheetTest alloc] init]); |
277 scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); | 278 base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); |
278 [system_sheet setAlert:alert]; | 279 [system_sheet setAlert:alert]; |
279 | 280 |
280 EXPECT_FALSE([[alert window] isVisible]); | 281 EXPECT_FALSE([[alert window] isVisible]); |
281 [controller_ showSheet:system_sheet | 282 [controller_ showSheet:system_sheet |
282 forParentView:tab1_]; | 283 forParentView:tab1_]; |
283 EXPECT_FALSE([[alert window] isVisible]); | 284 EXPECT_FALSE([[alert window] isVisible]); |
284 | 285 |
285 ActivateTabView(tab1_); | 286 ActivateTabView(tab1_); |
286 EXPECT_TRUE([[alert window] isVisible]); | 287 EXPECT_TRUE([[alert window] isVisible]); |
287 EXPECT_EQ(1.0, [[alert window] alphaValue]); | 288 EXPECT_EQ(1.0, [[alert window] alphaValue]); |
288 | 289 |
289 [controller_ closeSheet:system_sheet]; | 290 [controller_ closeSheet:system_sheet]; |
290 } | 291 } |
OLD | NEW |