Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | |
| 6 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" | |
| 7 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | |
| 8 #import "chrome/browser/ui/cocoa/fast_resize_view.h" | |
| 9 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" | |
| 10 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 // The height of the AppKit menu bar. | |
| 15 const CGFloat kMenuBarHeight = 22; | |
| 16 | |
| 17 } // namespace | |
| 18 | |
| 19 // -------------------BrowserWindowController (Testing)------------------------- | |
| 20 // Category methods that provide access to private ivars. | |
| 21 @interface BrowserWindowController (Testing) | |
| 22 | |
| 23 - (NSView*)infoBarContainerView; | |
| 24 - (NSView*)toolbarView; | |
| 25 - (NSView*)bookmarkView; | |
| 26 | |
| 27 @end | |
| 28 | |
| 29 @implementation BrowserWindowController (Testing) | |
| 30 | |
| 31 - (NSView*)infoBarContainerView { | |
| 32 return [infoBarContainerController_ view]; | |
| 33 } | |
| 34 | |
| 35 - (NSView*)toolbarView { | |
| 36 return [toolbarController_ view]; | |
| 37 } | |
| 38 | |
| 39 - (NSView*)bookmarkView { | |
| 40 return [bookmarkBarController_ view]; | |
|
Andre
2014/09/05 00:13:00
infoBarContainerController, toolbarController, and
erikchen
2014/09/05 17:57:49
These were copied from another test. I removed the
| |
| 41 } | |
| 42 | |
| 43 @end | |
| 44 | |
| 45 // -------------------PresentationModeController (Testing)---------------------- | |
| 46 // Category that provides access to private methods. | |
| 47 @interface PresentationModeController (Testing) | |
| 48 | |
| 49 - (void)changeToolbarFraction:(CGFloat)fraction; | |
| 50 | |
| 51 @end | |
| 52 | |
| 53 // -------------------MockPresentationModeController---------------------------- | |
| 54 // Mock of PresentationModeController that eliminates dependencies on AppKit. | |
| 55 @interface MockPresentationModeController : PresentationModeController | |
| 56 @end | |
| 57 | |
| 58 @implementation MockPresentationModeController | |
| 59 | |
| 60 - (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode { | |
| 61 } | |
| 62 - (CGFloat)floatingBarVerticalOffset { | |
| 63 return kMenuBarHeight; | |
| 64 } | |
| 65 | |
| 66 @end | |
| 67 | |
| 68 // -------------------MockBrowserWindowController------------------------------- | |
| 69 // Mock of BrowserWindowController that eliminates dependencies on AppKit. | |
| 70 @interface MockBrowserWindowController : BrowserWindowController { | |
| 71 @public | |
| 72 MockPresentationModeController* presentationController_; | |
| 73 BOOL isInAppKitFullscreen_; | |
| 74 } | |
| 75 @end | |
| 76 | |
| 77 @implementation MockBrowserWindowController | |
| 78 | |
| 79 // Use the mock presentation controller. | |
| 80 // Superclass override. | |
| 81 - (PresentationModeController*)newPresentationModeControllerWithStyle: | |
| 82 (fullscreen_mac::SlidingStyle)style { | |
| 83 presentationController_ = | |
| 84 [[MockPresentationModeController alloc] initWithBrowserController:self | |
| 85 style:style]; | |
| 86 return presentationController_; | |
| 87 } | |
| 88 | |
| 89 // Manually control whether the floating bar (omnibox, tabstrip, etc.) has | |
| 90 // focus. | |
| 91 // Superclass override. | |
| 92 - (BOOL)floatingBarHasFocus { | |
| 93 return NO; | |
| 94 } | |
| 95 | |
| 96 // Superclass override. | |
| 97 - (BOOL)isInAppKitFullscreen { | |
| 98 return isInAppKitFullscreen_; | |
| 99 } | |
| 100 | |
| 101 // Superclass override. | |
| 102 - (BOOL)placeBookmarkBarBelowInfoBar { | |
| 103 return NO; | |
| 104 } | |
| 105 @end | |
| 106 | |
| 107 // -------------------PresentationModeControllerTest---------------------------- | |
| 108 class PresentationModeControllerTest : public CocoaProfileTest { | |
| 109 public: | |
| 110 virtual void SetUp() { | |
| 111 CocoaProfileTest::SetUp(); | |
| 112 ASSERT_TRUE(browser()); | |
| 113 | |
| 114 controller_ = [[MockBrowserWindowController alloc] initWithBrowser:browser() | |
| 115 takeOwnership:NO]; | |
| 116 [[controller_ bookmarkBarController] | |
| 117 updateState:BookmarkBar::SHOW | |
| 118 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; | |
| 119 } | |
| 120 | |
| 121 virtual void TearDown() { | |
| 122 [controller_ close]; | |
| 123 CocoaProfileTest::TearDown(); | |
| 124 } | |
| 125 | |
| 126 public: | |
| 127 MockBrowserWindowController* controller_; | |
| 128 }; | |
| 129 | |
| 130 // Returns the frame of the view in window coordinates. | |
| 131 NSRect FrameInWindow(NSView* view) { | |
|
Andre
2014/09/05 00:13:01
Put helper functions in anonymous namespace.
erikchen
2014/09/05 17:57:49
Done.
| |
| 132 EXPECT_TRUE([view superview]); | |
| 133 NSView* root = [[[view window] contentView] superview]; | |
| 134 return [root convertRect:[view frame] fromView:[view superview]]; | |
|
Andre
2014/09/05 00:13:00
A simpler way to convert to window coordinates:
erikchen
2014/09/05 17:57:49
I used the latter.
| |
| 135 } | |
| 136 | |
| 137 // Returns the min Y of the view in window coordinates. | |
| 138 CGFloat MinYInWindow(NSView* view) { | |
| 139 return NSMinY(FrameInWindow(view)); | |
| 140 } | |
| 141 | |
| 142 // Returns the max Y of the view in window coordinates. | |
| 143 CGFloat MaxYInWindow(NSView* view) { | |
| 144 return NSMaxY(FrameInWindow(view)); | |
| 145 } | |
| 146 | |
| 147 // Returns the view positioned highest in the toolbar area. | |
| 148 NSView* HighestViewInToolbarArea(BrowserWindowController* controller) { | |
| 149 return [controller tabStripView]; | |
| 150 } | |
| 151 | |
| 152 // Returns the view positioned lowest in the toolbar area. | |
| 153 NSView* LowestViewInToolbarArea(BrowserWindowController* controller) { | |
| 154 return [controller bookmarkView]; | |
| 155 } | |
| 156 | |
| 157 // Check the layout of the views in the toolbar area when none of them overlap. | |
| 158 void CheckToolbarLayoutNoOverlap(BrowserWindowController* controller) { | |
| 159 EXPECT_EQ(MinYInWindow([controller tabStripView]), | |
| 160 MaxYInWindow([controller toolbarView])); | |
| 161 EXPECT_EQ(MinYInWindow([controller toolbarView]), | |
| 162 MaxYInWindow([controller bookmarkView])); | |
| 163 } | |
| 164 | |
| 165 // Check the layout of all of the views when none of them overlap. | |
| 166 void CheckLayoutNoOverlap(BrowserWindowController* controller) { | |
| 167 CheckToolbarLayoutNoOverlap(controller); | |
| 168 EXPECT_EQ(MinYInWindow([controller bookmarkView]), | |
| 169 MaxYInWindow([controller infoBarContainerView])); | |
| 170 EXPECT_EQ(MinYInWindow([controller infoBarContainerView]), | |
| 171 MaxYInWindow([controller tabContentArea])); | |
| 172 } | |
| 173 | |
| 174 // Tests the layout of views in Canonical Fullscreen (emulating AppKit | |
| 175 // Fullscreen API). | |
| 176 TEST_F(PresentationModeControllerTest, CanonicalFullscreenAppKitLayout) { | |
| 177 // Check initial layout. | |
| 178 CGFloat windowHeight = | |
| 179 NSHeight([[[[controller_ window] contentView] superview] bounds]); | |
|
Andre
2014/09/05 00:13:00
How about NSHeight([[controller_ window] frame])
erikchen
2014/09/05 17:57:49
Done. Also updated other test.
| |
| 180 EXPECT_EQ(windowHeight, MaxYInWindow([controller_ tabStripView])); | |
| 181 CheckLayoutNoOverlap(controller_); | |
| 182 | |
| 183 // No change after adjusting UI for Canonical Fullscreen. | |
| 184 controller_->isInAppKitFullscreen_ = YES; | |
| 185 [controller_ | |
| 186 adjustUIForSlidingFullscreenStyle:fullscreen_mac::OMNIBOX_TABS_PRESENT]; | |
| 187 EXPECT_EQ(windowHeight, MaxYInWindow([controller_ tabStripView])); | |
| 188 CheckLayoutNoOverlap(controller_); | |
| 189 | |
| 190 // The menu bar is starting to animate in. All views should slide down by a | |
| 191 // small amount. | |
| 192 [controller_->presentationController_ setMenuBarRevealProgress:0.3]; | |
| 193 EXPECT_LT(MaxYInWindow([controller_ tabStripView]), windowHeight - 1); | |
| 194 EXPECT_GT(MaxYInWindow([controller_ tabStripView]), | |
| 195 windowHeight - kMenuBarHeight + 1); | |
| 196 CheckLayoutNoOverlap(controller_); | |
| 197 | |
| 198 // The menu bar is fully visible. All views should slide down by the size of | |
| 199 // the menu bar. | |
| 200 [controller_->presentationController_ setMenuBarRevealProgress:1]; | |
| 201 EXPECT_FLOAT_EQ(windowHeight - kMenuBarHeight, | |
| 202 MaxYInWindow([controller_ tabStripView])); | |
| 203 CheckLayoutNoOverlap(controller_); | |
| 204 | |
| 205 // The menu bar has disappeared. All views should return to normal. | |
| 206 [controller_->presentationController_ setMenuBarRevealProgress:0]; | |
| 207 EXPECT_EQ(windowHeight, MaxYInWindow([controller_ tabStripView])); | |
| 208 CheckLayoutNoOverlap(controller_); | |
| 209 } | |
| 210 | |
| 211 // Tests the layout of views in Presentation Mode (emulating AppKit Fullscreen | |
| 212 // API). | |
| 213 TEST_F(PresentationModeControllerTest, PresentationModeAppKitLayout) { | |
| 214 // Check initial layout. | |
| 215 CGFloat windowHeight = | |
| 216 NSHeight([[[[controller_ window] contentView] superview] bounds]); | |
| 217 EXPECT_EQ(windowHeight, MaxYInWindow([controller_ tabStripView])); | |
| 218 CheckLayoutNoOverlap(controller_); | |
| 219 | |
| 220 // Adjust UI for Presentation Mode. | |
| 221 controller_->isInAppKitFullscreen_ = YES; | |
| 222 [controller_ | |
| 223 adjustUIForSlidingFullscreenStyle:fullscreen_mac::OMNIBOX_TABS_HIDDEN]; | |
| 224 | |
| 225 // In AppKit Fullscreen, the titlebar disappears. This test can't remove the | |
| 226 // titlebar without non-trivially changing the view hierarchy. Instead, it | |
| 227 // adjusts the expectations to sometimes use contentHeight instead of | |
| 228 // windowHeight (the two should be the same in AppKit Fullscreen). | |
| 229 CGFloat contentHeight = NSHeight([[[controller_ window] contentView] bounds]); | |
| 230 CheckToolbarLayoutNoOverlap(controller_); | |
| 231 EXPECT_EQ(windowHeight, MinYInWindow(LowestViewInToolbarArea(controller_))); | |
| 232 EXPECT_EQ(contentHeight, MaxYInWindow([controller_ tabContentArea])); | |
| 233 | |
| 234 // The menu bar is starting to animate in. All views except the content view | |
| 235 // should slide down by a small amount. | |
| 236 [controller_->presentationController_ setMenuBarRevealProgress:0.3]; | |
| 237 [controller_->presentationController_ changeToolbarFraction:0.3]; | |
| 238 CheckToolbarLayoutNoOverlap(controller_); | |
| 239 EXPECT_LT(MinYInWindow(LowestViewInToolbarArea(controller_)), contentHeight); | |
| 240 EXPECT_GT(MaxYInWindow(HighestViewInToolbarArea(controller_)), contentHeight); | |
| 241 EXPECT_EQ(contentHeight, MaxYInWindow([controller_ tabContentArea])); | |
| 242 | |
| 243 // The menu bar is fully visible. All views should slide down by the size of | |
| 244 // the menu bar. | |
| 245 [controller_->presentationController_ setMenuBarRevealProgress:1]; | |
| 246 [controller_->presentationController_ changeToolbarFraction:1]; | |
| 247 CheckToolbarLayoutNoOverlap(controller_); | |
| 248 EXPECT_EQ(contentHeight, MaxYInWindow(HighestViewInToolbarArea(controller_))); | |
| 249 EXPECT_EQ(contentHeight, MaxYInWindow([controller_ tabContentArea])); | |
| 250 | |
| 251 // The menu bar has disappeared. All views should return to normal. | |
| 252 [controller_->presentationController_ setMenuBarRevealProgress:0]; | |
| 253 [controller_->presentationController_ changeToolbarFraction:0]; | |
| 254 CheckToolbarLayoutNoOverlap(controller_); | |
| 255 EXPECT_EQ(windowHeight, MinYInWindow(LowestViewInToolbarArea(controller_))); | |
| 256 EXPECT_EQ(contentHeight, MaxYInWindow([controller_ tabContentArea])); | |
| 257 } | |
| OLD | NEW |