| 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" | |
| 24 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | 23 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
| 25 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 24 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
| 26 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 25 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
| 27 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 26 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 28 #include "chrome/browser/ui/host_desktop.h" | 27 #include "chrome/browser/ui/host_desktop.h" |
| 29 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/test/base/testing_profile.h" | 29 #include "chrome/test/base/testing_profile.h" |
| 31 #include "components/signin/core/browser/fake_auth_status_provider.h" | 30 #include "components/signin/core/browser/fake_auth_status_provider.h" |
| 32 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 31 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 33 #include "components/signin/core/browser/signin_error_controller.h" | 32 #include "components/signin/core/browser/signin_error_controller.h" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 [controller_ installIncognitoBadge]; | 235 [controller_ installIncognitoBadge]; |
| 237 NSRect newTabFrame = [[controller_ tabStripView] frame]; | 236 NSRect newTabFrame = [[controller_ tabStripView] frame]; |
| 238 EXPECT_GT(tabFrame.size.width, newTabFrame.size.width); | 237 EXPECT_GT(tabFrame.size.width, newTabFrame.size.width); |
| 239 | 238 |
| 240 controller_.release(); | 239 controller_.release(); |
| 241 } | 240 } |
| 242 #endif | 241 #endif |
| 243 | 242 |
| 244 namespace { | 243 namespace { |
| 245 | 244 |
| 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 | |
| 286 // Verifies that the toolbar, infobar, tab content area, and download shelf | 245 // Verifies that the toolbar, infobar, tab content area, and download shelf |
| 287 // completely fill the area under the tabstrip. | 246 // completely fill the area under the tabstrip. |
| 288 void CheckViewPositions(BrowserWindowController* controller) { | 247 void CheckViewPositions(BrowserWindowController* controller) { |
| 289 EXPECT_TRUE(ViewHierarchyContainmentValid([[controller window] contentView])); | 248 NSRect contentView = [[[controller window] contentView] bounds]; |
| 290 | 249 NSRect tabstrip = [[controller tabStripView] frame]; |
| 291 NSRect contentView = FrameInWindowForView([[controller window] contentView]); | 250 NSRect toolbar = [[controller toolbarView] frame]; |
| 292 NSRect tabstrip = FrameInWindowForView([controller tabStripView]); | 251 NSRect infobar = [[controller infoBarContainerView] frame]; |
| 293 NSRect toolbar = FrameInWindowForView([controller toolbarView]); | 252 NSRect contentArea = [[controller tabContentArea] frame]; |
| 294 NSRect infobar = FrameInWindowForView([controller infoBarContainerView]); | 253 NSRect download = [[[controller downloadShelf] view] frame]; |
| 295 NSRect tabContent = FrameInWindowForView([controller tabContentArea]); | |
| 296 NSRect download = FrameInWindowForView([[controller downloadShelf] view]); | |
| 297 | 254 |
| 298 EXPECT_EQ(NSMinY(contentView), NSMinY(download)); | 255 EXPECT_EQ(NSMinY(contentView), NSMinY(download)); |
| 299 EXPECT_EQ(NSMaxY(download), NSMinY(tabContent)); | 256 EXPECT_EQ(NSMaxY(download), NSMinY(contentArea)); |
| 300 EXPECT_EQ(NSMaxY(tabContent), NSMinY(infobar)); | 257 EXPECT_EQ(NSMaxY(contentArea), NSMinY(infobar)); |
| 301 | 258 |
| 302 // Bookmark bar frame is random memory when hidden. | 259 // Bookmark bar frame is random memory when hidden. |
| 303 if ([controller bookmarkBarVisible]) { | 260 if ([controller bookmarkBarVisible]) { |
| 304 NSRect bookmark = [[controller bookmarkView] frame]; | 261 NSRect bookmark = [[controller bookmarkView] frame]; |
| 305 EXPECT_EQ(NSMaxY(infobar), NSMinY(bookmark)); | 262 EXPECT_EQ(NSMaxY(infobar), NSMinY(bookmark)); |
| 306 EXPECT_EQ(NSMaxY(bookmark), NSMinY(toolbar)); | 263 EXPECT_EQ(NSMaxY(bookmark), NSMinY(toolbar)); |
| 307 EXPECT_FALSE([[controller bookmarkView] isHidden]); | 264 EXPECT_FALSE([[controller bookmarkView] isHidden]); |
| 308 } else { | 265 } else { |
| 309 EXPECT_EQ(NSMaxY(infobar), NSMinY(toolbar)); | 266 EXPECT_EQ(NSMaxY(infobar), NSMinY(toolbar)); |
| 310 EXPECT_TRUE([[controller bookmarkView] isHidden]); | 267 EXPECT_TRUE([[controller bookmarkView] isHidden]); |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) | 881 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) |
| 925 styleMask:NSBorderlessWindowMask | 882 styleMask:NSBorderlessWindowMask |
| 926 backing:NSBackingStoreBuffered | 883 backing:NSBackingStoreBuffered |
| 927 defer:NO]); | 884 defer:NO]); |
| 928 [[testFullscreenWindow_ contentView] cr_setWantsLayer:YES]; | 885 [[testFullscreenWindow_ contentView] cr_setWantsLayer:YES]; |
| 929 return testFullscreenWindow_.get(); | 886 return testFullscreenWindow_.get(); |
| 930 } | 887 } |
| 931 @end | 888 @end |
| 932 | 889 |
| 933 /* TODO(???): test other methods of BrowserWindowController */ | 890 /* TODO(???): test other methods of BrowserWindowController */ |
| OLD | NEW |