diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-02 17:01:19 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-02 17:01:19 +0000 |
commit | ee2bd0350faae7e862af993b8884d6c9c48559a4 (patch) | |
tree | b8bea2c83fd01eff0b47cea8d1976c244b978484 /chrome/browser/cocoa/browser_window_controller_unittest.mm | |
parent | 12f9faa592c28028cb833347a641ab0b9bab4b40 (diff) | |
download | chromium_src-ee2bd0350faae7e862af993b8884d6c9c48559a4.zip chromium_src-ee2bd0350faae7e862af993b8884d6c9c48559a4.tar.gz chromium_src-ee2bd0350faae7e862af993b8884d6c9c48559a4.tar.bz2 |
Mac: Fix zoom (green maximize) button.
We always maximally zoom vertically, since doing otherwise is too hard.
(We'd have to figure out the width and get the renderer to calculate the
height -- and somehow do this asynchronously.)
BUG=17472
TEST=Zoom/unzoom from a variety of window configurations (size and position), with the Dock in the different possible positions, with web content of differing intrinsic size.
Review URL: http://codereview.chromium.org/173254
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25182 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 | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/browser_window_controller_unittest.mm b/chrome/browser/cocoa/browser_window_controller_unittest.mm index 36b5626..1bbad3c 100644 --- a/chrome/browser/cocoa/browser_window_controller_unittest.mm +++ b/chrome/browser/cocoa/browser_window_controller_unittest.mm @@ -272,5 +272,89 @@ TEST_F(BrowserWindowControllerTest, TestTopLeftForBubble) { EXPECT_LT(p.x, all.origin.x + (all.size.width/2)); } +// By the "zoom frame", we mean what Apple calls the "standard frame". +TEST_F(BrowserWindowControllerTest, TestZoomFrame) { + NSWindow* window = [controller_ window]; + ASSERT_TRUE(window); + NSRect screenFrame = [[window screen] visibleFrame]; + ASSERT_FALSE(NSIsEmptyRect(screenFrame)); + + // Minimum zoomed width is the larger of 60% of available horizontal space or + // 60% of available vertical space, subject to available horizontal space. + CGFloat minZoomWidth = + std::min(std::max((CGFloat)0.6 * screenFrame.size.width, + (CGFloat)0.6 * screenFrame.size.height), + screenFrame.size.width); + + // |testFrame| is the size of the window we start out with, and |zoomFrame| is + // the one returned by |-windowWillUseStandardFrame:defaultFrame:|. + NSRect testFrame; + NSRect zoomFrame; + + // 1. Test a case where it zooms the window both horizontally and vertically, + // and only moves it vertically. "+ 32", etc. are just arbitrary constants + // used to check that the window is moved properly and not just to the origin; + // they should be small enough to not shove windows off the screen. + testFrame.size.width = 0.5 * minZoomWidth; + testFrame.size.height = 0.5 * screenFrame.size.height; + testFrame.origin.x = screenFrame.origin.x + 32; // See above. + testFrame.origin.y = screenFrame.origin.y + 23; + [window setFrame:testFrame display:NO]; + zoomFrame = [controller_ windowWillUseStandardFrame:window + defaultFrame:screenFrame]; + EXPECT_LE(minZoomWidth, zoomFrame.size.width); + EXPECT_EQ(screenFrame.size.height, zoomFrame.size.height); + EXPECT_EQ(testFrame.origin.x, zoomFrame.origin.x); + EXPECT_EQ(screenFrame.origin.y, zoomFrame.origin.y); + + // 2. Test a case where it zooms the window only horizontally, and only moves + // it horizontally. + testFrame.size.width = 0.5 * minZoomWidth; + testFrame.size.height = screenFrame.size.height; + testFrame.origin.x = screenFrame.origin.x + screenFrame.size.width - + testFrame.size.width; + testFrame.origin.y = screenFrame.origin.y; + [window setFrame:testFrame display:NO]; + zoomFrame = [controller_ windowWillUseStandardFrame:window + defaultFrame:screenFrame]; + EXPECT_LE(minZoomWidth, zoomFrame.size.width); + EXPECT_EQ(screenFrame.size.height, zoomFrame.size.height); + EXPECT_EQ(screenFrame.origin.x + screenFrame.size.width - + zoomFrame.size.width, zoomFrame.origin.x); + EXPECT_EQ(screenFrame.origin.y, zoomFrame.origin.y); + + // 3. Test a case where it zooms the window only vertically, and only moves it + // vertically. + testFrame.size.width = std::min((CGFloat)1.1 * minZoomWidth, + screenFrame.size.width); + testFrame.size.height = 0.3 * screenFrame.size.height; + testFrame.origin.x = screenFrame.origin.x + 32; // See above (in 1.). + testFrame.origin.y = screenFrame.origin.y + 123; + [window setFrame:testFrame display:NO]; + zoomFrame = [controller_ windowWillUseStandardFrame:window + defaultFrame:screenFrame]; + // Use the actual width of the window frame, since it's subject to rounding. + EXPECT_EQ([window frame].size.width, zoomFrame.size.width); + EXPECT_EQ(screenFrame.size.height, zoomFrame.size.height); + EXPECT_EQ(testFrame.origin.x, zoomFrame.origin.x); + EXPECT_EQ(screenFrame.origin.y, zoomFrame.origin.y); + + // 4. Test a case where zooming should do nothing (i.e., we're already at a + // zoomed frame). + testFrame.size.width = std::min((CGFloat)1.1 * minZoomWidth, + screenFrame.size.width); + testFrame.size.height = screenFrame.size.height; + testFrame.origin.x = screenFrame.origin.x + 32; // See above (in 1.). + testFrame.origin.y = screenFrame.origin.y; + [window setFrame:testFrame display:NO]; + zoomFrame = [controller_ windowWillUseStandardFrame:window + defaultFrame:screenFrame]; + // Use the actual width of the window frame, since it's subject to rounding. + EXPECT_EQ([window frame].size.width, zoomFrame.size.width); + EXPECT_EQ(screenFrame.size.height, zoomFrame.size.height); + EXPECT_EQ(testFrame.origin.x, zoomFrame.origin.x); + EXPECT_EQ(screenFrame.origin.y, zoomFrame.origin.y); +} + /* TODO(???): test other methods of BrowserWindowController */ |