Reland: Add browser_test for extension app API with missing schema
[chromium-blink-merge.git] / ash / wm / maximize_mode / maximize_mode_window_manager_unittest.cc
blob5a7c9b17bd7aa784c80dd13038641d4074d95b22
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h"
7 #include "ash/root_window_controller.h"
8 #include "ash/screen_util.h"
9 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shell.h"
11 #include "ash/switchable_windows.h"
12 #include "ash/test/ash_test_base.h"
13 #include "ash/test/shell_test_api.h"
14 #include "ash/wm/mru_window_tracker.h"
15 #include "ash/wm/overview/window_selector_controller.h"
16 #include "ash/wm/window_properties.h"
17 #include "ash/wm/window_state.h"
18 #include "ash/wm/window_util.h"
19 #include "ash/wm/wm_event.h"
20 #include "base/strings/stringprintf.h"
21 #include "base/strings/utf_string_conversions.h"
22 #include "base/values.h"
23 #include "ui/aura/client/aura_constants.h"
24 #include "ui/aura/test/event_generator.h"
25 #include "ui/aura/test/test_window_delegate.h"
26 #include "ui/aura/test/test_windows.h"
27 #include "ui/aura/window.h"
28 #include "ui/base/hit_test.h"
30 namespace ash {
32 // TODO(skuhne): These tests are failing on Widows because maximized is there
33 // differently handled. Fix this!
34 #if !defined(OS_WIN)
36 class MaximizeModeWindowManagerTest : public test::AshTestBase {
37 public:
38 MaximizeModeWindowManagerTest() {}
39 virtual ~MaximizeModeWindowManagerTest() {}
41 // Creates a window which has a fixed size.
42 aura::Window* CreateFixedSizeNonMaximizableWindow(ui::wm::WindowType type,
43 const gfx::Rect& bounds) {
44 return CreateWindowInWatchedContainer(
45 type, bounds, gfx::Size(), false, false);
48 // Creates a window which can not be maximized, but resized. |max_size|
49 // denotes the maximal possible size, if the size is empty, the window has no
50 // upper limit. Note: This function will only work with a single root window.
51 aura::Window* CreateNonMaximizableWindow(ui::wm::WindowType type,
52 const gfx::Rect& bounds,
53 const gfx::Size& max_size) {
54 return CreateWindowInWatchedContainer(type, bounds, max_size, false, true);
57 // Creates a maximizable and resizable window.
58 aura::Window* CreateWindow(ui::wm::WindowType type,
59 const gfx::Rect bounds) {
60 return CreateWindowInWatchedContainer(
61 type, bounds, gfx::Size(), true, true);
64 // Creates a window which also has a widget.
65 aura::Window* CreateWindowWithWidget(const gfx::Rect& bounds) {
66 views::Widget* widget = new views::Widget();
67 views::Widget::InitParams params;
68 params.context = CurrentContext();
69 // Note: The widget will get deleted with the window.
70 widget->Init(params);
71 widget->Show();
72 aura::Window* window = widget->GetNativeWindow();
73 window->SetBounds(bounds);
74 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
76 return window;
79 // Create the Maximized mode window manager.
80 ash::MaximizeModeWindowManager* CreateMaximizeModeWindowManager() {
81 EXPECT_FALSE(maximize_mode_window_manager());
82 Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
83 return maximize_mode_window_manager();
86 // Destroy the maximized mode window manager.
87 void DestroyMaximizeModeWindowManager() {
88 Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
89 EXPECT_FALSE(maximize_mode_window_manager());
92 // Get the maximze window manager.
93 ash::MaximizeModeWindowManager* maximize_mode_window_manager() {
94 test::ShellTestApi test_api(Shell::GetInstance());
95 return test_api.maximize_mode_window_manager();
98 // Resize our desktop.
99 void ResizeDesktop(int width_delta) {
100 gfx::Size size = Shell::GetScreen()->GetDisplayNearestWindow(
101 Shell::GetPrimaryRootWindow()).size();
102 size.Enlarge(0, width_delta);
103 UpdateDisplay(size.ToString());
106 private:
107 // Create a window in one of the containers which are watched by the
108 // MaximizeModeWindowManager. Note that this only works with one root window.
109 // If |can_maximize| is not set, |max_size| is the upper limiting size for
110 // the window, whereas an empty size means that there is no limit.
111 aura::Window* CreateWindowInWatchedContainer(ui::wm::WindowType type,
112 const gfx::Rect& bounds,
113 const gfx::Size& max_size,
114 bool can_maximize,
115 bool can_resize) {
116 aura::test::TestWindowDelegate* delegate = NULL;
117 if (!can_maximize) {
118 delegate = aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate();
119 delegate->set_window_component(HTCAPTION);
120 if (!max_size.IsEmpty())
121 delegate->set_maximum_size(max_size);
123 aura::Window* window = aura::test::CreateTestWindowWithDelegateAndType(
124 delegate, type, 0, bounds, NULL);
125 window->SetProperty(aura::client::kCanMaximizeKey, can_maximize);
126 if (!can_resize)
127 window->SetProperty(aura::client::kCanResizeKey, false);
128 aura::Window* container = Shell::GetContainer(
129 Shell::GetPrimaryRootWindow(),
130 kSwitchableWindowContainerIds[0]);
131 container->AddChild(window);
132 return window;
135 DISALLOW_COPY_AND_ASSIGN(MaximizeModeWindowManagerTest);
138 // Test that creating the object and destroying it without any windows should
139 // not cause any problems.
140 TEST_F(MaximizeModeWindowManagerTest, SimpleStart) {
141 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
142 ASSERT_TRUE(manager);
143 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
144 DestroyMaximizeModeWindowManager();
147 // Test that existing windows will handled properly when going into maximized
148 // mode.
149 TEST_F(MaximizeModeWindowManagerTest, PreCreateWindows) {
150 // Bounds for windows we know can be controlled.
151 gfx::Rect rect1(10, 10, 200, 50);
152 gfx::Rect rect2(10, 60, 200, 50);
153 gfx::Rect rect3(20, 140, 100, 100);
154 // Bounds for anything else.
155 gfx::Rect rect(80, 90, 100, 110);
156 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect1));
157 scoped_ptr<aura::Window> w2(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
158 scoped_ptr<aura::Window> w3(
159 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect3));
160 scoped_ptr<aura::Window> w4(CreateWindow(ui::wm::WINDOW_TYPE_PANEL, rect));
161 scoped_ptr<aura::Window> w5(CreateWindow(ui::wm::WINDOW_TYPE_POPUP, rect));
162 scoped_ptr<aura::Window> w6(CreateWindow(ui::wm::WINDOW_TYPE_CONTROL, rect));
163 scoped_ptr<aura::Window> w7(CreateWindow(ui::wm::WINDOW_TYPE_MENU, rect));
164 scoped_ptr<aura::Window> w8(CreateWindow(ui::wm::WINDOW_TYPE_TOOLTIP, rect));
165 EXPECT_FALSE(wm::GetWindowState(w1.get())->IsMaximized());
166 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized());
167 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
168 EXPECT_EQ(rect1.ToString(), w1->bounds().ToString());
169 EXPECT_EQ(rect2.ToString(), w2->bounds().ToString());
170 EXPECT_EQ(rect3.ToString(), w3->bounds().ToString());
172 // Create the manager and make sure that all qualifying windows were detected
173 // and changed.
174 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
175 ASSERT_TRUE(manager);
176 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
177 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsMaximized());
178 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized());
179 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
180 EXPECT_NE(rect3.origin().ToString(), w3->bounds().origin().ToString());
181 EXPECT_EQ(rect3.size().ToString(), w3->bounds().size().ToString());
183 // All other windows should not have been touched.
184 EXPECT_FALSE(wm::GetWindowState(w4.get())->IsMaximized());
185 EXPECT_FALSE(wm::GetWindowState(w5.get())->IsMaximized());
186 EXPECT_FALSE(wm::GetWindowState(w6.get())->IsMaximized());
187 EXPECT_FALSE(wm::GetWindowState(w7.get())->IsMaximized());
188 EXPECT_FALSE(wm::GetWindowState(w8.get())->IsMaximized());
189 EXPECT_EQ(rect.ToString(), w4->bounds().ToString());
190 EXPECT_EQ(rect.ToString(), w5->bounds().ToString());
191 EXPECT_EQ(rect.ToString(), w6->bounds().ToString());
192 EXPECT_EQ(rect.ToString(), w7->bounds().ToString());
193 EXPECT_EQ(rect.ToString(), w8->bounds().ToString());
195 // Destroy the manager again and check that the windows return to their
196 // previous state.
197 DestroyMaximizeModeWindowManager();
198 EXPECT_FALSE(wm::GetWindowState(w1.get())->IsMaximized());
199 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized());
200 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
201 EXPECT_EQ(rect1.ToString(), w1->bounds().ToString());
202 EXPECT_EQ(rect2.ToString(), w2->bounds().ToString());
203 EXPECT_EQ(rect3.ToString(), w3->bounds().ToString());
204 EXPECT_EQ(rect.ToString(), w4->bounds().ToString());
205 EXPECT_EQ(rect.ToString(), w5->bounds().ToString());
206 EXPECT_EQ(rect.ToString(), w6->bounds().ToString());
207 EXPECT_EQ(rect.ToString(), w7->bounds().ToString());
208 EXPECT_EQ(rect.ToString(), w8->bounds().ToString());
211 // Test that non-maximizable windows get properly handled when going into
212 // maximized mode.
213 TEST_F(MaximizeModeWindowManagerTest,
214 PreCreateNonMaximizableButResizableWindows) {
215 // The window bounds.
216 gfx::Rect rect(10, 10, 200, 50);
217 gfx::Size max_size(300, 200);
218 gfx::Size empty_size;
219 scoped_ptr<aura::Window> unlimited_window(
220 CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect, empty_size));
221 scoped_ptr<aura::Window> limited_window(
222 CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect, max_size));
223 scoped_ptr<aura::Window> fixed_window(
224 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
225 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
226 EXPECT_EQ(rect.ToString(), unlimited_window->bounds().ToString());
227 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
228 EXPECT_EQ(rect.ToString(), limited_window->bounds().ToString());
229 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
230 EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString());
232 gfx::Size workspace_size = ScreenUtil::GetMaximizedWindowBoundsInParent(
233 unlimited_window.get()).size();
235 // Create the manager and make sure that all qualifying windows were detected
236 // and changed.
237 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
238 ASSERT_TRUE(manager);
239 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
240 // The unlimited window should have the size of the workspace / parent window.
241 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
242 EXPECT_EQ("0,0", unlimited_window->bounds().origin().ToString());
243 EXPECT_EQ(workspace_size.ToString(),
244 unlimited_window->bounds().size().ToString());
245 // The limited window should have the size of the upper possible bounds.
246 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
247 EXPECT_NE(rect.origin().ToString(),
248 limited_window->bounds().origin().ToString());
249 EXPECT_EQ(max_size.ToString(),
250 limited_window->bounds().size().ToString());
251 // The fixed size window should have the size of the original window.
252 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
253 EXPECT_NE(rect.origin().ToString(),
254 fixed_window->bounds().origin().ToString());
255 EXPECT_EQ(rect.size().ToString(),
256 fixed_window->bounds().size().ToString());
258 // Destroy the manager again and check that the windows return to their
259 // previous state.
260 DestroyMaximizeModeWindowManager();
261 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
262 EXPECT_EQ(rect.ToString(), unlimited_window->bounds().ToString());
263 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
264 EXPECT_EQ(rect.ToString(), limited_window->bounds().ToString());
265 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
266 EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString());
269 // Test that creating windows while a maximizer exists picks them properly up.
270 TEST_F(MaximizeModeWindowManagerTest, CreateWindows) {
271 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
272 ASSERT_TRUE(manager);
273 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
275 // Create the windows and see that the window manager picks them up.
276 // Rects for windows we know can be controlled.
277 gfx::Rect rect1(10, 10, 200, 50);
278 gfx::Rect rect2(10, 60, 200, 50);
279 gfx::Rect rect3(20, 140, 100, 100);
280 // One rect for anything else.
281 gfx::Rect rect(80, 90, 100, 110);
282 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect1));
283 scoped_ptr<aura::Window> w2(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
284 scoped_ptr<aura::Window> w3(
285 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect3));
286 scoped_ptr<aura::Window> w4(CreateWindow(ui::wm::WINDOW_TYPE_PANEL, rect));
287 scoped_ptr<aura::Window> w5(CreateWindow(ui::wm::WINDOW_TYPE_POPUP, rect));
288 scoped_ptr<aura::Window> w6(CreateWindow(ui::wm::WINDOW_TYPE_CONTROL, rect));
289 scoped_ptr<aura::Window> w7(CreateWindow(ui::wm::WINDOW_TYPE_MENU, rect));
290 scoped_ptr<aura::Window> w8(CreateWindow(ui::wm::WINDOW_TYPE_TOOLTIP, rect));
291 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsMaximized());
292 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized());
293 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
294 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
296 // Make sure that the position of the unresizable window is in the middle of
297 // the screen.
298 gfx::Size work_area_size =
299 ScreenUtil::GetDisplayWorkAreaBoundsInParent(w3.get()).size();
300 gfx::Point center =
301 gfx::Point((work_area_size.width() - rect3.size().width()) / 2,
302 (work_area_size.height() - rect3.size().height()) / 2);
303 gfx::Rect centered_window_bounds = gfx::Rect(center, rect3.size());
304 EXPECT_EQ(centered_window_bounds.ToString(), w3->bounds().ToString());
306 // All other windows should not have been touched.
307 EXPECT_FALSE(wm::GetWindowState(w4.get())->IsMaximized());
308 EXPECT_FALSE(wm::GetWindowState(w5.get())->IsMaximized());
309 EXPECT_FALSE(wm::GetWindowState(w6.get())->IsMaximized());
310 EXPECT_FALSE(wm::GetWindowState(w7.get())->IsMaximized());
311 EXPECT_FALSE(wm::GetWindowState(w8.get())->IsMaximized());
312 EXPECT_EQ(rect.ToString(), w4->bounds().ToString());
313 EXPECT_EQ(rect.ToString(), w5->bounds().ToString());
314 EXPECT_EQ(rect.ToString(), w6->bounds().ToString());
315 EXPECT_EQ(rect.ToString(), w7->bounds().ToString());
316 EXPECT_EQ(rect.ToString(), w8->bounds().ToString());
318 // After the maximize mode was disabled all windows fall back into the mode
319 // they were created for.
320 DestroyMaximizeModeWindowManager();
321 EXPECT_FALSE(wm::GetWindowState(w1.get())->IsMaximized());
322 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized());
323 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
324 EXPECT_EQ(rect1.ToString(), w1->bounds().ToString());
325 EXPECT_EQ(rect2.ToString(), w2->bounds().ToString());
326 EXPECT_EQ(rect3.ToString(), w3->bounds().ToString());
327 EXPECT_EQ(rect.ToString(), w4->bounds().ToString());
328 EXPECT_EQ(rect.ToString(), w5->bounds().ToString());
329 EXPECT_EQ(rect.ToString(), w6->bounds().ToString());
330 EXPECT_EQ(rect.ToString(), w7->bounds().ToString());
331 EXPECT_EQ(rect.ToString(), w8->bounds().ToString());
334 // Test that a window which got created while the maximize mode window manager
335 // is active gets restored to a usable (non tiny) size upon switching back.
336 TEST_F(MaximizeModeWindowManagerTest,
337 CreateWindowInMaximizedModeRestoresToUsefulSize) {
338 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
339 ASSERT_TRUE(manager);
340 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
342 // We pass in an empty rectangle to simulate a window creation with no
343 // particular size.
344 gfx::Rect empty_rect(0, 0, 0, 0);
345 scoped_ptr<aura::Window> window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL,
346 empty_rect));
347 EXPECT_TRUE(wm::GetWindowState(window.get())->IsMaximized());
348 EXPECT_NE(empty_rect.ToString(), window->bounds().ToString());
349 gfx::Rect maximized_size = window->bounds();
351 // Destroy the maximize mode and check that the resulting size of the window
352 // is remaining as it is (but not maximized).
353 DestroyMaximizeModeWindowManager();
355 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized());
356 EXPECT_EQ(maximized_size.ToString(), window->bounds().ToString());
359 // Test that non-maximizable windows get properly handled when created in
360 // maximized mode.
361 TEST_F(MaximizeModeWindowManagerTest,
362 CreateNonMaximizableButResizableWindows) {
363 // Create the manager and make sure that all qualifying windows were detected
364 // and changed.
365 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
366 ASSERT_TRUE(manager);
368 gfx::Rect rect(10, 10, 200, 50);
369 gfx::Size max_size(300, 200);
370 gfx::Size empty_size;
371 scoped_ptr<aura::Window> unlimited_window(
372 CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect, empty_size));
373 scoped_ptr<aura::Window> limited_window(
374 CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect, max_size));
375 scoped_ptr<aura::Window> fixed_window(
376 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
378 gfx::Size workspace_size = ScreenUtil::GetMaximizedWindowBoundsInParent(
379 unlimited_window.get()).size();
381 // All windows should be sized now as big as possible and be centered.
382 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
383 // The unlimited window should have the size of the workspace / parent window.
384 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
385 EXPECT_EQ("0,0", unlimited_window->bounds().origin().ToString());
386 EXPECT_EQ(workspace_size.ToString(),
387 unlimited_window->bounds().size().ToString());
388 // The limited window should have the size of the upper possible bounds.
389 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
390 EXPECT_NE(rect.origin().ToString(),
391 limited_window->bounds().origin().ToString());
392 EXPECT_EQ(max_size.ToString(),
393 limited_window->bounds().size().ToString());
394 // The fixed size window should have the size of the original window.
395 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
396 EXPECT_NE(rect.origin().ToString(),
397 fixed_window->bounds().origin().ToString());
398 EXPECT_EQ(rect.size().ToString(),
399 fixed_window->bounds().size().ToString());
401 // Destroy the manager again and check that the windows return to their
402 // creation state.
403 DestroyMaximizeModeWindowManager();
405 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
406 EXPECT_EQ(rect.ToString(), unlimited_window->bounds().ToString());
407 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
408 EXPECT_EQ(rect.ToString(), limited_window->bounds().ToString());
409 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
410 EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString());
413 // Create a string which consists of the bounds and the state for comparison.
414 std::string GetPlacementString(const gfx::Rect& bounds,
415 ui::WindowShowState state) {
416 return bounds.ToString() + base::StringPrintf(" %d", state);
419 // Retrieves the window's restore state override - if any - and returns it as a
420 // string.
421 std::string GetPlacementOverride(aura::Window* window) {
422 gfx::Rect* bounds = window->GetProperty(ash::kRestoreBoundsOverrideKey);
423 if (bounds) {
424 gfx::Rect restore_bounds = *bounds;
425 ui::WindowShowState restore_state =
426 window->GetProperty(ash::kRestoreShowStateOverrideKey);
427 return GetPlacementString(restore_bounds, restore_state);
429 return std::string();
432 // Test that the restore state will be kept at its original value for
433 // session restauration purposes.
434 TEST_F(MaximizeModeWindowManagerTest, TestRestoreIntegrety) {
435 gfx::Rect bounds(10, 10, 200, 50);
436 gfx::Size empty_size;
437 gfx::Rect empty_bounds;
438 scoped_ptr<aura::Window> normal_window(
439 CreateWindowWithWidget(bounds));
440 scoped_ptr<aura::Window> maximized_window(
441 CreateWindowWithWidget(bounds));
442 wm::GetWindowState(maximized_window.get())->Maximize();
444 EXPECT_EQ(std::string(), GetPlacementOverride(normal_window.get()));
445 EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get()));
447 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
448 ASSERT_TRUE(manager);
450 // With the maximization the override states should be returned in its
451 // pre-maximized state.
452 EXPECT_EQ(GetPlacementString(bounds, ui::SHOW_STATE_NORMAL),
453 GetPlacementOverride(normal_window.get()));
454 EXPECT_EQ(GetPlacementString(bounds, ui::SHOW_STATE_MAXIMIZED),
455 GetPlacementOverride(maximized_window.get()));
457 // Changing a window's state now does not change the returned result.
458 wm::GetWindowState(maximized_window.get())->Minimize();
459 EXPECT_EQ(GetPlacementString(bounds, ui::SHOW_STATE_MAXIMIZED),
460 GetPlacementOverride(maximized_window.get()));
462 // Destroy the manager again and check that the overrides get reset.
463 DestroyMaximizeModeWindowManager();
464 EXPECT_EQ(std::string(), GetPlacementOverride(normal_window.get()));
465 EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get()));
467 // Changing a window's state now does not bring the overrides back.
468 wm::GetWindowState(maximized_window.get())->Restore();
469 gfx::Rect new_bounds(10, 10, 200, 50);
470 maximized_window->SetBounds(new_bounds);
472 EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get()));
475 // Test that windows which got created before the maximizer was created can be
476 // destroyed while the maximizer is still running.
477 TEST_F(MaximizeModeWindowManagerTest, PreCreateWindowsDeleteWhileActive) {
478 ash::MaximizeModeWindowManager* manager = NULL;
480 // Bounds for windows we know can be controlled.
481 gfx::Rect rect1(10, 10, 200, 50);
482 gfx::Rect rect2(10, 60, 200, 50);
483 gfx::Rect rect3(20, 140, 100, 100);
484 // Bounds for anything else.
485 gfx::Rect rect(80, 90, 100, 110);
486 scoped_ptr<aura::Window> w1(
487 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect1));
488 scoped_ptr<aura::Window> w2(
489 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
490 scoped_ptr<aura::Window> w3(
491 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect3));
493 // Create the manager and make sure that all qualifying windows were
494 // detected and changed.
495 manager = CreateMaximizeModeWindowManager();
496 ASSERT_TRUE(manager);
497 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
499 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
500 DestroyMaximizeModeWindowManager();
503 // Test that windows which got created while the maximizer was running can get
504 // destroyed before the maximizer gets destroyed.
505 TEST_F(MaximizeModeWindowManagerTest, CreateWindowsAndDeleteWhileActive) {
506 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
507 ASSERT_TRUE(manager);
508 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
510 // Bounds for windows we know can be controlled.
511 gfx::Rect rect1(10, 10, 200, 50);
512 gfx::Rect rect2(10, 60, 200, 50);
513 gfx::Rect rect3(20, 140, 100, 100);
514 scoped_ptr<aura::Window> w1(
515 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(10, 10, 200, 50)));
516 scoped_ptr<aura::Window> w2(
517 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(10, 60, 200, 50)));
518 scoped_ptr<aura::Window> w3(
519 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL,
520 gfx::Rect(20, 140, 100, 100)));
521 // Check that the windows got automatically maximized as well.
522 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
523 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsMaximized());
524 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized());
525 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
527 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
528 DestroyMaximizeModeWindowManager();
531 // Test that windows which were maximized stay maximized.
532 TEST_F(MaximizeModeWindowManagerTest, MaximizedShouldRemainMaximized) {
533 // Bounds for windows we know can be controlled.
534 gfx::Rect rect(10, 10, 200, 50);
535 scoped_ptr<aura::Window> window(
536 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
537 wm::GetWindowState(window.get())->Maximize();
539 // Create the manager and make sure that the window gets detected.
540 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
541 ASSERT_TRUE(manager);
542 EXPECT_EQ(1, manager->GetNumberOfManagedWindows());
543 EXPECT_TRUE(wm::GetWindowState(window.get())->IsMaximized());
545 // Destroy the manager again and check that the window will remain maximized.
546 DestroyMaximizeModeWindowManager();
547 EXPECT_TRUE(wm::GetWindowState(window.get())->IsMaximized());
548 wm::GetWindowState(window.get())->Restore();
549 EXPECT_EQ(rect.ToString(), window->bounds().ToString());
552 // Test that minimized windows do neither get maximized nor restored upon
553 // entering maximized mode and get restored to their previous state after
554 // leaving.
555 TEST_F(MaximizeModeWindowManagerTest, MinimizedWindowBehavior) {
556 // Bounds for windows we know can be controlled.
557 gfx::Rect rect(10, 10, 200, 50);
558 scoped_ptr<aura::Window> initially_minimized_window(
559 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
560 scoped_ptr<aura::Window> initially_normal_window(
561 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
562 scoped_ptr<aura::Window> initially_maximized_window(
563 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
564 wm::GetWindowState(initially_minimized_window.get())->Minimize();
565 wm::GetWindowState(initially_maximized_window.get())->Maximize();
567 // Create the manager and make sure that the window gets detected.
568 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
569 ASSERT_TRUE(manager);
570 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
571 EXPECT_TRUE(wm::GetWindowState(
572 initially_minimized_window.get())->IsMinimized());
573 EXPECT_TRUE(wm::GetWindowState(initially_normal_window.get())->IsMaximized());
574 EXPECT_TRUE(wm::GetWindowState(
575 initially_maximized_window.get())->IsMaximized());
576 // Now minimize the second window to check that upon leaving the window
577 // will get restored to its minimized state.
578 wm::GetWindowState(initially_normal_window.get())->Minimize();
579 wm::GetWindowState(initially_maximized_window.get())->Minimize();
580 EXPECT_TRUE(wm::GetWindowState(
581 initially_minimized_window.get())->IsMinimized());
582 EXPECT_TRUE(wm::GetWindowState(
583 initially_normal_window.get())->IsMinimized());
584 EXPECT_TRUE(wm::GetWindowState(
585 initially_maximized_window.get())->IsMinimized());
587 // Destroy the manager again and check that the window will get minimized.
588 DestroyMaximizeModeWindowManager();
589 EXPECT_TRUE(wm::GetWindowState(
590 initially_minimized_window.get())->IsMinimized());
591 EXPECT_FALSE(wm::GetWindowState(
592 initially_normal_window.get())->IsMinimized());
593 EXPECT_TRUE(wm::GetWindowState(
594 initially_maximized_window.get())->IsMaximized());
597 // Check that resizing the desktop does reposition unmaximizable, unresizable &
598 // managed windows.
599 TEST_F(MaximizeModeWindowManagerTest, DesktopSizeChangeMovesUnmaximizable) {
600 UpdateDisplay("400x400");
601 // This window will move because it does not fit the new bounds.
602 gfx::Rect rect(20, 300, 100, 100);
603 scoped_ptr<aura::Window> window1(
604 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
605 EXPECT_EQ(rect.ToString(), window1->bounds().ToString());
607 // This window will not move because it does fit the new bounds.
608 gfx::Rect rect2(20, 140, 100, 100);
609 scoped_ptr<aura::Window> window2(
610 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
612 // Turning on the manager will reposition (but not resize) the window.
613 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
614 ASSERT_TRUE(manager);
615 EXPECT_EQ(2, manager->GetNumberOfManagedWindows());
616 gfx::Rect moved_bounds(window1->bounds());
617 EXPECT_NE(rect.origin().ToString(), moved_bounds.origin().ToString());
618 EXPECT_EQ(rect.size().ToString(), moved_bounds.size().ToString());
620 // Simulating a desktop resize should move the window again.
621 UpdateDisplay("300x300");
622 gfx::Rect new_moved_bounds(window1->bounds());
623 EXPECT_NE(rect.origin().ToString(), new_moved_bounds.origin().ToString());
624 EXPECT_EQ(rect.size().ToString(), new_moved_bounds.size().ToString());
625 EXPECT_NE(moved_bounds.origin().ToString(), new_moved_bounds.ToString());
627 // Turning off the mode should not restore to the initial coordinates since
628 // the new resolution is smaller and the window was on the edge.
629 DestroyMaximizeModeWindowManager();
630 EXPECT_NE(rect.ToString(), window1->bounds().ToString());
631 EXPECT_EQ(rect2.ToString(), window2->bounds().ToString());
634 // Check that windows return to original location if desktop size changes to
635 // something else and back while in maximize mode.
636 TEST_F(MaximizeModeWindowManagerTest, SizeChangeReturnWindowToOriginalPos) {
637 gfx::Rect rect(20, 140, 100, 100);
638 scoped_ptr<aura::Window> window(
639 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
641 // Turning on the manager will reposition (but not resize) the window.
642 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
643 ASSERT_TRUE(manager);
644 EXPECT_EQ(1, manager->GetNumberOfManagedWindows());
645 gfx::Rect moved_bounds(window->bounds());
646 EXPECT_NE(rect.origin().ToString(), moved_bounds.origin().ToString());
647 EXPECT_EQ(rect.size().ToString(), moved_bounds.size().ToString());
649 // Simulating a desktop resize should move the window again.
650 ResizeDesktop(-10);
651 gfx::Rect new_moved_bounds(window->bounds());
652 EXPECT_NE(rect.origin().ToString(), new_moved_bounds.origin().ToString());
653 EXPECT_EQ(rect.size().ToString(), new_moved_bounds.size().ToString());
654 EXPECT_NE(moved_bounds.origin().ToString(), new_moved_bounds.ToString());
656 // Then resize back to the original desktop size which should move windows
657 // to their original location after leaving the maximize mode.
658 ResizeDesktop(10);
659 DestroyMaximizeModeWindowManager();
660 EXPECT_EQ(rect.ToString(), window->bounds().ToString());
663 // Check that enabling of the maximize mode does not have an impact on the MRU
664 // order of windows.
665 TEST_F(MaximizeModeWindowManagerTest, ModeChangeKeepsMRUOrder) {
666 gfx::Rect rect(20, 140, 100, 100);
667 scoped_ptr<aura::Window> w1(
668 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
669 scoped_ptr<aura::Window> w2(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
670 scoped_ptr<aura::Window> w3(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
671 scoped_ptr<aura::Window> w4(
672 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
673 scoped_ptr<aura::Window> w5(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
675 // The windows should be in the reverse order of creation in the MRU list.
677 MruWindowTracker::WindowList windows =
678 MruWindowTracker::BuildWindowList(false);
679 EXPECT_EQ(w1.get(), windows[4]);
680 EXPECT_EQ(w2.get(), windows[3]);
681 EXPECT_EQ(w3.get(), windows[2]);
682 EXPECT_EQ(w4.get(), windows[1]);
683 EXPECT_EQ(w5.get(), windows[0]);
686 // Activating the window manager should keep the order.
687 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
688 ASSERT_TRUE(manager);
689 EXPECT_EQ(5, manager->GetNumberOfManagedWindows());
691 MruWindowTracker::WindowList windows =
692 MruWindowTracker::BuildWindowList(false);
693 // We do not test maximization here again since that was done already.
694 EXPECT_EQ(w1.get(), windows[4]);
695 EXPECT_EQ(w2.get(), windows[3]);
696 EXPECT_EQ(w3.get(), windows[2]);
697 EXPECT_EQ(w4.get(), windows[1]);
698 EXPECT_EQ(w5.get(), windows[0]);
701 // Destroying should still keep the order.
702 DestroyMaximizeModeWindowManager();
704 MruWindowTracker::WindowList windows =
705 MruWindowTracker::BuildWindowList(false);
706 // We do not test maximization here again since that was done already.
707 EXPECT_EQ(w1.get(), windows[4]);
708 EXPECT_EQ(w2.get(), windows[3]);
709 EXPECT_EQ(w3.get(), windows[2]);
710 EXPECT_EQ(w4.get(), windows[1]);
711 EXPECT_EQ(w5.get(), windows[0]);
715 // Check that a restore state change does always restore to maximized.
716 TEST_F(MaximizeModeWindowManagerTest, IgnoreRestoreStateChages) {
717 gfx::Rect rect(20, 140, 100, 100);
718 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
719 wm::WindowState* window_state = wm::GetWindowState(w1.get());
720 CreateMaximizeModeWindowManager();
721 EXPECT_TRUE(window_state->IsMaximized());
722 window_state->Minimize();
723 EXPECT_TRUE(window_state->IsMinimized());
724 window_state->Restore();
725 EXPECT_TRUE(window_state->IsMaximized());
726 window_state->Restore();
727 EXPECT_TRUE(window_state->IsMaximized());
728 DestroyMaximizeModeWindowManager();
731 // Check that minimize and restore do the right thing.
732 TEST_F(MaximizeModeWindowManagerTest, TestMinimize) {
733 gfx::Rect rect(10, 10, 100, 100);
734 scoped_ptr<aura::Window> window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL,
735 rect));
736 wm::WindowState* window_state = wm::GetWindowState(window.get());
737 EXPECT_EQ(rect.ToString(), window->bounds().ToString());
738 ash::Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
739 EXPECT_TRUE(window_state->IsMaximized());
740 EXPECT_FALSE(window_state->IsMinimized());
741 EXPECT_TRUE(window->IsVisible());
743 window_state->Minimize();
744 EXPECT_FALSE(window_state->IsMaximized());
745 EXPECT_TRUE(window_state->IsMinimized());
746 EXPECT_FALSE(window->IsVisible());
748 window_state->Maximize();
749 EXPECT_TRUE(window_state->IsMaximized());
750 EXPECT_FALSE(window_state->IsMinimized());
751 EXPECT_TRUE(window->IsVisible());
753 ash::Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
754 EXPECT_FALSE(window_state->IsMaximized());
755 EXPECT_FALSE(window_state->IsMinimized());
756 EXPECT_TRUE(window->IsVisible());
759 // Check that a full screen window is staying full screen in maximize mode,
760 // and that it returns to full screen thereafter (if left).
761 TEST_F(MaximizeModeWindowManagerTest, KeepFullScreenModeOn) {
762 gfx::Rect rect(20, 140, 100, 100);
763 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
764 wm::WindowState* window_state = wm::GetWindowState(w1.get());
766 ShelfLayoutManager* shelf =
767 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
769 // Allow the shelf to hide.
770 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
771 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
773 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
774 window_state->OnWMEvent(&event);
776 // With full screen, the shelf should get hidden.
777 EXPECT_TRUE(window_state->IsFullscreen());
778 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
780 CreateMaximizeModeWindowManager();
782 // The Full screen mode should continue to be on.
783 EXPECT_TRUE(window_state->IsFullscreen());
784 EXPECT_FALSE(window_state->IsMaximized());
785 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
787 // With leaving the fullscreen mode, the maximized mode should return and the
788 // shelf should become visible.
789 window_state->OnWMEvent(&event);
790 EXPECT_FALSE(window_state->IsFullscreen());
791 EXPECT_TRUE(window_state->IsMaximized());
792 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
794 // Ending the maximize mode should return to full screen and the shelf should
795 // be hidden again.
796 DestroyMaximizeModeWindowManager();
797 EXPECT_TRUE(window_state->IsFullscreen());
798 EXPECT_FALSE(window_state->IsMaximized());
799 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
802 // Check that full screen mode can be turned on in maximized mode and remains
803 // upon coming back.
804 TEST_F(MaximizeModeWindowManagerTest, AllowFullScreenMode) {
805 gfx::Rect rect(20, 140, 100, 100);
806 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
807 wm::WindowState* window_state = wm::GetWindowState(w1.get());
809 ShelfLayoutManager* shelf =
810 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
812 // Allow the shelf to hide.
813 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
815 EXPECT_FALSE(window_state->IsFullscreen());
816 EXPECT_FALSE(window_state->IsMaximized());
817 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
819 CreateMaximizeModeWindowManager();
821 // Fullscreen mode should still be off and the shelf should be visible.
822 EXPECT_FALSE(window_state->IsFullscreen());
823 EXPECT_TRUE(window_state->IsMaximized());
824 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
826 // After going into fullscreen mode, the shelf should be hidden.
827 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
828 window_state->OnWMEvent(&event);
829 EXPECT_TRUE(window_state->IsFullscreen());
830 EXPECT_FALSE(window_state->IsMaximized());
831 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
833 // With the destruction of the manager we should remain in full screen.
834 DestroyMaximizeModeWindowManager();
835 EXPECT_TRUE(window_state->IsFullscreen());
836 EXPECT_FALSE(window_state->IsMaximized());
837 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
840 // Check that the full screen mode will stay active when the maximize mode is
841 // ended.
842 TEST_F(MaximizeModeWindowManagerTest,
843 FullScreenModeRemainsWhenCreatedInMaximizedMode) {
844 CreateMaximizeModeWindowManager();
846 gfx::Rect rect(20, 140, 100, 100);
847 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
848 wm::WindowState* window_state = wm::GetWindowState(w1.get());
849 wm::WMEvent event_full_screen(wm::WM_EVENT_TOGGLE_FULLSCREEN);
850 window_state->OnWMEvent(&event_full_screen);
851 EXPECT_TRUE(window_state->IsFullscreen());
853 // After the maximize mode manager is ended, full screen will remain.
854 DestroyMaximizeModeWindowManager();
855 EXPECT_TRUE(window_state->IsFullscreen());
858 // Check that the full screen mode will stay active throughout a maximzied mode
859 // session.
860 TEST_F(MaximizeModeWindowManagerTest,
861 FullScreenModeRemainsThroughMaximizeModeSwitch) {
862 gfx::Rect rect(20, 140, 100, 100);
863 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
864 wm::WindowState* window_state = wm::GetWindowState(w1.get());
865 wm::WMEvent event_full_screen(wm::WM_EVENT_TOGGLE_FULLSCREEN);
866 window_state->OnWMEvent(&event_full_screen);
867 EXPECT_TRUE(window_state->IsFullscreen());
869 CreateMaximizeModeWindowManager();
870 EXPECT_TRUE(window_state->IsFullscreen());
871 DestroyMaximizeModeWindowManager();
872 EXPECT_TRUE(window_state->IsFullscreen());
875 // Check that an empty window does not get restored to a tiny size.
876 TEST_F(MaximizeModeWindowManagerTest,
877 CreateAndMaximizeInMaximizeModeShouldRetoreToGoodSizeGoingToDefault) {
878 CreateMaximizeModeWindowManager();
879 gfx::Rect rect;
880 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
881 w1->Show();
882 wm::WindowState* window_state = wm::GetWindowState(w1.get());
883 EXPECT_TRUE(window_state->IsMaximized());
885 // There is a calling order in which the restore bounds can get set to an
886 // empty rectangle. We simulate this here.
887 window_state->SetRestoreBoundsInScreen(rect);
888 EXPECT_TRUE(window_state->GetRestoreBoundsInScreen().IsEmpty());
890 // Setting the window to a new size will physically not change the window,
891 // but the restore size should get updated so that a restore later on will
892 // return to this size.
893 gfx::Rect requested_bounds(10, 20, 50, 70);
894 w1->SetBounds(requested_bounds);
895 EXPECT_TRUE(window_state->IsMaximized());
896 EXPECT_EQ(requested_bounds.ToString(),
897 window_state->GetRestoreBoundsInScreen().ToString());
899 DestroyMaximizeModeWindowManager();
901 EXPECT_FALSE(window_state->IsMaximized());
902 EXPECT_EQ(w1->bounds().ToString(), requested_bounds.ToString());
905 // Check that snapping operations get ignored.
906 TEST_F(MaximizeModeWindowManagerTest, SnapModeTests) {
907 gfx::Rect rect(20, 140, 100, 100);
908 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
909 wm::WindowState* window_state = wm::GetWindowState(w1.get());
910 wm::WMEvent event_left(wm::WM_EVENT_SNAP_LEFT);
911 wm::WMEvent event_right(wm::WM_EVENT_SNAP_RIGHT);
912 window_state->OnWMEvent(&event_left);
913 EXPECT_TRUE(window_state->IsSnapped());
915 CreateMaximizeModeWindowManager();
917 // Fullscreen mode should now be off and it should not come back while in
918 // maximize mode.
919 EXPECT_FALSE(window_state->IsSnapped());
920 EXPECT_TRUE(window_state->IsMaximized());
921 window_state->OnWMEvent(&event_left);
922 EXPECT_FALSE(window_state->IsSnapped());
923 EXPECT_TRUE(window_state->IsMaximized());
924 window_state->OnWMEvent(&event_right);
925 EXPECT_FALSE(window_state->IsSnapped());
926 EXPECT_TRUE(window_state->IsMaximized());
928 DestroyMaximizeModeWindowManager();
929 EXPECT_TRUE(window_state->IsSnapped());
932 // Check that non maximizable windows cannot be dragged by the user.
933 TEST_F(MaximizeModeWindowManagerTest, TryToDesktopSizeDragUnmaximizable) {
934 gfx::Rect rect(10, 10, 100, 100);
935 scoped_ptr<aura::Window> window(
936 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
937 EXPECT_EQ(rect.ToString(), window->bounds().ToString());
939 // 1. Move the mouse over the caption and check that dragging the window does
940 // change the location.
941 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
942 generator.MoveMouseTo(gfx::Point(rect.x() + 2, rect.y() + 2));
943 generator.PressLeftButton();
944 generator.MoveMouseBy(10, 5);
945 RunAllPendingInMessageLoop();
946 generator.ReleaseLeftButton();
947 gfx::Point first_dragged_origin = window->bounds().origin();
948 EXPECT_EQ(rect.x() + 10, first_dragged_origin.x());
949 EXPECT_EQ(rect.y() + 5, first_dragged_origin.y());
951 // 2. Check that turning on the manager will stop allowing the window from
952 // dragging.
953 ash::Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
954 gfx::Rect center_bounds(window->bounds());
955 EXPECT_NE(rect.origin().ToString(), center_bounds.origin().ToString());
956 generator.MoveMouseTo(gfx::Point(center_bounds.x() + 1,
957 center_bounds.y() + 1));
958 generator.PressLeftButton();
959 generator.MoveMouseBy(10, 5);
960 RunAllPendingInMessageLoop();
961 generator.ReleaseLeftButton();
962 EXPECT_EQ(center_bounds.x(), window->bounds().x());
963 EXPECT_EQ(center_bounds.y(), window->bounds().y());
964 ash::Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
966 // 3. Releasing the mazimize manager again will restore the window to its
967 // previous bounds and
968 generator.MoveMouseTo(gfx::Point(first_dragged_origin.x() + 1,
969 first_dragged_origin.y() + 1));
970 generator.PressLeftButton();
971 generator.MoveMouseBy(10, 5);
972 RunAllPendingInMessageLoop();
973 generator.ReleaseLeftButton();
974 EXPECT_EQ(first_dragged_origin.x() + 10, window->bounds().x());
975 EXPECT_EQ(first_dragged_origin.y() + 5, window->bounds().y());
978 // Test that overview is exited before entering / exiting maximize mode so that
979 // the window changes made by MaximizeModeWindowManager do not conflict with
980 // those made in WindowOverview.
981 TEST_F(MaximizeModeWindowManagerTest, ExitsOverview) {
982 // Bounds for windows we know can be controlled.
983 gfx::Rect rect1(10, 10, 200, 50);
984 gfx::Rect rect2(10, 60, 200, 50);
985 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect1));
986 scoped_ptr<aura::Window> w2(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
988 WindowSelectorController* window_selector_controller =
989 Shell::GetInstance()->window_selector_controller();
990 window_selector_controller->ToggleOverview();
991 ASSERT_TRUE(window_selector_controller->IsSelecting());
992 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
993 ASSERT_TRUE(manager);
994 EXPECT_FALSE(window_selector_controller->IsSelecting());
996 window_selector_controller->ToggleOverview();
997 ASSERT_TRUE(window_selector_controller->IsSelecting());
998 // Destroy the manager again and check that the windows return to their
999 // previous state.
1000 DestroyMaximizeModeWindowManager();
1001 EXPECT_FALSE(window_selector_controller->IsSelecting());
1004 // Test that an edge swipe from the top will end full screen mode.
1005 TEST_F(MaximizeModeWindowManagerTest, ExitFullScreenWithEdgeSwipeFromTop) {
1006 gfx::Rect rect(10, 10, 200, 50);
1007 scoped_ptr<aura::Window>
1008 background_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1009 scoped_ptr<aura::Window>
1010 foreground_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1011 wm::WindowState* background_window_state =
1012 wm::GetWindowState(background_window.get());
1013 wm::WindowState* foreground_window_state =
1014 wm::GetWindowState(foreground_window.get());
1015 wm::ActivateWindow(foreground_window.get());
1016 CreateMaximizeModeWindowManager();
1018 // Fullscreen both windows.
1019 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
1020 background_window_state->OnWMEvent(&event);
1021 foreground_window_state->OnWMEvent(&event);
1022 EXPECT_TRUE(background_window_state->IsFullscreen());
1023 EXPECT_TRUE(foreground_window_state->IsFullscreen());
1024 EXPECT_EQ(foreground_window.get(), wm::GetActiveWindow());
1026 // Do an edge swipe top into screen.
1027 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1028 generator.GestureScrollSequence(gfx::Point(50, 0),
1029 gfx::Point(50, 100),
1030 base::TimeDelta::FromMilliseconds(20),
1031 10);
1033 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1034 EXPECT_TRUE(background_window_state->IsFullscreen());
1036 // Do a second edge swipe top into screen.
1037 generator.GestureScrollSequence(gfx::Point(50, 0),
1038 gfx::Point(50, 100),
1039 base::TimeDelta::FromMilliseconds(20),
1040 10);
1042 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1043 EXPECT_TRUE(background_window_state->IsFullscreen());
1045 DestroyMaximizeModeWindowManager();
1048 // Test that an edge swipe from the bottom will end full screen mode.
1049 TEST_F(MaximizeModeWindowManagerTest, ExitFullScreenWithEdgeSwipeFromBottom) {
1050 gfx::Rect rect(10, 10, 200, 50);
1051 scoped_ptr<aura::Window>
1052 background_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1053 scoped_ptr<aura::Window>
1054 foreground_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1055 wm::WindowState* background_window_state =
1056 wm::GetWindowState(background_window.get());
1057 wm::WindowState* foreground_window_state =
1058 wm::GetWindowState(foreground_window.get());
1059 wm::ActivateWindow(foreground_window.get());
1060 CreateMaximizeModeWindowManager();
1062 // Fullscreen both windows.
1063 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
1064 background_window_state->OnWMEvent(&event);
1065 foreground_window_state->OnWMEvent(&event);
1066 EXPECT_TRUE(background_window_state->IsFullscreen());
1067 EXPECT_TRUE(foreground_window_state->IsFullscreen());
1068 EXPECT_EQ(foreground_window.get(), wm::GetActiveWindow());
1070 // Do an edge swipe bottom into screen.
1071 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1072 int y = Shell::GetPrimaryRootWindow()->bounds().bottom();
1073 generator.GestureScrollSequence(gfx::Point(50, y),
1074 gfx::Point(50, y - 100),
1075 base::TimeDelta::FromMilliseconds(20),
1076 10);
1078 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1079 EXPECT_TRUE(background_window_state->IsFullscreen());
1081 DestroyMaximizeModeWindowManager();
1084 // Test that an edge touch press at the top will end full screen mode.
1085 TEST_F(MaximizeModeWindowManagerTest, ExitFullScreenWithEdgeTouchAtTop) {
1086 gfx::Rect rect(10, 10, 200, 50);
1087 scoped_ptr<aura::Window>
1088 background_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1089 scoped_ptr<aura::Window>
1090 foreground_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1091 wm::WindowState* background_window_state =
1092 wm::GetWindowState(background_window.get());
1093 wm::WindowState* foreground_window_state =
1094 wm::GetWindowState(foreground_window.get());
1095 wm::ActivateWindow(foreground_window.get());
1096 CreateMaximizeModeWindowManager();
1098 // Fullscreen both windows.
1099 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
1100 background_window_state->OnWMEvent(&event);
1101 foreground_window_state->OnWMEvent(&event);
1102 EXPECT_TRUE(background_window_state->IsFullscreen());
1103 EXPECT_TRUE(foreground_window_state->IsFullscreen());
1104 EXPECT_EQ(foreground_window.get(), wm::GetActiveWindow());
1106 // Touch tap on the top edge.
1107 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1108 generator.GestureTapAt(gfx::Point(100, 0));
1109 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1110 EXPECT_TRUE(background_window_state->IsFullscreen());
1112 // Try the same again and see that nothing changes.
1113 generator.GestureTapAt(gfx::Point(100, 0));
1114 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1115 EXPECT_TRUE(background_window_state->IsFullscreen());
1117 DestroyMaximizeModeWindowManager();
1120 // Test that an edge touch press at the bottom will end full screen mode.
1121 TEST_F(MaximizeModeWindowManagerTest, ExitFullScreenWithEdgeTouchAtBottom) {
1122 gfx::Rect rect(10, 10, 200, 50);
1123 scoped_ptr<aura::Window>
1124 background_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1125 scoped_ptr<aura::Window>
1126 foreground_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1127 wm::WindowState* background_window_state =
1128 wm::GetWindowState(background_window.get());
1129 wm::WindowState* foreground_window_state =
1130 wm::GetWindowState(foreground_window.get());
1131 wm::ActivateWindow(foreground_window.get());
1132 CreateMaximizeModeWindowManager();
1134 // Fullscreen both windows.
1135 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
1136 background_window_state->OnWMEvent(&event);
1137 foreground_window_state->OnWMEvent(&event);
1138 EXPECT_TRUE(background_window_state->IsFullscreen());
1139 EXPECT_TRUE(foreground_window_state->IsFullscreen());
1140 EXPECT_EQ(foreground_window.get(), wm::GetActiveWindow());
1142 // Touch tap on the bottom edge.
1143 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1144 generator.GestureTapAt(
1145 gfx::Point(100, Shell::GetPrimaryRootWindow()->bounds().bottom() - 1));
1146 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1147 EXPECT_TRUE(background_window_state->IsFullscreen());
1149 // Try the same again and see that nothing changes.
1150 generator.GestureTapAt(
1151 gfx::Point(100, Shell::GetPrimaryRootWindow()->bounds().bottom() - 1));
1152 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1153 EXPECT_TRUE(background_window_state->IsFullscreen());
1155 DestroyMaximizeModeWindowManager();
1158 #endif // OS_WIN
1160 } // namespace ash