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

Unified Diff: chrome/browser/cocoa/browser_window_controller_unittest.mm

Issue 173254: Mac: Fix zoom (green maximize) button. (Closed)
Patch Set: Added comments about arbitrary constants. Created 11 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/cocoa/browser_window_controller.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cocoa/browser_window_controller_unittest.mm
diff --git a/chrome/browser/cocoa/browser_window_controller_unittest.mm b/chrome/browser/cocoa/browser_window_controller_unittest.mm
index 36b5626f9673732d4360cd4c84c5702ca7bc43fa..1bbad3ca6421af9a504e4bdda6f3e8dfad199089 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 */
« no previous file with comments | « chrome/browser/cocoa/browser_window_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698