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)
7a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ash/ash_switches.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell.h"
968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ash/wm/window_state.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/command_line.h"
113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/apps/app_browsertest_util.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_commands.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_finder.h"
15eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "chrome/browser/ui/browser_window.h"
16a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/common/chrome_switches.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h"
18a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/test/base/test_switches.h"
191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/browser/app_window/app_window.h"
2003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "extensions/browser/app_window/native_app_window.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()
99a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      : initial_show_state_(GetParam()) {
100a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
101a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual ~AcceleratorCommandsFullscreenBrowserTest() {
102a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
103a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
104a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Sets |window_state|'s show state to |initial_show_state_|.
105a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void SetToInitialShowState(ash::wm::WindowState* window_state) {
106a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    if (initial_show_state_ == ui::SHOW_STATE_MAXIMIZED)
107a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      window_state->Maximize();
108a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    else
109a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      window_state->Restore();
110a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
111a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
112a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Returns true if |window_state|'s show state is |initial_show_state_|.
113a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  bool IsInitialShowState(const ash::wm::WindowState* window_state) const {
1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (initial_show_state_ == ui::SHOW_STATE_MAXIMIZED)
1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return window_state->IsMaximized();
1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    else
117a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      return window_state->IsNormalStateType();
118a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
119a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
120a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) private:
121a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ui::WindowShowState initial_show_state_;
122a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
123a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(AcceleratorCommandsFullscreenBrowserTest);
124a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)};
125a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
126a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Test that toggling window fullscreen works properly.
127a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)IN_PROC_BROWSER_TEST_P(AcceleratorCommandsFullscreenBrowserTest,
128a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                       ToggleFullscreen) {
129a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_WIN)
130a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Run the test on Win Ash only.
131a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
132a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return;
133a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif
134a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  ASSERT_TRUE(ash::Shell::HasInstance()) << "No Instance";
136a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
137a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // 1) Browser windows.
138eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  ASSERT_TRUE(browser()->is_type_tabbed());
139a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ash::wm::WindowState* window_state =
140a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      ash::wm::GetWindowState(browser()->window()->GetNativeWindow());
141a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ASSERT_TRUE(window_state->IsActive());
142a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  SetToInitialShowState(window_state);
143a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_TRUE(IsInitialShowState(window_state));
144eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  ash::accelerators::ToggleFullscreen();
146a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_TRUE(window_state->IsFullscreen());
147a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  EXPECT_TRUE(IsInImmersiveFullscreen(window_state));
148eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  ash::accelerators::ToggleFullscreen();
150a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_TRUE(IsInitialShowState(window_state));
151eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
152eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // 2) ToggleFullscreen() should have no effect on windows which cannot be
153eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // maximized.
154a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  window_state->window()->SetProperty(aura::client::kCanMaximizeKey, false);
1551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  ash::accelerators::ToggleFullscreen();
156a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_TRUE(IsInitialShowState(window_state));
157eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
158a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // 3) Hosted apps.
159a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  Browser::CreateParams browser_create_params(
160a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      Browser::CreateParams::CreateForApp("Test",
161a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                                          true /* trusted_source */,
162a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                                          gfx::Rect(),
163a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                                          browser()->profile(),
164a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                                          chrome::HOST_DESKTOP_TYPE_ASH));
165eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
166eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  Browser* app_host_browser = new Browser(browser_create_params);
167eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  ASSERT_TRUE(app_host_browser->is_app());
168eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AddBlankTabAndShow(app_host_browser);
169a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  window_state =
170a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      ash::wm::GetWindowState(app_host_browser->window()->GetNativeWindow());
171a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ASSERT_TRUE(window_state->IsActive());
172a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  SetToInitialShowState(window_state);
173a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_TRUE(IsInitialShowState(window_state));
174eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  ash::accelerators::ToggleFullscreen();
176a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_TRUE(window_state->IsFullscreen());
177a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  EXPECT_TRUE(IsInImmersiveFullscreen(window_state));
178eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  ash::accelerators::ToggleFullscreen();
180a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_TRUE(IsInitialShowState(window_state));
181eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
182a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // 4) Popup browser windows.
183a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  browser_create_params = Browser::CreateParams(
184a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      Browser::TYPE_POPUP, browser()->profile(), chrome::HOST_DESKTOP_TYPE_ASH);
185eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  Browser* popup_browser = new Browser(browser_create_params);
186eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  ASSERT_TRUE(popup_browser->is_type_popup());
187eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  ASSERT_FALSE(popup_browser->is_app());
188eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AddBlankTabAndShow(popup_browser);
189a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  window_state =
190a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      ash::wm::GetWindowState(popup_browser->window()->GetNativeWindow());
191a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ASSERT_TRUE(window_state->IsActive());
192a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  SetToInitialShowState(window_state);
193a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_TRUE(IsInitialShowState(window_state));
194a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
195a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ash::accelerators::ToggleFullscreen();
196a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_TRUE(window_state->IsFullscreen());
197a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  EXPECT_TRUE(IsInImmersiveFullscreen(window_state));
198eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  ash::accelerators::ToggleFullscreen();
200a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_TRUE(IsInitialShowState(window_state));
201eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
202a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // 5) Miscellaneous windows (e.g. task manager).
203a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  views::Widget::InitParams params;
204a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  params.delegate = new MaximizableWidgetDelegate();
205a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
206a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  scoped_ptr<views::Widget> widget(new views::Widget);
207a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  widget->Init(params);
208a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  widget->Show();
209a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
210a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  window_state = ash::wm::GetWindowState(widget->GetNativeWindow());
211a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ASSERT_TRUE(window_state->IsActive());
212a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  SetToInitialShowState(window_state);
213a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_TRUE(IsInitialShowState(window_state));
214a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
215a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ash::accelerators::ToggleFullscreen();
216a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_TRUE(window_state->IsFullscreen());
217a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  EXPECT_TRUE(IsInImmersiveFullscreen(window_state));
218a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
219a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // TODO(pkotwicz|oshima): Make toggling fullscreen restore the window to its
220a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // show state prior to entering fullscreen.
2211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  ash::accelerators::ToggleFullscreen();
222a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_FALSE(window_state->IsFullscreen());
223eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
224eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
225a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)INSTANTIATE_TEST_CASE_P(InitiallyRestored,
226a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                        AcceleratorCommandsFullscreenBrowserTest,
227a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                        Values(ui::SHOW_STATE_NORMAL));
228a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)INSTANTIATE_TEST_CASE_P(InitiallyMaximized,
229a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                        AcceleratorCommandsFullscreenBrowserTest,
230a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                        Values(ui::SHOW_STATE_MAXIMIZED));
231a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
232a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class AcceleratorCommandsPlatformAppFullscreenBrowserTest
233a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    : public WithParamInterface<ui::WindowShowState>,
234a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      public extensions::PlatformAppBrowserTest {
235a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public:
236a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  AcceleratorCommandsPlatformAppFullscreenBrowserTest()
237a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      : initial_show_state_(GetParam()) {
238a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
239a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual ~AcceleratorCommandsPlatformAppFullscreenBrowserTest() {
240a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
241a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Sets |app_window|'s show state to |initial_show_state_|.
2431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void SetToInitialShowState(extensions::AppWindow* app_window) {
244a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    if (initial_show_state_ == ui::SHOW_STATE_MAXIMIZED)
2455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      app_window->Maximize();
246a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    else
2475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      app_window->Restore();
248a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
249a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns true if |app_window|'s show state is |initial_show_state_|.
2511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  bool IsInitialShowState(extensions::AppWindow* app_window) const {
252a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    if (initial_show_state_ == ui::SHOW_STATE_MAXIMIZED)
2535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return app_window->GetBaseWindow()->IsMaximized();
254a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    else
2555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ui::BaseWindow::IsRestored(*app_window->GetBaseWindow());
256a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
257a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
258a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) private:
259a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ui::WindowShowState initial_show_state_;
260a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
261a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(AcceleratorCommandsPlatformAppFullscreenBrowserTest);
262a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)};
263a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
264a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Test the behavior of platform apps when ToggleFullscreen() is called.
265a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)IN_PROC_BROWSER_TEST_P(AcceleratorCommandsPlatformAppFullscreenBrowserTest,
266a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                       ToggleFullscreen) {
267a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_WIN)
268a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Run the test on Win Ash only.
269a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
270a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return;
271a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif
272eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  ASSERT_TRUE(ash::Shell::HasInstance()) << "No Instance";
274f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  const extensions::Extension* extension = LoadAndLaunchPlatformApp("minimal",
275f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                                                    "Launched");
276eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
277a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  {
278a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // Test that ToggleFullscreen() toggles a platform's app's fullscreen
279a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // state and that it additionally puts the app into immersive fullscreen
280a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // if put_all_windows_in_immersive() returns true.
2811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    extensions::AppWindow::CreateParams params;
2821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    params.frame = extensions::AppWindow::FRAME_CHROME;
2831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    extensions::AppWindow* app_window =
2841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        CreateAppWindowFromParams(extension, params);
28503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    extensions::NativeAppWindow* native_app_window =
28603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)        app_window->GetBaseWindow();
2875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    SetToInitialShowState(app_window);
2885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ASSERT_TRUE(app_window->GetBaseWindow()->IsActive());
2895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    EXPECT_TRUE(IsInitialShowState(app_window));
290eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
291a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ash::accelerators::ToggleFullscreen();
2925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    EXPECT_TRUE(native_app_window->IsFullscreen());
293a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ash::wm::WindowState* window_state =
2945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        ash::wm::GetWindowState(native_app_window->GetNativeWindow());
295a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    EXPECT_TRUE(IsInImmersiveFullscreen(window_state));
296a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
297a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ash::accelerators::ToggleFullscreen();
2985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    EXPECT_TRUE(IsInitialShowState(app_window));
299eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
3005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    CloseAppWindow(app_window);
301a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
302a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
303a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  {
304a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // Repeat the test, but make sure that frameless platform apps are never put
305a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // into immersive fullscreen.
3061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    extensions::AppWindow::CreateParams params;
3071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    params.frame = extensions::AppWindow::FRAME_NONE;
3081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    extensions::AppWindow* app_window =
3091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        CreateAppWindowFromParams(extension, params);
31003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    extensions::NativeAppWindow* native_app_window =
31103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)        app_window->GetBaseWindow();
3125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ASSERT_TRUE(app_window->GetBaseWindow()->IsActive());
3135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    SetToInitialShowState(app_window);
3145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    EXPECT_TRUE(IsInitialShowState(app_window));
315a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
316a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ash::accelerators::ToggleFullscreen();
3175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    EXPECT_TRUE(native_app_window->IsFullscreen());
318a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ash::wm::WindowState* window_state =
3195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        ash::wm::GetWindowState(native_app_window->GetNativeWindow());
320a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    EXPECT_FALSE(IsInImmersiveFullscreen(window_state));
321a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
322a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ash::accelerators::ToggleFullscreen();
3235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    EXPECT_TRUE(IsInitialShowState(app_window));
324a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
3255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    CloseAppWindow(app_window);
326a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
327eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
328a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
329a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)INSTANTIATE_TEST_CASE_P(InitiallyRestored,
330a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                        AcceleratorCommandsPlatformAppFullscreenBrowserTest,
331a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                        Values(ui::SHOW_STATE_NORMAL));
332a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)INSTANTIATE_TEST_CASE_P(InitiallyMaximized,
333a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                        AcceleratorCommandsPlatformAppFullscreenBrowserTest,
334a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                        Values(ui::SHOW_STATE_MAXIMIZED));
335