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) 590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h" 690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ash/ash_switches.h" 81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ash/root_window_controller.h" 91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ash/shelf/shelf_layout_manager.h" 101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ash/shelf/shelf_types.h" 11bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "ash/shell.h" 1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ash/test/ash_test_base.h" 13a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/command_line.h" 144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/app/chrome_command_ids.h" 154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/browser_commands.h" 164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/fullscreen/fullscreen_controller.h" 174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/fullscreen/fullscreen_controller_test.h" 184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/views/frame/browser_view.h" 194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/views/frame/test_with_browser_view.h" 204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/views/frame/top_container_view.h" 214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/views/tabs/tab_strip.h" 22f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/ui/views/toolbar/toolbar_view.h" 2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/aura/window.h" 244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/views/controls/webview/webview.h" 2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 26f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class ImmersiveModeControllerAshTest : public TestWithBrowserView { 2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public: 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ImmersiveModeControllerAshTest() 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : TestWithBrowserView(Browser::TYPE_TABBED, 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) chrome::HOST_DESKTOP_TYPE_ASH, 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) false) { 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ImmersiveModeControllerAshTest( 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Browser::Type browser_type, 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) chrome::HostDesktopType host_desktop_type, 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool hosted_app) 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : TestWithBrowserView(browser_type, 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) host_desktop_type, 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) hosted_app) { 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual ~ImmersiveModeControllerAshTest() {} 4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // TestWithBrowserView override: 444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual void SetUp() OVERRIDE { 454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) TestWithBrowserView::SetUp(); 464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) browser()->window()->Show(); 484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) controller_ = browser_view()->immersive_mode_controller(); 501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) controller_->SetupForTest(); 514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Returns the bounds of |view| in widget coordinates. 544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect GetBoundsInWidget(views::View* view) { 554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return view->ConvertRectToWidget(view->GetLocalBounds()); 564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Toggle the browser's fullscreen state. 591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void ToggleFullscreen() { 601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // NOTIFICATION_FULLSCREEN_CHANGED is sent asynchronously. The notification 611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // is used to trigger changes in whether the shelf is auto hidden and 621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // whether a "light bar" version of the tab strip is used when the 631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // top-of-window views are hidden. 641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<FullscreenNotificationObserver> waiter( 651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new FullscreenNotificationObserver()); 661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) chrome::ToggleFullscreenMode(browser()); 671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) waiter->Wait(); 681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Set whether the browser is in tab fullscreen. 711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void SetTabFullscreen(bool tab_fullscreen) { 721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) content::WebContents* web_contents = 731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) browser_view()->GetContentsWebViewForTest()->GetWebContents(); 741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<FullscreenNotificationObserver> waiter( 751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new FullscreenNotificationObserver()); 761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) browser()->fullscreen_controller()->ToggleFullscreenModeForTab( 771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) web_contents, tab_fullscreen); 781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) waiter->Wait(); 791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Attempt revealing the top-of-window views. 821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void AttemptReveal() { 831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (!revealed_lock_.get()) { 841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) revealed_lock_.reset(controller_->GetRevealedLock( 851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ImmersiveModeControllerAsh::ANIMATE_REVEAL_NO)); 861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Attempt unrevealing the top-of-window views. 901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void AttemptUnreveal() { 911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) revealed_lock_.reset(); 921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ImmersiveModeController* controller() { return controller_; } 954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) private: 974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Not owned. 981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ImmersiveModeController* controller_; 991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<ImmersiveRevealedLock> revealed_lock_; 1014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 102f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAshTest); 1034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}; 1044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Test the layout and visibility of the tabstrip, toolbar and TopContainerView 1064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// in immersive fullscreen. 107f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(ImmersiveModeControllerAshTest, Layout) { 1084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AddTab(browser(), GURL("about:blank")); 1094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) TabStrip* tabstrip = browser_view()->tabstrip(); 1114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ToolbarView* toolbar = browser_view()->toolbar(); 1124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) views::WebView* contents_web_view = 1134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) browser_view()->GetContentsWebViewForTest(); 1144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Immersive fullscreen starts out disabled. 1164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_FALSE(browser_view()->GetWidget()->IsFullscreen()); 1174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_FALSE(controller()->IsEnabled()); 1184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // By default, the tabstrip and toolbar should be visible. 1204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(tabstrip->visible()); 1214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(toolbar->visible()); 1224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ToggleFullscreen(); 1244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(browser_view()->GetWidget()->IsFullscreen()); 1254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(controller()->IsEnabled()); 1264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(controller()->IsRevealed()); 1274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Entering immersive fullscreen should make the tab strip use the immersive 1294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // style and hide the toolbar. 1304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(tabstrip->visible()); 1314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(tabstrip->IsImmersiveStyle()); 1324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(toolbar->visible()); 1334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // The tab indicators should be flush with the top of the widget. 1354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(0, GetBoundsInWidget(tabstrip).y()); 1364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // The web contents should be immediately below the tab indicators. 1384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(Tab::GetImmersiveHeight(), 1394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) GetBoundsInWidget(contents_web_view).y()); 1404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Revealing the top-of-window views should set the tab strip back to the 1424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // normal style and show the toolbar. 1431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AttemptReveal(); 1444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(controller()->IsRevealed()); 1454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(tabstrip->visible()); 1464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(tabstrip->IsImmersiveStyle()); 1474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(toolbar->visible()); 1484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // The TopContainerView should be flush with the top edge of the widget. If 1504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // it is not flush with the top edge the immersive reveal animation looks 1514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // wonky. 1524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(0, GetBoundsInWidget(browser_view()->top_container()).y()); 1534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // The web contents should be at the same y position as they were when the 1554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // top-of-window views were hidden. 1564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(Tab::GetImmersiveHeight(), 1574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) GetBoundsInWidget(contents_web_view).y()); 1584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Repeat the test for when in both immersive fullscreen and tab fullscreen. 1601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetTabFullscreen(true); 1614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Hide and reveal the top-of-window views so that they get relain out. 1621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AttemptUnreveal(); 1631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AttemptReveal(); 1644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // The tab strip and toolbar should still be visible and the TopContainerView 1664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // should still be flush with the top edge of the widget. 1674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(controller()->IsRevealed()); 1684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(tabstrip->visible()); 1694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(tabstrip->IsImmersiveStyle()); 1704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(toolbar->visible()); 1714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(0, GetBoundsInWidget(browser_view()->top_container()).y()); 1724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // The web contents should be flush with the top edge of the widget when in 1744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // both immersive and tab fullscreen. 1754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(0, GetBoundsInWidget(contents_web_view).y()); 1764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Hide the top-of-window views. Both the tab strip and the toolbar should 1784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // hide when in both immersive and tab fullscreen. 1791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AttemptUnreveal(); 1804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(controller()->IsRevealed()); 1814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(tabstrip->visible()); 1824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(toolbar->visible()); 1834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // The web contents should still be flush with the edge of the widget. 1854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(0, GetBoundsInWidget(contents_web_view).y()); 1864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Exiting both immersive and tab fullscreen should show the tab strip and 1884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // toolbar. 1891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ToggleFullscreen(); 1904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(browser_view()->GetWidget()->IsFullscreen()); 1914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(controller()->IsEnabled()); 1924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(controller()->IsRevealed()); 1934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(tabstrip->visible()); 1944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(tabstrip->IsImmersiveStyle()); 1954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(toolbar->visible()); 1964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 1974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Test that the browser commands which are usually disabled in fullscreen are 1994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// are enabled in immersive fullscreen. 200f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(ImmersiveModeControllerAshTest, EnabledCommands) { 2014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_FALSE(controller()->IsEnabled()); 2024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL)); 2034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ABOUT)); 2044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION)); 2054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ToggleFullscreen(); 2074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(controller()->IsEnabled()); 2084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL)); 2094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ABOUT)); 2104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION)); 2114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 2124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Test that restoring a window properly exits immersive fullscreen. 214f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(ImmersiveModeControllerAshTest, ExitUponRestore) { 2154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_FALSE(controller()->IsEnabled()); 2161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ToggleFullscreen(); 2171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AttemptReveal(); 2184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_TRUE(controller()->IsEnabled()); 2194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_TRUE(controller()->IsRevealed()); 2204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_TRUE(browser_view()->GetWidget()->IsFullscreen()); 2214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) browser_view()->GetWidget()->Restore(); 2234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(controller()->IsEnabled()); 2244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 2254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Test how being simultaneously in tab fullscreen and immersive fullscreen 2271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// affects the shelf visibility and whether the tab indicators are hidden. 228f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(ImmersiveModeControllerAshTest, TabAndBrowserFullscreen) { 2291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AddTab(browser(), GURL("about:blank")); 2301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The shelf should start out as visible. 232c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch ash::ShelfLayoutManager* shelf = 2331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ash::Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); 2341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASSERT_EQ(ash::SHELF_VISIBLE, shelf->visibility_state()); 2351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // 1) Test that entering tab fullscreen from immersive fullscreen hides the 2371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // tab indicators and the shelf. 2381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ToggleFullscreen(); 2391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASSERT_TRUE(controller()->IsEnabled()); 2401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(ash::SHELF_AUTO_HIDE, shelf->visibility_state()); 2411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_FALSE(controller()->ShouldHideTabIndicators()); 2421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetTabFullscreen(true); 2441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASSERT_TRUE(controller()->IsEnabled()); 2451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(ash::SHELF_HIDDEN, shelf->visibility_state()); 2461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(controller()->ShouldHideTabIndicators()); 2471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // 2) Test that exiting tab fullscreen shows the tab indicators and autohides 2491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // the shelf. 2501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetTabFullscreen(false); 2511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASSERT_TRUE(controller()->IsEnabled()); 2521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(ash::SHELF_AUTO_HIDE, shelf->visibility_state()); 2531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_FALSE(controller()->ShouldHideTabIndicators()); 2541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // 3) Test that exiting tab fullscreen and immersive fullscreen 2561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // simultaneously correctly updates the shelf visibility and whether the tab 2571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // indicators should be hidden. 2581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetTabFullscreen(true); 2591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ToggleFullscreen(); 2601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASSERT_FALSE(controller()->IsEnabled()); 2611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(ash::SHELF_VISIBLE, shelf->visibility_state()); 2621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(controller()->ShouldHideTabIndicators()); 2631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 2641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 265a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class ImmersiveModeControllerAshTestHostedApp 266a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) : public ImmersiveModeControllerAshTest { 267a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public: 2685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ImmersiveModeControllerAshTestHostedApp() 2695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : ImmersiveModeControllerAshTest(Browser::TYPE_POPUP, 2705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) chrome::HOST_DESKTOP_TYPE_ASH, 2715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) true) { 2725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 273a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual ~ImmersiveModeControllerAshTestHostedApp() {} 274a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 275a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) private: 276a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAshTestHostedApp); 277a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}; 278a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 279a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Test the layout and visibility of the TopContainerView and web contents when 280a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// a hosted app is put into immersive fullscreen. 281a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)TEST_F(ImmersiveModeControllerAshTestHostedApp, Layout) { 282a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Add a tab because the browser starts out without any tabs at all. 283a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) AddTab(browser(), GURL("about:blank")); 284a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 285a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) TabStrip* tabstrip = browser_view()->tabstrip(); 286a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ToolbarView* toolbar = browser_view()->toolbar(); 287a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) views::WebView* contents_web_view = 288a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) browser_view()->GetContentsWebViewForTest(); 289a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) views::View* top_container = browser_view()->top_container(); 290a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 291a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Immersive fullscreen starts out disabled. 292a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_FALSE(browser_view()->GetWidget()->IsFullscreen()); 293a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_FALSE(controller()->IsEnabled()); 294a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 295a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The tabstrip and toolbar are not visible for hosted apps. 296a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(tabstrip->visible()); 297a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(toolbar->visible()); 298a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 299a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The window header should be above the web contents. 300a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) int header_height = GetBoundsInWidget(contents_web_view).y(); 301a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 302a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ToggleFullscreen(); 303a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(browser_view()->GetWidget()->IsFullscreen()); 304a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(controller()->IsEnabled()); 305a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(controller()->IsRevealed()); 306a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 307a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Entering immersive fullscreen should make the web contents flush with the 308a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // top of the widget. 309a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(tabstrip->visible()); 310a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(toolbar->visible()); 311a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(top_container->GetVisibleBounds().IsEmpty()); 312a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(0, GetBoundsInWidget(contents_web_view).y()); 313a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 314a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Reveal the window header. 315a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) AttemptReveal(); 316a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 317a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The tabstrip and toolbar should still be hidden and the web contents should 318a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // still be flush with the top of the screen. 319a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(tabstrip->visible()); 320a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(toolbar->visible()); 321a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(0, GetBoundsInWidget(contents_web_view).y()); 322a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 323a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // During an immersive reveal, the window header should be painted to the 324a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // TopContainerView. The TopContainerView should be flush with the top of the 325a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // widget and have |header_height|. 326a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) gfx::Rect top_container_bounds_in_widget(GetBoundsInWidget(top_container)); 327a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(0, top_container_bounds_in_widget.y()); 328a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(header_height, top_container_bounds_in_widget.height()); 329a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 330a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Exit immersive fullscreen. The web contents should be back below the window 331a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // header. 332a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ToggleFullscreen(); 333a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(browser_view()->GetWidget()->IsFullscreen()); 334a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(controller()->IsEnabled()); 335a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(tabstrip->visible()); 336a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(toolbar->visible()); 337a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(header_height, GetBoundsInWidget(contents_web_view).y()); 338a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 339