immersive_mode_controller_ash_unittest.cc revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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) 790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ash/test/ash_test_base.h" 890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/ui/immersive_fullscreen_configuration.h" 990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/ui/views/frame/top_container_view.h" 1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/aura/root_window.h" 1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/aura/window.h" 1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// For now, immersive fullscreen is Chrome OS only. 1490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if defined(OS_CHROMEOS) 1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)///////////////////////////////////////////////////////////////////////////// 1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class MockImmersiveModeControllerDelegate 1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) : public ImmersiveModeController::Delegate { 2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public: 2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MockImmersiveModeControllerDelegate() : immersive_style_(false) {} 2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual ~MockImmersiveModeControllerDelegate() {} 2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool immersive_style() const { return immersive_style_; } 2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // ImmersiveModeController::Delegate overrides: 2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual BookmarkBarView* GetBookmarkBar() OVERRIDE { return NULL; } 2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual FullscreenController* GetFullscreenController() OVERRIDE { 2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return NULL; 3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void FocusLocationBar() OVERRIDE {} 3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void FullscreenStateChanged() OVERRIDE {} 3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void SetImmersiveStyle(bool immersive) OVERRIDE { 3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) immersive_style_ = immersive; 3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) private: 3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool immersive_style_; 3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(MockImmersiveModeControllerDelegate); 4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)///////////////////////////////////////////////////////////////////////////// 4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class ImmersiveModeControllerAshTest : public ash::test::AshTestBase { 4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public: 4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ImmersiveModeControllerAshTest() : widget_(NULL), top_container_(NULL) {} 4890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual ~ImmersiveModeControllerAshTest() {} 4990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 5090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ImmersiveModeControllerAsh* controller() { return controller_.get(); } 5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MockImmersiveModeControllerDelegate* delegate() { return delegate_.get(); } 5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 5390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // ash::test::AshTestBase overrides: 5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void SetUp() OVERRIDE { 5590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ash::test::AshTestBase::SetUp(); 5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 5790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ImmersiveFullscreenConfiguration::EnableImmersiveFullscreenForTest(); 5890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ASSERT_TRUE(ImmersiveFullscreenConfiguration::UseImmersiveFullscreen()); 5990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 6090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller_.reset(new ImmersiveModeControllerAsh); 6190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) delegate_.reset(new MockImmersiveModeControllerDelegate); 6290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 6390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) widget_ = new views::Widget(); 6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) views::Widget::InitParams params; 6590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) params.context = CurrentContext(); 6690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) widget_->Init(params); 6790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) widget_->Show(); 6890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 6990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) top_container_ = new TopContainerView(NULL); 7090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) widget_->GetContentsView()->AddChildView(top_container_); 7190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller_->Init(delegate_.get(), widget_, top_container_); 7390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 7490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) private: 7690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<ImmersiveModeControllerAsh> controller_; 7790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<MockImmersiveModeControllerDelegate> delegate_; 7890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) views::Widget* widget_; // Owned by the native widget. 7990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) TopContainerView* top_container_; // Owned by |root_view_|. 8090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAshTest); 8190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 8290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 8390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Test of initial state and basic functionality. 8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(ImmersiveModeControllerAshTest, ImmersiveModeControllerAsh) { 8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Initial state. 8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_FALSE(controller()->IsEnabled()); 8790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_FALSE(controller()->ShouldHideTopViews()); 8890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_FALSE(controller()->IsRevealed()); 8990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_FALSE(delegate()->immersive_style()); 9090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Enabling hides the top views. 9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->SetEnabled(true); 9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_TRUE(controller()->IsEnabled()); 9490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_FALSE(controller()->IsRevealed()); 9590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_TRUE(controller()->ShouldHideTopViews()); 9690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_FALSE(controller()->ShouldHideTabIndicators()); 9790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_TRUE(delegate()->immersive_style()); 9890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 9990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Revealing shows the top views. 10090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->StartRevealForTest(true); 10190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_TRUE(controller()->IsRevealed()); 10290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_FALSE(controller()->ShouldHideTopViews()); 10390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Tabs are painting in the normal style during a reveal. 10490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_FALSE(delegate()->immersive_style()); 10590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 10690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 10790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif // defined(OS_CHROMEOS) 108