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" |
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]; | 290 |
250 NSRect toolbar = [[controller toolbarView] frame]; | 291 NSRect contentView = FrameInWindowForView([[controller window] contentView]); |
251 NSRect infobar = [[controller infoBarContainerView] frame]; | 292 NSRect tabstrip = FrameInWindowForView([controller tabStripView]); |
252 NSRect contentArea = [[controller tabContentArea] frame]; | 293 NSRect toolbar = FrameInWindowForView([controller toolbarView]); |
253 NSRect download = [[[controller downloadShelf] view] frame]; | 294 NSRect infobar = FrameInWindowForView([controller infoBarContainerView]); |
| 295 NSRect tabContent = FrameInWindowForView([controller tabContentArea]); |
| 296 NSRect download = FrameInWindowForView([[controller downloadShelf] view]); |
254 | 297 |
255 EXPECT_EQ(NSMinY(contentView), NSMinY(download)); | 298 EXPECT_EQ(NSMinY(contentView), NSMinY(download)); |
256 EXPECT_EQ(NSMaxY(download), NSMinY(contentArea)); | 299 EXPECT_EQ(NSMaxY(download), NSMinY(tabContent)); |
257 EXPECT_EQ(NSMaxY(contentArea), NSMinY(infobar)); | 300 EXPECT_EQ(NSMaxY(tabContent), NSMinY(infobar)); |
258 | 301 |
259 // Bookmark bar frame is random memory when hidden. | 302 // Bookmark bar frame is random memory when hidden. |
260 if ([controller bookmarkBarVisible]) { | 303 if ([controller bookmarkBarVisible]) { |
261 NSRect bookmark = [[controller bookmarkView] frame]; | 304 NSRect bookmark = [[controller bookmarkView] frame]; |
262 EXPECT_EQ(NSMaxY(infobar), NSMinY(bookmark)); | 305 EXPECT_EQ(NSMaxY(infobar), NSMinY(bookmark)); |
263 EXPECT_EQ(NSMaxY(bookmark), NSMinY(toolbar)); | 306 EXPECT_EQ(NSMaxY(bookmark), NSMinY(toolbar)); |
264 EXPECT_FALSE([[controller bookmarkView] isHidden]); | 307 EXPECT_FALSE([[controller bookmarkView] isHidden]); |
265 } else { | 308 } else { |
266 EXPECT_EQ(NSMaxY(infobar), NSMinY(toolbar)); | 309 EXPECT_EQ(NSMaxY(infobar), NSMinY(toolbar)); |
267 EXPECT_TRUE([[controller bookmarkView] isHidden]); | 310 EXPECT_TRUE([[controller bookmarkView] isHidden]); |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) | 924 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) |
882 styleMask:NSBorderlessWindowMask | 925 styleMask:NSBorderlessWindowMask |
883 backing:NSBackingStoreBuffered | 926 backing:NSBackingStoreBuffered |
884 defer:NO]); | 927 defer:NO]); |
885 [[testFullscreenWindow_ contentView] cr_setWantsLayer:YES]; | 928 [[testFullscreenWindow_ contentView] cr_setWantsLayer:YES]; |
886 return testFullscreenWindow_.get(); | 929 return testFullscreenWindow_.get(); |
887 } | 930 } |
888 @end | 931 @end |
889 | 932 |
890 /* TODO(???): test other methods of BrowserWindowController */ | 933 /* TODO(???): test other methods of BrowserWindowController */ |
OLD | NEW |