OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
6 | 6 |
7 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
8 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/signin/fake_signin_manager.h" | 14 #include "chrome/browser/signin/fake_signin_manager.h" |
15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
16 #include "chrome/browser/signin/signin_manager_factory.h" | 16 #include "chrome/browser/signin/signin_manager_factory.h" |
17 #include "chrome/browser/sync/profile_sync_service.h" | 17 #include "chrome/browser/sync/profile_sync_service.h" |
18 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
19 #include "chrome/browser/sync/profile_sync_service_mock.h" | 19 #include "chrome/browser/sync/profile_sync_service_mock.h" |
20 #include "chrome/browser/ui/browser_list.h" | 20 #include "chrome/browser/ui/browser_list.h" |
21 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
22 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 22 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
23 #import "chrome/browser/ui/cocoa/fast_resize_view.h" | |
Scott Hess - ex-Googler
2014/07/25 23:59:05
This seems unlikely, now that I look at it.
erikchen
2014/07/26 00:12:16
Won't compile without it. FastResizeView is forwar
Scott Hess - ex-Googler
2014/07/26 00:21:27
Weird. So I'm guessing what you mean is that [con
| |
23 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | 24 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
24 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 25 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
25 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 26 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
26 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 27 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
27 #include "chrome/browser/ui/host_desktop.h" | 28 #include "chrome/browser/ui/host_desktop.h" |
28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
29 #include "chrome/test/base/testing_profile.h" | 30 #include "chrome/test/base/testing_profile.h" |
30 #include "components/signin/core/browser/fake_auth_status_provider.h" | 31 #include "components/signin/core/browser/fake_auth_status_provider.h" |
31 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 32 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
32 #include "components/signin/core/browser/signin_error_controller.h" | 33 #include "components/signin/core/browser/signin_error_controller.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 [controller_ installIncognitoBadge]; | 236 [controller_ installIncognitoBadge]; |
236 NSRect newTabFrame = [[controller_ tabStripView] frame]; | 237 NSRect newTabFrame = [[controller_ tabStripView] frame]; |
237 EXPECT_GT(tabFrame.size.width, newTabFrame.size.width); | 238 EXPECT_GT(tabFrame.size.width, newTabFrame.size.width); |
238 | 239 |
239 controller_.release(); | 240 controller_.release(); |
240 } | 241 } |
241 #endif | 242 #endif |
242 | 243 |
243 namespace { | 244 namespace { |
244 | 245 |
246 // Returns the frame of the view in window coordinates. | |
247 NSRect FrameInWindowForView(NSView* view) { | |
248 return [[view superview] convertRect:[view frame] toView:nil]; | |
249 } | |
250 | |
251 // Whether the view's frame is within the bounds of the superview. | |
252 BOOL ViewContainmentValid(NSView* view) { | |
253 if (NSIsEmptyRect([view frame])) | |
254 return true; | |
255 | |
256 return NSContainsRect([[view superview] bounds], [view frame]); | |
257 } | |
258 | |
259 // Checks the view hierarchy rooted at |view| to ensure that each view is | |
260 // properly contained. | |
261 BOOL ViewHierarchyContainmentValid(NSView* view) { | |
262 // TODO(erikchen): Fix these views to have correct containment. | |
263 // http://crbug.com/397665. | |
264 if ([view isKindOfClass:NSClassFromString(@"DownloadShelfView")]) | |
265 return YES; | |
266 if ([view isKindOfClass:NSClassFromString(@"BookmarkBarToolbarView")]) | |
267 return YES; | |
268 if ([view isKindOfClass:NSClassFromString(@"BrowserActionsContainerView")]) | |
269 return YES; | |
270 | |
271 if (!ViewContainmentValid(view)) { | |
272 LOG(ERROR) << "View violates containment: " << | |
273 [[view description] UTF8String]; | |
274 return false; | |
275 } | |
276 | |
277 for (NSView* subview in [view subviews]) { | |
278 BOOL result = ViewHierarchyContainmentValid(subview); | |
279 if (!result) | |
280 return false; | |
281 } | |
282 | |
283 return true; | |
284 } | |
285 | |
245 // Verifies that the toolbar, infobar, tab content area, and download shelf | 286 // Verifies that the toolbar, infobar, tab content area, and download shelf |
246 // completely fill the area under the tabstrip. | 287 // completely fill the area under the tabstrip. |
247 void CheckViewPositions(BrowserWindowController* controller) { | 288 void CheckViewPositions(BrowserWindowController* controller) { |
248 NSRect contentView = [[[controller window] contentView] bounds]; | 289 EXPECT_TRUE(ViewHierarchyContainmentValid([[controller window] contentView])); |
249 NSRect tabstrip = [[controller tabStripView] frame]; | |
250 NSRect toolbar = [[controller toolbarView] frame]; | |
251 NSRect infobar = [[controller infoBarContainerView] frame]; | |
252 NSRect contentArea = [[controller tabContentArea] frame]; | |
253 NSRect download = [[[controller downloadShelf] view] frame]; | |
254 | 290 |
291 NSRect contentView = FrameInWindowForView([[controller window] contentView]); | |
292 NSRect tabstrip = FrameInWindowForView([controller tabStripView]); | |
293 NSRect toolbar = FrameInWindowForView([controller toolbarView]); | |
294 NSRect infobar = FrameInWindowForView([controller infoBarContainerView]); | |
295 NSRect tabContent = FrameInWindowForView([controller tabContentArea]); | |
296 NSRect download = FrameInWindowForView([[controller downloadShelf] view]); | |
297 | |
298 // The height of the contentView varies between full height of the window | |
299 // (OSX 10.10+) and full height minus 22 points. Don't make any checks | |
300 // against NSMaxY of contentView. | |
Scott Hess - ex-Googler
2014/07/25 23:59:05
I don't think this comment helps, since this code
erikchen
2014/07/26 00:12:16
Removed the comment.
| |
255 EXPECT_EQ(NSMinY(contentView), NSMinY(download)); | 301 EXPECT_EQ(NSMinY(contentView), NSMinY(download)); |
256 EXPECT_EQ(NSMaxY(download), NSMinY(contentArea)); | 302 EXPECT_EQ(NSMaxY(download), NSMinY(tabContent)); |
257 EXPECT_EQ(NSMaxY(contentArea), NSMinY(infobar)); | 303 EXPECT_EQ(NSMaxY(tabContent), NSMinY(infobar)); |
304 | |
305 // Toolbar should start immediately under the tabstrip, but the tabstrip is | |
306 // not necessarily fixed with respect to the content view. | |
307 EXPECT_EQ(NSMaxY(toolbar), NSMinY(tabstrip)); | |
258 | 308 |
259 // Bookmark bar frame is random memory when hidden. | 309 // Bookmark bar frame is random memory when hidden. |
260 if ([controller bookmarkBarVisible]) { | 310 if ([controller bookmarkBarVisible]) { |
261 NSRect bookmark = [[controller bookmarkView] frame]; | 311 NSRect bookmark = [[controller bookmarkView] frame]; |
262 EXPECT_EQ(NSMaxY(infobar), NSMinY(bookmark)); | 312 EXPECT_EQ(NSMaxY(infobar), NSMinY(bookmark)); |
263 EXPECT_EQ(NSMaxY(bookmark), NSMinY(toolbar)); | 313 EXPECT_EQ(NSMaxY(bookmark), NSMinY(toolbar)); |
264 EXPECT_FALSE([[controller bookmarkView] isHidden]); | 314 EXPECT_FALSE([[controller bookmarkView] isHidden]); |
265 } else { | 315 } else { |
266 EXPECT_EQ(NSMaxY(infobar), NSMinY(toolbar)); | 316 EXPECT_EQ(NSMaxY(infobar), NSMinY(toolbar)); |
267 EXPECT_TRUE([[controller bookmarkView] isHidden]); | 317 EXPECT_TRUE([[controller bookmarkView] isHidden]); |
268 } | 318 } |
269 | |
270 // Toolbar should start immediately under the tabstrip, but the tabstrip is | |
271 // not necessarily fixed with respect to the content view. | |
272 EXPECT_EQ(NSMinY(tabstrip), NSMaxY(toolbar)); | |
273 } | 319 } |
274 | 320 |
275 } // end namespace | 321 } // end namespace |
276 | 322 |
277 TEST_F(BrowserWindowControllerTest, TestAdjustWindowHeight) { | 323 TEST_F(BrowserWindowControllerTest, TestAdjustWindowHeight) { |
278 NSWindow* window = [controller_ window]; | 324 NSWindow* window = [controller_ window]; |
279 NSRect workarea = [[window screen] visibleFrame]; | 325 NSRect workarea = [[window screen] visibleFrame]; |
280 | 326 |
281 // Place the window well above the bottom of the screen and try to adjust its | 327 // Place the window well above the bottom of the screen and try to adjust its |
282 // height. It should change appropriately (and only downwards). Then get it to | 328 // height. It should change appropriately (and only downwards). Then get it to |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
881 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) | 927 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) |
882 styleMask:NSBorderlessWindowMask | 928 styleMask:NSBorderlessWindowMask |
883 backing:NSBackingStoreBuffered | 929 backing:NSBackingStoreBuffered |
884 defer:NO]); | 930 defer:NO]); |
885 [[testFullscreenWindow_ contentView] cr_setWantsLayer:YES]; | 931 [[testFullscreenWindow_ contentView] cr_setWantsLayer:YES]; |
886 return testFullscreenWindow_.get(); | 932 return testFullscreenWindow_.get(); |
887 } | 933 } |
888 @end | 934 @end |
889 | 935 |
890 /* TODO(???): test other methods of BrowserWindowController */ | 936 /* TODO(???): test other methods of BrowserWindowController */ |
OLD | NEW |