| Index: chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_layout_unittest.mm
|
| diff --git a/chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_layout_unittest.mm b/chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_layout_unittest.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..eadb1191d32ad334e6b97d37c93d18b775011da7
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_layout_unittest.mm
|
| @@ -0,0 +1,287 @@
|
| +// Copyright 2016 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 <Cocoa/Cocoa.h>
|
| +
|
| +#include "base/mac/scoped_nsobject.h"
|
| +#include "base/macros.h"
|
| +#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_menubar_tracker.h"
|
| +#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_manager.h"
|
| +#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_layout_manager.h"
|
| +#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_mouse_tracker.h"
|
| +#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_visibility_locks_controller.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#import "testing/gtest_mac.h"
|
| +
|
| +//////////////////////////////////////////////////////////////////
|
| +// MockFullscreenToolbarMouseTracker
|
| +// Mocks the mouse interactions with the toolbar.
|
| +
|
| +@interface MockFullscreenToolbarMouseTracker : FullscreenToolbarMouseTracker
|
| +
|
| +@property(nonatomic, assign) BOOL mouseInside;
|
| +
|
| +// Overridden to prevent a tracking area from being created.
|
| +- (void)updateTrackingArea;
|
| +
|
| +- (BOOL)mouseInsideTrackingArea;
|
| +
|
| +@end
|
| +
|
| +@implementation MockFullscreenToolbarMouseTracker
|
| +
|
| +@synthesize mouseInside = mouseInside_;
|
| +
|
| +- (void)updateTrackingArea {
|
| +}
|
| +
|
| +- (BOOL)mouseInsideTrackingArea {
|
| + return mouseInside_;
|
| +}
|
| +
|
| +@end
|
| +
|
| +//////////////////////////////////////////////////////////////////
|
| +// MockFullscreenMenubarTracker
|
| +// Mocks the state of the menubar.
|
| +
|
| +@interface MockFullscreenMenubarTracker : FullscreenMenubarTracker {
|
| + CGFloat menubarFraction_;
|
| + FullscreenMenubarState menubarState_;
|
| +}
|
| +
|
| +- (CGFloat)menubarFraction;
|
| +- (FullscreenMenubarState)state;
|
| +- (void)setMenubarProgress:(CGFloat)progress;
|
| +
|
| +@end
|
| +
|
| +@implementation MockFullscreenMenubarTracker
|
| +
|
| +- (CGFloat)menubarFraction {
|
| + return menubarFraction_;
|
| +}
|
| +
|
| +- (FullscreenMenubarState)state {
|
| + return menubarState_;
|
| +}
|
| +
|
| +- (void)setMenubarProgress:(CGFloat)progress {
|
| + if (base::mac::IsCGFloatEqual(progress, 1.0))
|
| + menubarState_ = FullscreenMenubarState::SHOWN;
|
| + else if (base::mac::IsCGFloatEqual(progress, 0.0))
|
| + menubarState_ = FullscreenMenubarState::HIDDEN;
|
| + else if (progress < menubarFraction_)
|
| + menubarState_ = FullscreenMenubarState::HIDING;
|
| + else if (progress > menubarFraction_)
|
| + menubarState_ = FullscreenMenubarState::SHOWING;
|
| + menubarFraction_ = progress;
|
| +}
|
| +
|
| +@end
|
| +
|
| +namespace {
|
| +
|
| +// The amount by which the toolbar is offset downwards (to avoid the menu).
|
| +// Copied from FullscreenToolbarLayoutManager.
|
| +const CGFloat kToolbarVerticalOffset = -22;
|
| +
|
| +class FullscreenToolbarLayoutTest : public testing::Test {
|
| + public:
|
| + FullscreenToolbarLayoutTest() {}
|
| + void SetUp() override {
|
| + layoutManager_.reset(new FullscreenToolbarLayoutManager(nil));
|
| + layoutManager_->in_fullscreen_ = YES;
|
| + SetToolbarStyle(FullscreenToolbarStyle::TOOLBAR_HIDDEN);
|
| +
|
| + menubar_tracker_ = [[MockFullscreenMenubarTracker alloc] init];
|
| + layoutManager_->menubar_tracker_.reset(menubar_tracker_);
|
| + [menubar_tracker_ setMenubarProgress:0.0];
|
| +
|
| + mouse_tracker_ = [[MockFullscreenToolbarMouseTracker alloc] init];
|
| + layoutManager_->mouse_tracker_.reset(mouse_tracker_);
|
| +
|
| + FullscreenToolbarAnimationManager* animation_manager =
|
| + layoutManager_->animation_manager_.get();
|
| + animation_manager->disable_animations_during_testing_ = YES;
|
| + }
|
| +
|
| + void TearDown() override { layoutManager_->in_fullscreen_ = NO; }
|
| +
|
| + void SetToolbarStyle(FullscreenToolbarStyle style) {
|
| + layoutManager_->toolbar_style_ = style;
|
| + }
|
| +
|
| + void CheckLayout(CGFloat toolbarFraction, CGFloat menubarFraction) {
|
| + FullscreenToolbarLayout layout = layoutManager_->ComputeToolbarLayout();
|
| + DCHECK_EQ(layout.toolbarFraction, toolbarFraction);
|
| + DCHECK_EQ(layout.menubarOffset, menubarFraction * kToolbarVerticalOffset);
|
| + }
|
| +
|
| + // The FullscreenToolbarLayoutManager object being tested.
|
| + std::unique_ptr<FullscreenToolbarLayoutManager> layoutManager_;
|
| +
|
| + // Mocks the state of the menubar.
|
| + MockFullscreenMenubarTracker* menubar_tracker_;
|
| +
|
| + // Mocks the mouse interactions with the toolbar.
|
| + MockFullscreenToolbarMouseTracker* mouse_tracker_;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(FullscreenToolbarLayoutTest);
|
| +};
|
| +
|
| +// Tests the toolbar fraction is for the TOOLBAR_NONE and TOOLBAR_PRESENT
|
| +// styles.
|
| +TEST_F(FullscreenToolbarLayoutTest, TestPresentAndNoneToolbarStyle) {
|
| + CheckLayout(0, 0);
|
| +
|
| + SetToolbarStyle(FullscreenToolbarStyle::TOOLBAR_NONE);
|
| + DCHECK_EQ(layoutManager_->ComputeToolbarLayout().toolbarFraction, 0);
|
| +
|
| + SetToolbarStyle(FullscreenToolbarStyle::TOOLBAR_PRESENT);
|
| + DCHECK_EQ(layoutManager_->ComputeToolbarLayout().toolbarFraction, 1);
|
| +}
|
| +
|
| +// Basic test that checks if the toolbar fraction for different menubar values.
|
| +// This test simulates the showing and hiding the menubar.
|
| +TEST_F(FullscreenToolbarLayoutTest, TestHiddenToolbarWithMenubar) {
|
| + [menubar_tracker_ setMenubarProgress:0];
|
| + CheckLayout(0, 0);
|
| +
|
| + [menubar_tracker_ setMenubarProgress:0.5];
|
| + CheckLayout(0.5, 0.5);
|
| +
|
| + [menubar_tracker_ setMenubarProgress:1];
|
| + CheckLayout(1, 1);
|
| +
|
| + [menubar_tracker_ setMenubarProgress:0.5];
|
| + CheckLayout(0.5, 0.5);
|
| +
|
| + [menubar_tracker_ setMenubarProgress:0];
|
| + CheckLayout(0, 0);
|
| +}
|
| +
|
| +// Test that checks the visibility lock functions and the toolbar fraction.
|
| +TEST_F(FullscreenToolbarLayoutTest, TestHiddenToolbarWithVisibilityLocks) {
|
| + FullscreenToolbarVisibilityLocksController* locks =
|
| + layoutManager_->toolbar_visibility_locks();
|
| + base::scoped_nsobject<NSObject> owner([[NSObject alloc] init]);
|
| + base::scoped_nsobject<NSObject> alternative_owner([[NSObject alloc] init]);
|
| +
|
| + [menubar_tracker_ setMenubarProgress:0];
|
| + CheckLayout(0, 0);
|
| +
|
| + // Lock the toolbar visibility. Toolbar should be fully visible.
|
| + [locks lockToolbarVisibilityForOwner:owner.get() withAnimation:NO];
|
| + DCHECK([locks isToolbarVisibilityLocked]);
|
| + DCHECK([locks isToolbarVisibilityLockedForOwner:owner.get()]);
|
| + DCHECK(![locks isToolbarVisibilityLockedForOwner:alternative_owner.get()]);
|
| + CheckLayout(1, 0);
|
| +
|
| + // Show the menubar.
|
| + [menubar_tracker_ setMenubarProgress:1];
|
| + CheckLayout(1, 1);
|
| +
|
| + // Hide the menubar. The toolbar should still be fully visible.
|
| + [menubar_tracker_ setMenubarProgress:0.5];
|
| + CheckLayout(1, 0.5);
|
| + [menubar_tracker_ setMenubarProgress:0];
|
| + CheckLayout(1, 0);
|
| +
|
| + // Release the lock. Toolbar should now be hidden.
|
| + [locks releaseToolbarVisibilityForOwner:owner.get() withAnimation:NO];
|
| + DCHECK(![locks isToolbarVisibilityLocked]);
|
| + DCHECK(![locks isToolbarVisibilityLockedForOwner:owner.get()]);
|
| + CheckLayout(0, 0);
|
| +
|
| + // Lock and release the toolbar visibility with multiple owners.
|
| + [locks lockToolbarVisibilityForOwner:owner.get() withAnimation:NO];
|
| + [locks lockToolbarVisibilityForOwner:alternative_owner.get()
|
| + withAnimation:NO];
|
| + DCHECK([locks isToolbarVisibilityLocked]);
|
| + DCHECK([locks isToolbarVisibilityLockedForOwner:owner.get()]);
|
| + DCHECK([locks isToolbarVisibilityLockedForOwner:alternative_owner.get()]);
|
| + CheckLayout(1, 0);
|
| +
|
| + [locks releaseToolbarVisibilityForOwner:owner.get() withAnimation:NO];
|
| + DCHECK([locks isToolbarVisibilityLocked]);
|
| + DCHECK(![locks isToolbarVisibilityLockedForOwner:owner.get()]);
|
| + DCHECK([locks isToolbarVisibilityLockedForOwner:alternative_owner.get()]);
|
| + CheckLayout(1, 0);
|
| +
|
| + [locks releaseToolbarVisibilityForOwner:alternative_owner.get()
|
| + withAnimation:NO];
|
| + DCHECK(![locks isToolbarVisibilityLocked]);
|
| + DCHECK(![locks isToolbarVisibilityLockedForOwner:alternative_owner.get()]);
|
| + CheckLayout(0, 0);
|
| +}
|
| +
|
| +// Basic test that checks the toolbar fraction for different mouse tracking
|
| +// values.
|
| +TEST_F(FullscreenToolbarLayoutTest, TestHiddenToolbarWithMouseTracking) {
|
| + CheckLayout(0, 0);
|
| +
|
| + [mouse_tracker_ setMouseInside:YES];
|
| + CheckLayout(1, 0);
|
| +
|
| + [menubar_tracker_ setMenubarProgress:1];
|
| + CheckLayout(1, 1);
|
| +
|
| + [menubar_tracker_ setMenubarProgress:0];
|
| + CheckLayout(1, 0);
|
| +
|
| + [mouse_tracker_ setMouseInside:NO];
|
| + CheckLayout(0, 0);
|
| +}
|
| +
|
| +// Test that checks the toolbar fraction with mouse tracking, menubar fraction,
|
| +// and visibility locks.
|
| +TEST_F(FullscreenToolbarLayoutTest, TestHiddenToolbarWithMultipleFactors) {
|
| + FullscreenToolbarVisibilityLocksController* locks =
|
| + layoutManager_->toolbar_visibility_locks();
|
| + base::scoped_nsobject<NSObject> owner([[NSObject alloc] init]);
|
| + CheckLayout(0, 0);
|
| +
|
| + // Toolbar should be shown with the menubar.
|
| + [menubar_tracker_ setMenubarProgress:1];
|
| + CheckLayout(1, 1);
|
| +
|
| + // Move the mouse to the toolbar and start hiding the menubar. Toolbar
|
| + // should be fully visible.
|
| + [mouse_tracker_ setMouseInside:YES];
|
| + CheckLayout(1, 1);
|
| + [menubar_tracker_ setMenubarProgress:0.5];
|
| + CheckLayout(1, 0.5);
|
| +
|
| + // Lock the toolbar's visibility.
|
| + [locks lockToolbarVisibilityForOwner:owner.get() withAnimation:NO];
|
| + CheckLayout(1, 0.5);
|
| +
|
| + // Hide the menubar. Toolbar should be fully visible.
|
| + [menubar_tracker_ setMenubarProgress:0];
|
| + CheckLayout(1, 0);
|
| +
|
| + // Lock the toolbar's visibility. Toolbar should be fully visible.
|
| + [locks releaseToolbarVisibilityForOwner:owner.get() withAnimation:NO];
|
| + CheckLayout(1, 0);
|
| +
|
| + // Move the mouse away from the toolbar. Toolbar should hide.
|
| + [mouse_tracker_ setMouseInside:NO];
|
| + CheckLayout(0, 0);
|
| +
|
| + // Lock the toolbar and move the mouse to it.
|
| + [locks lockToolbarVisibilityForOwner:owner.get() withAnimation:NO];
|
| + [mouse_tracker_ setMouseInside:YES];
|
| + CheckLayout(1, 0);
|
| +
|
| + // Move the mouse away from the toolbar. Toolbar should be fully visible.
|
| + [mouse_tracker_ setMouseInside:NO];
|
| + CheckLayout(1, 0);
|
| +
|
| + // Release the toolbar. Toolbar should be hidden.
|
| + [locks releaseToolbarVisibilityForOwner:owner.get() withAnimation:NO];
|
| +}
|
| +
|
| +} // namespace
|
|
|