browser_non_client_frame_view_ash_browsertest.cc revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
1// Copyright (c) 2012 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#include "chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h" 6 7#include "ash/ash_constants.h" 8#include "ash/ash_switches.h" 9#include "base/command_line.h" 10#include "chrome/browser/ui/browser.h" 11#include "chrome/browser/ui/immersive_fullscreen_configuration.h" 12#include "chrome/browser/ui/views/frame/browser_view.h" 13#include "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h" 14#include "chrome/test/base/in_process_browser_test.h" 15#include "ui/base/hit_test.h" 16#include "ui/compositor/scoped_animation_duration_scale_mode.h" 17#include "ui/views/controls/button/image_button.h" 18#include "ui/views/widget/widget.h" 19 20using views::Widget; 21 22typedef InProcessBrowserTest BrowserNonClientFrameViewAshTest; 23 24IN_PROC_BROWSER_TEST_F(BrowserNonClientFrameViewAshTest, WindowHeader) { 25 // We know we're using Views, so static cast. 26 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); 27 Widget* widget = browser_view->GetWidget(); 28 // We know we're using Ash, so static cast. 29 BrowserNonClientFrameViewAsh* frame_view = 30 static_cast<BrowserNonClientFrameViewAsh*>( 31 widget->non_client_view()->frame_view()); 32 33 // Restored window uses tall header. 34 const int kWindowWidth = 300; 35 const int kWindowHeight = 290; 36 widget->SetBounds(gfx::Rect(10, 10, kWindowWidth, kWindowHeight)); 37 EXPECT_FALSE(frame_view->UseShortHeader()); 38 39 // Click on the top edge of a window hits the top edge resize handle. 40 gfx::Point top_edge(kWindowWidth / 2, 0); 41 EXPECT_EQ(HTTOP, frame_view->NonClientHitTest(top_edge)); 42 43 // Click just below the resize handle hits the caption. 44 gfx::Point below_resize(kWindowWidth / 2, ash::kResizeInsideBoundsSize); 45 EXPECT_EQ(HTCAPTION, frame_view->NonClientHitTest(below_resize)); 46 47 // Window at top of screen uses normal header. 48 widget->SetBounds(gfx::Rect(10, 0, kWindowWidth, kWindowHeight)); 49 EXPECT_FALSE(frame_view->UseShortHeader()); 50 51 // Maximized window uses short header. 52 widget->Maximize(); 53 EXPECT_TRUE(frame_view->UseShortHeader()); 54 55 // Click in the top edge of a maximized window now hits the client area, 56 // because we want it to fall through to the tab strip and select a tab. 57 EXPECT_EQ(HTCLIENT, frame_view->NonClientHitTest(top_edge)); 58 59 // Popups tall header. 60 Browser* popup = CreateBrowserForPopup(browser()->profile()); 61 Widget* popup_widget = 62 static_cast<BrowserView*>(popup->window())->GetWidget(); 63 BrowserNonClientFrameViewAsh* popup_frame_view = 64 static_cast<BrowserNonClientFrameViewAsh*>( 65 popup_widget->non_client_view()->frame_view()); 66 popup_widget->SetBounds(gfx::Rect(5, 5, 200, 200)); 67 EXPECT_FALSE(popup_frame_view->UseShortHeader()); 68 69 // Apps use tall header. 70 Browser* app = CreateBrowserForApp("name", browser()->profile()); 71 Widget* app_widget = 72 static_cast<BrowserView*>(app->window())->GetWidget(); 73 BrowserNonClientFrameViewAsh* app_frame_view = 74 static_cast<BrowserNonClientFrameViewAsh*>( 75 app_widget->non_client_view()->frame_view()); 76 app_widget->SetBounds(gfx::Rect(15, 15, 250, 250)); 77 EXPECT_FALSE(app_frame_view->UseShortHeader()); 78} 79 80IN_PROC_BROWSER_TEST_F(BrowserNonClientFrameViewAshTest, ImmersiveMode) { 81 if (!ImmersiveFullscreenConfiguration::UseImmersiveFullscreen()) 82 return; 83 84 ui::ScopedAnimationDurationScaleMode zero_duration_mode( 85 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); 86 87 // We know we're using Views, so static cast. 88 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); 89 Widget* widget = browser_view->GetWidget(); 90 // We know we're using Ash, so static cast. 91 BrowserNonClientFrameViewAsh* frame_view = 92 static_cast<BrowserNonClientFrameViewAsh*>( 93 widget->non_client_view()->frame_view()); 94 ASSERT_FALSE(widget->IsFullscreen()); 95 96 ImmersiveModeControllerAsh* immersive_mode_controller = 97 static_cast<ImmersiveModeControllerAsh*>( 98 browser_view->immersive_mode_controller()); 99 100 // Immersive mode starts disabled. 101 EXPECT_FALSE(immersive_mode_controller->IsEnabled()); 102 103 // Frame paints by default. 104 EXPECT_TRUE(frame_view->ShouldPaint()); 105 106 // Going fullscreen enables immersive mode. 107 browser_view->EnterFullscreen(GURL(), FEB_TYPE_NONE); 108 EXPECT_TRUE(immersive_mode_controller->IsEnabled()); 109 110 // TODO(jamescook): When adding back the slide-out animation for immersive 111 // mode, this is a good place to test the button visibility. 112 113 // Frame abuts top of window. 114 EXPECT_EQ(0, frame_view->NonClientTopBorderHeight(false)); 115 116 // An immersive reveal shows the buttons and the top of the frame. 117 immersive_mode_controller->StartRevealForTest(true); 118 EXPECT_TRUE(frame_view->size_button_->visible()); 119 EXPECT_TRUE(frame_view->close_button_->visible()); 120 EXPECT_TRUE(frame_view->ShouldPaint()); 121 122 // Ending reveal hides them again. 123 immersive_mode_controller->SetMouseHoveredForTest(false); 124 EXPECT_FALSE(immersive_mode_controller->IsRevealed()); 125 EXPECT_FALSE(frame_view->size_button_->visible()); 126 EXPECT_FALSE(frame_view->close_button_->visible()); 127 EXPECT_FALSE(frame_view->ShouldPaint()); 128 129 // Exiting fullscreen exits immersive mode. 130 browser_view->ExitFullscreen(); 131 EXPECT_FALSE(immersive_mode_controller->IsEnabled()); 132 133 // Exiting immersive mode makes controls and frame visible again. 134 EXPECT_TRUE(frame_view->size_button_->visible()); 135 EXPECT_TRUE(frame_view->close_button_->visible()); 136 EXPECT_TRUE(frame_view->ShouldPaint()); 137} 138