diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-05 19:55:29 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-05 19:55:29 +0000 |
commit | 6dcefa2aded298fa4015a5da4f54e56c65061ab0 (patch) | |
tree | 716fc188a1c25beac2bf039ad32749a7788fc722 /chrome/browser/cocoa/browser_window_controller_unittest.mm | |
parent | efc3315b53e2c3cc6d6aecfa04738447b701f806 (diff) | |
download | chromium_src-6dcefa2aded298fa4015a5da4f54e56c65061ab0.zip chromium_src-6dcefa2aded298fa4015a5da4f54e56c65061ab0.tar.gz chromium_src-6dcefa2aded298fa4015a5da4f54e56c65061ab0.tar.bz2 |
Rewrites the Mac view resizing logic to have the BrowserWindowController
directly resize and relayout its children views. Now when a view needs
to be resized, it asks its resize delegate (typically its controller's
parent) to perform the resize.
BUG=http://crbug.com/17619
TEST=Make sure that views are laid out correctly, even when they change size.
Open and close the bookmark bar. Trigger an infobar and then close it. Trigger
the download shelf and then close it. Trigger a download shelf with the infobar
open, or with the bookmark bar open. Switch to and from fullscreen with various
bars open. Resize the browser window with various bars open. Start the browser
with and without the bookmark bar open. Try all of the above in a popup window.
Review URL: http://codereview.chromium.org/159776
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22517 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/browser_window_controller_unittest.mm')
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller_unittest.mm | 111 |
1 files changed, 110 insertions, 1 deletions
diff --git a/chrome/browser/cocoa/browser_window_controller_unittest.mm b/chrome/browser/cocoa/browser_window_controller_unittest.mm index f816a76..18db2b6 100644 --- a/chrome/browser/cocoa/browser_window_controller_unittest.mm +++ b/chrome/browser/cocoa/browser_window_controller_unittest.mm @@ -15,8 +15,26 @@ #include "chrome/test/testing_profile.h" #include "testing/gtest/include/gtest/gtest.h" -@interface BrowserWindowController (ExposedForTesting) +@interface BrowserWindowController (JustForTesting) +// Already defined in BWC. - (void)saveWindowPositionToPrefs:(PrefService*)prefs; +- (void)layoutSubviews; +@end + +@interface BrowserWindowController (ExposedForTesting) +// Implementations are below. +- (NSView*)infoBarContainerView; +- (NSView*)toolbarView; +@end + +@implementation BrowserWindowController (ExposedForTesting) +- (NSView*)infoBarContainerView { + return [infoBarContainerController_ view]; +} + +- (NSView*)toolbarView { + return [toolbarController_ view]; +} @end class BrowserWindowControllerTest : public testing::Test { @@ -132,4 +150,95 @@ TEST_F(BrowserWindowControllerTest, TestIncognitoWidthSpace) { } #endif +@interface BrowserWindowControllerResizePong : BrowserWindowController { +} +@end + +@implementation BrowserWindowControllerResizePong +@end + +// Test to make sure resizing and relaying-out subviews works correctly. +TEST_F(BrowserWindowControllerTest, TestResizeViews) { + TabStripView* tabstrip = [controller_ tabStripView]; + NSView* contentView = [[tabstrip window] contentView]; + NSView* toolbar = [controller_ toolbarView]; + NSView* infobar = [controller_ infoBarContainerView]; + NSView* contentArea = [controller_ tabContentArea]; + + // We need to muck with the views a bit to put us in a consistent state before + // we start resizing. In particular, we need to move the tab strip to be + // immediately above the content area, since we layout views to be directly + // under the tab strip. We also explicitly set the contentView's frame to be + // 800x600. + [contentView setFrame:NSMakeRect(0, 0, 800, 600)]; + NSRect tabstripFrame = [tabstrip frame]; + tabstripFrame.origin.y = NSMaxY([contentView frame]); + [tabstrip setFrame:tabstripFrame]; + + // Make sure each view is as tall as we expect. + ASSERT_EQ(39, NSHeight([toolbar frame])); + ASSERT_EQ(0, NSHeight([infobar frame])); + + // Force a layout and check each view's frame. + // contentView should be at 0,0 800x600 + // contentArea should be at 0,0 800x561 + // infobar should be at 0,561 800x0 + // toolbar should be at 0,561 800x39 + [controller_ layoutSubviews]; + EXPECT_TRUE(NSEqualRects([contentView frame], NSMakeRect(0, 0, 800, 600))); + EXPECT_TRUE(NSEqualRects([contentArea frame], NSMakeRect(0, 0, 800, 561))); + EXPECT_TRUE(NSEqualRects([infobar frame], NSMakeRect(0, 561, 800, 0))); + EXPECT_TRUE(NSEqualRects([toolbar frame], NSMakeRect(0, 561, 800, 39))); + + // Expand the infobar to 60px and recheck + // contentView should be at 0,0 800x600 + // contentArea should be at 0,0 800x501 + // infobar should be at 0,501 800x60 + // toolbar should be at 0,561 800x39 + [controller_ resizeView:infobar newHeight:60]; + EXPECT_TRUE(NSEqualRects([contentView frame], NSMakeRect(0, 0, 800, 600))); + EXPECT_TRUE(NSEqualRects([contentArea frame], NSMakeRect(0, 0, 800, 501))); + EXPECT_TRUE(NSEqualRects([infobar frame], NSMakeRect(0, 501, 800, 60))); + EXPECT_TRUE(NSEqualRects([toolbar frame], NSMakeRect(0, 561, 800, 39))); + + // Expand the toolbar to 64px and recheck + // contentView should be at 0,0 800x600 + // contentArea should be at 0,0 800x476 + // infobar should be at 0,476 800x60 + // toolbar should be at 0,536 800x64 + [controller_ resizeView:toolbar newHeight:64]; + EXPECT_TRUE(NSEqualRects([contentView frame], NSMakeRect(0, 0, 800, 600))); + EXPECT_TRUE(NSEqualRects([contentArea frame], NSMakeRect(0, 0, 800, 476))); + EXPECT_TRUE(NSEqualRects([infobar frame], NSMakeRect(0, 476, 800, 60))); + EXPECT_TRUE(NSEqualRects([toolbar frame], NSMakeRect(0, 536, 800, 64))); + + // Add a 30px download shelf and recheck + // contentView should be at 0,0 800x600 + // download should be at 0,0 800x30 + // contentArea should be at 0,30 800x446 + // infobar should be at 0,476 800x60 + // toolbar should be at 0,536 800x64 + NSView* download = [[controller_ downloadShelf] view]; + [controller_ resizeView:download newHeight:30]; + EXPECT_TRUE(NSEqualRects([contentView frame], NSMakeRect(0, 0, 800, 600))); + EXPECT_TRUE(NSEqualRects([download frame], NSMakeRect(0, 0, 800, 30))); + EXPECT_TRUE(NSEqualRects([contentArea frame], NSMakeRect(0, 30, 800, 446))); + EXPECT_TRUE(NSEqualRects([infobar frame], NSMakeRect(0, 476, 800, 60))); + EXPECT_TRUE(NSEqualRects([toolbar frame], NSMakeRect(0, 536, 800, 64))); + + // Shrink the infobar to 0px and toolbar to 39px and recheck + // contentView should be at 0,0 800x600 + // download should be at 0,0 800x30 + // contentArea should be at 0,30 800x531 + // infobar should be at 0,561 800x0 + // toolbar should be at 0,561 800x39 + [controller_ resizeView:infobar newHeight:0]; + [controller_ resizeView:toolbar newHeight:39]; + EXPECT_TRUE(NSEqualRects([contentView frame], NSMakeRect(0, 0, 800, 600))); + EXPECT_TRUE(NSEqualRects([download frame], NSMakeRect(0, 0, 800, 30))); + EXPECT_TRUE(NSEqualRects([contentArea frame], NSMakeRect(0, 30, 800, 531))); + EXPECT_TRUE(NSEqualRects([infobar frame], NSMakeRect(0, 561, 800, 0))); + EXPECT_TRUE(NSEqualRects([toolbar frame], NSMakeRect(0, 561, 800, 39))); +} + /* TODO(???): test other methods of BrowserWindowController */ |