This source file includes following definitions.
- SetUp
- GetBoundsInWidget
- ToggleFullscreen
- SetTabFullscreen
- AttemptReveal
- AttemptUnreveal
- controller
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h"
#include "ash/ash_switches.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_types.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "base/command_line.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
#include "chrome/browser/ui/fullscreen/fullscreen_controller_test.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/test_with_browser_view.h"
#include "chrome/browser/ui/views/frame/top_container_view.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "ui/aura/window.h"
#include "ui/views/controls/webview/webview.h"
class ImmersiveModeControllerAshTest : public TestWithBrowserView {
public:
ImmersiveModeControllerAshTest()
: TestWithBrowserView(Browser::TYPE_TABBED,
chrome::HOST_DESKTOP_TYPE_ASH,
false) {
}
ImmersiveModeControllerAshTest(
Browser::Type browser_type,
chrome::HostDesktopType host_desktop_type,
bool hosted_app)
: TestWithBrowserView(browser_type,
host_desktop_type,
hosted_app) {
}
virtual ~ImmersiveModeControllerAshTest() {}
virtual void SetUp() OVERRIDE {
TestWithBrowserView::SetUp();
browser()->window()->Show();
controller_ = browser_view()->immersive_mode_controller();
controller_->SetupForTest();
}
gfx::Rect GetBoundsInWidget(views::View* view) {
return view->ConvertRectToWidget(view->GetLocalBounds());
}
void ToggleFullscreen() {
scoped_ptr<FullscreenNotificationObserver> waiter(
new FullscreenNotificationObserver());
chrome::ToggleFullscreenMode(browser());
waiter->Wait();
}
void SetTabFullscreen(bool tab_fullscreen) {
content::WebContents* web_contents =
browser_view()->GetContentsWebViewForTest()->GetWebContents();
scoped_ptr<FullscreenNotificationObserver> waiter(
new FullscreenNotificationObserver());
browser()->fullscreen_controller()->ToggleFullscreenModeForTab(
web_contents, tab_fullscreen);
waiter->Wait();
}
void AttemptReveal() {
if (!revealed_lock_.get()) {
revealed_lock_.reset(controller_->GetRevealedLock(
ImmersiveModeControllerAsh::ANIMATE_REVEAL_NO));
}
}
void AttemptUnreveal() {
revealed_lock_.reset();
}
ImmersiveModeController* controller() { return controller_; }
private:
ImmersiveModeController* controller_;
scoped_ptr<ImmersiveRevealedLock> revealed_lock_;
DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAshTest);
};
TEST_F(ImmersiveModeControllerAshTest, Layout) {
AddTab(browser(), GURL("about:blank"));
TabStrip* tabstrip = browser_view()->tabstrip();
ToolbarView* toolbar = browser_view()->toolbar();
views::WebView* contents_web_view =
browser_view()->GetContentsWebViewForTest();
ASSERT_FALSE(browser_view()->GetWidget()->IsFullscreen());
ASSERT_FALSE(controller()->IsEnabled());
EXPECT_TRUE(tabstrip->visible());
EXPECT_TRUE(toolbar->visible());
ToggleFullscreen();
EXPECT_TRUE(browser_view()->GetWidget()->IsFullscreen());
EXPECT_TRUE(controller()->IsEnabled());
EXPECT_FALSE(controller()->IsRevealed());
EXPECT_TRUE(tabstrip->visible());
EXPECT_TRUE(tabstrip->IsImmersiveStyle());
EXPECT_FALSE(toolbar->visible());
EXPECT_EQ(0, GetBoundsInWidget(tabstrip).y());
EXPECT_EQ(Tab::GetImmersiveHeight(),
GetBoundsInWidget(contents_web_view).y());
AttemptReveal();
EXPECT_TRUE(controller()->IsRevealed());
EXPECT_TRUE(tabstrip->visible());
EXPECT_FALSE(tabstrip->IsImmersiveStyle());
EXPECT_TRUE(toolbar->visible());
EXPECT_EQ(0, GetBoundsInWidget(browser_view()->top_container()).y());
EXPECT_EQ(Tab::GetImmersiveHeight(),
GetBoundsInWidget(contents_web_view).y());
SetTabFullscreen(true);
AttemptUnreveal();
AttemptReveal();
EXPECT_TRUE(controller()->IsRevealed());
EXPECT_TRUE(tabstrip->visible());
EXPECT_FALSE(tabstrip->IsImmersiveStyle());
EXPECT_TRUE(toolbar->visible());
EXPECT_EQ(0, GetBoundsInWidget(browser_view()->top_container()).y());
EXPECT_EQ(0, GetBoundsInWidget(contents_web_view).y());
AttemptUnreveal();
EXPECT_FALSE(controller()->IsRevealed());
EXPECT_FALSE(tabstrip->visible());
EXPECT_FALSE(toolbar->visible());
EXPECT_EQ(0, GetBoundsInWidget(contents_web_view).y());
ToggleFullscreen();
EXPECT_FALSE(browser_view()->GetWidget()->IsFullscreen());
EXPECT_FALSE(controller()->IsEnabled());
EXPECT_FALSE(controller()->IsRevealed());
EXPECT_TRUE(tabstrip->visible());
EXPECT_FALSE(tabstrip->IsImmersiveStyle());
EXPECT_TRUE(toolbar->visible());
}
TEST_F(ImmersiveModeControllerAshTest, EnabledCommands) {
ASSERT_FALSE(controller()->IsEnabled());
EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL));
EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ABOUT));
EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION));
ToggleFullscreen();
EXPECT_TRUE(controller()->IsEnabled());
EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL));
EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ABOUT));
EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION));
}
TEST_F(ImmersiveModeControllerAshTest, ExitUponRestore) {
ASSERT_FALSE(controller()->IsEnabled());
ToggleFullscreen();
AttemptReveal();
ASSERT_TRUE(controller()->IsEnabled());
ASSERT_TRUE(controller()->IsRevealed());
ASSERT_TRUE(browser_view()->GetWidget()->IsFullscreen());
browser_view()->GetWidget()->Restore();
EXPECT_FALSE(controller()->IsEnabled());
}
TEST_F(ImmersiveModeControllerAshTest, TabAndBrowserFullscreen) {
AddTab(browser(), GURL("about:blank"));
ash::ShelfLayoutManager* shelf =
ash::Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
ASSERT_EQ(ash::SHELF_VISIBLE, shelf->visibility_state());
ToggleFullscreen();
ASSERT_TRUE(controller()->IsEnabled());
EXPECT_EQ(ash::SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_FALSE(controller()->ShouldHideTabIndicators());
SetTabFullscreen(true);
ASSERT_TRUE(controller()->IsEnabled());
EXPECT_EQ(ash::SHELF_HIDDEN, shelf->visibility_state());
EXPECT_TRUE(controller()->ShouldHideTabIndicators());
SetTabFullscreen(false);
ASSERT_TRUE(controller()->IsEnabled());
EXPECT_EQ(ash::SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_FALSE(controller()->ShouldHideTabIndicators());
SetTabFullscreen(true);
ToggleFullscreen();
ASSERT_FALSE(controller()->IsEnabled());
EXPECT_EQ(ash::SHELF_VISIBLE, shelf->visibility_state());
EXPECT_TRUE(controller()->ShouldHideTabIndicators());
}
class ImmersiveModeControllerAshTestHostedApp
: public ImmersiveModeControllerAshTest {
public:
ImmersiveModeControllerAshTestHostedApp()
: ImmersiveModeControllerAshTest(Browser::TYPE_POPUP,
chrome::HOST_DESKTOP_TYPE_ASH,
true) {
}
virtual ~ImmersiveModeControllerAshTestHostedApp() {}
private:
DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAshTestHostedApp);
};
TEST_F(ImmersiveModeControllerAshTestHostedApp, Layout) {
AddTab(browser(), GURL("about:blank"));
TabStrip* tabstrip = browser_view()->tabstrip();
ToolbarView* toolbar = browser_view()->toolbar();
views::WebView* contents_web_view =
browser_view()->GetContentsWebViewForTest();
views::View* top_container = browser_view()->top_container();
ASSERT_FALSE(browser_view()->GetWidget()->IsFullscreen());
ASSERT_FALSE(controller()->IsEnabled());
EXPECT_FALSE(tabstrip->visible());
EXPECT_FALSE(toolbar->visible());
int header_height = GetBoundsInWidget(contents_web_view).y();
ToggleFullscreen();
EXPECT_TRUE(browser_view()->GetWidget()->IsFullscreen());
EXPECT_TRUE(controller()->IsEnabled());
EXPECT_FALSE(controller()->IsRevealed());
EXPECT_FALSE(tabstrip->visible());
EXPECT_FALSE(toolbar->visible());
EXPECT_TRUE(top_container->GetVisibleBounds().IsEmpty());
EXPECT_EQ(0, GetBoundsInWidget(contents_web_view).y());
AttemptReveal();
EXPECT_FALSE(tabstrip->visible());
EXPECT_FALSE(toolbar->visible());
EXPECT_EQ(0, GetBoundsInWidget(contents_web_view).y());
gfx::Rect top_container_bounds_in_widget(GetBoundsInWidget(top_container));
EXPECT_EQ(0, top_container_bounds_in_widget.y());
EXPECT_EQ(header_height, top_container_bounds_in_widget.height());
ToggleFullscreen();
EXPECT_FALSE(browser_view()->GetWidget()->IsFullscreen());
EXPECT_FALSE(controller()->IsEnabled());
EXPECT_FALSE(tabstrip->visible());
EXPECT_FALSE(toolbar->visible());
EXPECT_EQ(header_height, GetBoundsInWidget(contents_web_view).y());
}