This source file includes following definitions.
- CanMaximize
- IsInImmersiveFullscreen
- IN_PROC_BROWSER_TEST_F
- initial_show_state_
- SetToInitialShowState
- IsInitialShowState
- put_window_in_immersive
- IN_PROC_BROWSER_TEST_P
- initial_show_state_
- SetToInitialShowState
- IsInitialShowState
- put_window_in_immersive
- IN_PROC_BROWSER_TEST_P
#include "ash/accelerators/accelerator_commands.h"
#include "apps/app_window.h"
#include "apps/ui/native_app_window.h"
#include "ash/ash_switches.h"
#include "ash/shell.h"
#include "ash/wm/window_state.h"
#include "base/command_line.h"
#include "chrome/browser/apps/app_browsertest_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/test_switches.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
using testing::Combine;
using testing::Values;
using testing::WithParamInterface;
namespace {
class MaximizableWidgetDelegate : public views::WidgetDelegateView {
public:
MaximizableWidgetDelegate() {
}
virtual ~MaximizableWidgetDelegate() {
}
virtual bool CanMaximize() const OVERRIDE {
return true;
}
private:
DISALLOW_COPY_AND_ASSIGN(MaximizableWidgetDelegate);
};
bool IsInImmersiveFullscreen(ash::wm::WindowState* window_state) {
return window_state->IsFullscreen() &&
!window_state->hide_shelf_when_fullscreen();
}
}
typedef InProcessBrowserTest AcceleratorCommandsBrowserTest;
IN_PROC_BROWSER_TEST_F(AcceleratorCommandsBrowserTest, ToggleMaximized) {
#if defined(OS_WIN)
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
return;
#endif
ASSERT_TRUE(ash::Shell::HasInstance()) << "No Instance";
ash::wm::WindowState* window_state = ash::wm::GetActiveWindowState();
ASSERT_TRUE(window_state);
EXPECT_FALSE(window_state->IsMaximized());
ash::accelerators::ToggleMaximized();
EXPECT_TRUE(window_state->IsMaximized());
ash::accelerators::ToggleMaximized();
EXPECT_FALSE(window_state->IsMaximized());
EXPECT_FALSE(window_state->IsFullscreen());
Browser* browser = chrome::FindBrowserWithWindow(window_state->window());
ASSERT_TRUE(browser);
chrome::ToggleFullscreenMode(browser);
EXPECT_TRUE(window_state->IsFullscreen());
ash::accelerators::ToggleMaximized();
EXPECT_FALSE(window_state->IsFullscreen());
EXPECT_FALSE(window_state->IsMaximized());
ash::accelerators::ToggleMaximized();
EXPECT_FALSE(window_state->IsFullscreen());
EXPECT_TRUE(window_state->IsMaximized());
}
class AcceleratorCommandsFullscreenBrowserTest
: public WithParamInterface<ui::WindowShowState>,
public InProcessBrowserTest {
public:
AcceleratorCommandsFullscreenBrowserTest()
#if defined(OS_CHROMEOS)
: put_window_in_immersive_(true),
#else
: put_window_in_immersive_(false),
#endif
initial_show_state_(GetParam()) {
}
virtual ~AcceleratorCommandsFullscreenBrowserTest() {
}
void SetToInitialShowState(ash::wm::WindowState* window_state) {
if (initial_show_state_ == ui::SHOW_STATE_MAXIMIZED)
window_state->Maximize();
else
window_state->Restore();
}
bool IsInitialShowState(const ash::wm::WindowState* window_state) const {
if (initial_show_state_ == ui::SHOW_STATE_MAXIMIZED)
return window_state->IsMaximized();
else
return window_state->IsNormalStateType();
}
bool put_window_in_immersive() const {
return put_window_in_immersive_;
}
private:
bool put_window_in_immersive_;
ui::WindowShowState initial_show_state_;
DISALLOW_COPY_AND_ASSIGN(AcceleratorCommandsFullscreenBrowserTest);
};
IN_PROC_BROWSER_TEST_P(AcceleratorCommandsFullscreenBrowserTest,
ToggleFullscreen) {
#if defined(OS_WIN)
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
return;
#endif
ASSERT_TRUE(ash::Shell::HasInstance()) << "No Instance";
ASSERT_TRUE(browser()->is_type_tabbed());
ash::wm::WindowState* window_state =
ash::wm::GetWindowState(browser()->window()->GetNativeWindow());
ASSERT_TRUE(window_state->IsActive());
SetToInitialShowState(window_state);
EXPECT_TRUE(IsInitialShowState(window_state));
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(window_state->IsFullscreen());
EXPECT_EQ(put_window_in_immersive(), IsInImmersiveFullscreen(window_state));
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(IsInitialShowState(window_state));
window_state->window()->SetProperty(aura::client::kCanMaximizeKey, false);
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(IsInitialShowState(window_state));
Browser::CreateParams browser_create_params(Browser::TYPE_POPUP,
browser()->profile(), chrome::HOST_DESKTOP_TYPE_ASH);
browser_create_params.app_name = "Test";
Browser* app_host_browser = new Browser(browser_create_params);
ASSERT_TRUE(app_host_browser->is_app());
AddBlankTabAndShow(app_host_browser);
window_state =
ash::wm::GetWindowState(app_host_browser->window()->GetNativeWindow());
ASSERT_TRUE(window_state->IsActive());
SetToInitialShowState(window_state);
EXPECT_TRUE(IsInitialShowState(window_state));
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(window_state->IsFullscreen());
EXPECT_EQ(put_window_in_immersive(), IsInImmersiveFullscreen(window_state));
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(IsInitialShowState(window_state));
browser_create_params.app_name = "";
Browser* popup_browser = new Browser(browser_create_params);
ASSERT_TRUE(popup_browser->is_type_popup());
ASSERT_FALSE(popup_browser->is_app());
AddBlankTabAndShow(popup_browser);
window_state =
ash::wm::GetWindowState(popup_browser->window()->GetNativeWindow());
ASSERT_TRUE(window_state->IsActive());
SetToInitialShowState(window_state);
EXPECT_TRUE(IsInitialShowState(window_state));
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(window_state->IsFullscreen());
EXPECT_EQ(put_window_in_immersive(), IsInImmersiveFullscreen(window_state));
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(IsInitialShowState(window_state));
views::Widget::InitParams params;
params.delegate = new MaximizableWidgetDelegate();
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
scoped_ptr<views::Widget> widget(new views::Widget);
widget->Init(params);
widget->Show();
window_state = ash::wm::GetWindowState(widget->GetNativeWindow());
ASSERT_TRUE(window_state->IsActive());
SetToInitialShowState(window_state);
EXPECT_TRUE(IsInitialShowState(window_state));
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(window_state->IsFullscreen());
EXPECT_EQ(put_window_in_immersive(), IsInImmersiveFullscreen(window_state));
ash::accelerators::ToggleFullscreen();
EXPECT_FALSE(window_state->IsFullscreen());
}
INSTANTIATE_TEST_CASE_P(InitiallyRestored,
AcceleratorCommandsFullscreenBrowserTest,
Values(ui::SHOW_STATE_NORMAL));
INSTANTIATE_TEST_CASE_P(InitiallyMaximized,
AcceleratorCommandsFullscreenBrowserTest,
Values(ui::SHOW_STATE_MAXIMIZED));
class AcceleratorCommandsPlatformAppFullscreenBrowserTest
: public WithParamInterface<ui::WindowShowState>,
public extensions::PlatformAppBrowserTest {
public:
AcceleratorCommandsPlatformAppFullscreenBrowserTest()
#if defined(OS_CHROMEOS)
: put_window_in_immersive_(true),
#else
: put_window_in_immersive_(false),
#endif
initial_show_state_(GetParam()) {
}
virtual ~AcceleratorCommandsPlatformAppFullscreenBrowserTest() {
}
void SetToInitialShowState(apps::AppWindow* app_window) {
if (initial_show_state_ == ui::SHOW_STATE_MAXIMIZED)
app_window->Maximize();
else
app_window->Restore();
}
bool IsInitialShowState(apps::AppWindow* app_window) const {
if (initial_show_state_ == ui::SHOW_STATE_MAXIMIZED)
return app_window->GetBaseWindow()->IsMaximized();
else
return ui::BaseWindow::IsRestored(*app_window->GetBaseWindow());
}
bool put_window_in_immersive() const {
return put_window_in_immersive_;
}
private:
bool put_window_in_immersive_;
ui::WindowShowState initial_show_state_;
DISALLOW_COPY_AND_ASSIGN(AcceleratorCommandsPlatformAppFullscreenBrowserTest);
};
IN_PROC_BROWSER_TEST_P(AcceleratorCommandsPlatformAppFullscreenBrowserTest,
ToggleFullscreen) {
#if defined(OS_WIN)
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
return;
#endif
ASSERT_TRUE(ash::Shell::HasInstance()) << "No Instance";
const extensions::Extension* extension = LoadAndLaunchPlatformApp("minimal");
{
apps::AppWindow::CreateParams params;
params.frame = apps::AppWindow::FRAME_CHROME;
apps::AppWindow* app_window = CreateAppWindowFromParams(extension, params);
apps::NativeAppWindow* native_app_window = app_window->GetBaseWindow();
SetToInitialShowState(app_window);
ASSERT_TRUE(app_window->GetBaseWindow()->IsActive());
EXPECT_TRUE(IsInitialShowState(app_window));
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(native_app_window->IsFullscreen());
ash::wm::WindowState* window_state =
ash::wm::GetWindowState(native_app_window->GetNativeWindow());
EXPECT_EQ(put_window_in_immersive(),
IsInImmersiveFullscreen(window_state));
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(IsInitialShowState(app_window));
CloseAppWindow(app_window);
}
{
apps::AppWindow::CreateParams params;
params.frame = apps::AppWindow::FRAME_NONE;
apps::AppWindow* app_window = CreateAppWindowFromParams(extension, params);
apps::NativeAppWindow* native_app_window = app_window->GetBaseWindow();
ASSERT_TRUE(app_window->GetBaseWindow()->IsActive());
SetToInitialShowState(app_window);
EXPECT_TRUE(IsInitialShowState(app_window));
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(native_app_window->IsFullscreen());
ash::wm::WindowState* window_state =
ash::wm::GetWindowState(native_app_window->GetNativeWindow());
EXPECT_FALSE(IsInImmersiveFullscreen(window_state));
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(IsInitialShowState(app_window));
CloseAppWindow(app_window);
}
}
INSTANTIATE_TEST_CASE_P(InitiallyRestored,
AcceleratorCommandsPlatformAppFullscreenBrowserTest,
Values(ui::SHOW_STATE_NORMAL));
INSTANTIATE_TEST_CASE_P(InitiallyMaximized,
AcceleratorCommandsPlatformAppFullscreenBrowserTest,
Values(ui::SHOW_STATE_MAXIMIZED));