accelerator_commands_browsertest.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ash/accelerators/accelerator_commands.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "apps/app_window.h" 84e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "apps/ui/native_app_window.h" 9a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ash/ash_switches.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell.h" 1168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ash/wm/window_state.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/command_line.h" 133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/apps/app_browsertest_util.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_commands.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_finder.h" 17eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "chrome/browser/ui/browser_window.h" 18a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/common/chrome_switches.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h" 20a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/test/base/test_switches.h" 21eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/aura/client/aura_constants.h" 22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ui/views/widget/widget.h" 23a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ui/views/widget/widget_delegate.h" 24a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 25a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)using testing::Combine; 26a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)using testing::Values; 27a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)using testing::WithParamInterface; 28eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 29eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochnamespace { 30eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// WidgetDelegateView which allows the widget to be maximized. 32a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class MaximizableWidgetDelegate : public views::WidgetDelegateView { 33a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public: 34a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) MaximizableWidgetDelegate() { 35a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 36a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual ~MaximizableWidgetDelegate() { 37a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 38a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 39a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual bool CanMaximize() const OVERRIDE { 40a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return true; 41a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 42a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 43a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) private: 44a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(MaximizableWidgetDelegate); 45a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}; 46a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 47a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Returns true if |window_state|'s window is in immersive fullscreen. Infer 48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// whether the window is in immersive fullscreen based on whether the shelf is 49a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// hidden when the window is fullscreen. (This is not quite right because the 50a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// shelf is hidden if a window is in both immersive fullscreen and tab 51a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// fullscreen.) 52a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool IsInImmersiveFullscreen(ash::wm::WindowState* window_state) { 531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return window_state->IsFullscreen() && 541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) !window_state->hide_shelf_when_fullscreen(); 55eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 56eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 57eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} // namespace 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)typedef InProcessBrowserTest AcceleratorCommandsBrowserTest; 608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Confirm that toggling window miximized works properly 621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AcceleratorCommandsBrowserTest, ToggleMaximized) { 63a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_WIN) 64a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Run the test on Win Ash only. 65a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 66a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return; 67a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif 68a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASSERT_TRUE(ash::Shell::HasInstance()) << "No Instance"; 7068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) ash::wm::WindowState* window_state = ash::wm::GetActiveWindowState(); 7168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) ASSERT_TRUE(window_state); 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // When not in fullscreen, accelerators::ToggleMaximized toggles Maximized. 7468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_FALSE(window_state->IsMaximized()); 758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ash::accelerators::ToggleMaximized(); 7668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_TRUE(window_state->IsMaximized()); 778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ash::accelerators::ToggleMaximized(); 7868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_FALSE(window_state->IsMaximized()); 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // When in fullscreen accelerators::ToggleMaximized gets out of fullscreen. 8168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_FALSE(window_state->IsFullscreen()); 8268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) Browser* browser = chrome::FindBrowserWithWindow(window_state->window()); 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(browser); 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome::ToggleFullscreenMode(browser); 8568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_TRUE(window_state->IsFullscreen()); 868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ash::accelerators::ToggleMaximized(); 8768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_FALSE(window_state->IsFullscreen()); 8868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_FALSE(window_state->IsMaximized()); 898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ash::accelerators::ToggleMaximized(); 9068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_FALSE(window_state->IsFullscreen()); 9168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_TRUE(window_state->IsMaximized()); 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 93eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 94a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class AcceleratorCommandsFullscreenBrowserTest 95a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) : public WithParamInterface<ui::WindowShowState>, 96a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public InProcessBrowserTest { 97a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public: 98a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) AcceleratorCommandsFullscreenBrowserTest() 99a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_CHROMEOS) 100a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) : put_window_in_immersive_(true), 101a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#else 102a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) : put_window_in_immersive_(false), 103a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif 104a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) initial_show_state_(GetParam()) { 105a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 106a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual ~AcceleratorCommandsFullscreenBrowserTest() { 107a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 108a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 109a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Sets |window_state|'s show state to |initial_show_state_|. 110a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void SetToInitialShowState(ash::wm::WindowState* window_state) { 111a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (initial_show_state_ == ui::SHOW_STATE_MAXIMIZED) 112a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) window_state->Maximize(); 113a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) else 114a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) window_state->Restore(); 115a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 116a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 117a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Returns true if |window_state|'s show state is |initial_show_state_|. 118a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) bool IsInitialShowState(const ash::wm::WindowState* window_state) const { 1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (initial_show_state_ == ui::SHOW_STATE_MAXIMIZED) 1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return window_state->IsMaximized(); 1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) else 122a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return window_state->IsNormalStateType(); 123a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 124a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 125a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool put_window_in_immersive() const { 126a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return put_window_in_immersive_; 127a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 128a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 129a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) private: 130a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool put_window_in_immersive_; 131a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ui::WindowShowState initial_show_state_; 132a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 133a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(AcceleratorCommandsFullscreenBrowserTest); 134a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}; 135a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 136a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Test that toggling window fullscreen works properly. 137a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)IN_PROC_BROWSER_TEST_P(AcceleratorCommandsFullscreenBrowserTest, 138a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ToggleFullscreen) { 139a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_WIN) 140a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Run the test on Win Ash only. 141a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 142a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return; 143a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif 144a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 1451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASSERT_TRUE(ash::Shell::HasInstance()) << "No Instance"; 146a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 147a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // 1) Browser windows. 148eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(browser()->is_type_tabbed()); 149a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::wm::WindowState* window_state = 150a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::wm::GetWindowState(browser()->window()->GetNativeWindow()); 151a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_TRUE(window_state->IsActive()); 152a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) SetToInitialShowState(window_state); 153a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(IsInitialShowState(window_state)); 154eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ash::accelerators::ToggleFullscreen(); 156a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(window_state->IsFullscreen()); 157a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(put_window_in_immersive(), IsInImmersiveFullscreen(window_state)); 158eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ash::accelerators::ToggleFullscreen(); 160a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(IsInitialShowState(window_state)); 161eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 162eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // 2) ToggleFullscreen() should have no effect on windows which cannot be 163eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // maximized. 164a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) window_state->window()->SetProperty(aura::client::kCanMaximizeKey, false); 1651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ash::accelerators::ToggleFullscreen(); 166a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(IsInitialShowState(window_state)); 167eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 168a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // 3) Hosted apps. 169eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Browser::CreateParams browser_create_params(Browser::TYPE_POPUP, 170a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) browser()->profile(), chrome::HOST_DESKTOP_TYPE_ASH); 171eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch browser_create_params.app_name = "Test"; 172eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 173eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Browser* app_host_browser = new Browser(browser_create_params); 174eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(app_host_browser->is_app()); 175eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AddBlankTabAndShow(app_host_browser); 176a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) window_state = 177a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::wm::GetWindowState(app_host_browser->window()->GetNativeWindow()); 178a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_TRUE(window_state->IsActive()); 179a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) SetToInitialShowState(window_state); 180a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(IsInitialShowState(window_state)); 181eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ash::accelerators::ToggleFullscreen(); 183a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(window_state->IsFullscreen()); 184a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(put_window_in_immersive(), IsInImmersiveFullscreen(window_state)); 185eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ash::accelerators::ToggleFullscreen(); 187a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(IsInitialShowState(window_state)); 188eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 189a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // 4) Popup browser windows. 190eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch browser_create_params.app_name = ""; 191eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Browser* popup_browser = new Browser(browser_create_params); 192eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(popup_browser->is_type_popup()); 193eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_FALSE(popup_browser->is_app()); 194eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AddBlankTabAndShow(popup_browser); 195a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) window_state = 196a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::wm::GetWindowState(popup_browser->window()->GetNativeWindow()); 197a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_TRUE(window_state->IsActive()); 198a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) SetToInitialShowState(window_state); 199a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(IsInitialShowState(window_state)); 200a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 201a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::accelerators::ToggleFullscreen(); 202a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(window_state->IsFullscreen()); 203a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(put_window_in_immersive(), IsInImmersiveFullscreen(window_state)); 204eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ash::accelerators::ToggleFullscreen(); 206a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(IsInitialShowState(window_state)); 207eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 208a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // 5) Miscellaneous windows (e.g. task manager). 209a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) views::Widget::InitParams params; 210a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) params.delegate = new MaximizableWidgetDelegate(); 211a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 212a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) scoped_ptr<views::Widget> widget(new views::Widget); 213a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) widget->Init(params); 214a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) widget->Show(); 215a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 216a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) window_state = ash::wm::GetWindowState(widget->GetNativeWindow()); 217a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_TRUE(window_state->IsActive()); 218a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) SetToInitialShowState(window_state); 219a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(IsInitialShowState(window_state)); 220a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 221a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::accelerators::ToggleFullscreen(); 222a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(window_state->IsFullscreen()); 223a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(put_window_in_immersive(), IsInImmersiveFullscreen(window_state)); 224a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 225a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // TODO(pkotwicz|oshima): Make toggling fullscreen restore the window to its 226a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // show state prior to entering fullscreen. 2271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ash::accelerators::ToggleFullscreen(); 228a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(window_state->IsFullscreen()); 229eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 230eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 231a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)INSTANTIATE_TEST_CASE_P(InitiallyRestored, 232a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) AcceleratorCommandsFullscreenBrowserTest, 233a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Values(ui::SHOW_STATE_NORMAL)); 234a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)INSTANTIATE_TEST_CASE_P(InitiallyMaximized, 235a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) AcceleratorCommandsFullscreenBrowserTest, 236a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Values(ui::SHOW_STATE_MAXIMIZED)); 237a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 238a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class AcceleratorCommandsPlatformAppFullscreenBrowserTest 239a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) : public WithParamInterface<ui::WindowShowState>, 240a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public extensions::PlatformAppBrowserTest { 241a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public: 242a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) AcceleratorCommandsPlatformAppFullscreenBrowserTest() 243a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_CHROMEOS) 244a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) : put_window_in_immersive_(true), 245a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#else 246a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) : put_window_in_immersive_(false), 247a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif 248a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) initial_show_state_(GetParam()) { 249a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 250a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual ~AcceleratorCommandsPlatformAppFullscreenBrowserTest() { 251a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 252a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 2535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Sets |app_window|'s show state to |initial_show_state_|. 2545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void SetToInitialShowState(apps::AppWindow* app_window) { 255a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (initial_show_state_ == ui::SHOW_STATE_MAXIMIZED) 2565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) app_window->Maximize(); 257a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) else 2585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) app_window->Restore(); 259a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 260a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 2615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Returns true if |app_window|'s show state is |initial_show_state_|. 2625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool IsInitialShowState(apps::AppWindow* app_window) const { 263a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (initial_show_state_ == ui::SHOW_STATE_MAXIMIZED) 2645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return app_window->GetBaseWindow()->IsMaximized(); 265a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) else 2665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return ui::BaseWindow::IsRestored(*app_window->GetBaseWindow()); 267a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 268a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 269a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool put_window_in_immersive() const { 270a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return put_window_in_immersive_; 271a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 272a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 273a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) private: 274a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool put_window_in_immersive_; 275a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ui::WindowShowState initial_show_state_; 276a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 277a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(AcceleratorCommandsPlatformAppFullscreenBrowserTest); 278a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}; 279a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 280a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Test the behavior of platform apps when ToggleFullscreen() is called. 281a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)IN_PROC_BROWSER_TEST_P(AcceleratorCommandsPlatformAppFullscreenBrowserTest, 282a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ToggleFullscreen) { 283a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_WIN) 284a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Run the test on Win Ash only. 285a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 286a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return; 287a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif 288eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASSERT_TRUE(ash::Shell::HasInstance()) << "No Instance"; 290eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const extensions::Extension* extension = LoadAndLaunchPlatformApp("minimal"); 291eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 292a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { 293a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Test that ToggleFullscreen() toggles a platform's app's fullscreen 294a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // state and that it additionally puts the app into immersive fullscreen 295a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // if put_all_windows_in_immersive() returns true. 2965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) apps::AppWindow::CreateParams params; 2975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.frame = apps::AppWindow::FRAME_CHROME; 2985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) apps::AppWindow* app_window = CreateAppWindowFromParams(extension, params); 2995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) apps::NativeAppWindow* native_app_window = app_window->GetBaseWindow(); 3005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetToInitialShowState(app_window); 3015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(app_window->GetBaseWindow()->IsActive()); 3025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(IsInitialShowState(app_window)); 303eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 304a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::accelerators::ToggleFullscreen(); 3055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(native_app_window->IsFullscreen()); 306a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::wm::WindowState* window_state = 3075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::wm::GetWindowState(native_app_window->GetNativeWindow()); 308a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(put_window_in_immersive(), 309a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) IsInImmersiveFullscreen(window_state)); 310a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 311a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::accelerators::ToggleFullscreen(); 3125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(IsInitialShowState(app_window)); 313eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 3145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CloseAppWindow(app_window); 315a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 316a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 317a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { 318a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Repeat the test, but make sure that frameless platform apps are never put 319a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // into immersive fullscreen. 3205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) apps::AppWindow::CreateParams params; 3215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.frame = apps::AppWindow::FRAME_NONE; 3225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) apps::AppWindow* app_window = CreateAppWindowFromParams(extension, params); 3235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) apps::NativeAppWindow* native_app_window = app_window->GetBaseWindow(); 3245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(app_window->GetBaseWindow()->IsActive()); 3255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetToInitialShowState(app_window); 3265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(IsInitialShowState(app_window)); 327a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 328a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::accelerators::ToggleFullscreen(); 3295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(native_app_window->IsFullscreen()); 330a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::wm::WindowState* window_state = 3315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::wm::GetWindowState(native_app_window->GetNativeWindow()); 332a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(IsInImmersiveFullscreen(window_state)); 333a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 334a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::accelerators::ToggleFullscreen(); 3355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(IsInitialShowState(app_window)); 336a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 3375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CloseAppWindow(app_window); 338a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 339eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 340a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 341a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)INSTANTIATE_TEST_CASE_P(InitiallyRestored, 342a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) AcceleratorCommandsPlatformAppFullscreenBrowserTest, 343a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Values(ui::SHOW_STATE_NORMAL)); 344a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)INSTANTIATE_TEST_CASE_P(InitiallyMaximized, 345a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) AcceleratorCommandsPlatformAppFullscreenBrowserTest, 346a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Values(ui::SHOW_STATE_MAXIMIZED)); 347