Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / wm / maximize_mode / maximize_mode_window_manager_unittest.cc
blob986d041da11a1a2e511c4cb534db032f87da0be1
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 <string>
9 #include "ash/root_window_controller.h"
10 #include "ash/screen_util.h"
11 #include "ash/shelf/shelf_layout_manager.h"
12 #include "ash/shell.h"
13 #include "ash/switchable_windows.h"
14 #include "ash/test/ash_test_base.h"
15 #include "ash/test/shell_test_api.h"
16 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
17 #include "ash/wm/mru_window_tracker.h"
18 #include "ash/wm/overview/window_selector_controller.h"
19 #include "ash/wm/window_properties.h"
20 #include "ash/wm/window_state.h"
21 #include "ash/wm/window_util.h"
22 #include "ash/wm/wm_event.h"
23 #include "base/strings/stringprintf.h"
24 #include "base/strings/utf_string_conversions.h"
25 #include "base/values.h"
26 #include "ui/aura/client/aura_constants.h"
27 #include "ui/aura/test/test_window_delegate.h"
28 #include "ui/aura/test/test_windows.h"
29 #include "ui/aura/window.h"
30 #include "ui/base/hit_test.h"
31 #include "ui/events/test/event_generator.h"
33 namespace ash {
35 // TODO(skuhne): These tests are failing on Widows because maximized is there
36 // differently handled. Fix this!
37 #if !defined(OS_WIN)
39 class MaximizeModeWindowManagerTest : public test::AshTestBase {
40 public:
41 MaximizeModeWindowManagerTest() {}
42 virtual ~MaximizeModeWindowManagerTest() {}
44 // Creates a window which has a fixed size.
45 aura::Window* CreateFixedSizeNonMaximizableWindow(ui::wm::WindowType type,
46 const gfx::Rect& bounds) {
47 return CreateWindowInWatchedContainer(
48 type, bounds, gfx::Size(), false, false);
51 // Creates a window which can not be maximized, but resized. |max_size|
52 // denotes the maximal possible size, if the size is empty, the window has no
53 // upper limit. Note: This function will only work with a single root window.
54 aura::Window* CreateNonMaximizableWindow(ui::wm::WindowType type,
55 const gfx::Rect& bounds,
56 const gfx::Size& max_size) {
57 return CreateWindowInWatchedContainer(type, bounds, max_size, false, true);
60 // Creates a maximizable and resizable window.
61 aura::Window* CreateWindow(ui::wm::WindowType type,
62 const gfx::Rect bounds) {
63 return CreateWindowInWatchedContainer(
64 type, bounds, gfx::Size(), true, true);
67 // Creates a window which also has a widget.
68 aura::Window* CreateWindowWithWidget(const gfx::Rect& bounds) {
69 views::Widget* widget = new views::Widget();
70 views::Widget::InitParams params;
71 params.context = CurrentContext();
72 // Note: The widget will get deleted with the window.
73 widget->Init(params);
74 widget->Show();
75 aura::Window* window = widget->GetNativeWindow();
76 window->SetBounds(bounds);
77 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
79 return window;
82 // Create the Maximized mode window manager.
83 ash::MaximizeModeWindowManager* CreateMaximizeModeWindowManager() {
84 EXPECT_FALSE(maximize_mode_window_manager());
85 Shell::GetInstance()->maximize_mode_controller()->
86 EnableMaximizeModeWindowManager(true);
87 return maximize_mode_window_manager();
90 // Destroy the maximized mode window manager.
91 void DestroyMaximizeModeWindowManager() {
92 Shell::GetInstance()->maximize_mode_controller()->
93 EnableMaximizeModeWindowManager(false);
94 EXPECT_FALSE(maximize_mode_window_manager());
97 // Get the maximze window manager.
98 ash::MaximizeModeWindowManager* maximize_mode_window_manager() {
99 return Shell::GetInstance()->maximize_mode_controller()->
100 maximize_mode_window_manager_.get();
103 // Resize our desktop.
104 void ResizeDesktop(int width_delta) {
105 gfx::Size size = Shell::GetScreen()->GetDisplayNearestWindow(
106 Shell::GetPrimaryRootWindow()).size();
107 size.Enlarge(0, width_delta);
108 UpdateDisplay(size.ToString());
111 private:
112 // Create a window in one of the containers which are watched by the
113 // MaximizeModeWindowManager. Note that this only works with one root window.
114 // If |can_maximize| is not set, |max_size| is the upper limiting size for
115 // the window, whereas an empty size means that there is no limit.
116 aura::Window* CreateWindowInWatchedContainer(ui::wm::WindowType type,
117 const gfx::Rect& bounds,
118 const gfx::Size& max_size,
119 bool can_maximize,
120 bool can_resize) {
121 aura::test::TestWindowDelegate* delegate = NULL;
122 if (!can_maximize) {
123 delegate = aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate();
124 delegate->set_window_component(HTCAPTION);
125 if (!max_size.IsEmpty())
126 delegate->set_maximum_size(max_size);
128 aura::Window* window = aura::test::CreateTestWindowWithDelegateAndType(
129 delegate, type, 0, bounds, NULL);
130 window->SetProperty(aura::client::kCanMaximizeKey, can_maximize);
131 if (!can_resize)
132 window->SetProperty(aura::client::kCanResizeKey, false);
133 aura::Window* container = Shell::GetContainer(
134 Shell::GetPrimaryRootWindow(),
135 kSwitchableWindowContainerIds[0]);
136 container->AddChild(window);
137 return window;
140 DISALLOW_COPY_AND_ASSIGN(MaximizeModeWindowManagerTest);
143 // Test that creating the object and destroying it without any windows should
144 // not cause any problems.
145 TEST_F(MaximizeModeWindowManagerTest, SimpleStart) {
146 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
147 ASSERT_TRUE(manager);
148 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
149 DestroyMaximizeModeWindowManager();
152 // Test that existing windows will handled properly when going into maximized
153 // mode.
154 TEST_F(MaximizeModeWindowManagerTest, PreCreateWindows) {
155 // Bounds for windows we know can be controlled.
156 gfx::Rect rect1(10, 10, 200, 50);
157 gfx::Rect rect2(10, 60, 200, 50);
158 gfx::Rect rect3(20, 140, 100, 100);
159 // Bounds for anything else.
160 gfx::Rect rect(80, 90, 100, 110);
161 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect1));
162 scoped_ptr<aura::Window> w2(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
163 scoped_ptr<aura::Window> w3(
164 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect3));
165 scoped_ptr<aura::Window> w4(CreateWindow(ui::wm::WINDOW_TYPE_PANEL, rect));
166 scoped_ptr<aura::Window> w5(CreateWindow(ui::wm::WINDOW_TYPE_POPUP, rect));
167 scoped_ptr<aura::Window> w6(CreateWindow(ui::wm::WINDOW_TYPE_CONTROL, rect));
168 scoped_ptr<aura::Window> w7(CreateWindow(ui::wm::WINDOW_TYPE_MENU, rect));
169 scoped_ptr<aura::Window> w8(CreateWindow(ui::wm::WINDOW_TYPE_TOOLTIP, rect));
170 EXPECT_FALSE(wm::GetWindowState(w1.get())->IsMaximized());
171 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized());
172 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
173 EXPECT_EQ(rect1.ToString(), w1->bounds().ToString());
174 EXPECT_EQ(rect2.ToString(), w2->bounds().ToString());
175 EXPECT_EQ(rect3.ToString(), w3->bounds().ToString());
177 // Create the manager and make sure that all qualifying windows were detected
178 // and changed.
179 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
180 ASSERT_TRUE(manager);
181 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
182 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsMaximized());
183 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized());
184 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
185 EXPECT_NE(rect3.origin().ToString(), w3->bounds().origin().ToString());
186 EXPECT_EQ(rect3.size().ToString(), w3->bounds().size().ToString());
188 // All other windows should not have been touched.
189 EXPECT_FALSE(wm::GetWindowState(w4.get())->IsMaximized());
190 EXPECT_FALSE(wm::GetWindowState(w5.get())->IsMaximized());
191 EXPECT_FALSE(wm::GetWindowState(w6.get())->IsMaximized());
192 EXPECT_FALSE(wm::GetWindowState(w7.get())->IsMaximized());
193 EXPECT_FALSE(wm::GetWindowState(w8.get())->IsMaximized());
194 EXPECT_EQ(rect.ToString(), w4->bounds().ToString());
195 EXPECT_EQ(rect.ToString(), w5->bounds().ToString());
196 EXPECT_EQ(rect.ToString(), w6->bounds().ToString());
197 EXPECT_EQ(rect.ToString(), w7->bounds().ToString());
198 EXPECT_EQ(rect.ToString(), w8->bounds().ToString());
200 // Destroy the manager again and check that the windows return to their
201 // previous state.
202 DestroyMaximizeModeWindowManager();
203 EXPECT_FALSE(wm::GetWindowState(w1.get())->IsMaximized());
204 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized());
205 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
206 EXPECT_EQ(rect1.ToString(), w1->bounds().ToString());
207 EXPECT_EQ(rect2.ToString(), w2->bounds().ToString());
208 EXPECT_EQ(rect3.ToString(), w3->bounds().ToString());
209 EXPECT_EQ(rect.ToString(), w4->bounds().ToString());
210 EXPECT_EQ(rect.ToString(), w5->bounds().ToString());
211 EXPECT_EQ(rect.ToString(), w6->bounds().ToString());
212 EXPECT_EQ(rect.ToString(), w7->bounds().ToString());
213 EXPECT_EQ(rect.ToString(), w8->bounds().ToString());
216 // Test that non-maximizable windows get properly handled when going into
217 // maximized mode.
218 TEST_F(MaximizeModeWindowManagerTest,
219 PreCreateNonMaximizableButResizableWindows) {
220 // The window bounds.
221 gfx::Rect rect(10, 10, 200, 50);
222 gfx::Size max_size(300, 200);
223 gfx::Size empty_size;
224 scoped_ptr<aura::Window> unlimited_window(
225 CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect, empty_size));
226 scoped_ptr<aura::Window> limited_window(
227 CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect, max_size));
228 scoped_ptr<aura::Window> fixed_window(
229 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
230 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
231 EXPECT_EQ(rect.ToString(), unlimited_window->bounds().ToString());
232 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
233 EXPECT_EQ(rect.ToString(), limited_window->bounds().ToString());
234 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
235 EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString());
237 gfx::Size workspace_size = ScreenUtil::GetMaximizedWindowBoundsInParent(
238 unlimited_window.get()).size();
240 // Create the manager and make sure that all qualifying windows were detected
241 // and changed.
242 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
243 ASSERT_TRUE(manager);
244 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
245 // The unlimited window should have the size of the workspace / parent window.
246 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
247 EXPECT_EQ("0,0", unlimited_window->bounds().origin().ToString());
248 EXPECT_EQ(workspace_size.ToString(),
249 unlimited_window->bounds().size().ToString());
250 // The limited window should have the size of the upper possible bounds.
251 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
252 EXPECT_NE(rect.origin().ToString(),
253 limited_window->bounds().origin().ToString());
254 EXPECT_EQ(max_size.ToString(),
255 limited_window->bounds().size().ToString());
256 // The fixed size window should have the size of the original window.
257 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
258 EXPECT_NE(rect.origin().ToString(),
259 fixed_window->bounds().origin().ToString());
260 EXPECT_EQ(rect.size().ToString(),
261 fixed_window->bounds().size().ToString());
263 // Destroy the manager again and check that the windows return to their
264 // previous state.
265 DestroyMaximizeModeWindowManager();
266 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
267 EXPECT_EQ(rect.ToString(), unlimited_window->bounds().ToString());
268 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
269 EXPECT_EQ(rect.ToString(), limited_window->bounds().ToString());
270 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
271 EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString());
274 // Test that creating windows while a maximizer exists picks them properly up.
275 TEST_F(MaximizeModeWindowManagerTest, CreateWindows) {
276 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
277 ASSERT_TRUE(manager);
278 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
280 // Create the windows and see that the window manager picks them up.
281 // Rects for windows we know can be controlled.
282 gfx::Rect rect1(10, 10, 200, 50);
283 gfx::Rect rect2(10, 60, 200, 50);
284 gfx::Rect rect3(20, 140, 100, 100);
285 // One rect for anything else.
286 gfx::Rect rect(80, 90, 100, 110);
287 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect1));
288 scoped_ptr<aura::Window> w2(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
289 scoped_ptr<aura::Window> w3(
290 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect3));
291 scoped_ptr<aura::Window> w4(CreateWindow(ui::wm::WINDOW_TYPE_PANEL, rect));
292 scoped_ptr<aura::Window> w5(CreateWindow(ui::wm::WINDOW_TYPE_POPUP, rect));
293 scoped_ptr<aura::Window> w6(CreateWindow(ui::wm::WINDOW_TYPE_CONTROL, rect));
294 scoped_ptr<aura::Window> w7(CreateWindow(ui::wm::WINDOW_TYPE_MENU, rect));
295 scoped_ptr<aura::Window> w8(CreateWindow(ui::wm::WINDOW_TYPE_TOOLTIP, rect));
296 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsMaximized());
297 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized());
298 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
299 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
301 // Make sure that the position of the unresizable window is in the middle of
302 // the screen.
303 gfx::Size work_area_size =
304 ScreenUtil::GetDisplayWorkAreaBoundsInParent(w3.get()).size();
305 gfx::Point center =
306 gfx::Point((work_area_size.width() - rect3.size().width()) / 2,
307 (work_area_size.height() - rect3.size().height()) / 2);
308 gfx::Rect centered_window_bounds = gfx::Rect(center, rect3.size());
309 EXPECT_EQ(centered_window_bounds.ToString(), w3->bounds().ToString());
311 // All other windows should not have been touched.
312 EXPECT_FALSE(wm::GetWindowState(w4.get())->IsMaximized());
313 EXPECT_FALSE(wm::GetWindowState(w5.get())->IsMaximized());
314 EXPECT_FALSE(wm::GetWindowState(w6.get())->IsMaximized());
315 EXPECT_FALSE(wm::GetWindowState(w7.get())->IsMaximized());
316 EXPECT_FALSE(wm::GetWindowState(w8.get())->IsMaximized());
317 EXPECT_EQ(rect.ToString(), w4->bounds().ToString());
318 EXPECT_EQ(rect.ToString(), w5->bounds().ToString());
319 EXPECT_EQ(rect.ToString(), w6->bounds().ToString());
320 EXPECT_EQ(rect.ToString(), w7->bounds().ToString());
321 EXPECT_EQ(rect.ToString(), w8->bounds().ToString());
323 // After the maximize mode was disabled all windows fall back into the mode
324 // they were created for.
325 DestroyMaximizeModeWindowManager();
326 EXPECT_FALSE(wm::GetWindowState(w1.get())->IsMaximized());
327 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized());
328 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
329 EXPECT_EQ(rect1.ToString(), w1->bounds().ToString());
330 EXPECT_EQ(rect2.ToString(), w2->bounds().ToString());
331 EXPECT_EQ(rect3.ToString(), w3->bounds().ToString());
332 EXPECT_EQ(rect.ToString(), w4->bounds().ToString());
333 EXPECT_EQ(rect.ToString(), w5->bounds().ToString());
334 EXPECT_EQ(rect.ToString(), w6->bounds().ToString());
335 EXPECT_EQ(rect.ToString(), w7->bounds().ToString());
336 EXPECT_EQ(rect.ToString(), w8->bounds().ToString());
339 // Test that a window which got created while the maximize mode window manager
340 // is active gets restored to a usable (non tiny) size upon switching back.
341 TEST_F(MaximizeModeWindowManagerTest,
342 CreateWindowInMaximizedModeRestoresToUsefulSize) {
343 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
344 ASSERT_TRUE(manager);
345 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
347 // We pass in an empty rectangle to simulate a window creation with no
348 // particular size.
349 gfx::Rect empty_rect(0, 0, 0, 0);
350 scoped_ptr<aura::Window> window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL,
351 empty_rect));
352 EXPECT_TRUE(wm::GetWindowState(window.get())->IsMaximized());
353 EXPECT_NE(empty_rect.ToString(), window->bounds().ToString());
354 gfx::Rect maximized_size = window->bounds();
356 // Destroy the maximize mode and check that the resulting size of the window
357 // is remaining as it is (but not maximized).
358 DestroyMaximizeModeWindowManager();
360 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized());
361 EXPECT_EQ(maximized_size.ToString(), window->bounds().ToString());
364 // Test that non-maximizable windows get properly handled when created in
365 // maximized mode.
366 TEST_F(MaximizeModeWindowManagerTest,
367 CreateNonMaximizableButResizableWindows) {
368 // Create the manager and make sure that all qualifying windows were detected
369 // and changed.
370 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
371 ASSERT_TRUE(manager);
373 gfx::Rect rect(10, 10, 200, 50);
374 gfx::Size max_size(300, 200);
375 gfx::Size empty_size;
376 scoped_ptr<aura::Window> unlimited_window(
377 CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect, empty_size));
378 scoped_ptr<aura::Window> limited_window(
379 CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect, max_size));
380 scoped_ptr<aura::Window> fixed_window(
381 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
383 gfx::Size workspace_size = ScreenUtil::GetMaximizedWindowBoundsInParent(
384 unlimited_window.get()).size();
386 // All windows should be sized now as big as possible and be centered.
387 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
388 // The unlimited window should have the size of the workspace / parent window.
389 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
390 EXPECT_EQ("0,0", unlimited_window->bounds().origin().ToString());
391 EXPECT_EQ(workspace_size.ToString(),
392 unlimited_window->bounds().size().ToString());
393 // The limited window should have the size of the upper possible bounds.
394 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
395 EXPECT_NE(rect.origin().ToString(),
396 limited_window->bounds().origin().ToString());
397 EXPECT_EQ(max_size.ToString(),
398 limited_window->bounds().size().ToString());
399 // The fixed size window should have the size of the original window.
400 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
401 EXPECT_NE(rect.origin().ToString(),
402 fixed_window->bounds().origin().ToString());
403 EXPECT_EQ(rect.size().ToString(),
404 fixed_window->bounds().size().ToString());
406 // Destroy the manager again and check that the windows return to their
407 // creation state.
408 DestroyMaximizeModeWindowManager();
410 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
411 EXPECT_EQ(rect.ToString(), unlimited_window->bounds().ToString());
412 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
413 EXPECT_EQ(rect.ToString(), limited_window->bounds().ToString());
414 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
415 EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString());
418 // Create a string which consists of the bounds and the state for comparison.
419 std::string GetPlacementString(const gfx::Rect& bounds,
420 ui::WindowShowState state) {
421 return bounds.ToString() + base::StringPrintf(" %d", state);
424 // Retrieves the window's restore state override - if any - and returns it as a
425 // string.
426 std::string GetPlacementOverride(aura::Window* window) {
427 gfx::Rect* bounds = window->GetProperty(ash::kRestoreBoundsOverrideKey);
428 if (bounds) {
429 gfx::Rect restore_bounds = *bounds;
430 ui::WindowShowState restore_state =
431 window->GetProperty(ash::kRestoreShowStateOverrideKey);
432 return GetPlacementString(restore_bounds, restore_state);
434 return std::string();
437 // Test that the restore state will be kept at its original value for
438 // session restauration purposes.
439 TEST_F(MaximizeModeWindowManagerTest, TestRestoreIntegrety) {
440 gfx::Rect bounds(10, 10, 200, 50);
441 gfx::Size empty_size;
442 gfx::Rect empty_bounds;
443 scoped_ptr<aura::Window> normal_window(
444 CreateWindowWithWidget(bounds));
445 scoped_ptr<aura::Window> maximized_window(
446 CreateWindowWithWidget(bounds));
447 wm::GetWindowState(maximized_window.get())->Maximize();
449 EXPECT_EQ(std::string(), GetPlacementOverride(normal_window.get()));
450 EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get()));
452 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
453 ASSERT_TRUE(manager);
455 // With the maximization the override states should be returned in its
456 // pre-maximized state.
457 EXPECT_EQ(GetPlacementString(bounds, ui::SHOW_STATE_NORMAL),
458 GetPlacementOverride(normal_window.get()));
459 EXPECT_EQ(GetPlacementString(bounds, ui::SHOW_STATE_MAXIMIZED),
460 GetPlacementOverride(maximized_window.get()));
462 // Changing a window's state now does not change the returned result.
463 wm::GetWindowState(maximized_window.get())->Minimize();
464 EXPECT_EQ(GetPlacementString(bounds, ui::SHOW_STATE_MAXIMIZED),
465 GetPlacementOverride(maximized_window.get()));
467 // Destroy the manager again and check that the overrides get reset.
468 DestroyMaximizeModeWindowManager();
469 EXPECT_EQ(std::string(), GetPlacementOverride(normal_window.get()));
470 EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get()));
472 // Changing a window's state now does not bring the overrides back.
473 wm::GetWindowState(maximized_window.get())->Restore();
474 gfx::Rect new_bounds(10, 10, 200, 50);
475 maximized_window->SetBounds(new_bounds);
477 EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get()));
480 // Test that windows which got created before the maximizer was created can be
481 // destroyed while the maximizer is still running.
482 TEST_F(MaximizeModeWindowManagerTest, PreCreateWindowsDeleteWhileActive) {
483 ash::MaximizeModeWindowManager* manager = NULL;
485 // Bounds for windows we know can be controlled.
486 gfx::Rect rect1(10, 10, 200, 50);
487 gfx::Rect rect2(10, 60, 200, 50);
488 gfx::Rect rect3(20, 140, 100, 100);
489 // Bounds for anything else.
490 gfx::Rect rect(80, 90, 100, 110);
491 scoped_ptr<aura::Window> w1(
492 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect1));
493 scoped_ptr<aura::Window> w2(
494 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
495 scoped_ptr<aura::Window> w3(
496 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect3));
498 // Create the manager and make sure that all qualifying windows were
499 // detected and changed.
500 manager = CreateMaximizeModeWindowManager();
501 ASSERT_TRUE(manager);
502 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
504 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
505 DestroyMaximizeModeWindowManager();
508 // Test that windows which got created while the maximizer was running can get
509 // destroyed before the maximizer gets destroyed.
510 TEST_F(MaximizeModeWindowManagerTest, CreateWindowsAndDeleteWhileActive) {
511 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
512 ASSERT_TRUE(manager);
513 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
515 // Bounds for windows we know can be controlled.
516 gfx::Rect rect1(10, 10, 200, 50);
517 gfx::Rect rect2(10, 60, 200, 50);
518 gfx::Rect rect3(20, 140, 100, 100);
519 scoped_ptr<aura::Window> w1(
520 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(10, 10, 200, 50)));
521 scoped_ptr<aura::Window> w2(
522 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(10, 60, 200, 50)));
523 scoped_ptr<aura::Window> w3(
524 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL,
525 gfx::Rect(20, 140, 100, 100)));
526 // Check that the windows got automatically maximized as well.
527 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
528 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsMaximized());
529 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized());
530 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
532 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
533 DestroyMaximizeModeWindowManager();
536 // Test that windows which were maximized stay maximized.
537 TEST_F(MaximizeModeWindowManagerTest, MaximizedShouldRemainMaximized) {
538 // Bounds for windows we know can be controlled.
539 gfx::Rect rect(10, 10, 200, 50);
540 scoped_ptr<aura::Window> window(
541 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
542 wm::GetWindowState(window.get())->Maximize();
544 // Create the manager and make sure that the window gets detected.
545 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
546 ASSERT_TRUE(manager);
547 EXPECT_EQ(1, manager->GetNumberOfManagedWindows());
548 EXPECT_TRUE(wm::GetWindowState(window.get())->IsMaximized());
550 // Destroy the manager again and check that the window will remain maximized.
551 DestroyMaximizeModeWindowManager();
552 EXPECT_TRUE(wm::GetWindowState(window.get())->IsMaximized());
553 wm::GetWindowState(window.get())->Restore();
554 EXPECT_EQ(rect.ToString(), window->bounds().ToString());
557 // Test that minimized windows do neither get maximized nor restored upon
558 // entering maximized mode and get restored to their previous state after
559 // leaving.
560 TEST_F(MaximizeModeWindowManagerTest, MinimizedWindowBehavior) {
561 // Bounds for windows we know can be controlled.
562 gfx::Rect rect(10, 10, 200, 50);
563 scoped_ptr<aura::Window> initially_minimized_window(
564 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
565 scoped_ptr<aura::Window> initially_normal_window(
566 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
567 scoped_ptr<aura::Window> initially_maximized_window(
568 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
569 wm::GetWindowState(initially_minimized_window.get())->Minimize();
570 wm::GetWindowState(initially_maximized_window.get())->Maximize();
572 // Create the manager and make sure that the window gets detected.
573 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
574 ASSERT_TRUE(manager);
575 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
576 EXPECT_TRUE(wm::GetWindowState(
577 initially_minimized_window.get())->IsMinimized());
578 EXPECT_TRUE(wm::GetWindowState(initially_normal_window.get())->IsMaximized());
579 EXPECT_TRUE(wm::GetWindowState(
580 initially_maximized_window.get())->IsMaximized());
581 // Now minimize the second window to check that upon leaving the window
582 // will get restored to its minimized state.
583 wm::GetWindowState(initially_normal_window.get())->Minimize();
584 wm::GetWindowState(initially_maximized_window.get())->Minimize();
585 EXPECT_TRUE(wm::GetWindowState(
586 initially_minimized_window.get())->IsMinimized());
587 EXPECT_TRUE(wm::GetWindowState(
588 initially_normal_window.get())->IsMinimized());
589 EXPECT_TRUE(wm::GetWindowState(
590 initially_maximized_window.get())->IsMinimized());
592 // Destroy the manager again and check that the window will get minimized.
593 DestroyMaximizeModeWindowManager();
594 EXPECT_TRUE(wm::GetWindowState(
595 initially_minimized_window.get())->IsMinimized());
596 EXPECT_FALSE(wm::GetWindowState(
597 initially_normal_window.get())->IsMinimized());
598 EXPECT_TRUE(wm::GetWindowState(
599 initially_maximized_window.get())->IsMaximized());
602 // Check that resizing the desktop does reposition unmaximizable, unresizable &
603 // managed windows.
604 TEST_F(MaximizeModeWindowManagerTest, DesktopSizeChangeMovesUnmaximizable) {
605 UpdateDisplay("400x400");
606 // This window will move because it does not fit the new bounds.
607 gfx::Rect rect(20, 300, 100, 100);
608 scoped_ptr<aura::Window> window1(
609 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
610 EXPECT_EQ(rect.ToString(), window1->bounds().ToString());
612 // This window will not move because it does fit the new bounds.
613 gfx::Rect rect2(20, 140, 100, 100);
614 scoped_ptr<aura::Window> window2(
615 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
617 // Turning on the manager will reposition (but not resize) the window.
618 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
619 ASSERT_TRUE(manager);
620 EXPECT_EQ(2, manager->GetNumberOfManagedWindows());
621 gfx::Rect moved_bounds(window1->bounds());
622 EXPECT_NE(rect.origin().ToString(), moved_bounds.origin().ToString());
623 EXPECT_EQ(rect.size().ToString(), moved_bounds.size().ToString());
625 // Simulating a desktop resize should move the window again.
626 UpdateDisplay("300x300");
627 gfx::Rect new_moved_bounds(window1->bounds());
628 EXPECT_NE(rect.origin().ToString(), new_moved_bounds.origin().ToString());
629 EXPECT_EQ(rect.size().ToString(), new_moved_bounds.size().ToString());
630 EXPECT_NE(moved_bounds.origin().ToString(), new_moved_bounds.ToString());
632 // Turning off the mode should not restore to the initial coordinates since
633 // the new resolution is smaller and the window was on the edge.
634 DestroyMaximizeModeWindowManager();
635 EXPECT_NE(rect.ToString(), window1->bounds().ToString());
636 EXPECT_EQ(rect2.ToString(), window2->bounds().ToString());
639 // Check that windows return to original location if desktop size changes to
640 // something else and back while in maximize mode.
641 TEST_F(MaximizeModeWindowManagerTest, SizeChangeReturnWindowToOriginalPos) {
642 gfx::Rect rect(20, 140, 100, 100);
643 scoped_ptr<aura::Window> window(
644 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
646 // Turning on the manager will reposition (but not resize) the window.
647 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
648 ASSERT_TRUE(manager);
649 EXPECT_EQ(1, manager->GetNumberOfManagedWindows());
650 gfx::Rect moved_bounds(window->bounds());
651 EXPECT_NE(rect.origin().ToString(), moved_bounds.origin().ToString());
652 EXPECT_EQ(rect.size().ToString(), moved_bounds.size().ToString());
654 // Simulating a desktop resize should move the window again.
655 ResizeDesktop(-10);
656 gfx::Rect new_moved_bounds(window->bounds());
657 EXPECT_NE(rect.origin().ToString(), new_moved_bounds.origin().ToString());
658 EXPECT_EQ(rect.size().ToString(), new_moved_bounds.size().ToString());
659 EXPECT_NE(moved_bounds.origin().ToString(), new_moved_bounds.ToString());
661 // Then resize back to the original desktop size which should move windows
662 // to their original location after leaving the maximize mode.
663 ResizeDesktop(10);
664 DestroyMaximizeModeWindowManager();
665 EXPECT_EQ(rect.ToString(), window->bounds().ToString());
668 // Check that enabling of the maximize mode does not have an impact on the MRU
669 // order of windows.
670 TEST_F(MaximizeModeWindowManagerTest, ModeChangeKeepsMRUOrder) {
671 gfx::Rect rect(20, 140, 100, 100);
672 scoped_ptr<aura::Window> w1(
673 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
674 scoped_ptr<aura::Window> w2(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
675 scoped_ptr<aura::Window> w3(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
676 scoped_ptr<aura::Window> w4(
677 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
678 scoped_ptr<aura::Window> w5(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
680 // The windows should be in the reverse order of creation in the MRU list.
682 MruWindowTracker::WindowList windows =
683 MruWindowTracker::BuildWindowList(false);
684 EXPECT_EQ(w1.get(), windows[4]);
685 EXPECT_EQ(w2.get(), windows[3]);
686 EXPECT_EQ(w3.get(), windows[2]);
687 EXPECT_EQ(w4.get(), windows[1]);
688 EXPECT_EQ(w5.get(), windows[0]);
691 // Activating the window manager should keep the order.
692 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
693 ASSERT_TRUE(manager);
694 EXPECT_EQ(5, manager->GetNumberOfManagedWindows());
696 MruWindowTracker::WindowList windows =
697 MruWindowTracker::BuildWindowList(false);
698 // We do not test maximization here again since that was done already.
699 EXPECT_EQ(w1.get(), windows[4]);
700 EXPECT_EQ(w2.get(), windows[3]);
701 EXPECT_EQ(w3.get(), windows[2]);
702 EXPECT_EQ(w4.get(), windows[1]);
703 EXPECT_EQ(w5.get(), windows[0]);
706 // Destroying should still keep the order.
707 DestroyMaximizeModeWindowManager();
709 MruWindowTracker::WindowList windows =
710 MruWindowTracker::BuildWindowList(false);
711 // We do not test maximization here again since that was done already.
712 EXPECT_EQ(w1.get(), windows[4]);
713 EXPECT_EQ(w2.get(), windows[3]);
714 EXPECT_EQ(w3.get(), windows[2]);
715 EXPECT_EQ(w4.get(), windows[1]);
716 EXPECT_EQ(w5.get(), windows[0]);
720 // Check that a restore state change does always restore to maximized.
721 TEST_F(MaximizeModeWindowManagerTest, IgnoreRestoreStateChages) {
722 gfx::Rect rect(20, 140, 100, 100);
723 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
724 wm::WindowState* window_state = wm::GetWindowState(w1.get());
725 CreateMaximizeModeWindowManager();
726 EXPECT_TRUE(window_state->IsMaximized());
727 window_state->Minimize();
728 EXPECT_TRUE(window_state->IsMinimized());
729 window_state->Restore();
730 EXPECT_TRUE(window_state->IsMaximized());
731 window_state->Restore();
732 EXPECT_TRUE(window_state->IsMaximized());
733 DestroyMaximizeModeWindowManager();
736 // Check that minimize and restore do the right thing.
737 TEST_F(MaximizeModeWindowManagerTest, TestMinimize) {
738 gfx::Rect rect(10, 10, 100, 100);
739 scoped_ptr<aura::Window> window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL,
740 rect));
741 wm::WindowState* window_state = wm::GetWindowState(window.get());
742 EXPECT_EQ(rect.ToString(), window->bounds().ToString());
743 ash::Shell::GetInstance()->maximize_mode_controller()->
744 EnableMaximizeModeWindowManager(true);
745 EXPECT_TRUE(window_state->IsMaximized());
746 EXPECT_FALSE(window_state->IsMinimized());
747 EXPECT_TRUE(window->IsVisible());
749 window_state->Minimize();
750 EXPECT_FALSE(window_state->IsMaximized());
751 EXPECT_TRUE(window_state->IsMinimized());
752 EXPECT_FALSE(window->IsVisible());
754 window_state->Maximize();
755 EXPECT_TRUE(window_state->IsMaximized());
756 EXPECT_FALSE(window_state->IsMinimized());
757 EXPECT_TRUE(window->IsVisible());
759 ash::Shell::GetInstance()->maximize_mode_controller()->
760 EnableMaximizeModeWindowManager(false);
761 EXPECT_FALSE(window_state->IsMaximized());
762 EXPECT_FALSE(window_state->IsMinimized());
763 EXPECT_TRUE(window->IsVisible());
766 // Check that a full screen window is staying full screen in maximize mode,
767 // and that it returns to full screen thereafter (if left).
768 TEST_F(MaximizeModeWindowManagerTest, KeepFullScreenModeOn) {
769 gfx::Rect rect(20, 140, 100, 100);
770 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
771 wm::WindowState* window_state = wm::GetWindowState(w1.get());
773 ShelfLayoutManager* shelf =
774 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
776 // Allow the shelf to hide.
777 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
778 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
780 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
781 window_state->OnWMEvent(&event);
783 // With full screen, the shelf should get hidden.
784 EXPECT_TRUE(window_state->IsFullscreen());
785 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
787 CreateMaximizeModeWindowManager();
789 // The Full screen mode should continue to be on.
790 EXPECT_TRUE(window_state->IsFullscreen());
791 EXPECT_FALSE(window_state->IsMaximized());
792 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
794 // With leaving the fullscreen mode, the maximized mode should return and the
795 // shelf should maintain its state from before maximize mode.
796 window_state->OnWMEvent(&event);
797 EXPECT_FALSE(window_state->IsFullscreen());
798 EXPECT_TRUE(window_state->IsMaximized());
799 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
801 // Ending the maximize mode should return to full screen and the shelf should
802 // be hidden again.
803 DestroyMaximizeModeWindowManager();
804 EXPECT_TRUE(window_state->IsFullscreen());
805 EXPECT_FALSE(window_state->IsMaximized());
806 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
809 // Check that full screen mode can be turned on in maximized mode and remains
810 // upon coming back.
811 TEST_F(MaximizeModeWindowManagerTest, AllowFullScreenMode) {
812 gfx::Rect rect(20, 140, 100, 100);
813 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
814 wm::WindowState* window_state = wm::GetWindowState(w1.get());
816 ShelfLayoutManager* shelf =
817 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
819 // Allow the shelf to hide.
820 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
822 EXPECT_FALSE(window_state->IsFullscreen());
823 EXPECT_FALSE(window_state->IsMaximized());
824 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
826 CreateMaximizeModeWindowManager();
828 // Fullscreen mode should still be off and the shelf should maintain its
829 // state.
830 EXPECT_FALSE(window_state->IsFullscreen());
831 EXPECT_TRUE(window_state->IsMaximized());
832 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
834 // After going into fullscreen mode, the shelf should be hidden.
835 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
836 window_state->OnWMEvent(&event);
837 EXPECT_TRUE(window_state->IsFullscreen());
838 EXPECT_FALSE(window_state->IsMaximized());
839 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
841 // With the destruction of the manager we should remain in full screen.
842 DestroyMaximizeModeWindowManager();
843 EXPECT_TRUE(window_state->IsFullscreen());
844 EXPECT_FALSE(window_state->IsMaximized());
845 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
848 // Check that the full screen mode will stay active when the maximize mode is
849 // ended.
850 TEST_F(MaximizeModeWindowManagerTest,
851 FullScreenModeRemainsWhenCreatedInMaximizedMode) {
852 CreateMaximizeModeWindowManager();
854 gfx::Rect rect(20, 140, 100, 100);
855 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
856 wm::WindowState* window_state = wm::GetWindowState(w1.get());
857 wm::WMEvent event_full_screen(wm::WM_EVENT_TOGGLE_FULLSCREEN);
858 window_state->OnWMEvent(&event_full_screen);
859 EXPECT_TRUE(window_state->IsFullscreen());
861 // After the maximize mode manager is ended, full screen will remain.
862 DestroyMaximizeModeWindowManager();
863 EXPECT_TRUE(window_state->IsFullscreen());
866 // Check that the full screen mode will stay active throughout a maximzied mode
867 // session.
868 TEST_F(MaximizeModeWindowManagerTest,
869 FullScreenModeRemainsThroughMaximizeModeSwitch) {
870 gfx::Rect rect(20, 140, 100, 100);
871 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
872 wm::WindowState* window_state = wm::GetWindowState(w1.get());
873 wm::WMEvent event_full_screen(wm::WM_EVENT_TOGGLE_FULLSCREEN);
874 window_state->OnWMEvent(&event_full_screen);
875 EXPECT_TRUE(window_state->IsFullscreen());
877 CreateMaximizeModeWindowManager();
878 EXPECT_TRUE(window_state->IsFullscreen());
879 DestroyMaximizeModeWindowManager();
880 EXPECT_TRUE(window_state->IsFullscreen());
883 // Check that an empty window does not get restored to a tiny size.
884 TEST_F(MaximizeModeWindowManagerTest,
885 CreateAndMaximizeInMaximizeModeShouldRetoreToGoodSizeGoingToDefault) {
886 CreateMaximizeModeWindowManager();
887 gfx::Rect rect;
888 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
889 w1->Show();
890 wm::WindowState* window_state = wm::GetWindowState(w1.get());
891 EXPECT_TRUE(window_state->IsMaximized());
893 // There is a calling order in which the restore bounds can get set to an
894 // empty rectangle. We simulate this here.
895 window_state->SetRestoreBoundsInScreen(rect);
896 EXPECT_TRUE(window_state->GetRestoreBoundsInScreen().IsEmpty());
898 // Setting the window to a new size will physically not change the window,
899 // but the restore size should get updated so that a restore later on will
900 // return to this size.
901 gfx::Rect requested_bounds(10, 20, 50, 70);
902 w1->SetBounds(requested_bounds);
903 EXPECT_TRUE(window_state->IsMaximized());
904 EXPECT_EQ(requested_bounds.ToString(),
905 window_state->GetRestoreBoundsInScreen().ToString());
907 DestroyMaximizeModeWindowManager();
909 EXPECT_FALSE(window_state->IsMaximized());
910 EXPECT_EQ(w1->bounds().ToString(), requested_bounds.ToString());
913 // Check that snapping operations get ignored.
914 TEST_F(MaximizeModeWindowManagerTest, SnapModeTests) {
915 gfx::Rect rect(20, 140, 100, 100);
916 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
917 wm::WindowState* window_state = wm::GetWindowState(w1.get());
918 wm::WMEvent event_left(wm::WM_EVENT_SNAP_LEFT);
919 wm::WMEvent event_right(wm::WM_EVENT_SNAP_RIGHT);
920 window_state->OnWMEvent(&event_left);
921 EXPECT_TRUE(window_state->IsSnapped());
923 CreateMaximizeModeWindowManager();
925 // Fullscreen mode should now be off and it should not come back while in
926 // maximize mode.
927 EXPECT_FALSE(window_state->IsSnapped());
928 EXPECT_TRUE(window_state->IsMaximized());
929 window_state->OnWMEvent(&event_left);
930 EXPECT_FALSE(window_state->IsSnapped());
931 EXPECT_TRUE(window_state->IsMaximized());
932 window_state->OnWMEvent(&event_right);
933 EXPECT_FALSE(window_state->IsSnapped());
934 EXPECT_TRUE(window_state->IsMaximized());
936 DestroyMaximizeModeWindowManager();
937 EXPECT_TRUE(window_state->IsSnapped());
940 // Check that non maximizable windows cannot be dragged by the user.
941 TEST_F(MaximizeModeWindowManagerTest, TryToDesktopSizeDragUnmaximizable) {
942 gfx::Rect rect(10, 10, 100, 100);
943 scoped_ptr<aura::Window> window(
944 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
945 EXPECT_EQ(rect.ToString(), window->bounds().ToString());
947 // 1. Move the mouse over the caption and check that dragging the window does
948 // change the location.
949 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
950 generator.MoveMouseTo(gfx::Point(rect.x() + 2, rect.y() + 2));
951 generator.PressLeftButton();
952 generator.MoveMouseBy(10, 5);
953 RunAllPendingInMessageLoop();
954 generator.ReleaseLeftButton();
955 gfx::Point first_dragged_origin = window->bounds().origin();
956 EXPECT_EQ(rect.x() + 10, first_dragged_origin.x());
957 EXPECT_EQ(rect.y() + 5, first_dragged_origin.y());
959 // 2. Check that turning on the manager will stop allowing the window from
960 // dragging.
961 ash::Shell::GetInstance()->maximize_mode_controller()->
962 EnableMaximizeModeWindowManager(true);
963 gfx::Rect center_bounds(window->bounds());
964 EXPECT_NE(rect.origin().ToString(), center_bounds.origin().ToString());
965 generator.MoveMouseTo(gfx::Point(center_bounds.x() + 1,
966 center_bounds.y() + 1));
967 generator.PressLeftButton();
968 generator.MoveMouseBy(10, 5);
969 RunAllPendingInMessageLoop();
970 generator.ReleaseLeftButton();
971 EXPECT_EQ(center_bounds.x(), window->bounds().x());
972 EXPECT_EQ(center_bounds.y(), window->bounds().y());
973 ash::Shell::GetInstance()->maximize_mode_controller()->
974 EnableMaximizeModeWindowManager(false);
976 // 3. Releasing the mazimize manager again will restore the window to its
977 // previous bounds and
978 generator.MoveMouseTo(gfx::Point(first_dragged_origin.x() + 1,
979 first_dragged_origin.y() + 1));
980 generator.PressLeftButton();
981 generator.MoveMouseBy(10, 5);
982 RunAllPendingInMessageLoop();
983 generator.ReleaseLeftButton();
984 EXPECT_EQ(first_dragged_origin.x() + 10, window->bounds().x());
985 EXPECT_EQ(first_dragged_origin.y() + 5, window->bounds().y());
988 // Test that overview is exited before entering / exiting maximize mode so that
989 // the window changes made by MaximizeModeWindowManager do not conflict with
990 // those made in WindowOverview.
991 TEST_F(MaximizeModeWindowManagerTest, ExitsOverview) {
992 // Bounds for windows we know can be controlled.
993 gfx::Rect rect1(10, 10, 200, 50);
994 gfx::Rect rect2(10, 60, 200, 50);
995 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect1));
996 scoped_ptr<aura::Window> w2(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
998 WindowSelectorController* window_selector_controller =
999 Shell::GetInstance()->window_selector_controller();
1000 window_selector_controller->ToggleOverview();
1001 ASSERT_TRUE(window_selector_controller->IsSelecting());
1002 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
1003 ASSERT_TRUE(manager);
1004 EXPECT_FALSE(window_selector_controller->IsSelecting());
1006 window_selector_controller->ToggleOverview();
1007 ASSERT_TRUE(window_selector_controller->IsSelecting());
1008 // Destroy the manager again and check that the windows return to their
1009 // previous state.
1010 DestroyMaximizeModeWindowManager();
1011 EXPECT_FALSE(window_selector_controller->IsSelecting());
1014 // Test that an edge swipe from the top will end full screen mode.
1015 TEST_F(MaximizeModeWindowManagerTest, ExitFullScreenWithEdgeSwipeFromTop) {
1016 gfx::Rect rect(10, 10, 200, 50);
1017 scoped_ptr<aura::Window>
1018 background_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1019 scoped_ptr<aura::Window>
1020 foreground_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1021 wm::WindowState* background_window_state =
1022 wm::GetWindowState(background_window.get());
1023 wm::WindowState* foreground_window_state =
1024 wm::GetWindowState(foreground_window.get());
1025 wm::ActivateWindow(foreground_window.get());
1026 CreateMaximizeModeWindowManager();
1028 // Fullscreen both windows.
1029 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
1030 background_window_state->OnWMEvent(&event);
1031 foreground_window_state->OnWMEvent(&event);
1032 EXPECT_TRUE(background_window_state->IsFullscreen());
1033 EXPECT_TRUE(foreground_window_state->IsFullscreen());
1034 EXPECT_EQ(foreground_window.get(), wm::GetActiveWindow());
1036 // Do an edge swipe top into screen.
1037 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1038 generator.GestureScrollSequence(gfx::Point(50, 0),
1039 gfx::Point(50, 100),
1040 base::TimeDelta::FromMilliseconds(20),
1041 10);
1043 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1044 EXPECT_TRUE(background_window_state->IsFullscreen());
1046 // Do a second edge swipe top into screen.
1047 generator.GestureScrollSequence(gfx::Point(50, 0),
1048 gfx::Point(50, 100),
1049 base::TimeDelta::FromMilliseconds(20),
1050 10);
1052 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1053 EXPECT_TRUE(background_window_state->IsFullscreen());
1055 DestroyMaximizeModeWindowManager();
1058 // Test that an edge swipe from the bottom will end full screen mode.
1059 TEST_F(MaximizeModeWindowManagerTest, ExitFullScreenWithEdgeSwipeFromBottom) {
1060 gfx::Rect rect(10, 10, 200, 50);
1061 scoped_ptr<aura::Window>
1062 background_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1063 scoped_ptr<aura::Window>
1064 foreground_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1065 wm::WindowState* background_window_state =
1066 wm::GetWindowState(background_window.get());
1067 wm::WindowState* foreground_window_state =
1068 wm::GetWindowState(foreground_window.get());
1069 wm::ActivateWindow(foreground_window.get());
1070 CreateMaximizeModeWindowManager();
1072 // Fullscreen both windows.
1073 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
1074 background_window_state->OnWMEvent(&event);
1075 foreground_window_state->OnWMEvent(&event);
1076 EXPECT_TRUE(background_window_state->IsFullscreen());
1077 EXPECT_TRUE(foreground_window_state->IsFullscreen());
1078 EXPECT_EQ(foreground_window.get(), wm::GetActiveWindow());
1080 // Do an edge swipe bottom into screen.
1081 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1082 int y = Shell::GetPrimaryRootWindow()->bounds().bottom();
1083 generator.GestureScrollSequence(gfx::Point(50, y),
1084 gfx::Point(50, y - 100),
1085 base::TimeDelta::FromMilliseconds(20),
1086 10);
1088 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1089 EXPECT_TRUE(background_window_state->IsFullscreen());
1091 DestroyMaximizeModeWindowManager();
1094 // Test that an edge touch press at the top will end full screen mode.
1095 TEST_F(MaximizeModeWindowManagerTest, ExitFullScreenWithEdgeTouchAtTop) {
1096 gfx::Rect rect(10, 10, 200, 50);
1097 scoped_ptr<aura::Window>
1098 background_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1099 scoped_ptr<aura::Window>
1100 foreground_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1101 wm::WindowState* background_window_state =
1102 wm::GetWindowState(background_window.get());
1103 wm::WindowState* foreground_window_state =
1104 wm::GetWindowState(foreground_window.get());
1105 wm::ActivateWindow(foreground_window.get());
1106 CreateMaximizeModeWindowManager();
1108 // Fullscreen both windows.
1109 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
1110 background_window_state->OnWMEvent(&event);
1111 foreground_window_state->OnWMEvent(&event);
1112 EXPECT_TRUE(background_window_state->IsFullscreen());
1113 EXPECT_TRUE(foreground_window_state->IsFullscreen());
1114 EXPECT_EQ(foreground_window.get(), wm::GetActiveWindow());
1116 // Touch tap on the top edge.
1117 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1118 generator.GestureTapAt(gfx::Point(100, 0));
1119 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1120 EXPECT_TRUE(background_window_state->IsFullscreen());
1122 // Try the same again and see that nothing changes.
1123 generator.GestureTapAt(gfx::Point(100, 0));
1124 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1125 EXPECT_TRUE(background_window_state->IsFullscreen());
1127 DestroyMaximizeModeWindowManager();
1130 // Test that an edge touch press at the bottom will end full screen mode.
1131 TEST_F(MaximizeModeWindowManagerTest, ExitFullScreenWithEdgeTouchAtBottom) {
1132 gfx::Rect rect(10, 10, 200, 50);
1133 scoped_ptr<aura::Window>
1134 background_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1135 scoped_ptr<aura::Window>
1136 foreground_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1137 wm::WindowState* background_window_state =
1138 wm::GetWindowState(background_window.get());
1139 wm::WindowState* foreground_window_state =
1140 wm::GetWindowState(foreground_window.get());
1141 wm::ActivateWindow(foreground_window.get());
1142 CreateMaximizeModeWindowManager();
1144 // Fullscreen both windows.
1145 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
1146 background_window_state->OnWMEvent(&event);
1147 foreground_window_state->OnWMEvent(&event);
1148 EXPECT_TRUE(background_window_state->IsFullscreen());
1149 EXPECT_TRUE(foreground_window_state->IsFullscreen());
1150 EXPECT_EQ(foreground_window.get(), wm::GetActiveWindow());
1152 // Touch tap on the bottom edge.
1153 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1154 generator.GestureTapAt(
1155 gfx::Point(100, Shell::GetPrimaryRootWindow()->bounds().bottom() - 1));
1156 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1157 EXPECT_TRUE(background_window_state->IsFullscreen());
1159 // Try the same again and see that nothing changes.
1160 generator.GestureTapAt(
1161 gfx::Point(100, Shell::GetPrimaryRootWindow()->bounds().bottom() - 1));
1162 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1163 EXPECT_TRUE(background_window_state->IsFullscreen());
1165 DestroyMaximizeModeWindowManager();
1168 // Test that an edge swipe from the top on an immersive mode window will not end
1169 // full screen mode.
1170 TEST_F(MaximizeModeWindowManagerTest, NoExitImmersiveModeWithEdgeSwipeFromTop) {
1171 scoped_ptr<aura::Window> window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL,
1172 gfx::Rect(10, 10, 200, 50)));
1173 wm::WindowState* window_state = wm::GetWindowState(window.get());
1174 wm::ActivateWindow(window.get());
1175 CreateMaximizeModeWindowManager();
1177 // Fullscreen the window.
1178 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
1179 window_state->OnWMEvent(&event);
1180 EXPECT_TRUE(window_state->IsFullscreen());
1181 EXPECT_FALSE(window_state->in_immersive_fullscreen());
1182 EXPECT_EQ(window.get(), wm::GetActiveWindow());
1184 window_state->set_in_immersive_fullscreen(true);
1186 // Do an edge swipe top into screen.
1187 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1188 generator.GestureScrollSequence(gfx::Point(50, 0),
1189 gfx::Point(50, 100),
1190 base::TimeDelta::FromMilliseconds(20),
1191 10);
1193 // It should have not exited full screen or immersive mode.
1194 EXPECT_TRUE(window_state->IsFullscreen());
1195 EXPECT_TRUE(window_state->in_immersive_fullscreen());
1197 DestroyMaximizeModeWindowManager();
1200 // Test that an edge swipe from the bottom will not end immersive mode.
1201 TEST_F(MaximizeModeWindowManagerTest,
1202 NoExitImmersiveModeWithEdgeSwipeFromBottom) {
1203 scoped_ptr<aura::Window> window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL,
1204 gfx::Rect(10, 10, 200, 50)));
1205 wm::WindowState* window_state = wm::GetWindowState(window.get());
1206 wm::ActivateWindow(window.get());
1207 CreateMaximizeModeWindowManager();
1209 // Fullscreen the window.
1210 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
1211 window_state->OnWMEvent(&event);
1212 EXPECT_TRUE(window_state->IsFullscreen());
1213 EXPECT_FALSE(window_state->in_immersive_fullscreen());
1214 EXPECT_EQ(window.get(), wm::GetActiveWindow());
1215 window_state->set_in_immersive_fullscreen(true);
1216 EXPECT_TRUE(window_state->in_immersive_fullscreen());
1218 // Do an edge swipe bottom into screen.
1219 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1220 int y = Shell::GetPrimaryRootWindow()->bounds().bottom();
1221 generator.GestureScrollSequence(gfx::Point(50, y),
1222 gfx::Point(50, y - 100),
1223 base::TimeDelta::FromMilliseconds(20),
1224 10);
1226 // The window should still be full screen and immersive.
1227 EXPECT_TRUE(window_state->IsFullscreen());
1228 EXPECT_TRUE(window_state->in_immersive_fullscreen());
1230 DestroyMaximizeModeWindowManager();
1233 #endif // OS_WIN
1235 } // namespace ash