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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_controller_unittest.mm

Issue 555243002: mac: Refactor browser_window_controller layout logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fullscreen_layout
Patch Set: Comments from rsesek. Created 6 years, 3 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 (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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 namespace { 242 namespace {
243 243
244 // Verifies that the toolbar, infobar, tab content area, and download shelf 244 // Verifies that the toolbar, infobar, tab content area, and download shelf
245 // completely fill the area under the tabstrip. 245 // completely fill the area under the tabstrip.
246 void CheckViewPositions(BrowserWindowController* controller) { 246 void CheckViewPositions(BrowserWindowController* controller) {
247 NSRect contentView = [[[controller window] contentView] bounds]; 247 NSRect contentView = [[[controller window] contentView] bounds];
248 NSRect tabstrip = [[controller tabStripView] frame]; 248 NSRect tabstrip = [[controller tabStripView] frame];
249 NSRect toolbar = [[controller toolbarView] frame]; 249 NSRect toolbar = [[controller toolbarView] frame];
250 NSRect infobar = [[controller infoBarContainerView] frame]; 250 NSRect infobar = [[controller infoBarContainerView] frame];
251 NSRect contentArea = [[controller tabContentArea] frame]; 251 NSRect contentArea = [[controller tabContentArea] frame];
252 NSRect download = [[[controller downloadShelf] view] frame]; 252 NSRect download = NSZeroRect;
253 if ([[[controller downloadShelf] view] superview])
254 download = [[[controller downloadShelf] view] frame];
253 255
254 EXPECT_EQ(NSMinY(contentView), NSMinY(download)); 256 EXPECT_EQ(NSMinY(contentView), NSMinY(download));
255 EXPECT_EQ(NSMaxY(download), NSMinY(contentArea)); 257 EXPECT_EQ(NSMaxY(download), NSMinY(contentArea));
256 EXPECT_EQ(NSMaxY(contentArea), NSMinY(infobar)); 258 EXPECT_EQ(NSMaxY(contentArea), NSMinY(infobar));
257 259
258 // Bookmark bar frame is random memory when hidden. 260 // Bookmark bar frame is random memory when hidden.
259 if ([controller bookmarkBarVisible]) { 261 if ([controller bookmarkBarVisible]) {
260 NSRect bookmark = [[controller bookmarkView] frame]; 262 NSRect bookmark = [[controller bookmarkView] frame];
261 EXPECT_EQ(NSMaxY(infobar), NSMinY(bookmark)); 263 EXPECT_EQ(NSMaxY(infobar), NSMinY(bookmark));
262 EXPECT_EQ(NSMaxY(bookmark), NSMinY(toolbar)); 264 EXPECT_EQ(NSMaxY(bookmark), NSMinY(toolbar));
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 NSView* infobar = [controller_ infoBarContainerView]; 409 NSView* infobar = [controller_ infoBarContainerView];
408 410
409 // We need to muck with the views a bit to put us in a consistent state before 411 // We need to muck with the views a bit to put us in a consistent state before
410 // we start resizing. In particular, we need to move the tab strip to be 412 // we start resizing. In particular, we need to move the tab strip to be
411 // immediately above the content area, since we layout views to be directly 413 // immediately above the content area, since we layout views to be directly
412 // under the tab strip. 414 // under the tab strip.
413 NSRect tabstripFrame = [tabstrip frame]; 415 NSRect tabstripFrame = [tabstrip frame];
414 tabstripFrame.origin.y = NSMaxY([contentView frame]); 416 tabstripFrame.origin.y = NSMaxY([contentView frame]);
415 [tabstrip setFrame:tabstripFrame]; 417 [tabstrip setFrame:tabstripFrame];
416 418
417 // The download shelf is created lazily. Force-create it and set its initial 419 // Make the download shelf and set its initial height to 0.
418 // height to 0. 420 [controller_ createAndAddDownloadShelf];
419 NSView* download = [[controller_ downloadShelf] view]; 421 NSView* download = [[controller_ downloadShelf] view];
420 NSRect downloadFrame = [download frame]; 422 NSRect downloadFrame = [download frame];
421 downloadFrame.size.height = 0; 423 downloadFrame.size.height = 0;
422 [download setFrame:downloadFrame]; 424 [download setFrame:downloadFrame];
423 425
424 // Force a layout and check each view's frame. 426 // Force a layout and check each view's frame.
425 [controller_ layoutSubviews]; 427 [controller_ layoutSubviews];
426 CheckViewPositions(controller_); 428 CheckViewPositions(controller_);
427 429
428 // Expand the infobar to 60px and recheck 430 // Expand the infobar to 60px and recheck
(...skipping 29 matching lines...) Expand all
458 // We need to muck with the views a bit to put us in a consistent state before 460 // We need to muck with the views a bit to put us in a consistent state before
459 // we start resizing. In particular, we need to move the tab strip to be 461 // we start resizing. In particular, we need to move the tab strip to be
460 // immediately above the content area, since we layout views to be directly 462 // immediately above the content area, since we layout views to be directly
461 // under the tab strip. 463 // under the tab strip.
462 NSRect tabstripFrame = [tabstrip frame]; 464 NSRect tabstripFrame = [tabstrip frame];
463 tabstripFrame.origin.y = NSMaxY([contentView frame]); 465 tabstripFrame.origin.y = NSMaxY([contentView frame]);
464 [tabstrip setFrame:tabstripFrame]; 466 [tabstrip setFrame:tabstripFrame];
465 467
466 // The download shelf is created lazily. Force-create it and set its initial 468 // The download shelf is created lazily. Force-create it and set its initial
467 // height to 0. 469 // height to 0.
470 [controller_ createAndAddDownloadShelf];
468 NSView* download = [[controller_ downloadShelf] view]; 471 NSView* download = [[controller_ downloadShelf] view];
469 NSRect downloadFrame = [download frame]; 472 NSRect downloadFrame = [download frame];
470 downloadFrame.size.height = 0; 473 downloadFrame.size.height = 0;
471 [download setFrame:downloadFrame]; 474 [download setFrame:downloadFrame];
472 475
473 // Force a layout and check each view's frame. 476 // Force a layout and check each view's frame.
474 [controller_ layoutSubviews]; 477 [controller_ layoutSubviews];
475 CheckViewPositions(controller_); 478 CheckViewPositions(controller_);
476 479
477 // Add the bookmark bar and recheck. 480 // Add the bookmark bar and recheck.
478 [controller_ resizeView:bookmark newHeight:40]; 481 [controller_ resizeView:bookmark newHeight:40];
479 CheckViewPositions(controller_); 482 CheckViewPositions(controller_);
480 483
481 // Expand the infobar to 60px and recheck 484 // Expand the infobar to 60px and recheck
482 [controller_ resizeView:infobar newHeight:60]; 485 [controller_ resizeView:infobar newHeight:60];
483 CheckViewPositions(controller_); 486 CheckViewPositions(controller_);
484 487
485 // Expand the toolbar to 64px and recheck 488 // Expand the toolbar to 64px and recheck
486 [controller_ resizeView:toolbar newHeight:64]; 489 [controller_ resizeView:toolbar newHeight:64];
487 CheckViewPositions(controller_); 490 CheckViewPositions(controller_);
488 491
489 // Add a 30px download shelf and recheck 492 // Add a 30px download shelf and recheck
490 [controller_ resizeView:download newHeight:30]; 493 [controller_ resizeView:download newHeight:30];
491 CheckViewPositions(controller_); 494 CheckViewPositions(controller_);
492 495
493 // Remove the bookmark bar and recheck 496 // Remove the bookmark bar and recheck
494 profile()->GetPrefs()->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false); 497 profile()->GetPrefs()->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false);
498 [controller_ browserWindow]->BookmarkBarStateChanged(
499 BookmarkBar::DONT_ANIMATE_STATE_CHANGE);
495 [controller_ resizeView:bookmark newHeight:0]; 500 [controller_ resizeView:bookmark newHeight:0];
496 CheckViewPositions(controller_); 501 CheckViewPositions(controller_);
497 502
498 // Shrink the infobar to 0px and toolbar to 39px and recheck 503 // Shrink the infobar to 0px and toolbar to 39px and recheck
499 [controller_ resizeView:infobar newHeight:0]; 504 [controller_ resizeView:infobar newHeight:0];
500 [controller_ resizeView:toolbar newHeight:39]; 505 [controller_ resizeView:toolbar newHeight:39];
501 CheckViewPositions(controller_); 506 CheckViewPositions(controller_);
502 } 507 }
503 508
504 // Make sure, by default, the bookmark bar and the toolbar are the same width. 509 // Make sure, by default, the bookmark bar and the toolbar are the same width.
505 TEST_F(BrowserWindowControllerTest, BookmarkBarIsSameWidth) { 510 TEST_F(BrowserWindowControllerTest, BookmarkBarIsSameWidth) {
506 // Set the pref to the bookmark bar is visible when the toolbar is 511 // Set the pref to the bookmark bar is visible when the toolbar is
507 // first created. 512 // first created.
508 profile()->GetPrefs()->SetBoolean(bookmarks::prefs::kShowBookmarkBar, true); 513 profile()->GetPrefs()->SetBoolean(bookmarks::prefs::kShowBookmarkBar, true);
509 514
510 // Make sure the bookmark bar is the same width as the toolbar 515 // Make sure the bookmark bar is the same width as the toolbar
511 NSView* bookmarkBarView = [controller_ bookmarkView]; 516 NSView* bookmarkBarView = [controller_ bookmarkView];
512 NSView* toolbarView = [controller_ toolbarView]; 517 NSView* toolbarView = [controller_ toolbarView];
513 EXPECT_EQ([toolbarView frame].size.width, 518 EXPECT_EQ([toolbarView frame].size.width,
514 [bookmarkBarView frame].size.width); 519 [bookmarkBarView frame].size.width);
515 } 520 }
516 521
517 TEST_F(BrowserWindowControllerTest, TestTopRightForBubble) { 522 TEST_F(BrowserWindowControllerTest, TestTopRightForBubble) {
518 // The bookmark bubble must be attached to a lit and visible star. 523 // The bookmark bubble must be attached to a lit and visible star.
519 [controller_ setStarredState:YES]; 524 [controller_ setStarredState:YES];
520 NSPoint p = [controller_ bookmarkBubblePoint]; 525 NSPoint p = [controller_ bookmarkBubblePoint]; // Window coordinates.
521 NSRect all = [[controller_ window] frame]; 526 NSRect all = [[controller_ window] frame]; // Screen coordinates.
522 527
523 // As a sanity check make sure the point is vaguely in the top right 528 // As a sanity check make sure the point is vaguely in the top right
524 // of the window. 529 // of the window.
525 EXPECT_GT(p.y, all.origin.y + (all.size.height/2)); 530 EXPECT_GT(p.y, all.size.height / 2);
526 EXPECT_GT(p.x, all.origin.x + (all.size.width/2)); 531 EXPECT_GT(p.x, all.size.width / 2);
527 } 532 }
528 533
529 // By the "zoom frame", we mean what Apple calls the "standard frame". 534 // By the "zoom frame", we mean what Apple calls the "standard frame".
530 TEST_F(BrowserWindowControllerTest, TestZoomFrame) { 535 TEST_F(BrowserWindowControllerTest, TestZoomFrame) {
531 NSWindow* window = [controller_ window]; 536 NSWindow* window = [controller_ window];
532 ASSERT_TRUE(window); 537 ASSERT_TRUE(window);
533 NSRect screenFrame = [[window screen] visibleFrame]; 538 NSRect screenFrame = [[window screen] visibleFrame];
534 ASSERT_FALSE(NSIsEmptyRect(screenFrame)); 539 ASSERT_FALSE(NSIsEmptyRect(screenFrame));
535 540
536 // Minimum zoomed width is the larger of 60% of available horizontal space or 541 // Minimum zoomed width is the larger of 60% of available horizontal space or
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 testFullscreenWindow_.reset( 886 testFullscreenWindow_.reset(
882 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) 887 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400)
883 styleMask:NSBorderlessWindowMask 888 styleMask:NSBorderlessWindowMask
884 backing:NSBackingStoreBuffered 889 backing:NSBackingStoreBuffered
885 defer:NO]); 890 defer:NO]);
886 return testFullscreenWindow_.get(); 891 return testFullscreenWindow_.get();
887 } 892 }
888 @end 893 @end
889 894
890 /* TODO(???): test other methods of BrowserWindowController */ 895 /* TODO(???): test other methods of BrowserWindowController */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698