1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#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 {
// WidgetDelegateView which allows the widget to be maximized.
class MaximizableWidgetDelegate : public views::WidgetDelegateView {
public:
MaximizableWidgetDelegate() {
}
virtual ~MaximizableWidgetDelegate() {
}
virtual bool CanMaximize() const OVERRIDE {
return true;
}
private:
DISALLOW_COPY_AND_ASSIGN(MaximizableWidgetDelegate);
};
// Returns true if |window_state|'s window is in immersive fullscreen. Infer
// whether the window is in immersive fullscreen based on whether the shelf is
// hidden when the window is fullscreen. (This is not quite right because the
// shelf is hidden if a window is in both immersive fullscreen and tab
// fullscreen.)
bool IsInImmersiveFullscreen(ash::wm::WindowState* window_state) {
return window_state->IsFullscreen() &&
!window_state->hide_shelf_when_fullscreen();
}
} // namespace
typedef InProcessBrowserTest AcceleratorCommandsBrowserTest;
// Confirm that toggling window miximized works properly
IN_PROC_BROWSER_TEST_F(AcceleratorCommandsBrowserTest, ToggleMaximized) {
#if defined(OS_WIN)
// Run the test on Win Ash only.
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);
// When not in fullscreen, accelerators::ToggleMaximized toggles Maximized.
EXPECT_FALSE(window_state->IsMaximized());
ash::accelerators::ToggleMaximized();
EXPECT_TRUE(window_state->IsMaximized());
ash::accelerators::ToggleMaximized();
EXPECT_FALSE(window_state->IsMaximized());
// When in fullscreen accelerators::ToggleMaximized gets out of fullscreen.
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()
: initial_show_state_(GetParam()) {
}
virtual ~AcceleratorCommandsFullscreenBrowserTest() {
}
// Sets |window_state|'s show state to |initial_show_state_|.
void SetToInitialShowState(ash::wm::WindowState* window_state) {
if (initial_show_state_ == ui::SHOW_STATE_MAXIMIZED)
window_state->Maximize();
else
window_state->Restore();
}
// Returns true if |window_state|'s show state is |initial_show_state_|.
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();
}
private:
ui::WindowShowState initial_show_state_;
DISALLOW_COPY_AND_ASSIGN(AcceleratorCommandsFullscreenBrowserTest);
};
// Test that toggling window fullscreen works properly.
IN_PROC_BROWSER_TEST_P(AcceleratorCommandsFullscreenBrowserTest,
ToggleFullscreen) {
#if defined(OS_WIN)
// Run the test on Win Ash only.
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
return;
#endif
ASSERT_TRUE(ash::Shell::HasInstance()) << "No Instance";
// 1) Browser windows.
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_TRUE(IsInImmersiveFullscreen(window_state));
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(IsInitialShowState(window_state));
// 2) ToggleFullscreen() should have no effect on windows which cannot be
// maximized.
window_state->window()->SetProperty(aura::client::kCanMaximizeKey, false);
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(IsInitialShowState(window_state));
// 3) Hosted apps.
Browser::CreateParams browser_create_params(
Browser::CreateParams::CreateForApp("Test",
true /* trusted_source */,
gfx::Rect(),
browser()->profile(),
chrome::HOST_DESKTOP_TYPE_ASH));
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_TRUE(IsInImmersiveFullscreen(window_state));
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(IsInitialShowState(window_state));
// 4) Popup browser windows.
browser_create_params = Browser::CreateParams(
Browser::TYPE_POPUP, browser()->profile(), chrome::HOST_DESKTOP_TYPE_ASH);
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_TRUE(IsInImmersiveFullscreen(window_state));
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(IsInitialShowState(window_state));
// 5) Miscellaneous windows (e.g. task manager).
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_TRUE(IsInImmersiveFullscreen(window_state));
// TODO(pkotwicz|oshima): Make toggling fullscreen restore the window to its
// show state prior to entering fullscreen.
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()
: initial_show_state_(GetParam()) {
}
virtual ~AcceleratorCommandsPlatformAppFullscreenBrowserTest() {
}
// Sets |app_window|'s show state to |initial_show_state_|.
void SetToInitialShowState(apps::AppWindow* app_window) {
if (initial_show_state_ == ui::SHOW_STATE_MAXIMIZED)
app_window->Maximize();
else
app_window->Restore();
}
// Returns true if |app_window|'s show state is |initial_show_state_|.
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());
}
private:
ui::WindowShowState initial_show_state_;
DISALLOW_COPY_AND_ASSIGN(AcceleratorCommandsPlatformAppFullscreenBrowserTest);
};
// Test the behavior of platform apps when ToggleFullscreen() is called.
IN_PROC_BROWSER_TEST_P(AcceleratorCommandsPlatformAppFullscreenBrowserTest,
ToggleFullscreen) {
#if defined(OS_WIN)
// Run the test on Win Ash only.
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
return;
#endif
ASSERT_TRUE(ash::Shell::HasInstance()) << "No Instance";
const extensions::Extension* extension = LoadAndLaunchPlatformApp("minimal",
"Launched");
{
// Test that ToggleFullscreen() toggles a platform's app's fullscreen
// state and that it additionally puts the app into immersive fullscreen
// if put_all_windows_in_immersive() returns true.
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_TRUE(IsInImmersiveFullscreen(window_state));
ash::accelerators::ToggleFullscreen();
EXPECT_TRUE(IsInitialShowState(app_window));
CloseAppWindow(app_window);
}
{
// Repeat the test, but make sure that frameless platform apps are never put
// into immersive fullscreen.
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));
|