immersive_mode_controller_ash_unittest.cc revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// found in the LICENSE file. 490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 5a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// For now, immersive fullscreen is Chrome OS only. 6a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_CHROMEOS) 7a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h" 990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 10a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ash/ash_switches.h" 111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ash/root_window_controller.h" 121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ash/shelf/shelf_layout_manager.h" 131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ash/shelf/shelf_types.h" 14bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "ash/shell.h" 1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ash/test/ash_test_base.h" 16a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/command_line.h" 174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/app/chrome_command_ids.h" 184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/browser_commands.h" 194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/fullscreen/fullscreen_controller.h" 204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/fullscreen/fullscreen_controller_test.h" 214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/views/frame/browser_view.h" 224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/views/frame/test_with_browser_view.h" 234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/views/frame/top_container_view.h" 244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/views/tabs/tab_strip.h" 25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/ui/views/toolbar/toolbar_view.h" 2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/aura/window.h" 274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/views/controls/webview/webview.h" 2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 29f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class ImmersiveModeControllerAshTest : public TestWithBrowserView { 3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public: 31f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ImmersiveModeControllerAshTest() {} 3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual ~ImmersiveModeControllerAshTest() {} 3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // TestWithBrowserView override: 354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual void SetUp() OVERRIDE { 364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) TestWithBrowserView::SetUp(); 374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) browser()->window()->Show(); 394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) controller_ = browser_view()->immersive_mode_controller(); 411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) controller_->SetupForTest(); 424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Returns the bounds of |view| in widget coordinates. 454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect GetBoundsInWidget(views::View* view) { 464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return view->ConvertRectToWidget(view->GetLocalBounds()); 474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Toggle the browser's fullscreen state. 501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void ToggleFullscreen() { 511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // NOTIFICATION_FULLSCREEN_CHANGED is sent asynchronously. The notification 521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // is used to trigger changes in whether the shelf is auto hidden and 531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // whether a "light bar" version of the tab strip is used when the 541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // top-of-window views are hidden. 551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<FullscreenNotificationObserver> waiter( 561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new FullscreenNotificationObserver()); 571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) chrome::ToggleFullscreenMode(browser()); 581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) waiter->Wait(); 591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Set whether the browser is in tab fullscreen. 621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void SetTabFullscreen(bool tab_fullscreen) { 631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) content::WebContents* web_contents = 641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) browser_view()->GetContentsWebViewForTest()->GetWebContents(); 651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<FullscreenNotificationObserver> waiter( 661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new FullscreenNotificationObserver()); 671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) browser()->fullscreen_controller()->ToggleFullscreenModeForTab( 681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) web_contents, tab_fullscreen); 691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) waiter->Wait(); 701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Attempt revealing the top-of-window views. 731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void AttemptReveal() { 741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (!revealed_lock_.get()) { 751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) revealed_lock_.reset(controller_->GetRevealedLock( 761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ImmersiveModeControllerAsh::ANIMATE_REVEAL_NO)); 771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Attempt unrevealing the top-of-window views. 811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void AttemptUnreveal() { 821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) revealed_lock_.reset(); 831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ImmersiveModeController* controller() { return controller_; } 864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) private: 884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Not owned. 891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ImmersiveModeController* controller_; 901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<ImmersiveRevealedLock> revealed_lock_; 924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 93f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAshTest); 944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}; 954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Test the layout and visibility of the tabstrip, toolbar and TopContainerView 974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// in immersive fullscreen. 98f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(ImmersiveModeControllerAshTest, Layout) { 994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AddTab(browser(), GURL("about:blank")); 1004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) TabStrip* tabstrip = browser_view()->tabstrip(); 1024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ToolbarView* toolbar = browser_view()->toolbar(); 1034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) views::WebView* contents_web_view = 1044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) browser_view()->GetContentsWebViewForTest(); 1054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Immersive fullscreen starts out disabled. 1074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_FALSE(browser_view()->GetWidget()->IsFullscreen()); 1084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_FALSE(controller()->IsEnabled()); 1094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // By default, the tabstrip and toolbar should be visible. 1114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(tabstrip->visible()); 1124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(toolbar->visible()); 1134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ToggleFullscreen(); 1154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(browser_view()->GetWidget()->IsFullscreen()); 1164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(controller()->IsEnabled()); 1174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(controller()->IsRevealed()); 1184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Entering immersive fullscreen should make the tab strip use the immersive 1204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // style and hide the toolbar. 1214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(tabstrip->visible()); 1224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(tabstrip->IsImmersiveStyle()); 1234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(toolbar->visible()); 1244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // The tab indicators should be flush with the top of the widget. 1264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(0, GetBoundsInWidget(tabstrip).y()); 1274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // The web contents should be immediately below the tab indicators. 1294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(Tab::GetImmersiveHeight(), 1304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) GetBoundsInWidget(contents_web_view).y()); 1314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Revealing the top-of-window views should set the tab strip back to the 1334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // normal style and show the toolbar. 1341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AttemptReveal(); 1354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(controller()->IsRevealed()); 1364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(tabstrip->visible()); 1374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(tabstrip->IsImmersiveStyle()); 1384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(toolbar->visible()); 1394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // The TopContainerView should be flush with the top edge of the widget. If 1414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // it is not flush with the top edge the immersive reveal animation looks 1424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // wonky. 1434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(0, GetBoundsInWidget(browser_view()->top_container()).y()); 1444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // The web contents should be at the same y position as they were when the 1464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // top-of-window views were hidden. 1474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(Tab::GetImmersiveHeight(), 1484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) GetBoundsInWidget(contents_web_view).y()); 1494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Repeat the test for when in both immersive fullscreen and tab fullscreen. 1511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetTabFullscreen(true); 1524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Hide and reveal the top-of-window views so that they get relain out. 1531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AttemptUnreveal(); 1541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AttemptReveal(); 1554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // The tab strip and toolbar should still be visible and the TopContainerView 1574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // should still be flush with the top edge of the widget. 1584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(controller()->IsRevealed()); 1594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(tabstrip->visible()); 1604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(tabstrip->IsImmersiveStyle()); 1614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(toolbar->visible()); 1624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(0, GetBoundsInWidget(browser_view()->top_container()).y()); 1634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // The web contents should be flush with the top edge of the widget when in 1654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // both immersive and tab fullscreen. 1664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(0, GetBoundsInWidget(contents_web_view).y()); 1674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Hide the top-of-window views. Both the tab strip and the toolbar should 1694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // hide when in both immersive and tab fullscreen. 1701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AttemptUnreveal(); 1714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(controller()->IsRevealed()); 1724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(tabstrip->visible()); 1734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(toolbar->visible()); 1744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // The web contents should still be flush with the edge of the widget. 1764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(0, GetBoundsInWidget(contents_web_view).y()); 1774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Exiting both immersive and tab fullscreen should show the tab strip and 1794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // toolbar. 1801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ToggleFullscreen(); 1814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(browser_view()->GetWidget()->IsFullscreen()); 1824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(controller()->IsEnabled()); 1834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(controller()->IsRevealed()); 1844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(tabstrip->visible()); 1854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(tabstrip->IsImmersiveStyle()); 1864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(toolbar->visible()); 1874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 1884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Test that the browser commands which are usually disabled in fullscreen are 1904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// are enabled in immersive fullscreen. 191f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(ImmersiveModeControllerAshTest, EnabledCommands) { 1924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_FALSE(controller()->IsEnabled()); 1934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL)); 1944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ABOUT)); 1954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION)); 1964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ToggleFullscreen(); 1984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(controller()->IsEnabled()); 1994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL)); 2004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ABOUT)); 2014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION)); 2024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 2034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Test that restoring a window properly exits immersive fullscreen. 205f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(ImmersiveModeControllerAshTest, ExitUponRestore) { 2064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_FALSE(controller()->IsEnabled()); 2071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ToggleFullscreen(); 2081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AttemptReveal(); 2094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_TRUE(controller()->IsEnabled()); 2104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_TRUE(controller()->IsRevealed()); 2114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_TRUE(browser_view()->GetWidget()->IsFullscreen()); 2124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) browser_view()->GetWidget()->Restore(); 2144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(controller()->IsEnabled()); 2154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 2164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Test how being simultaneously in tab fullscreen and immersive fullscreen 2181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// affects the shelf visibility and whether the tab indicators are hidden. 219f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(ImmersiveModeControllerAshTest, TabAndBrowserFullscreen) { 2201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AddTab(browser(), GURL("about:blank")); 2211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The shelf should start out as visible. 2231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ash::internal::ShelfLayoutManager* shelf = 2241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ash::Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); 2251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASSERT_EQ(ash::SHELF_VISIBLE, shelf->visibility_state()); 2261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // 1) Test that entering tab fullscreen from immersive fullscreen hides the 2281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // tab indicators and the shelf. 2291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ToggleFullscreen(); 2301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASSERT_TRUE(controller()->IsEnabled()); 2311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(ash::SHELF_AUTO_HIDE, shelf->visibility_state()); 2321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_FALSE(controller()->ShouldHideTabIndicators()); 2331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetTabFullscreen(true); 2351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASSERT_TRUE(controller()->IsEnabled()); 2361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(ash::SHELF_HIDDEN, shelf->visibility_state()); 2371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(controller()->ShouldHideTabIndicators()); 2381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // 2) Test that exiting tab fullscreen shows the tab indicators and autohides 2401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // the shelf. 2411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetTabFullscreen(false); 2421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASSERT_TRUE(controller()->IsEnabled()); 2431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(ash::SHELF_AUTO_HIDE, shelf->visibility_state()); 2441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_FALSE(controller()->ShouldHideTabIndicators()); 2451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // 3) Test that exiting tab fullscreen and immersive fullscreen 2471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // simultaneously correctly updates the shelf visibility and whether the tab 2481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // indicators should be hidden. 2491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetTabFullscreen(true); 2501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ToggleFullscreen(); 2511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASSERT_FALSE(controller()->IsEnabled()); 2521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(ash::SHELF_VISIBLE, shelf->visibility_state()); 2531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(controller()->ShouldHideTabIndicators()); 2541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 2551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 256a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class ImmersiveModeControllerAshTestHostedApp 257a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) : public ImmersiveModeControllerAshTest { 258a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public: 259a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ImmersiveModeControllerAshTestHostedApp() {} 260a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual ~ImmersiveModeControllerAshTestHostedApp() {} 261a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 262a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // ImmersiveModeControllerAshTest override: 263a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual void SetUp() OVERRIDE { 264a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) CommandLine::ForCurrentProcess()->AppendSwitch( 265a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::switches::kAshEnableImmersiveFullscreenForAllWindows); 266a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ImmersiveModeControllerAshTest::SetUp(); 267a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 268a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 269a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // BrowserWithTestWindowTest override: 270a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual Browser* CreateBrowser(Profile* profile, 271a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) chrome::HostDesktopType host_desktop_type, 272a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) BrowserWindow* browser_window) OVERRIDE { 273a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) Browser::CreateParams params(profile, host_desktop_type); 274a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) params.type = Browser::TYPE_POPUP; 275a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) params.app_name = "Test"; 276a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) params.window = browser_window; 277a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return new Browser(params); 278a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 279a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 280a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) private: 281a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAshTestHostedApp); 282a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}; 283a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 284a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Test the layout and visibility of the TopContainerView and web contents when 285a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// a hosted app is put into immersive fullscreen. 286a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)TEST_F(ImmersiveModeControllerAshTestHostedApp, Layout) { 287a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Add a tab because the browser starts out without any tabs at all. 288a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) AddTab(browser(), GURL("about:blank")); 289a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 290a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) TabStrip* tabstrip = browser_view()->tabstrip(); 291a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ToolbarView* toolbar = browser_view()->toolbar(); 292a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) views::WebView* contents_web_view = 293a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) browser_view()->GetContentsWebViewForTest(); 294a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) views::View* top_container = browser_view()->top_container(); 295a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 296a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Immersive fullscreen starts out disabled. 297a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_FALSE(browser_view()->GetWidget()->IsFullscreen()); 298a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_FALSE(controller()->IsEnabled()); 299a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 300a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The tabstrip and toolbar are not visible for hosted apps. 301a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(tabstrip->visible()); 302a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(toolbar->visible()); 303a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 304a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The window header should be above the web contents. 305a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) int header_height = GetBoundsInWidget(contents_web_view).y(); 306a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 307a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ToggleFullscreen(); 308a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(browser_view()->GetWidget()->IsFullscreen()); 309a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(controller()->IsEnabled()); 310a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(controller()->IsRevealed()); 311a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 312a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Entering immersive fullscreen should make the web contents flush with the 313a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // top of the widget. 314a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(tabstrip->visible()); 315a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(toolbar->visible()); 316a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(top_container->GetVisibleBounds().IsEmpty()); 317a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(0, GetBoundsInWidget(contents_web_view).y()); 318a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 319a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Reveal the window header. 320a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) AttemptReveal(); 321a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 322a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The tabstrip and toolbar should still be hidden and the web contents should 323a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // still be flush with the top of the screen. 324a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(tabstrip->visible()); 325a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(toolbar->visible()); 326a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(0, GetBoundsInWidget(contents_web_view).y()); 327a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 328a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // During an immersive reveal, the window header should be painted to the 329a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // TopContainerView. The TopContainerView should be flush with the top of the 330a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // widget and have |header_height|. 331a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) gfx::Rect top_container_bounds_in_widget(GetBoundsInWidget(top_container)); 332a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(0, top_container_bounds_in_widget.y()); 333a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(header_height, top_container_bounds_in_widget.height()); 334a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 335a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Exit immersive fullscreen. The web contents should be back below the window 336a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // header. 337a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ToggleFullscreen(); 338a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(browser_view()->GetWidget()->IsFullscreen()); 339a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(controller()->IsEnabled()); 340a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(tabstrip->visible()); 341a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(toolbar->visible()); 342a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(header_height, GetBoundsInWidget(contents_web_view).y()); 343a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 344a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 34590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif // defined(OS_CHROMEOS) 346