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

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

Issue 391035: [Mac] Add support for growing or shrinking the window during animations.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | Annotate | Revision Log
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 "app/l10n_util_mac.h" 5 #include "app/l10n_util_mac.h"
6 #include "base/scoped_nsobject.h" 6 #include "base/scoped_nsobject.h"
7 #include "base/scoped_nsautorelease_pool.h" 7 #include "base/scoped_nsautorelease_pool.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "chrome/app/chrome_dll_resource.h" 9 #include "chrome/app/chrome_dll_resource.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 EXPECT_EQ(NSMaxY(infobar), NSMinY(bookmark)); 187 EXPECT_EQ(NSMaxY(infobar), NSMinY(bookmark));
188 EXPECT_EQ(NSMaxY(bookmark), NSMinY(toolbar)); 188 EXPECT_EQ(NSMaxY(bookmark), NSMinY(toolbar));
189 } else { 189 } else {
190 EXPECT_EQ(NSMaxY(infobar), NSMinY(toolbar)); 190 EXPECT_EQ(NSMaxY(infobar), NSMinY(toolbar));
191 } 191 }
192 192
193 EXPECT_EQ(NSMaxY(contentView), NSMaxY(toolbar)); 193 EXPECT_EQ(NSMaxY(contentView), NSMaxY(toolbar));
194 } 194 }
195 } // end namespace 195 } // end namespace
196 196
197 TEST_F(BrowserWindowControllerTest, TestAdjustWindowHeight) {
198 NSWindow* window = [controller_ window];
199 NSRect workarea = [[window screen] visibleFrame];
200
201 // Place the window well above the bottom of the screen and try to adjust its
202 // height.
203 NSRect initialFrame = NSMakeRect(workarea.origin.x, workarea.origin.y + 100,
204 200, 200);
205 [window setFrame:initialFrame display:YES];
206 [controller_ adjustWindowHeightBy:40];
207 NSRect finalFrame = [window frame];
208 EXPECT_FALSE(NSEqualRects(finalFrame, initialFrame));
209 EXPECT_FLOAT_EQ(NSHeight(finalFrame), NSHeight(initialFrame) + 40);
210
211 // Place the window at the bottom of the screen and try again. Its height
212 // should still change, but it should not grow down below the work area.
213 initialFrame = NSMakeRect(workarea.origin.x, workarea.origin.y, 200, 200);
214 [window setFrame:initialFrame display:YES];
215 [controller_ adjustWindowHeightBy:40];
216 EXPECT_FALSE(NSEqualRects(finalFrame, initialFrame));
217 EXPECT_GE(NSMinY(finalFrame), NSMinY(initialFrame));
218 EXPECT_FLOAT_EQ(NSHeight(finalFrame), NSHeight(initialFrame) + 40);
219
220 // Move the window slightly offscreen and try again. The height should not
221 // change this time.
222 initialFrame = NSMakeRect(workarea.origin.x - 10, 0, 200, 200);
223 [window setFrame:initialFrame display:YES];
224 [controller_ adjustWindowHeightBy:40];
225 EXPECT_TRUE(NSEqualRects([window frame], initialFrame));
226
227 // Make the window the same size as the workarea. Resizing both larger and
228 // smaller should have no effect.
229 [window setFrame:workarea display:YES];
230 [controller_ adjustWindowHeightBy:40];
231 EXPECT_TRUE(NSEqualRects([window frame], workarea));
232 [controller_ adjustWindowHeightBy:-40];
233 EXPECT_TRUE(NSEqualRects([window frame], workarea));
234
235 // Make the window smaller than the workarea and place it near the bottom of
236 // the workarea. The window should grow down until it hits the bottom and
237 // then continue to grow up.
238 initialFrame = NSMakeRect(workarea.origin.x, workarea.origin.y + 5,
239 200, 200);
240 [window setFrame:initialFrame display:YES];
241 [controller_ adjustWindowHeightBy:40];
242 finalFrame = [window frame];
243 EXPECT_EQ(NSMinY(workarea), NSMinY(finalFrame));
244 EXPECT_FLOAT_EQ(NSHeight(finalFrame), NSHeight(initialFrame) + 40);
245
246 // Inset the window slightly from the workarea. It should not grow to be
247 // larger than the workarea.
248 initialFrame = NSInsetRect(workarea, 0, 5);
249 [window setFrame:initialFrame display:YES];
250 [controller_ adjustWindowHeightBy:40];
251 EXPECT_EQ(NSHeight(workarea), NSHeight([window frame]));
252 }
253
197 // Test to make sure resizing and relaying-out subviews works correctly. 254 // Test to make sure resizing and relaying-out subviews works correctly.
198 TEST_F(BrowserWindowControllerTest, TestResizeViews) { 255 TEST_F(BrowserWindowControllerTest, TestResizeViews) {
199 TabStripView* tabstrip = [controller_ tabStripView]; 256 TabStripView* tabstrip = [controller_ tabStripView];
200 NSView* contentView = [[tabstrip window] contentView]; 257 NSView* contentView = [[tabstrip window] contentView];
201 NSView* toolbar = [controller_ toolbarView]; 258 NSView* toolbar = [controller_ toolbarView];
202 NSView* infobar = [controller_ infoBarContainerView]; 259 NSView* infobar = [controller_ infoBarContainerView];
203 NSView* extensionShelf = [controller_ extensionShelfView]; 260 NSView* extensionShelf = [controller_ extensionShelfView];
204 261
205 // We need to muck with the views a bit to put us in a consistent state before 262 // We need to muck with the views a bit to put us in a consistent state before
206 // we start resizing. In particular, we need to move the tab strip to be 263 // we start resizing. In particular, we need to move the tab strip to be
207 // immediately above the content area, since we layout views to be directly 264 // immediately above the content area, since we layout views to be directly
208 // under the tab strip. We also explicitly set the contentView's frame to be 265 // under the tab strip.
209 // 800x600.
210 [contentView setFrame:NSMakeRect(0, 0, 800, 600)];
211 NSRect tabstripFrame = [tabstrip frame]; 266 NSRect tabstripFrame = [tabstrip frame];
212 tabstripFrame.origin.y = NSMaxY([contentView frame]); 267 tabstripFrame.origin.y = NSMaxY([contentView frame]);
213 [tabstrip setFrame:tabstripFrame]; 268 [tabstrip setFrame:tabstripFrame];
214 269
215 // The download shelf is created lazily. Force-create it and set its initial 270 // The download shelf is created lazily. Force-create it and set its initial
216 // height to 0. 271 // height to 0.
217 NSView* download = [[controller_ downloadShelf] view]; 272 NSView* download = [[controller_ downloadShelf] view];
218 [controller_ resizeView:download newHeight:0]; 273 NSRect downloadFrame = [download frame];
274 downloadFrame.size.height = 0;
275 [download setFrame:downloadFrame];
219 276
220 // Force a layout and check each view's frame. 277 // Force a layout and check each view's frame.
221 [controller_ layoutSubviews]; 278 [controller_ layoutSubviews];
222 CheckViewPositions(controller_); 279 CheckViewPositions(controller_);
223 280
224 // Add an extension shelf and recheck. 281 // Add an extension shelf and recheck.
225 [controller_ resizeView:extensionShelf newHeight:40]; 282 [controller_ resizeView:extensionShelf newHeight:40];
226 CheckViewPositions(controller_); 283 CheckViewPositions(controller_);
227 284
228 // Expand the infobar to 60px and recheck 285 // Expand the infobar to 60px and recheck
(...skipping 23 matching lines...) Expand all
252 TabStripView* tabstrip = [controller_ tabStripView]; 309 TabStripView* tabstrip = [controller_ tabStripView];
253 NSView* contentView = [[tabstrip window] contentView]; 310 NSView* contentView = [[tabstrip window] contentView];
254 NSView* toolbar = [controller_ toolbarView]; 311 NSView* toolbar = [controller_ toolbarView];
255 NSView* bookmark = [controller_ bookmarkView]; 312 NSView* bookmark = [controller_ bookmarkView];
256 NSView* infobar = [controller_ infoBarContainerView]; 313 NSView* infobar = [controller_ infoBarContainerView];
257 NSView* extensionShelf = [controller_ extensionShelfView]; 314 NSView* extensionShelf = [controller_ extensionShelfView];
258 315
259 // We need to muck with the views a bit to put us in a consistent state before 316 // We need to muck with the views a bit to put us in a consistent state before
260 // we start resizing. In particular, we need to move the tab strip to be 317 // we start resizing. In particular, we need to move the tab strip to be
261 // immediately above the content area, since we layout views to be directly 318 // immediately above the content area, since we layout views to be directly
262 // under the tab strip. We also explicitly set the contentView's frame to be 319 // under the tab strip.
263 // 800x600.
264 [contentView setFrame:NSMakeRect(0, 0, 800, 600)];
265 NSRect tabstripFrame = [tabstrip frame]; 320 NSRect tabstripFrame = [tabstrip frame];
266 tabstripFrame.origin.y = NSMaxY([contentView frame]); 321 tabstripFrame.origin.y = NSMaxY([contentView frame]);
267 [tabstrip setFrame:tabstripFrame]; 322 [tabstrip setFrame:tabstripFrame];
268 323
269 // The download shelf is created lazily. Force-create it and set its initial 324 // The download shelf is created lazily. Force-create it and set its initial
270 // height to 0. 325 // height to 0.
271 NSView* download = [[controller_ downloadShelf] view]; 326 NSView* download = [[controller_ downloadShelf] view];
272 [controller_ resizeView:download newHeight:0]; 327 NSRect downloadFrame = [download frame];
328 downloadFrame.size.height = 0;
329 [download setFrame:downloadFrame];
273 330
274 // Force a layout and check each view's frame. 331 // Force a layout and check each view's frame.
275 [controller_ layoutSubviews]; 332 [controller_ layoutSubviews];
276 CheckViewPositions(controller_); 333 CheckViewPositions(controller_);
277 334
278 // Add the bookmark bar and recheck. 335 // Add the bookmark bar and recheck.
279 [controller_ resizeView:bookmark newHeight:40]; 336 [controller_ resizeView:bookmark newHeight:40];
280 CheckViewPositions(controller_); 337 CheckViewPositions(controller_);
281 338
282 // Add an extension shelf and recheck. 339 // Add an extension shelf and recheck.
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 fullscreenWindow_.reset( 638 fullscreenWindow_.reset(
582 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) 639 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400)
583 styleMask:NSBorderlessWindowMask 640 styleMask:NSBorderlessWindowMask
584 backing:NSBackingStoreBuffered 641 backing:NSBackingStoreBuffered
585 defer:NO]); 642 defer:NO]);
586 return fullscreenWindow_.get(); 643 return fullscreenWindow_.get();
587 } 644 }
588 @end 645 @end
589 646
590 /* TODO(???): test other methods of BrowserWindowController */ 647 /* TODO(???): test other methods of BrowserWindowController */
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/browser_window_controller.mm ('k') | chrome/browser/cocoa/toolbar_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698