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 // Returns the frame of the view in window coordinates. |
| 18 NSRect FrameInWindow(NSView* view) { |
| 19 return [view convertRect:[view bounds] toView:nil]; |
| 20 } |
| 21 |
| 22 // Returns the min Y of the view in window coordinates. |
| 23 CGFloat MinYInWindow(NSView* view) { |
| 24 return NSMinY(FrameInWindow(view)); |
| 25 } |
| 26 |
| 27 // Returns the max Y of the view in window coordinates. |
| 28 CGFloat MaxYInWindow(NSView* view) { |
| 29 return NSMaxY(FrameInWindow(view)); |
| 30 } |
| 31 |
| 32 // Returns the view positioned highest in the toolbar area. |
| 33 NSView* HighestViewInToolbarArea(BrowserWindowController* controller) { |
| 34 return [controller tabStripView]; |
| 35 } |
| 36 |
| 37 // Returns the view positioned lowest in the toolbar area. |
| 38 NSView* LowestViewInToolbarArea(BrowserWindowController* controller) { |
| 39 return [[controller bookmarkBarController] view]; |
| 40 } |
| 41 |
| 42 // Check the layout of the views in the toolbar area when none of them overlap. |
| 43 void CheckToolbarLayoutNoOverlap(BrowserWindowController* controller) { |
| 44 EXPECT_EQ(MinYInWindow([controller tabStripView]), |
| 45 MaxYInWindow([[controller toolbarController] view])); |
| 46 EXPECT_EQ(MinYInWindow([[controller toolbarController] view]), |
| 47 MaxYInWindow([[controller bookmarkBarController] view])); |
| 48 } |
| 49 |
| 50 // Check the layout of all of the views when none of them overlap. |
| 51 void CheckLayoutNoOverlap(BrowserWindowController* controller) { |
| 52 CheckToolbarLayoutNoOverlap(controller); |
| 53 EXPECT_EQ(MinYInWindow([[controller bookmarkBarController] view]), |
| 54 MaxYInWindow([[controller infoBarContainerController] view])); |
| 55 EXPECT_EQ(MinYInWindow([[controller infoBarContainerController] view]), |
| 56 MaxYInWindow([controller tabContentArea])); |
| 57 } |
| 58 |
| 59 } // namespace |
| 60 |
| 61 // -------------------MockPresentationModeController---------------------------- |
| 62 // Mock of PresentationModeController that eliminates dependencies on AppKit. |
| 63 @interface MockPresentationModeController : PresentationModeController |
| 64 @end |
| 65 |
| 66 @implementation MockPresentationModeController |
| 67 |
| 68 - (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode { |
| 69 } |
| 70 |
| 71 - (CGFloat)floatingBarVerticalOffset { |
| 72 return kMenuBarHeight; |
| 73 } |
| 74 |
| 75 @end |
| 76 |
| 77 // -------------------MockBrowserWindowController------------------------------- |
| 78 // Mock of BrowserWindowController that eliminates dependencies on AppKit. |
| 79 @interface MockBrowserWindowController : BrowserWindowController { |
| 80 @public |
| 81 MockPresentationModeController* presentationController_; |
| 82 BOOL isInAppKitFullscreen_; |
| 83 } |
| 84 @end |
| 85 |
| 86 @implementation MockBrowserWindowController |
| 87 |
| 88 // Use the mock presentation controller. |
| 89 // Superclass override. |
| 90 - (PresentationModeController*)newPresentationModeControllerWithStyle: |
| 91 (fullscreen_mac::SlidingStyle)style { |
| 92 presentationController_ = |
| 93 [[MockPresentationModeController alloc] initWithBrowserController:self |
| 94 style:style]; |
| 95 return presentationController_; |
| 96 } |
| 97 |
| 98 // Manually control whether the floating bar (omnibox, tabstrip, etc.) has |
| 99 // focus. |
| 100 // Superclass override. |
| 101 - (BOOL)floatingBarHasFocus { |
| 102 return NO; |
| 103 } |
| 104 |
| 105 // Superclass override. |
| 106 - (BOOL)isInAppKitFullscreen { |
| 107 return isInAppKitFullscreen_; |
| 108 } |
| 109 |
| 110 // Superclass override. |
| 111 - (BOOL)placeBookmarkBarBelowInfoBar { |
| 112 return NO; |
| 113 } |
| 114 @end |
| 115 |
| 116 // -------------------PresentationModeControllerTest---------------------------- |
| 117 class PresentationModeControllerTest : public CocoaProfileTest { |
| 118 public: |
| 119 virtual void SetUp() OVERRIDE { |
| 120 CocoaProfileTest::SetUp(); |
| 121 ASSERT_TRUE(browser()); |
| 122 |
| 123 controller_ = [[MockBrowserWindowController alloc] initWithBrowser:browser() |
| 124 takeOwnership:NO]; |
| 125 [[controller_ bookmarkBarController] |
| 126 updateState:BookmarkBar::SHOW |
| 127 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; |
| 128 } |
| 129 |
| 130 virtual void TearDown() OVERRIDE { |
| 131 [controller_ close]; |
| 132 CocoaProfileTest::TearDown(); |
| 133 } |
| 134 |
| 135 public: |
| 136 MockBrowserWindowController* controller_; |
| 137 }; |
| 138 |
| 139 // Tests the layout of views in Canonical Fullscreen (emulating AppKit |
| 140 // Fullscreen API). |
| 141 TEST_F(PresentationModeControllerTest, CanonicalFullscreenAppKitLayout) { |
| 142 // Check initial layout. |
| 143 CGFloat windowHeight = NSHeight([[controller_ window] frame]); |
| 144 EXPECT_EQ(windowHeight, MaxYInWindow([controller_ tabStripView])); |
| 145 CheckLayoutNoOverlap(controller_); |
| 146 |
| 147 // No change after adjusting UI for Canonical Fullscreen. |
| 148 controller_->isInAppKitFullscreen_ = YES; |
| 149 [controller_ |
| 150 adjustUIForSlidingFullscreenStyle:fullscreen_mac::OMNIBOX_TABS_PRESENT]; |
| 151 EXPECT_EQ(windowHeight, MaxYInWindow([controller_ tabStripView])); |
| 152 CheckLayoutNoOverlap(controller_); |
| 153 |
| 154 // The menu bar is starting to animate in. All views should slide down by a |
| 155 // small amount. |
| 156 [controller_->presentationController_ setMenuBarRevealProgress:0.3]; |
| 157 EXPECT_LT(MaxYInWindow([controller_ tabStripView]), windowHeight - 1); |
| 158 EXPECT_GT(MaxYInWindow([controller_ tabStripView]), |
| 159 windowHeight - kMenuBarHeight + 1); |
| 160 CheckLayoutNoOverlap(controller_); |
| 161 |
| 162 // The menu bar is fully visible. All views should slide down by the size of |
| 163 // the menu bar. |
| 164 [controller_->presentationController_ setMenuBarRevealProgress:1]; |
| 165 EXPECT_FLOAT_EQ(windowHeight - kMenuBarHeight, |
| 166 MaxYInWindow([controller_ tabStripView])); |
| 167 CheckLayoutNoOverlap(controller_); |
| 168 |
| 169 // The menu bar has disappeared. All views should return to normal. |
| 170 [controller_->presentationController_ setMenuBarRevealProgress:0]; |
| 171 EXPECT_EQ(windowHeight, MaxYInWindow([controller_ tabStripView])); |
| 172 CheckLayoutNoOverlap(controller_); |
| 173 } |
| 174 |
| 175 // Tests the layout of views in Presentation Mode (emulating AppKit Fullscreen |
| 176 // API). |
| 177 TEST_F(PresentationModeControllerTest, PresentationModeAppKitLayout) { |
| 178 // Check initial layout. |
| 179 CGFloat windowHeight = NSHeight([[controller_ window] frame]); |
| 180 EXPECT_EQ(windowHeight, MaxYInWindow([controller_ tabStripView])); |
| 181 CheckLayoutNoOverlap(controller_); |
| 182 |
| 183 // Adjust UI for Presentation Mode. |
| 184 controller_->isInAppKitFullscreen_ = YES; |
| 185 [controller_ |
| 186 adjustUIForSlidingFullscreenStyle:fullscreen_mac::OMNIBOX_TABS_HIDDEN]; |
| 187 |
| 188 // In AppKit Fullscreen, the titlebar disappears. This test can't remove the |
| 189 // titlebar without non-trivially changing the view hierarchy. Instead, it |
| 190 // adjusts the expectations to sometimes use contentHeight instead of |
| 191 // windowHeight (the two should be the same in AppKit Fullscreen). |
| 192 CGFloat contentHeight = NSHeight([[[controller_ window] contentView] bounds]); |
| 193 CheckToolbarLayoutNoOverlap(controller_); |
| 194 EXPECT_EQ(windowHeight, MinYInWindow(LowestViewInToolbarArea(controller_))); |
| 195 EXPECT_EQ(contentHeight, MaxYInWindow([controller_ tabContentArea])); |
| 196 |
| 197 // The menu bar is starting to animate in. All views except the content view |
| 198 // should slide down by a small amount. |
| 199 [controller_->presentationController_ setMenuBarRevealProgress:0.3]; |
| 200 [controller_->presentationController_ changeToolbarFraction:0.3]; |
| 201 CheckToolbarLayoutNoOverlap(controller_); |
| 202 EXPECT_LT(MinYInWindow(LowestViewInToolbarArea(controller_)), contentHeight); |
| 203 EXPECT_GT(MaxYInWindow(HighestViewInToolbarArea(controller_)), contentHeight); |
| 204 EXPECT_EQ(contentHeight, MaxYInWindow([controller_ tabContentArea])); |
| 205 |
| 206 // The menu bar is fully visible. All views should slide down by the size of |
| 207 // the menu bar. |
| 208 [controller_->presentationController_ setMenuBarRevealProgress:1]; |
| 209 [controller_->presentationController_ changeToolbarFraction:1]; |
| 210 CheckToolbarLayoutNoOverlap(controller_); |
| 211 EXPECT_EQ(contentHeight, MaxYInWindow(HighestViewInToolbarArea(controller_))); |
| 212 EXPECT_EQ(contentHeight, MaxYInWindow([controller_ tabContentArea])); |
| 213 |
| 214 // The menu bar has disappeared. All views should return to normal. |
| 215 [controller_->presentationController_ setMenuBarRevealProgress:0]; |
| 216 [controller_->presentationController_ changeToolbarFraction:0]; |
| 217 CheckToolbarLayoutNoOverlap(controller_); |
| 218 EXPECT_EQ(windowHeight, MinYInWindow(LowestViewInToolbarArea(controller_))); |
| 219 EXPECT_EQ(contentHeight, MaxYInWindow([controller_ tabContentArea])); |
| 220 } |
OLD | NEW |