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/browser_window_controller.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
6 | 6 |
7 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
8 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 | 196 |
197 // Explicitly show the bar. Can't use chrome::ToggleBookmarkBarWhenVisible() | 197 // Explicitly show the bar. Can't use chrome::ToggleBookmarkBarWhenVisible() |
198 // because of the notification issues. | 198 // because of the notification issues. |
199 profile()->GetPrefs()->SetBoolean(bookmarks::prefs::kShowBookmarkBar, true); | 199 profile()->GetPrefs()->SetBoolean(bookmarks::prefs::kShowBookmarkBar, true); |
200 | 200 |
201 [controller_ browserWindow]->BookmarkBarStateChanged( | 201 [controller_ browserWindow]->BookmarkBarStateChanged( |
202 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); | 202 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); |
203 EXPECT_TRUE([controller_ isBookmarkBarVisible]); | 203 EXPECT_TRUE([controller_ isBookmarkBarVisible]); |
204 } | 204 } |
205 | 205 |
206 TEST_F(BrowserWindowControllerTest, BookmarkBarToggleRespectMinWindowHeight) { | |
207 Browser::CreateParams params(Browser::TYPE_TABBED, profile(), | |
208 chrome::GetActiveDesktop()); | |
209 params.initial_bounds = gfx::Rect(0, 0, 50, 280); | |
210 Browser* browser = new Browser(params); | |
211 NSWindow *cocoaWindow = browser->window()->GetNativeWindow(); | |
Avi (use Gerrit)
2015/04/15 04:27:26
space after *
(yeah, fix it elsewhere in the file
shrike
2015/04/15 17:01:33
Sorry about that. Fixed it in other spots too.
| |
212 BrowserWindowController* controller = | |
213 static_cast<BrowserWindowController*>([cocoaWindow windowController]); | |
214 BrowserWindow* browser_window = [controller browserWindow]; | |
215 gfx::Rect bounds = browser_window->GetBounds(); | |
216 EXPECT_EQ(280, bounds.height()); | |
217 | |
218 // Try to set the bounds smaller than the minimum. | |
219 // Explicitly show the bar. Can't use chrome::ToggleBookmarkBarWhenVisible() | |
220 // because of the notification issues. | |
221 [controller adjustWindowHeightBy:-20]; | |
222 bounds = browser_window->GetBounds(); | |
223 EXPECT_EQ(272, bounds.height()); | |
224 | |
225 [controller close]; | |
226 } | |
227 | |
206 #if 0 | 228 #if 0 |
207 // TODO(jrg): This crashes trying to create the BookmarkBarController, adding | 229 // TODO(jrg): This crashes trying to create the BookmarkBarController, adding |
208 // an observer to the BookmarkModel. | 230 // an observer to the BookmarkModel. |
209 TEST_F(BrowserWindowControllerTest, TestIncognitoWidthSpace) { | 231 TEST_F(BrowserWindowControllerTest, TestIncognitoWidthSpace) { |
210 scoped_ptr<TestingProfile> incognito_profile(new TestingProfile()); | 232 scoped_ptr<TestingProfile> incognito_profile(new TestingProfile()); |
211 incognito_profile->set_off_the_record(true); | 233 incognito_profile->set_off_the_record(true); |
212 scoped_ptr<Browser> browser( | 234 scoped_ptr<Browser> browser( |
213 new Browser(Browser::CreateParams(incognito_profile.get(), | 235 new Browser(Browser::CreateParams(incognito_profile.get(), |
214 chrome::GetActiveDesktop())); | 236 chrome::GetActiveDesktop())); |
215 controller_.reset([[BrowserWindowController alloc] | 237 controller_.reset([[BrowserWindowController alloc] |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 } // end namespace | 326 } // end namespace |
305 | 327 |
306 TEST_F(BrowserWindowControllerTest, TestAdjustWindowHeight) { | 328 TEST_F(BrowserWindowControllerTest, TestAdjustWindowHeight) { |
307 NSWindow* window = [controller_ window]; | 329 NSWindow* window = [controller_ window]; |
308 NSRect workarea = [[window screen] visibleFrame]; | 330 NSRect workarea = [[window screen] visibleFrame]; |
309 | 331 |
310 // Place the window well above the bottom of the screen and try to adjust its | 332 // Place the window well above the bottom of the screen and try to adjust its |
311 // height. It should change appropriately (and only downwards). Then get it to | 333 // height. It should change appropriately (and only downwards). Then get it to |
312 // shrink by the same amount; it should return to its original state. | 334 // shrink by the same amount; it should return to its original state. |
313 NSRect initialFrame = NSMakeRect(workarea.origin.x, workarea.origin.y + 100, | 335 NSRect initialFrame = NSMakeRect(workarea.origin.x, workarea.origin.y + 100, |
314 200, 200); | 336 200, 280); |
315 [window setFrame:initialFrame display:YES]; | 337 [window setFrame:initialFrame display:YES]; |
316 [controller_ resetWindowGrowthState]; | 338 [controller_ resetWindowGrowthState]; |
317 [controller_ adjustWindowHeightBy:40]; | 339 [controller_ adjustWindowHeightBy:40]; |
318 NSRect finalFrame = [window frame]; | 340 NSRect finalFrame = [window frame]; |
319 EXPECT_FALSE(NSEqualRects(finalFrame, initialFrame)); | 341 EXPECT_FALSE(NSEqualRects(finalFrame, initialFrame)); |
320 EXPECT_FLOAT_EQ(NSMaxY(finalFrame), NSMaxY(initialFrame)); | 342 EXPECT_FLOAT_EQ(NSMaxY(finalFrame), NSMaxY(initialFrame)); |
321 EXPECT_FLOAT_EQ(NSHeight(finalFrame), NSHeight(initialFrame) + 40); | 343 EXPECT_FLOAT_EQ(NSHeight(finalFrame), NSHeight(initialFrame) + 40); |
322 [controller_ adjustWindowHeightBy:-40]; | 344 [controller_ adjustWindowHeightBy:-40]; |
323 finalFrame = [window frame]; | 345 finalFrame = [window frame]; |
324 EXPECT_FLOAT_EQ(NSMaxY(finalFrame), NSMaxY(initialFrame)); | 346 EXPECT_FLOAT_EQ(NSMaxY(finalFrame), NSMaxY(initialFrame)); |
325 EXPECT_FLOAT_EQ(NSHeight(finalFrame), NSHeight(initialFrame)); | 347 EXPECT_FLOAT_EQ(NSHeight(finalFrame), NSHeight(initialFrame)); |
326 | 348 |
327 // Place the window at the bottom of the screen and try again. Its height | 349 // Place the window at the bottom of the screen and try again. Its height |
328 // should still change, but it should not grow down below the work area; it | 350 // should still change, but it should not grow down below the work area; it |
329 // should instead move upwards. Then shrink it and make sure it goes back to | 351 // should instead move upwards. Then shrink it and make sure it goes back to |
330 // the way it was. | 352 // the way it was. |
331 initialFrame = NSMakeRect(workarea.origin.x, workarea.origin.y, 200, 200); | 353 initialFrame = NSMakeRect(workarea.origin.x, workarea.origin.y, 200, 280); |
332 [window setFrame:initialFrame display:YES]; | 354 [window setFrame:initialFrame display:YES]; |
333 [controller_ resetWindowGrowthState]; | 355 [controller_ resetWindowGrowthState]; |
334 [controller_ adjustWindowHeightBy:40]; | 356 [controller_ adjustWindowHeightBy:40]; |
335 finalFrame = [window frame]; | 357 finalFrame = [window frame]; |
336 EXPECT_FALSE(NSEqualRects(finalFrame, initialFrame)); | 358 EXPECT_FALSE(NSEqualRects(finalFrame, initialFrame)); |
337 EXPECT_FLOAT_EQ(NSMinY(finalFrame), NSMinY(initialFrame)); | 359 EXPECT_FLOAT_EQ(NSMinY(finalFrame), NSMinY(initialFrame)); |
338 EXPECT_FLOAT_EQ(NSHeight(finalFrame), NSHeight(initialFrame) + 40); | 360 EXPECT_FLOAT_EQ(NSHeight(finalFrame), NSHeight(initialFrame) + 40); |
339 [controller_ adjustWindowHeightBy:-40]; | 361 [controller_ adjustWindowHeightBy:-40]; |
340 finalFrame = [window frame]; | 362 finalFrame = [window frame]; |
341 EXPECT_FLOAT_EQ(NSMinY(finalFrame), NSMinY(initialFrame)); | 363 EXPECT_FLOAT_EQ(NSMinY(finalFrame), NSMinY(initialFrame)); |
342 EXPECT_FLOAT_EQ(NSHeight(finalFrame), NSHeight(initialFrame)); | 364 EXPECT_FLOAT_EQ(NSHeight(finalFrame), NSHeight(initialFrame)); |
343 | 365 |
344 // Put the window slightly offscreen and try again. The height should not | 366 // Put the window slightly offscreen and try again. The height should not |
345 // change this time. | 367 // change this time. |
346 initialFrame = NSMakeRect(workarea.origin.x - 10, 0, 200, 200); | 368 initialFrame = NSMakeRect(workarea.origin.x - 10, 0, 200, 280); |
347 [window setFrame:initialFrame display:YES]; | 369 [window setFrame:initialFrame display:YES]; |
348 [controller_ resetWindowGrowthState]; | 370 [controller_ resetWindowGrowthState]; |
349 [controller_ adjustWindowHeightBy:40]; | 371 [controller_ adjustWindowHeightBy:40]; |
350 EXPECT_TRUE(NSEqualRects([window frame], initialFrame)); | 372 EXPECT_TRUE(NSEqualRects([window frame], initialFrame)); |
351 [controller_ adjustWindowHeightBy:-40]; | 373 [controller_ adjustWindowHeightBy:-40]; |
352 EXPECT_TRUE(NSEqualRects([window frame], initialFrame)); | 374 EXPECT_TRUE(NSEqualRects([window frame], initialFrame)); |
353 | 375 |
354 // Make the window the same size as the workarea. Resizing both larger and | 376 // Make the window the same size as the workarea. Resizing both larger and |
355 // smaller should have no effect. | 377 // smaller should have no effect. |
356 [window setFrame:workarea display:YES]; | 378 [window setFrame:workarea display:YES]; |
357 [controller_ resetWindowGrowthState]; | 379 [controller_ resetWindowGrowthState]; |
358 [controller_ adjustWindowHeightBy:40]; | 380 [controller_ adjustWindowHeightBy:40]; |
359 EXPECT_TRUE(NSEqualRects([window frame], workarea)); | 381 EXPECT_TRUE(NSEqualRects([window frame], workarea)); |
360 [controller_ adjustWindowHeightBy:-40]; | 382 [controller_ adjustWindowHeightBy:-40]; |
361 EXPECT_TRUE(NSEqualRects([window frame], workarea)); | 383 EXPECT_TRUE(NSEqualRects([window frame], workarea)); |
362 | 384 |
363 // Make the window smaller than the workarea and place it near the bottom of | 385 // Make the window smaller than the workarea and place it near the bottom of |
364 // the workarea. The window should grow down until it hits the bottom and | 386 // the workarea. The window should grow down until it hits the bottom and |
365 // then continue to grow up. Then shrink it, and it should return to where it | 387 // then continue to grow up. Then shrink it, and it should return to where it |
366 // was. | 388 // was. |
367 initialFrame = NSMakeRect(workarea.origin.x, workarea.origin.y + 5, | 389 initialFrame = NSMakeRect(workarea.origin.x, workarea.origin.y + 5, |
368 200, 200); | 390 200, 280); |
369 [window setFrame:initialFrame display:YES]; | 391 [window setFrame:initialFrame display:YES]; |
370 [controller_ resetWindowGrowthState]; | 392 [controller_ resetWindowGrowthState]; |
371 [controller_ adjustWindowHeightBy:40]; | 393 [controller_ adjustWindowHeightBy:40]; |
372 finalFrame = [window frame]; | 394 finalFrame = [window frame]; |
373 EXPECT_FLOAT_EQ(NSMinY(workarea), NSMinY(finalFrame)); | 395 EXPECT_FLOAT_EQ(NSMinY(workarea), NSMinY(finalFrame)); |
374 EXPECT_FLOAT_EQ(NSHeight(finalFrame), NSHeight(initialFrame) + 40); | 396 EXPECT_FLOAT_EQ(NSHeight(finalFrame), NSHeight(initialFrame) + 40); |
375 [controller_ adjustWindowHeightBy:-40]; | 397 [controller_ adjustWindowHeightBy:-40]; |
376 finalFrame = [window frame]; | 398 finalFrame = [window frame]; |
377 EXPECT_FLOAT_EQ(NSMinY(initialFrame), NSMinY(finalFrame)); | 399 EXPECT_FLOAT_EQ(NSMinY(initialFrame), NSMinY(finalFrame)); |
378 EXPECT_FLOAT_EQ(NSHeight(initialFrame), NSHeight(finalFrame)); | 400 EXPECT_FLOAT_EQ(NSHeight(initialFrame), NSHeight(finalFrame)); |
379 | 401 |
380 // Inset the window slightly from the workarea. It should not grow to be | 402 // Inset the window slightly from the workarea. It should not grow to be |
381 // larger than the workarea. Shrink it; it should return to where it started. | 403 // larger than the workarea. Shrink it; it should return to where it started. |
382 initialFrame = NSInsetRect(workarea, 0, 5); | 404 initialFrame = NSInsetRect(workarea, 0, 5); |
383 [window setFrame:initialFrame display:YES]; | 405 [window setFrame:initialFrame display:YES]; |
384 [controller_ resetWindowGrowthState]; | 406 [controller_ resetWindowGrowthState]; |
385 [controller_ adjustWindowHeightBy:40]; | 407 [controller_ adjustWindowHeightBy:40]; |
386 finalFrame = [window frame]; | 408 finalFrame = [window frame]; |
387 EXPECT_FLOAT_EQ(NSMinY(workarea), NSMinY(finalFrame)); | 409 EXPECT_FLOAT_EQ(NSMinY(workarea), NSMinY(finalFrame)); |
388 EXPECT_FLOAT_EQ(NSHeight(workarea), NSHeight(finalFrame)); | 410 EXPECT_FLOAT_EQ(NSHeight(workarea), NSHeight(finalFrame)); |
389 [controller_ adjustWindowHeightBy:-40]; | 411 [controller_ adjustWindowHeightBy:-40]; |
390 finalFrame = [window frame]; | 412 finalFrame = [window frame]; |
391 EXPECT_FLOAT_EQ(NSMinY(initialFrame), NSMinY(finalFrame)); | 413 EXPECT_FLOAT_EQ(NSMinY(initialFrame), NSMinY(finalFrame)); |
392 EXPECT_FLOAT_EQ(NSHeight(initialFrame), NSHeight(finalFrame)); | 414 EXPECT_FLOAT_EQ(NSHeight(initialFrame), NSHeight(finalFrame)); |
393 | 415 |
394 // Place the window at the bottom of the screen and grow; it should grow | 416 // Place the window at the bottom of the screen and grow; it should grow |
395 // upwards. Move the window off the bottom, then shrink. It should then shrink | 417 // upwards. Move the window off the bottom, then shrink. It should then shrink |
396 // from the bottom. | 418 // from the bottom. |
397 initialFrame = NSMakeRect(workarea.origin.x, workarea.origin.y, 200, 200); | 419 initialFrame = NSMakeRect(workarea.origin.x, workarea.origin.y, 200, 280); |
398 [window setFrame:initialFrame display:YES]; | 420 [window setFrame:initialFrame display:YES]; |
399 [controller_ resetWindowGrowthState]; | 421 [controller_ resetWindowGrowthState]; |
400 [controller_ adjustWindowHeightBy:40]; | 422 [controller_ adjustWindowHeightBy:40]; |
401 finalFrame = [window frame]; | 423 finalFrame = [window frame]; |
402 EXPECT_FALSE(NSEqualRects(finalFrame, initialFrame)); | 424 EXPECT_FALSE(NSEqualRects(finalFrame, initialFrame)); |
403 EXPECT_FLOAT_EQ(NSMinY(finalFrame), NSMinY(initialFrame)); | 425 EXPECT_FLOAT_EQ(NSMinY(finalFrame), NSMinY(initialFrame)); |
404 EXPECT_FLOAT_EQ(NSHeight(finalFrame), NSHeight(initialFrame) + 40); | 426 EXPECT_FLOAT_EQ(NSHeight(finalFrame), NSHeight(initialFrame) + 40); |
405 NSPoint oldOrigin = initialFrame.origin; | 427 NSPoint oldOrigin = initialFrame.origin; |
406 NSPoint newOrigin = NSMakePoint(oldOrigin.x, oldOrigin.y + 10); | 428 NSPoint newOrigin = NSMakePoint(oldOrigin.x, oldOrigin.y + 10); |
407 [window setFrameOrigin:newOrigin]; | 429 [window setFrameOrigin:newOrigin]; |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
775 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) | 797 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) |
776 styleMask:NSBorderlessWindowMask | 798 styleMask:NSBorderlessWindowMask |
777 backing:NSBackingStoreBuffered | 799 backing:NSBackingStoreBuffered |
778 defer:NO]); | 800 defer:NO]); |
779 [[testFullscreenWindow_ contentView] setWantsLayer:YES]; | 801 [[testFullscreenWindow_ contentView] setWantsLayer:YES]; |
780 return testFullscreenWindow_.get(); | 802 return testFullscreenWindow_.get(); |
781 } | 803 } |
782 @end | 804 @end |
783 | 805 |
784 /* TODO(???): test other methods of BrowserWindowController */ | 806 /* TODO(???): test other methods of BrowserWindowController */ |
OLD | NEW |