Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / frame / immersive_mode_controller_ash_unittest.cc
blob3461783f6584cf97dbd20fb08e30be49739b9444
1 // Copyright 2013 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.
5 // For now, immersive fullscreen is Chrome OS only.
6 #if defined(OS_CHROMEOS)
8 #include "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h"
10 #include "ash/ash_switches.h"
11 #include "ash/root_window_controller.h"
12 #include "ash/shelf/shelf_layout_manager.h"
13 #include "ash/shelf/shelf_types.h"
14 #include "ash/shell.h"
15 #include "ash/test/ash_test_base.h"
16 #include "base/command_line.h"
17 #include "chrome/app/chrome_command_ids.h"
18 #include "chrome/browser/ui/browser_commands.h"
19 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
20 #include "chrome/browser/ui/fullscreen/fullscreen_controller_test.h"
21 #include "chrome/browser/ui/views/frame/browser_view.h"
22 #include "chrome/browser/ui/views/frame/test_with_browser_view.h"
23 #include "chrome/browser/ui/views/frame/top_container_view.h"
24 #include "chrome/browser/ui/views/tabs/tab_strip.h"
25 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
26 #include "ui/aura/window.h"
27 #include "ui/views/controls/webview/webview.h"
29 class ImmersiveModeControllerAshTest : public TestWithBrowserView {
30 public:
31 ImmersiveModeControllerAshTest() {}
32 virtual ~ImmersiveModeControllerAshTest() {}
34 // TestWithBrowserView override:
35 virtual void SetUp() OVERRIDE {
36 TestWithBrowserView::SetUp();
38 browser()->window()->Show();
40 controller_ = browser_view()->immersive_mode_controller();
41 controller_->SetupForTest();
44 // Returns the bounds of |view| in widget coordinates.
45 gfx::Rect GetBoundsInWidget(views::View* view) {
46 return view->ConvertRectToWidget(view->GetLocalBounds());
49 // Toggle the browser's fullscreen state.
50 void ToggleFullscreen() {
51 // NOTIFICATION_FULLSCREEN_CHANGED is sent asynchronously. The notification
52 // is used to trigger changes in whether the shelf is auto hidden and
53 // whether a "light bar" version of the tab strip is used when the
54 // top-of-window views are hidden.
55 scoped_ptr<FullscreenNotificationObserver> waiter(
56 new FullscreenNotificationObserver());
57 chrome::ToggleFullscreenMode(browser());
58 waiter->Wait();
61 // Set whether the browser is in tab fullscreen.
62 void SetTabFullscreen(bool tab_fullscreen) {
63 content::WebContents* web_contents =
64 browser_view()->GetContentsWebViewForTest()->GetWebContents();
65 scoped_ptr<FullscreenNotificationObserver> waiter(
66 new FullscreenNotificationObserver());
67 browser()->fullscreen_controller()->ToggleFullscreenModeForTab(
68 web_contents, tab_fullscreen);
69 waiter->Wait();
72 // Attempt revealing the top-of-window views.
73 void AttemptReveal() {
74 if (!revealed_lock_.get()) {
75 revealed_lock_.reset(controller_->GetRevealedLock(
76 ImmersiveModeControllerAsh::ANIMATE_REVEAL_NO));
80 // Attempt unrevealing the top-of-window views.
81 void AttemptUnreveal() {
82 revealed_lock_.reset();
85 ImmersiveModeController* controller() { return controller_; }
87 private:
88 // Not owned.
89 ImmersiveModeController* controller_;
91 scoped_ptr<ImmersiveRevealedLock> revealed_lock_;
93 DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAshTest);
96 // Test the layout and visibility of the tabstrip, toolbar and TopContainerView
97 // in immersive fullscreen.
98 TEST_F(ImmersiveModeControllerAshTest, Layout) {
99 AddTab(browser(), GURL("about:blank"));
101 TabStrip* tabstrip = browser_view()->tabstrip();
102 ToolbarView* toolbar = browser_view()->toolbar();
103 views::WebView* contents_web_view =
104 browser_view()->GetContentsWebViewForTest();
106 // Immersive fullscreen starts out disabled.
107 ASSERT_FALSE(browser_view()->GetWidget()->IsFullscreen());
108 ASSERT_FALSE(controller()->IsEnabled());
110 // By default, the tabstrip and toolbar should be visible.
111 EXPECT_TRUE(tabstrip->visible());
112 EXPECT_TRUE(toolbar->visible());
114 ToggleFullscreen();
115 EXPECT_TRUE(browser_view()->GetWidget()->IsFullscreen());
116 EXPECT_TRUE(controller()->IsEnabled());
117 EXPECT_FALSE(controller()->IsRevealed());
119 // Entering immersive fullscreen should make the tab strip use the immersive
120 // style and hide the toolbar.
121 EXPECT_TRUE(tabstrip->visible());
122 EXPECT_TRUE(tabstrip->IsImmersiveStyle());
123 EXPECT_FALSE(toolbar->visible());
125 // The tab indicators should be flush with the top of the widget.
126 EXPECT_EQ(0, GetBoundsInWidget(tabstrip).y());
128 // The web contents should be immediately below the tab indicators.
129 EXPECT_EQ(Tab::GetImmersiveHeight(),
130 GetBoundsInWidget(contents_web_view).y());
132 // Revealing the top-of-window views should set the tab strip back to the
133 // normal style and show the toolbar.
134 AttemptReveal();
135 EXPECT_TRUE(controller()->IsRevealed());
136 EXPECT_TRUE(tabstrip->visible());
137 EXPECT_FALSE(tabstrip->IsImmersiveStyle());
138 EXPECT_TRUE(toolbar->visible());
140 // The TopContainerView should be flush with the top edge of the widget. If
141 // it is not flush with the top edge the immersive reveal animation looks
142 // wonky.
143 EXPECT_EQ(0, GetBoundsInWidget(browser_view()->top_container()).y());
145 // The web contents should be at the same y position as they were when the
146 // top-of-window views were hidden.
147 EXPECT_EQ(Tab::GetImmersiveHeight(),
148 GetBoundsInWidget(contents_web_view).y());
150 // Repeat the test for when in both immersive fullscreen and tab fullscreen.
151 SetTabFullscreen(true);
152 // Hide and reveal the top-of-window views so that they get relain out.
153 AttemptUnreveal();
154 AttemptReveal();
156 // The tab strip and toolbar should still be visible and the TopContainerView
157 // should still be flush with the top edge of the widget.
158 EXPECT_TRUE(controller()->IsRevealed());
159 EXPECT_TRUE(tabstrip->visible());
160 EXPECT_FALSE(tabstrip->IsImmersiveStyle());
161 EXPECT_TRUE(toolbar->visible());
162 EXPECT_EQ(0, GetBoundsInWidget(browser_view()->top_container()).y());
164 // The web contents should be flush with the top edge of the widget when in
165 // both immersive and tab fullscreen.
166 EXPECT_EQ(0, GetBoundsInWidget(contents_web_view).y());
168 // Hide the top-of-window views. Both the tab strip and the toolbar should
169 // hide when in both immersive and tab fullscreen.
170 AttemptUnreveal();
171 EXPECT_FALSE(controller()->IsRevealed());
172 EXPECT_FALSE(tabstrip->visible());
173 EXPECT_FALSE(toolbar->visible());
175 // The web contents should still be flush with the edge of the widget.
176 EXPECT_EQ(0, GetBoundsInWidget(contents_web_view).y());
178 // Exiting both immersive and tab fullscreen should show the tab strip and
179 // toolbar.
180 ToggleFullscreen();
181 EXPECT_FALSE(browser_view()->GetWidget()->IsFullscreen());
182 EXPECT_FALSE(controller()->IsEnabled());
183 EXPECT_FALSE(controller()->IsRevealed());
184 EXPECT_TRUE(tabstrip->visible());
185 EXPECT_FALSE(tabstrip->IsImmersiveStyle());
186 EXPECT_TRUE(toolbar->visible());
189 // Test that the browser commands which are usually disabled in fullscreen are
190 // are enabled in immersive fullscreen.
191 TEST_F(ImmersiveModeControllerAshTest, EnabledCommands) {
192 ASSERT_FALSE(controller()->IsEnabled());
193 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL));
194 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ABOUT));
195 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION));
197 ToggleFullscreen();
198 EXPECT_TRUE(controller()->IsEnabled());
199 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL));
200 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ABOUT));
201 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION));
204 // Test that restoring a window properly exits immersive fullscreen.
205 TEST_F(ImmersiveModeControllerAshTest, ExitUponRestore) {
206 ASSERT_FALSE(controller()->IsEnabled());
207 ToggleFullscreen();
208 AttemptReveal();
209 ASSERT_TRUE(controller()->IsEnabled());
210 ASSERT_TRUE(controller()->IsRevealed());
211 ASSERT_TRUE(browser_view()->GetWidget()->IsFullscreen());
213 browser_view()->GetWidget()->Restore();
214 EXPECT_FALSE(controller()->IsEnabled());
217 // Test how being simultaneously in tab fullscreen and immersive fullscreen
218 // affects the shelf visibility and whether the tab indicators are hidden.
219 TEST_F(ImmersiveModeControllerAshTest, TabAndBrowserFullscreen) {
220 AddTab(browser(), GURL("about:blank"));
222 // The shelf should start out as visible.
223 ash::internal::ShelfLayoutManager* shelf =
224 ash::Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
225 ASSERT_EQ(ash::SHELF_VISIBLE, shelf->visibility_state());
227 // 1) Test that entering tab fullscreen from immersive fullscreen hides the
228 // tab indicators and the shelf.
229 ToggleFullscreen();
230 ASSERT_TRUE(controller()->IsEnabled());
231 EXPECT_EQ(ash::SHELF_AUTO_HIDE, shelf->visibility_state());
232 EXPECT_FALSE(controller()->ShouldHideTabIndicators());
234 SetTabFullscreen(true);
235 ASSERT_TRUE(controller()->IsEnabled());
236 EXPECT_EQ(ash::SHELF_HIDDEN, shelf->visibility_state());
237 EXPECT_TRUE(controller()->ShouldHideTabIndicators());
239 // 2) Test that exiting tab fullscreen shows the tab indicators and autohides
240 // the shelf.
241 SetTabFullscreen(false);
242 ASSERT_TRUE(controller()->IsEnabled());
243 EXPECT_EQ(ash::SHELF_AUTO_HIDE, shelf->visibility_state());
244 EXPECT_FALSE(controller()->ShouldHideTabIndicators());
246 // 3) Test that exiting tab fullscreen and immersive fullscreen
247 // simultaneously correctly updates the shelf visibility and whether the tab
248 // indicators should be hidden.
249 SetTabFullscreen(true);
250 ToggleFullscreen();
251 ASSERT_FALSE(controller()->IsEnabled());
252 EXPECT_EQ(ash::SHELF_VISIBLE, shelf->visibility_state());
253 EXPECT_TRUE(controller()->ShouldHideTabIndicators());
256 class ImmersiveModeControllerAshTestHostedApp
257 : public ImmersiveModeControllerAshTest {
258 public:
259 ImmersiveModeControllerAshTestHostedApp() {}
260 virtual ~ImmersiveModeControllerAshTestHostedApp() {}
262 // ImmersiveModeControllerAshTest override:
263 virtual void SetUp() OVERRIDE {
264 CommandLine::ForCurrentProcess()->AppendSwitch(
265 ash::switches::kAshEnableImmersiveFullscreenForAllWindows);
266 ImmersiveModeControllerAshTest::SetUp();
269 // BrowserWithTestWindowTest override:
270 virtual Browser* CreateBrowser(Profile* profile,
271 chrome::HostDesktopType host_desktop_type,
272 BrowserWindow* browser_window) OVERRIDE {
273 Browser::CreateParams params(profile, host_desktop_type);
274 params.type = Browser::TYPE_POPUP;
275 params.app_name = "Test";
276 params.window = browser_window;
277 return new Browser(params);
280 private:
281 DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAshTestHostedApp);
284 // Test the layout and visibility of the TopContainerView and web contents when
285 // a hosted app is put into immersive fullscreen.
286 TEST_F(ImmersiveModeControllerAshTestHostedApp, Layout) {
287 // Add a tab because the browser starts out without any tabs at all.
288 AddTab(browser(), GURL("about:blank"));
290 TabStrip* tabstrip = browser_view()->tabstrip();
291 ToolbarView* toolbar = browser_view()->toolbar();
292 views::WebView* contents_web_view =
293 browser_view()->GetContentsWebViewForTest();
294 views::View* top_container = browser_view()->top_container();
296 // Immersive fullscreen starts out disabled.
297 ASSERT_FALSE(browser_view()->GetWidget()->IsFullscreen());
298 ASSERT_FALSE(controller()->IsEnabled());
300 // The tabstrip and toolbar are not visible for hosted apps.
301 EXPECT_FALSE(tabstrip->visible());
302 EXPECT_FALSE(toolbar->visible());
304 // The window header should be above the web contents.
305 int header_height = GetBoundsInWidget(contents_web_view).y();
307 ToggleFullscreen();
308 EXPECT_TRUE(browser_view()->GetWidget()->IsFullscreen());
309 EXPECT_TRUE(controller()->IsEnabled());
310 EXPECT_FALSE(controller()->IsRevealed());
312 // Entering immersive fullscreen should make the web contents flush with the
313 // top of the widget.
314 EXPECT_FALSE(tabstrip->visible());
315 EXPECT_FALSE(toolbar->visible());
316 EXPECT_TRUE(top_container->GetVisibleBounds().IsEmpty());
317 EXPECT_EQ(0, GetBoundsInWidget(contents_web_view).y());
319 // Reveal the window header.
320 AttemptReveal();
322 // The tabstrip and toolbar should still be hidden and the web contents should
323 // still be flush with the top of the screen.
324 EXPECT_FALSE(tabstrip->visible());
325 EXPECT_FALSE(toolbar->visible());
326 EXPECT_EQ(0, GetBoundsInWidget(contents_web_view).y());
328 // During an immersive reveal, the window header should be painted to the
329 // TopContainerView. The TopContainerView should be flush with the top of the
330 // widget and have |header_height|.
331 gfx::Rect top_container_bounds_in_widget(GetBoundsInWidget(top_container));
332 EXPECT_EQ(0, top_container_bounds_in_widget.y());
333 EXPECT_EQ(header_height, top_container_bounds_in_widget.height());
335 // Exit immersive fullscreen. The web contents should be back below the window
336 // header.
337 ToggleFullscreen();
338 EXPECT_FALSE(browser_view()->GetWidget()->IsFullscreen());
339 EXPECT_FALSE(controller()->IsEnabled());
340 EXPECT_FALSE(tabstrip->visible());
341 EXPECT_FALSE(toolbar->visible());
342 EXPECT_EQ(header_height, GetBoundsInWidget(contents_web_view).y());
345 #endif // defined(OS_CHROMEOS)