browser_non_client_frame_view_ash_browsertest.cc revision f2477e01787aa58f445919b809d89e252beef54f
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 "ash/wm/caption_buttons/frame_caption_button_container_view.h"
10#include "base/command_line.h"
11#include "chrome/browser/ui/browser.h"
12#include "chrome/browser/ui/browser_commands.h"
13#include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
14#include "chrome/browser/ui/fullscreen/fullscreen_controller_test.h"
15#include "chrome/browser/ui/views/frame/browser_view.h"
16#include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
17#include "chrome/test/base/in_process_browser_test.h"
18#include "ui/base/hit_test.h"
19#include "ui/compositor/scoped_animation_duration_scale_mode.h"
20#include "ui/views/widget/widget.h"
21
22using views::Widget;
23
24typedef InProcessBrowserTest BrowserNonClientFrameViewAshTest;
25
26IN_PROC_BROWSER_TEST_F(BrowserNonClientFrameViewAshTest, NonClientHitTest) {
27  // We know we're using Views, so static cast.
28  BrowserView* browser_view = static_cast<BrowserView*>(browser()->window());
29  Widget* widget = browser_view->GetWidget();
30  // We know we're using Ash, so static cast.
31  BrowserNonClientFrameViewAsh* frame_view =
32      static_cast<BrowserNonClientFrameViewAsh*>(
33          widget->non_client_view()->frame_view());
34
35  // Click on the top edge of a restored window hits the top edge resize handle.
36  const int kWindowWidth = 300;
37  const int kWindowHeight = 290;
38  widget->SetBounds(gfx::Rect(10, 10, kWindowWidth, kWindowHeight));
39  gfx::Point top_edge(kWindowWidth / 2, 0);
40  EXPECT_EQ(HTTOP, frame_view->NonClientHitTest(top_edge));
41
42  // Click just below the resize handle hits the caption.
43  gfx::Point below_resize(kWindowWidth / 2, ash::kResizeInsideBoundsSize);
44  EXPECT_EQ(HTCAPTION, frame_view->NonClientHitTest(below_resize));
45
46  // Click in the top edge of a maximized window now hits the client area,
47  // because we want it to fall through to the tab strip and select a tab.
48  widget->Maximize();
49  EXPECT_EQ(HTCLIENT, frame_view->NonClientHitTest(top_edge));
50}
51
52// Test that the frame view does not do any painting in non-immersive
53// fullscreen.
54IN_PROC_BROWSER_TEST_F(BrowserNonClientFrameViewAshTest,
55                       NonImmersiveFullscreen) {
56  // We know we're using Views, so static cast.
57  BrowserView* browser_view = static_cast<BrowserView*>(browser()->window());
58  content::WebContents* web_contents = browser_view->GetActiveWebContents();
59  Widget* widget = browser_view->GetWidget();
60  // We know we're using Ash, so static cast.
61  BrowserNonClientFrameViewAsh* frame_view =
62      static_cast<BrowserNonClientFrameViewAsh*>(
63          widget->non_client_view()->frame_view());
64
65  // Frame paints by default.
66  EXPECT_TRUE(frame_view->ShouldPaint());
67
68  // No painting should occur in non-immersive fullscreen. (We enter into tab
69  // fullscreen here because tab fullscreen is non-immersive even on ChromeOS).
70  {
71    // NOTIFICATION_FULLSCREEN_CHANGED is sent asynchronously.
72    scoped_ptr<FullscreenNotificationObserver> waiter(
73        new FullscreenNotificationObserver());
74    browser()->fullscreen_controller()->ToggleFullscreenModeForTab(
75        web_contents, true);
76    waiter->Wait();
77  }
78  EXPECT_FALSE(browser_view->immersive_mode_controller()->IsEnabled());
79  EXPECT_FALSE(frame_view->ShouldPaint());
80
81  // The client view abuts top of the window.
82  EXPECT_EQ(0, frame_view->NonClientTopBorderHeight());
83
84  // The frame should be painted again when fullscreen is exited and the caption
85  // buttons should be visible.
86  {
87    scoped_ptr<FullscreenNotificationObserver> waiter(
88        new FullscreenNotificationObserver());
89    chrome::ToggleFullscreenMode(browser());
90    waiter->Wait();
91  }
92  EXPECT_TRUE(frame_view->ShouldPaint());
93  EXPECT_TRUE(frame_view->caption_button_container_->visible());
94}
95
96IN_PROC_BROWSER_TEST_F(BrowserNonClientFrameViewAshTest, ImmersiveFullscreen) {
97  // We know we're using Views, so static cast.
98  BrowserView* browser_view = static_cast<BrowserView*>(browser()->window());
99  content::WebContents* web_contents = browser_view->GetActiveWebContents();
100  Widget* widget = browser_view->GetWidget();
101  // We know we're using Ash, so static cast.
102  BrowserNonClientFrameViewAsh* frame_view =
103      static_cast<BrowserNonClientFrameViewAsh*>(
104          widget->non_client_view()->frame_view());
105
106  ImmersiveModeController* immersive_mode_controller =
107      browser_view->immersive_mode_controller();
108  immersive_mode_controller->SetupForTest();
109
110  // Immersive mode starts disabled.
111  ASSERT_FALSE(widget->IsFullscreen());
112  EXPECT_FALSE(immersive_mode_controller->IsEnabled());
113
114  // Frame paints by default.
115  EXPECT_TRUE(frame_view->ShouldPaint());
116
117  // Enter both browser fullscreen and tab fullscreen. Entering browser
118  // fullscreen should enable immersive fullscreen.
119  {
120    // NOTIFICATION_FULLSCREEN_CHANGED is sent asynchronously.
121    scoped_ptr<FullscreenNotificationObserver> waiter(
122        new FullscreenNotificationObserver());
123    chrome::ToggleFullscreenMode(browser());
124    waiter->Wait();
125  }
126  {
127    scoped_ptr<FullscreenNotificationObserver> waiter(
128        new FullscreenNotificationObserver());
129    browser()->fullscreen_controller()->ToggleFullscreenModeForTab(
130        web_contents, true);
131    waiter->Wait();
132  }
133  EXPECT_TRUE(immersive_mode_controller->IsEnabled());
134
135  // An immersive reveal shows the buttons and the top of the frame.
136  scoped_ptr<ImmersiveRevealedLock> revealed_lock(
137      immersive_mode_controller->GetRevealedLock(
138          ImmersiveModeController::ANIMATE_REVEAL_NO));
139  EXPECT_TRUE(immersive_mode_controller->IsRevealed());
140  EXPECT_TRUE(frame_view->ShouldPaint());
141  EXPECT_TRUE(frame_view->caption_button_container_->visible());
142  EXPECT_TRUE(frame_view->UseShortHeader());
143  EXPECT_FALSE(frame_view->UseImmersiveLightbarHeaderStyle());
144
145  // End the reveal. When in both immersive browser fullscreen and tab
146  // fullscreen, the tab lightbars should not be painted.
147  revealed_lock.reset();
148  EXPECT_FALSE(immersive_mode_controller->IsRevealed());
149  EXPECT_FALSE(frame_view->ShouldPaint());
150
151  // Repeat test but without tab fullscreen. The tab lightbars should now show
152  // when the top-of-window views are not revealed.
153  {
154    scoped_ptr<FullscreenNotificationObserver> waiter(
155        new FullscreenNotificationObserver());
156    browser()->fullscreen_controller()->ToggleFullscreenModeForTab(
157        web_contents, false);
158    waiter->Wait();
159  }
160
161  // Immersive reveal should have same behavior as before.
162  revealed_lock.reset(immersive_mode_controller->GetRevealedLock(
163      ImmersiveModeController::ANIMATE_REVEAL_NO));
164  EXPECT_TRUE(immersive_mode_controller->IsRevealed());
165  EXPECT_TRUE(frame_view->ShouldPaint());
166  EXPECT_TRUE(frame_view->caption_button_container_->visible());
167  EXPECT_TRUE(frame_view->UseShortHeader());
168  EXPECT_FALSE(frame_view->UseImmersiveLightbarHeaderStyle());
169
170  // Ending the reveal should hide the caption buttons and the header should
171  // be in the lightbar style.
172  revealed_lock.reset();
173  EXPECT_TRUE(frame_view->ShouldPaint());
174  EXPECT_FALSE(frame_view->caption_button_container_->visible());
175  EXPECT_TRUE(frame_view->UseShortHeader());
176  EXPECT_TRUE(frame_view->UseImmersiveLightbarHeaderStyle());
177
178  // Exiting immersive fullscreen should make the caption buttons and the frame
179  // visible again.
180  {
181    scoped_ptr<FullscreenNotificationObserver> waiter(
182        new FullscreenNotificationObserver());
183    browser_view->ExitFullscreen();
184    waiter->Wait();
185  }
186  EXPECT_FALSE(immersive_mode_controller->IsEnabled());
187  EXPECT_TRUE(frame_view->ShouldPaint());
188  EXPECT_TRUE(frame_view->caption_button_container_->visible());
189  EXPECT_FALSE(frame_view->UseImmersiveLightbarHeaderStyle());
190}
191