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