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) { | |
Scott Hess - ex-Googler
2014/07/25 22:26:53
What, not implementing this as a private category?
| |
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 contentArea = 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)); |
Scott Hess - ex-Googler
2014/07/25 22:26:53
Nobody ever checks:
EXPECT_EQ(NSMaxY(contentView
erikchen
2014/07/25 23:22:06
I added a comment. The height of the contentView v
| |
256 EXPECT_EQ(NSMaxY(download), NSMinY(contentArea)); | 299 EXPECT_EQ(NSMaxY(download), NSMinY(contentArea)); |
257 EXPECT_EQ(NSMaxY(contentArea), NSMinY(infobar)); | 300 EXPECT_EQ(NSMaxY(contentArea), NSMinY(infobar)); |
301 EXPECT_EQ(NSMaxY(toolbar), NSMinY(tabstrip)); | |
Scott Hess - ex-Googler
2014/07/25 22:26:53
Isn't this identical to the last line of the test?
erikchen
2014/07/25 23:22:06
yeah. I removed the last line, and moved the comme
Scott Hess - ex-Googler
2014/07/25 23:59:04
Hmm, I was more wondering why this was added here,
erikchen
2014/07/26 00:12:16
Moved it back down.
| |
258 | 302 |
259 // Bookmark bar frame is random memory when hidden. | 303 // Bookmark bar frame is random memory when hidden. |
260 if ([controller bookmarkBarVisible]) { | 304 if ([controller bookmarkBarVisible]) { |
261 NSRect bookmark = [[controller bookmarkView] frame]; | 305 NSRect bookmark = [[controller bookmarkView] frame]; |
262 EXPECT_EQ(NSMaxY(infobar), NSMinY(bookmark)); | 306 EXPECT_EQ(NSMaxY(infobar), NSMinY(bookmark)); |
263 EXPECT_EQ(NSMaxY(bookmark), NSMinY(toolbar)); | 307 EXPECT_EQ(NSMaxY(bookmark), NSMinY(toolbar)); |
264 EXPECT_FALSE([[controller bookmarkView] isHidden]); | 308 EXPECT_FALSE([[controller bookmarkView] isHidden]); |
265 } else { | 309 } else { |
266 EXPECT_EQ(NSMaxY(infobar), NSMinY(toolbar)); | 310 EXPECT_EQ(NSMaxY(infobar), NSMinY(toolbar)); |
267 EXPECT_TRUE([[controller bookmarkView] isHidden]); | 311 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) | 925 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) |
882 styleMask:NSBorderlessWindowMask | 926 styleMask:NSBorderlessWindowMask |
883 backing:NSBackingStoreBuffered | 927 backing:NSBackingStoreBuffered |
884 defer:NO]); | 928 defer:NO]); |
885 [[testFullscreenWindow_ contentView] cr_setWantsLayer:YES]; | 929 [[testFullscreenWindow_ contentView] cr_setWantsLayer:YES]; |
886 return testFullscreenWindow_.get(); | 930 return testFullscreenWindow_.get(); |
887 } | 931 } |
888 @end | 932 @end |
889 | 933 |
890 /* TODO(???): test other methods of BrowserWindowController */ | 934 /* TODO(???): test other methods of BrowserWindowController */ |
OLD | NEW |