| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 return rect; | 129 return rect; |
| 130 } | 130 } |
| 131 | 131 |
| 132 void VerifySheetXPosition(NSRect sheet_frame, NSView* parent_view) { | 132 void VerifySheetXPosition(NSRect sheet_frame, NSView* parent_view) { |
| 133 NSRect parent_frame = GetViewFrameInScreenCoordinates(parent_view); | 133 NSRect parent_frame = GetViewFrameInScreenCoordinates(parent_view); |
| 134 CGFloat expected_x = NSMinX(parent_frame) + | 134 CGFloat expected_x = NSMinX(parent_frame) + |
| 135 (NSWidth(parent_frame) - NSWidth(sheet_frame)) / 2.0; | 135 (NSWidth(parent_frame) - NSWidth(sheet_frame)) / 2.0; |
| 136 EXPECT_EQ(expected_x, NSMinX(sheet_frame)); | 136 EXPECT_EQ(expected_x, NSMinX(sheet_frame)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 CGFloat GetSheetYOffset(NSRect sheet_frame, NSView* parent_view) { |
| 140 return NSMaxY(sheet_frame) - |
| 141 NSMaxY(GetViewFrameInScreenCoordinates(parent_view)); |
| 142 } |
| 143 |
| 139 base::scoped_nsobject<NSWindow> sheet_window_; | 144 base::scoped_nsobject<NSWindow> sheet_window_; |
| 140 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet_; | 145 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet_; |
| 141 base::scoped_nsobject<ConstrainedWindowSheetController> controller_; | 146 base::scoped_nsobject<ConstrainedWindowSheetController> controller_; |
| 142 base::scoped_nsobject<NSMutableArray> tab_views_; | 147 base::scoped_nsobject<NSMutableArray> tab_views_; |
| 143 base::scoped_nsobject<NSView> active_tab_view_; | 148 base::scoped_nsobject<NSView> active_tab_view_; |
| 144 base::scoped_nsobject<NSView> tab0_; | 149 base::scoped_nsobject<NSView> tab0_; |
| 145 base::scoped_nsobject<NSView> tab1_; | 150 base::scoped_nsobject<NSView> tab1_; |
| 146 }; | 151 }; |
| 147 | 152 |
| 148 // Test showing then hiding the sheet. | 153 // Test showing then hiding the sheet. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 [sheet_window_ setFrame:new_inactive_frame display:YES]; | 252 [sheet_window_ setFrame:new_inactive_frame display:YES]; |
| 248 | 253 |
| 249 ActivateTabView(tab0_); | 254 ActivateTabView(tab0_); |
| 250 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); | 255 EXPECT_EQ(1.0, [sheet_window_ alphaValue]); |
| 251 | 256 |
| 252 NSRect new_active_frame = [sheet_window_ frame]; | 257 NSRect new_active_frame = [sheet_window_ frame]; |
| 253 EXPECT_EQ(NSWidth(new_inactive_frame), NSWidth(new_active_frame)); | 258 EXPECT_EQ(NSWidth(new_inactive_frame), NSWidth(new_active_frame)); |
| 254 EXPECT_EQ(NSHeight(new_inactive_frame), NSHeight(new_active_frame)); | 259 EXPECT_EQ(NSHeight(new_inactive_frame), NSHeight(new_active_frame)); |
| 255 } | 260 } |
| 256 | 261 |
| 262 // Test resizing parent window keeps the sheet anchored. |
| 263 TEST_F(ConstrainedWindowSheetControllerTest, ResizeParentWindow) { |
| 264 [controller_ showSheet:sheet_ forParentView:active_tab_view_]; |
| 265 CGFloat sheet_offset = |
| 266 GetSheetYOffset([sheet_window_ frame], active_tab_view_); |
| 267 |
| 268 // Test 3x3 different parent window sizes. |
| 269 CGFloat insets[] = {-10, 0, 10}; |
| 270 NSRect old_frame = [test_window() frame]; |
| 271 |
| 272 for (size_t x = 0; x < sizeof(insets) / sizeof(CGFloat); x++) { |
| 273 for (size_t y = 0; y < sizeof(insets) / sizeof(CGFloat); y++) { |
| 274 NSRect resized_frame = NSInsetRect(old_frame, insets[x], insets[y]); |
| 275 [test_window() setFrame:resized_frame display:YES]; |
| 276 NSRect sheet_frame = [sheet_window_ frame]; |
| 277 |
| 278 // Y pos should track parent view's position. |
| 279 EXPECT_EQ(sheet_offset, GetSheetYOffset(sheet_frame, active_tab_view_)); |
| 280 |
| 281 // X pos should be centered on parent view. |
| 282 VerifySheetXPosition(sheet_frame, active_tab_view_); |
| 283 } |
| 284 } |
| 285 } |
| 286 |
| 257 // Test system sheets. | 287 // Test system sheets. |
| 258 TEST_F(ConstrainedWindowSheetControllerTest, SystemSheet) { | 288 TEST_F(ConstrainedWindowSheetControllerTest, SystemSheet) { |
| 259 base::scoped_nsobject<ConstrainedWindowSystemSheetTest> system_sheet( | 289 base::scoped_nsobject<ConstrainedWindowSystemSheetTest> system_sheet( |
| 260 [[ConstrainedWindowSystemSheetTest alloc] init]); | 290 [[ConstrainedWindowSystemSheetTest alloc] init]); |
| 261 base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); | 291 base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); |
| 262 [system_sheet setAlert:alert]; | 292 [system_sheet setAlert:alert]; |
| 263 | 293 |
| 264 EXPECT_FALSE([[alert window] isVisible]); | 294 EXPECT_FALSE([[alert window] isVisible]); |
| 265 [controller_ showSheet:system_sheet | 295 [controller_ showSheet:system_sheet |
| 266 forParentView:active_tab_view_]; | 296 forParentView:active_tab_view_]; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 282 [controller_ showSheet:system_sheet | 312 [controller_ showSheet:system_sheet |
| 283 forParentView:tab1_]; | 313 forParentView:tab1_]; |
| 284 EXPECT_FALSE([[alert window] isVisible]); | 314 EXPECT_FALSE([[alert window] isVisible]); |
| 285 | 315 |
| 286 ActivateTabView(tab1_); | 316 ActivateTabView(tab1_); |
| 287 EXPECT_TRUE([[alert window] isVisible]); | 317 EXPECT_TRUE([[alert window] isVisible]); |
| 288 EXPECT_EQ(1.0, [[alert window] alphaValue]); | 318 EXPECT_EQ(1.0, [[alert window] alphaValue]); |
| 289 | 319 |
| 290 [controller_ closeSheet:system_sheet]; | 320 [controller_ closeSheet:system_sheet]; |
| 291 } | 321 } |
| OLD | NEW |