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

Side by Side 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, 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
« no previous file with comments | « chrome/browser/cocoa/browser_window_controller.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #include "base/scoped_nsobject.h" 5 #include "base/scoped_nsobject.h"
6 #include "base/scoped_nsautorelease_pool.h" 6 #include "base/scoped_nsautorelease_pool.h"
7 #include "base/scoped_ptr.h" 7 #include "base/scoped_ptr.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/cocoa/browser_test_helper.h" 9 #include "chrome/browser/cocoa/browser_test_helper.h"
10 #include "chrome/browser/cocoa/browser_window_controller.h" 10 #include "chrome/browser/cocoa/browser_window_controller.h"
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 TEST_F(BrowserWindowControllerTest, TestTopLeftForBubble) { 265 TEST_F(BrowserWindowControllerTest, TestTopLeftForBubble) {
266 NSPoint p = [controller_ topLeftForBubble]; 266 NSPoint p = [controller_ topLeftForBubble];
267 NSRect all = [[controller_ window] frame]; 267 NSRect all = [[controller_ window] frame];
268 268
269 // As a sanity check make sure the point is vaguely in the top left 269 // As a sanity check make sure the point is vaguely in the top left
270 // of the window. 270 // of the window.
271 EXPECT_GT(p.y, all.origin.y + (all.size.height/2)); 271 EXPECT_GT(p.y, all.origin.y + (all.size.height/2));
272 EXPECT_LT(p.x, all.origin.x + (all.size.width/2)); 272 EXPECT_LT(p.x, all.origin.x + (all.size.width/2));
273 } 273 }
274 274
275 // By the "zoom frame", we mean what Apple calls the "standard frame".
276 TEST_F(BrowserWindowControllerTest, TestZoomFrame) {
277 NSWindow* window = [controller_ window];
278 ASSERT_TRUE(window);
279 NSRect screenFrame = [[window screen] visibleFrame];
280 ASSERT_FALSE(NSIsEmptyRect(screenFrame));
281
282 // Minimum zoomed width is the larger of 60% of available horizontal space or
283 // 60% of available vertical space, subject to available horizontal space.
284 CGFloat minZoomWidth =
285 std::min(std::max((CGFloat)0.6 * screenFrame.size.width,
286 (CGFloat)0.6 * screenFrame.size.height),
287 screenFrame.size.width);
288
289 // |testFrame| is the size of the window we start out with, and |zoomFrame| is
290 // the one returned by |-windowWillUseStandardFrame:defaultFrame:|.
291 NSRect testFrame;
292 NSRect zoomFrame;
293
294 // 1. Test a case where it zooms the window both horizontally and vertically,
295 // and only moves it vertically. "+ 32", etc. are just arbitrary constants
296 // used to check that the window is moved properly and not just to the origin;
297 // they should be small enough to not shove windows off the screen.
298 testFrame.size.width = 0.5 * minZoomWidth;
299 testFrame.size.height = 0.5 * screenFrame.size.height;
300 testFrame.origin.x = screenFrame.origin.x + 32; // See above.
301 testFrame.origin.y = screenFrame.origin.y + 23;
302 [window setFrame:testFrame display:NO];
303 zoomFrame = [controller_ windowWillUseStandardFrame:window
304 defaultFrame:screenFrame];
305 EXPECT_LE(minZoomWidth, zoomFrame.size.width);
306 EXPECT_EQ(screenFrame.size.height, zoomFrame.size.height);
307 EXPECT_EQ(testFrame.origin.x, zoomFrame.origin.x);
308 EXPECT_EQ(screenFrame.origin.y, zoomFrame.origin.y);
309
310 // 2. Test a case where it zooms the window only horizontally, and only moves
311 // it horizontally.
312 testFrame.size.width = 0.5 * minZoomWidth;
313 testFrame.size.height = screenFrame.size.height;
314 testFrame.origin.x = screenFrame.origin.x + screenFrame.size.width -
315 testFrame.size.width;
316 testFrame.origin.y = screenFrame.origin.y;
317 [window setFrame:testFrame display:NO];
318 zoomFrame = [controller_ windowWillUseStandardFrame:window
319 defaultFrame:screenFrame];
320 EXPECT_LE(minZoomWidth, zoomFrame.size.width);
321 EXPECT_EQ(screenFrame.size.height, zoomFrame.size.height);
322 EXPECT_EQ(screenFrame.origin.x + screenFrame.size.width -
323 zoomFrame.size.width, zoomFrame.origin.x);
324 EXPECT_EQ(screenFrame.origin.y, zoomFrame.origin.y);
325
326 // 3. Test a case where it zooms the window only vertically, and only moves it
327 // vertically.
328 testFrame.size.width = std::min((CGFloat)1.1 * minZoomWidth,
329 screenFrame.size.width);
330 testFrame.size.height = 0.3 * screenFrame.size.height;
331 testFrame.origin.x = screenFrame.origin.x + 32; // See above (in 1.).
332 testFrame.origin.y = screenFrame.origin.y + 123;
333 [window setFrame:testFrame display:NO];
334 zoomFrame = [controller_ windowWillUseStandardFrame:window
335 defaultFrame:screenFrame];
336 // Use the actual width of the window frame, since it's subject to rounding.
337 EXPECT_EQ([window frame].size.width, zoomFrame.size.width);
338 EXPECT_EQ(screenFrame.size.height, zoomFrame.size.height);
339 EXPECT_EQ(testFrame.origin.x, zoomFrame.origin.x);
340 EXPECT_EQ(screenFrame.origin.y, zoomFrame.origin.y);
341
342 // 4. Test a case where zooming should do nothing (i.e., we're already at a
343 // zoomed frame).
344 testFrame.size.width = std::min((CGFloat)1.1 * minZoomWidth,
345 screenFrame.size.width);
346 testFrame.size.height = screenFrame.size.height;
347 testFrame.origin.x = screenFrame.origin.x + 32; // See above (in 1.).
348 testFrame.origin.y = screenFrame.origin.y;
349 [window setFrame:testFrame display:NO];
350 zoomFrame = [controller_ windowWillUseStandardFrame:window
351 defaultFrame:screenFrame];
352 // Use the actual width of the window frame, since it's subject to rounding.
353 EXPECT_EQ([window frame].size.width, zoomFrame.size.width);
354 EXPECT_EQ(screenFrame.size.height, zoomFrame.size.height);
355 EXPECT_EQ(testFrame.origin.x, zoomFrame.origin.x);
356 EXPECT_EQ(screenFrame.origin.y, zoomFrame.origin.y);
357 }
358
275 359
276 /* TODO(???): test other methods of BrowserWindowController */ 360 /* TODO(???): test other methods of BrowserWindowController */
OLDNEW
« 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