Commit 52ec3e50 authored by erikchen's avatar erikchen Committed by Commit bot

mac: Add basic layout unit tests for AppKit Fullscreen.

Previous tests were flaky and keep getting disabled.

BUG=

Review URL: https://codereview.chromium.org/545643002

Cr-Commit-Position: refs/heads/master@{#293759}
parent 8949dcba
......@@ -159,6 +159,11 @@
// omnibox from sliding.
- (void)adjustUIForExitingFullscreenAndStopOmniboxSliding;
// Exposed for testing.
// Creates a PresentationModeController with the given style.
- (PresentationModeController*)newPresentationModeControllerWithStyle:
(fullscreen_mac::SlidingStyle)style;
// Toggles the AppKit Fullscreen API. By default, doing so enters Canonical
// Fullscreen.
- (void)enterAppKitFullscreen;
......
......@@ -295,9 +295,6 @@ willPositionSheet:(NSWindow*)sheet
return 0;
CGFloat totalHeight = 0;
if (presentationModeController_)
totalHeight = [presentationModeController_ floatingBarVerticalOffset];
if ([self hasTabStrip])
totalHeight += NSHeight([[self tabStripView] frame]);
......@@ -720,8 +717,7 @@ willPositionSheet:(NSWindow*)sheet
- (void)adjustUIForSlidingFullscreenStyle:(fullscreen_mac::SlidingStyle)style {
if (!presentationModeController_) {
presentationModeController_.reset(
[[PresentationModeController alloc] initWithBrowserController:self
style:style]);
[self newPresentationModeControllerWithStyle:style]);
[self configurePresentationModeController];
} else {
presentationModeController_.get().slidingStyle = style;
......@@ -740,6 +736,12 @@ willPositionSheet:(NSWindow*)sheet
[self layoutSubviews];
}
- (PresentationModeController*)newPresentationModeControllerWithStyle:
(fullscreen_mac::SlidingStyle)style {
return [[PresentationModeController alloc] initWithBrowserController:self
style:style];
}
- (void)enterImmersiveFullscreen {
// Set to NO by |-windowDidEnterFullScreen:|.
enteringImmersiveFullscreen_ = YES;
......
......@@ -143,6 +143,20 @@ enum SlidingStyle {
@end
// Private methods exposed for testing.
@interface PresentationModeController (ExposedForTesting)
// Adjusts the AppKit Fullscreen options of the application.
- (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode;
// Callback for menu bar animations.
- (void)setMenuBarRevealProgress:(CGFloat)progress;
// Updates the local state that reflects the fraction of the toolbar area that
// is showing. This function has the side effect of changing the AppKit
// Fullscreen option for whether the menu bar is shown.
- (void)changeToolbarFraction:(CGFloat)fraction;
@end
// Notification posted when we're about to enter or leave fullscreen.
extern NSString* const kWillEnterFullscreenNotification;
extern NSString* const kWillLeaveFullscreenNotification;
......
......@@ -20,15 +20,6 @@ NSString* const kWillEnterFullscreenNotification =
NSString* const kWillLeaveFullscreenNotification =
@"WillLeaveFullscreenNotification";
@interface PresentationModeController ()
// Sets a new current floating bar shown fraction. NOTE: This function has side
// effects, such as modifying the system fullscreen mode (menu bar shown state).
- (void)changeToolbarFraction:(CGFloat)fraction;
// Callback for menu bar animations.
- (void)setMenuBarRevealProgress:(CGFloat)progress;
@end
namespace {
// The activation zone for the main menu is 4 pixels high; if we make it any
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/browser_window_controller_private.h"
#include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
#import "chrome/browser/ui/cocoa/fast_resize_view.h"
#import "chrome/browser/ui/cocoa/presentation_mode_controller.h"
#import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
namespace {
// The height of the AppKit menu bar.
const CGFloat kMenuBarHeight = 22;
// Returns the frame of the view in window coordinates.
NSRect FrameInWindow(NSView* view) {
return [view convertRect:[view bounds] toView:nil];
}
// Returns the min Y of the view in window coordinates.
CGFloat MinYInWindow(NSView* view) {
return NSMinY(FrameInWindow(view));
}
// Returns the max Y of the view in window coordinates.
CGFloat MaxYInWindow(NSView* view) {
return NSMaxY(FrameInWindow(view));
}
// Returns the view positioned highest in the toolbar area.
NSView* HighestViewInToolbarArea(BrowserWindowController* controller) {
return [controller tabStripView];
}
// Returns the view positioned lowest in the toolbar area.
NSView* LowestViewInToolbarArea(BrowserWindowController* controller) {
return [[controller bookmarkBarController] view];
}
// Check the layout of the views in the toolbar area when none of them overlap.
void CheckToolbarLayoutNoOverlap(BrowserWindowController* controller) {
EXPECT_EQ(MinYInWindow([controller tabStripView]),
MaxYInWindow([[controller toolbarController] view]));
EXPECT_EQ(MinYInWindow([[controller toolbarController] view]),
MaxYInWindow([[controller bookmarkBarController] view]));
}
// Check the layout of all of the views when none of them overlap.
void CheckLayoutNoOverlap(BrowserWindowController* controller) {
CheckToolbarLayoutNoOverlap(controller);
EXPECT_EQ(MinYInWindow([[controller bookmarkBarController] view]),
MaxYInWindow([[controller infoBarContainerController] view]));
EXPECT_EQ(MinYInWindow([[controller infoBarContainerController] view]),
MaxYInWindow([controller tabContentArea]));
}
} // namespace
// -------------------MockPresentationModeController----------------------------
// Mock of PresentationModeController that eliminates dependencies on AppKit.
@interface MockPresentationModeController : PresentationModeController
@end
@implementation MockPresentationModeController
- (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode {
}
- (CGFloat)floatingBarVerticalOffset {
return kMenuBarHeight;
}
@end
// -------------------MockBrowserWindowController-------------------------------
// Mock of BrowserWindowController that eliminates dependencies on AppKit.
@interface MockBrowserWindowController : BrowserWindowController {
@public
MockPresentationModeController* presentationController_;
BOOL isInAppKitFullscreen_;
}
@end
@implementation MockBrowserWindowController
// Use the mock presentation controller.
// Superclass override.
- (PresentationModeController*)newPresentationModeControllerWithStyle:
(fullscreen_mac::SlidingStyle)style {
presentationController_ =
[[MockPresentationModeController alloc] initWithBrowserController:self
style:style];
return presentationController_;
}
// Manually control whether the floating bar (omnibox, tabstrip, etc.) has
// focus.
// Superclass override.
- (BOOL)floatingBarHasFocus {
return NO;
}
// Superclass override.
- (BOOL)isInAppKitFullscreen {
return isInAppKitFullscreen_;
}
// Superclass override.
- (BOOL)placeBookmarkBarBelowInfoBar {
return NO;
}
@end
// -------------------PresentationModeControllerTest----------------------------
class PresentationModeControllerTest : public CocoaProfileTest {
public:
virtual void SetUp() OVERRIDE {
CocoaProfileTest::SetUp();
ASSERT_TRUE(browser());
controller_ = [[MockBrowserWindowController alloc] initWithBrowser:browser()
takeOwnership:NO];
[[controller_ bookmarkBarController]
updateState:BookmarkBar::SHOW
changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE];
}
virtual void TearDown() OVERRIDE {
[controller_ close];
CocoaProfileTest::TearDown();
}
public:
MockBrowserWindowController* controller_;
};
// Tests the layout of views in Canonical Fullscreen (emulating AppKit
// Fullscreen API).
TEST_F(PresentationModeControllerTest, CanonicalFullscreenAppKitLayout) {
// Check initial layout.
CGFloat windowHeight = NSHeight([[controller_ window] frame]);
EXPECT_EQ(windowHeight, MaxYInWindow([controller_ tabStripView]));
CheckLayoutNoOverlap(controller_);
// No change after adjusting UI for Canonical Fullscreen.
controller_->isInAppKitFullscreen_ = YES;
[controller_
adjustUIForSlidingFullscreenStyle:fullscreen_mac::OMNIBOX_TABS_PRESENT];
EXPECT_EQ(windowHeight, MaxYInWindow([controller_ tabStripView]));
CheckLayoutNoOverlap(controller_);
// The menu bar is starting to animate in. All views should slide down by a
// small amount.
[controller_->presentationController_ setMenuBarRevealProgress:0.3];
EXPECT_LT(MaxYInWindow([controller_ tabStripView]), windowHeight - 1);
EXPECT_GT(MaxYInWindow([controller_ tabStripView]),
windowHeight - kMenuBarHeight + 1);
CheckLayoutNoOverlap(controller_);
// The menu bar is fully visible. All views should slide down by the size of
// the menu bar.
[controller_->presentationController_ setMenuBarRevealProgress:1];
EXPECT_FLOAT_EQ(windowHeight - kMenuBarHeight,
MaxYInWindow([controller_ tabStripView]));
CheckLayoutNoOverlap(controller_);
// The menu bar has disappeared. All views should return to normal.
[controller_->presentationController_ setMenuBarRevealProgress:0];
EXPECT_EQ(windowHeight, MaxYInWindow([controller_ tabStripView]));
CheckLayoutNoOverlap(controller_);
}
// Tests the layout of views in Presentation Mode (emulating AppKit Fullscreen
// API).
TEST_F(PresentationModeControllerTest, PresentationModeAppKitLayout) {
// Check initial layout.
CGFloat windowHeight = NSHeight([[controller_ window] frame]);
EXPECT_EQ(windowHeight, MaxYInWindow([controller_ tabStripView]));
CheckLayoutNoOverlap(controller_);
// Adjust UI for Presentation Mode.
controller_->isInAppKitFullscreen_ = YES;
[controller_
adjustUIForSlidingFullscreenStyle:fullscreen_mac::OMNIBOX_TABS_HIDDEN];
// In AppKit Fullscreen, the titlebar disappears. This test can't remove the
// titlebar without non-trivially changing the view hierarchy. Instead, it
// adjusts the expectations to sometimes use contentHeight instead of
// windowHeight (the two should be the same in AppKit Fullscreen).
CGFloat contentHeight = NSHeight([[[controller_ window] contentView] bounds]);
CheckToolbarLayoutNoOverlap(controller_);
EXPECT_EQ(windowHeight, MinYInWindow(LowestViewInToolbarArea(controller_)));
EXPECT_EQ(contentHeight, MaxYInWindow([controller_ tabContentArea]));
// The menu bar is starting to animate in. All views except the content view
// should slide down by a small amount.
[controller_->presentationController_ setMenuBarRevealProgress:0.3];
[controller_->presentationController_ changeToolbarFraction:0.3];
CheckToolbarLayoutNoOverlap(controller_);
EXPECT_LT(MinYInWindow(LowestViewInToolbarArea(controller_)), contentHeight);
EXPECT_GT(MaxYInWindow(HighestViewInToolbarArea(controller_)), contentHeight);
EXPECT_EQ(contentHeight, MaxYInWindow([controller_ tabContentArea]));
// The menu bar is fully visible. All views should slide down by the size of
// the menu bar.
[controller_->presentationController_ setMenuBarRevealProgress:1];
[controller_->presentationController_ changeToolbarFraction:1];
CheckToolbarLayoutNoOverlap(controller_);
EXPECT_EQ(contentHeight, MaxYInWindow(HighestViewInToolbarArea(controller_)));
EXPECT_EQ(contentHeight, MaxYInWindow([controller_ tabContentArea]));
// The menu bar has disappeared. All views should return to normal.
[controller_->presentationController_ setMenuBarRevealProgress:0];
[controller_->presentationController_ changeToolbarFraction:0];
CheckToolbarLayoutNoOverlap(controller_);
EXPECT_EQ(windowHeight, MinYInWindow(LowestViewInToolbarArea(controller_)));
EXPECT_EQ(contentHeight, MaxYInWindow([controller_ tabContentArea]));
}
......@@ -1617,6 +1617,7 @@
'browser/ui/cocoa/passwords/manage_passwords_bubble_pending_view_controller_unittest.mm',
'browser/ui/cocoa/passwords/manage_passwords_controller_test.h',
'browser/ui/cocoa/passwords/manage_passwords_controller_test.mm',
'browser/ui/cocoa/presentation_mode_controller_unittest.mm',
'browser/ui/cocoa/profiles/avatar_button_controller_unittest.mm',
'browser/ui/cocoa/profiles/avatar_icon_controller_unittest.mm',
'browser/ui/cocoa/profiles/avatar_label_button_unittest.mm',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment