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 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 25 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
25 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 26 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
26 #include "chrome/browser/ui/host_desktop.h" | 27 #include "chrome/browser/ui/host_desktop.h" |
27 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
28 #include "chrome/grit/chromium_strings.h" | 29 #include "chrome/grit/chromium_strings.h" |
29 #include "chrome/grit/generated_resources.h" | 30 #include "chrome/grit/generated_resources.h" |
30 #include "chrome/test/base/testing_profile.h" | 31 #include "chrome/test/base/testing_profile.h" |
31 #include "components/signin/core/browser/fake_auth_status_provider.h" | 32 #include "components/signin/core/browser/fake_auth_status_provider.h" |
32 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 33 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 [controller_ installIncognitoBadge]; | 235 [controller_ installIncognitoBadge]; |
235 NSRect newTabFrame = [[controller_ tabStripView] frame]; | 236 NSRect newTabFrame = [[controller_ tabStripView] frame]; |
236 EXPECT_GT(tabFrame.size.width, newTabFrame.size.width); | 237 EXPECT_GT(tabFrame.size.width, newTabFrame.size.width); |
237 | 238 |
238 controller_.release(); | 239 controller_.release(); |
239 } | 240 } |
240 #endif | 241 #endif |
241 | 242 |
242 namespace { | 243 namespace { |
243 | 244 |
| 245 // Returns the frame of the view in window coordinates. |
| 246 NSRect FrameInWindowForView(NSView* view) { |
| 247 return [[view superview] convertRect:[view frame] toView:nil]; |
| 248 } |
| 249 |
| 250 // Whether the view's frame is within the bounds of the superview. |
| 251 BOOL ViewContainmentValid(NSView* view) { |
| 252 if (NSIsEmptyRect([view frame])) |
| 253 return YES; |
| 254 |
| 255 return NSContainsRect([[view superview] bounds], [view frame]); |
| 256 } |
| 257 |
| 258 // Checks the view hierarchy rooted at |view| to ensure that each view is |
| 259 // properly contained. |
| 260 BOOL ViewHierarchyContainmentValid(NSView* view) { |
| 261 // TODO(erikchen): Fix these views to have correct containment. |
| 262 // http://crbug.com/397665. |
| 263 if ([view isKindOfClass:NSClassFromString(@"DownloadShelfView")]) |
| 264 return YES; |
| 265 if ([view isKindOfClass:NSClassFromString(@"BookmarkBarToolbarView")]) |
| 266 return YES; |
| 267 if ([view isKindOfClass:NSClassFromString(@"BrowserActionsContainerView")]) |
| 268 return YES; |
| 269 |
| 270 if (!ViewContainmentValid(view)) { |
| 271 LOG(ERROR) << "View violates containment: " << |
| 272 [[view description] UTF8String]; |
| 273 return NO; |
| 274 } |
| 275 |
| 276 for (NSView* subview in [view subviews]) { |
| 277 BOOL result = ViewHierarchyContainmentValid(subview); |
| 278 if (!result) |
| 279 return NO; |
| 280 } |
| 281 |
| 282 return YES; |
| 283 } |
| 284 |
244 // Verifies that the toolbar, infobar, tab content area, and download shelf | 285 // Verifies that the toolbar, infobar, tab content area, and download shelf |
245 // completely fill the area under the tabstrip. | 286 // completely fill the area under the tabstrip. |
246 void CheckViewPositions(BrowserWindowController* controller) { | 287 void CheckViewPositions(BrowserWindowController* controller) { |
247 NSRect contentView = [[[controller window] contentView] bounds]; | 288 EXPECT_TRUE(ViewHierarchyContainmentValid([[controller window] contentView])); |
248 NSRect tabstrip = [[controller tabStripView] frame]; | 289 |
249 NSRect toolbar = [[controller toolbarView] frame]; | 290 NSRect contentView = FrameInWindowForView([[controller window] contentView]); |
250 NSRect infobar = [[controller infoBarContainerView] frame]; | 291 NSRect tabstrip = FrameInWindowForView([controller tabStripView]); |
251 NSRect contentArea = [[controller tabContentArea] frame]; | 292 NSRect toolbar = FrameInWindowForView([controller toolbarView]); |
| 293 NSRect infobar = FrameInWindowForView([controller infoBarContainerView]); |
| 294 NSRect tabContent = FrameInWindowForView([controller tabContentArea]); |
252 NSRect download = NSZeroRect; | 295 NSRect download = NSZeroRect; |
253 if ([[[controller downloadShelf] view] superview]) | 296 if ([[[controller downloadShelf] view] superview]) |
254 download = [[[controller downloadShelf] view] frame]; | 297 download = [[[controller downloadShelf] view] frame]; |
255 | 298 |
256 EXPECT_EQ(NSMinY(contentView), NSMinY(download)); | 299 EXPECT_EQ(NSMinY(contentView), NSMinY(download)); |
257 EXPECT_EQ(NSMaxY(download), NSMinY(contentArea)); | 300 EXPECT_EQ(NSMaxY(download), NSMinY(tabContent)); |
258 EXPECT_EQ(NSMaxY(contentArea), NSMinY(infobar)); | 301 EXPECT_EQ(NSMaxY(tabContent), NSMinY(infobar)); |
259 | 302 |
260 // Bookmark bar frame is random memory when hidden. | 303 // Bookmark bar frame is random memory when hidden. |
261 if ([controller bookmarkBarVisible]) { | 304 if ([controller bookmarkBarVisible]) { |
262 NSRect bookmark = [[controller bookmarkView] frame]; | 305 NSRect bookmark = [[controller bookmarkView] frame]; |
263 EXPECT_EQ(NSMaxY(infobar), NSMinY(bookmark)); | 306 EXPECT_EQ(NSMaxY(infobar), NSMinY(bookmark)); |
264 EXPECT_EQ(NSMaxY(bookmark), NSMinY(toolbar)); | 307 EXPECT_EQ(NSMaxY(bookmark), NSMinY(toolbar)); |
265 EXPECT_FALSE([[controller bookmarkView] isHidden]); | 308 EXPECT_FALSE([[controller bookmarkView] isHidden]); |
266 } else { | 309 } else { |
267 EXPECT_EQ(NSMaxY(infobar), NSMinY(toolbar)); | 310 EXPECT_EQ(NSMaxY(infobar), NSMinY(toolbar)); |
268 EXPECT_TRUE([[controller bookmarkView] isHidden]); | 311 EXPECT_TRUE([[controller bookmarkView] isHidden]); |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 EXPECT_EQ(screenFrame.size.height, zoomFrame.size.height); | 656 EXPECT_EQ(screenFrame.size.height, zoomFrame.size.height); |
614 EXPECT_EQ(testFrame.origin.x, zoomFrame.origin.x); | 657 EXPECT_EQ(testFrame.origin.x, zoomFrame.origin.x); |
615 EXPECT_EQ(screenFrame.origin.y, zoomFrame.origin.y); | 658 EXPECT_EQ(screenFrame.origin.y, zoomFrame.origin.y); |
616 } | 659 } |
617 | 660 |
618 TEST_F(BrowserWindowControllerTest, TestFindBarOnTop) { | 661 TEST_F(BrowserWindowControllerTest, TestFindBarOnTop) { |
619 FindBarBridge bridge(NULL); | 662 FindBarBridge bridge(NULL); |
620 [controller_ addFindBar:bridge.find_bar_cocoa_controller()]; | 663 [controller_ addFindBar:bridge.find_bar_cocoa_controller()]; |
621 | 664 |
622 // Test that the Z-order of the find bar is on top of everything. | 665 // Test that the Z-order of the find bar is on top of everything. |
623 NSArray* subviews = [[[controller_ window] contentView] subviews]; | 666 NSArray* subviews = [controller_.chromeContentView subviews]; |
624 NSUInteger findBar_index = | 667 NSUInteger findBar_index = |
625 [subviews indexOfObject:[controller_ findBarView]]; | 668 [subviews indexOfObject:[controller_ findBarView]]; |
626 EXPECT_NE(NSNotFound, findBar_index); | 669 EXPECT_NE(NSNotFound, findBar_index); |
627 NSUInteger toolbar_index = | 670 NSUInteger toolbar_index = |
628 [subviews indexOfObject:[controller_ toolbarView]]; | 671 [subviews indexOfObject:[controller_ toolbarView]]; |
629 EXPECT_NE(NSNotFound, toolbar_index); | 672 EXPECT_NE(NSNotFound, toolbar_index); |
630 NSUInteger bookmark_index = | 673 NSUInteger bookmark_index = |
631 [subviews indexOfObject:[controller_ bookmarkView]]; | 674 [subviews indexOfObject:[controller_ bookmarkView]]; |
632 EXPECT_NE(NSNotFound, bookmark_index); | 675 EXPECT_NE(NSNotFound, bookmark_index); |
633 | 676 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 // looks at the window's frame. | 924 // looks at the window's frame. |
882 - (NSWindow*)createFullscreenWindow { | 925 - (NSWindow*)createFullscreenWindow { |
883 if (testFullscreenWindow_.get()) | 926 if (testFullscreenWindow_.get()) |
884 return testFullscreenWindow_.get(); | 927 return testFullscreenWindow_.get(); |
885 | 928 |
886 testFullscreenWindow_.reset( | 929 testFullscreenWindow_.reset( |
887 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) | 930 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) |
888 styleMask:NSBorderlessWindowMask | 931 styleMask:NSBorderlessWindowMask |
889 backing:NSBackingStoreBuffered | 932 backing:NSBackingStoreBuffered |
890 defer:NO]); | 933 defer:NO]); |
| 934 [[testFullscreenWindow_ contentView] setWantsLayer:YES]; |
891 return testFullscreenWindow_.get(); | 935 return testFullscreenWindow_.get(); |
892 } | 936 } |
893 @end | 937 @end |
894 | 938 |
895 /* TODO(???): test other methods of BrowserWindowController */ | 939 /* TODO(???): test other methods of BrowserWindowController */ |
OLD | NEW |