platformKeys: Add per-extension sign permissions.
[chromium-blink-merge.git] / ash / wm / maximize_mode / maximize_mode_window_manager_unittest.cc
bloba57fa75ef3a00896b5262a4460b5a67dd8f1778c
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 ~MaximizeModeWindowManagerTest() override {}
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 // The same test as the above but while a system modal dialog is shown.
217 TEST_F(MaximizeModeWindowManagerTest, GoingToMaximizedWithModalDialogPresent) {
218 // Bounds for windows we know can be controlled.
219 gfx::Rect rect1(10, 10, 200, 50);
220 gfx::Rect rect2(10, 60, 200, 50);
221 gfx::Rect rect3(20, 140, 100, 100);
222 // Bounds for anything else.
223 gfx::Rect rect(80, 90, 100, 110);
224 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect1));
225 scoped_ptr<aura::Window> w2(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
226 scoped_ptr<aura::Window> w3(
227 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect3));
228 scoped_ptr<aura::Window> w4(CreateWindow(ui::wm::WINDOW_TYPE_PANEL, rect));
229 scoped_ptr<aura::Window> w5(CreateWindow(ui::wm::WINDOW_TYPE_POPUP, rect));
230 scoped_ptr<aura::Window> w6(CreateWindow(ui::wm::WINDOW_TYPE_CONTROL, rect));
231 scoped_ptr<aura::Window> w7(CreateWindow(ui::wm::WINDOW_TYPE_MENU, rect));
232 scoped_ptr<aura::Window> w8(CreateWindow(ui::wm::WINDOW_TYPE_TOOLTIP, rect));
233 EXPECT_FALSE(wm::GetWindowState(w1.get())->IsMaximized());
234 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized());
235 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
236 EXPECT_EQ(rect1.ToString(), w1->bounds().ToString());
237 EXPECT_EQ(rect2.ToString(), w2->bounds().ToString());
238 EXPECT_EQ(rect3.ToString(), w3->bounds().ToString());
240 // Enable system modal dialog, and make sure both shelves are still hidden.
241 ash::Shell::GetInstance()->SimulateModalWindowOpenForTesting(true);
242 EXPECT_TRUE(ash::Shell::GetInstance()->IsSystemModalWindowOpen());
244 // Create the manager and make sure that all qualifying windows were detected
245 // and changed.
246 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
247 ASSERT_TRUE(manager);
248 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
249 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsMaximized());
250 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized());
251 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
252 EXPECT_NE(rect3.origin().ToString(), w3->bounds().origin().ToString());
253 EXPECT_EQ(rect3.size().ToString(), w3->bounds().size().ToString());
255 // All other windows should not have been touched.
256 EXPECT_FALSE(wm::GetWindowState(w4.get())->IsMaximized());
257 EXPECT_FALSE(wm::GetWindowState(w5.get())->IsMaximized());
258 EXPECT_FALSE(wm::GetWindowState(w6.get())->IsMaximized());
259 EXPECT_FALSE(wm::GetWindowState(w7.get())->IsMaximized());
260 EXPECT_FALSE(wm::GetWindowState(w8.get())->IsMaximized());
261 EXPECT_EQ(rect.ToString(), w4->bounds().ToString());
262 EXPECT_EQ(rect.ToString(), w5->bounds().ToString());
263 EXPECT_EQ(rect.ToString(), w6->bounds().ToString());
264 EXPECT_EQ(rect.ToString(), w7->bounds().ToString());
265 EXPECT_EQ(rect.ToString(), w8->bounds().ToString());
267 // Destroy the manager again and check that the windows return to their
268 // previous state.
269 DestroyMaximizeModeWindowManager();
270 EXPECT_FALSE(wm::GetWindowState(w1.get())->IsMaximized());
271 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized());
272 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
273 EXPECT_EQ(rect1.ToString(), w1->bounds().ToString());
274 EXPECT_EQ(rect2.ToString(), w2->bounds().ToString());
275 EXPECT_EQ(rect3.ToString(), w3->bounds().ToString());
276 EXPECT_EQ(rect.ToString(), w4->bounds().ToString());
277 EXPECT_EQ(rect.ToString(), w5->bounds().ToString());
278 EXPECT_EQ(rect.ToString(), w6->bounds().ToString());
279 EXPECT_EQ(rect.ToString(), w7->bounds().ToString());
280 EXPECT_EQ(rect.ToString(), w8->bounds().ToString());
283 // Test that non-maximizable windows get properly handled when going into
284 // maximized mode.
285 TEST_F(MaximizeModeWindowManagerTest,
286 PreCreateNonMaximizableButResizableWindows) {
287 // The window bounds.
288 gfx::Rect rect(10, 10, 200, 50);
289 gfx::Size max_size(300, 200);
290 gfx::Size empty_size;
291 scoped_ptr<aura::Window> unlimited_window(
292 CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect, empty_size));
293 scoped_ptr<aura::Window> limited_window(
294 CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect, max_size));
295 scoped_ptr<aura::Window> fixed_window(
296 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
297 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
298 EXPECT_EQ(rect.ToString(), unlimited_window->bounds().ToString());
299 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
300 EXPECT_EQ(rect.ToString(), limited_window->bounds().ToString());
301 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
302 EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString());
304 gfx::Size workspace_size = ScreenUtil::GetMaximizedWindowBoundsInParent(
305 unlimited_window.get()).size();
307 // Create the manager and make sure that all qualifying windows were detected
308 // and changed.
309 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
310 ASSERT_TRUE(manager);
311 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
312 // The unlimited window should have the size of the workspace / parent window.
313 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
314 EXPECT_EQ("0,0", unlimited_window->bounds().origin().ToString());
315 EXPECT_EQ(workspace_size.ToString(),
316 unlimited_window->bounds().size().ToString());
317 // The limited window should have the size of the upper possible bounds.
318 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
319 EXPECT_NE(rect.origin().ToString(),
320 limited_window->bounds().origin().ToString());
321 EXPECT_EQ(max_size.ToString(),
322 limited_window->bounds().size().ToString());
323 // The fixed size window should have the size of the original window.
324 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
325 EXPECT_NE(rect.origin().ToString(),
326 fixed_window->bounds().origin().ToString());
327 EXPECT_EQ(rect.size().ToString(),
328 fixed_window->bounds().size().ToString());
330 // Destroy the manager again and check that the windows return to their
331 // previous state.
332 DestroyMaximizeModeWindowManager();
333 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
334 EXPECT_EQ(rect.ToString(), unlimited_window->bounds().ToString());
335 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
336 EXPECT_EQ(rect.ToString(), limited_window->bounds().ToString());
337 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
338 EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString());
341 // Test that creating windows while a maximizer exists picks them properly up.
342 TEST_F(MaximizeModeWindowManagerTest, CreateWindows) {
343 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
344 ASSERT_TRUE(manager);
345 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
347 // Create the windows and see that the window manager picks them up.
348 // Rects for windows we know can be controlled.
349 gfx::Rect rect1(10, 10, 200, 50);
350 gfx::Rect rect2(10, 60, 200, 50);
351 gfx::Rect rect3(20, 140, 100, 100);
352 // One rect for anything else.
353 gfx::Rect rect(80, 90, 100, 110);
354 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect1));
355 scoped_ptr<aura::Window> w2(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
356 scoped_ptr<aura::Window> w3(
357 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect3));
358 scoped_ptr<aura::Window> w4(CreateWindow(ui::wm::WINDOW_TYPE_PANEL, rect));
359 scoped_ptr<aura::Window> w5(CreateWindow(ui::wm::WINDOW_TYPE_POPUP, rect));
360 scoped_ptr<aura::Window> w6(CreateWindow(ui::wm::WINDOW_TYPE_CONTROL, rect));
361 scoped_ptr<aura::Window> w7(CreateWindow(ui::wm::WINDOW_TYPE_MENU, rect));
362 scoped_ptr<aura::Window> w8(CreateWindow(ui::wm::WINDOW_TYPE_TOOLTIP, rect));
363 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsMaximized());
364 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized());
365 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
366 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
368 // Make sure that the position of the unresizable window is in the middle of
369 // the screen.
370 gfx::Size work_area_size =
371 ScreenUtil::GetDisplayWorkAreaBoundsInParent(w3.get()).size();
372 gfx::Point center =
373 gfx::Point((work_area_size.width() - rect3.size().width()) / 2,
374 (work_area_size.height() - rect3.size().height()) / 2);
375 gfx::Rect centered_window_bounds = gfx::Rect(center, rect3.size());
376 EXPECT_EQ(centered_window_bounds.ToString(), w3->bounds().ToString());
378 // All other windows should not have been touched.
379 EXPECT_FALSE(wm::GetWindowState(w4.get())->IsMaximized());
380 EXPECT_FALSE(wm::GetWindowState(w5.get())->IsMaximized());
381 EXPECT_FALSE(wm::GetWindowState(w6.get())->IsMaximized());
382 EXPECT_FALSE(wm::GetWindowState(w7.get())->IsMaximized());
383 EXPECT_FALSE(wm::GetWindowState(w8.get())->IsMaximized());
384 EXPECT_EQ(rect.ToString(), w4->bounds().ToString());
385 EXPECT_EQ(rect.ToString(), w5->bounds().ToString());
386 EXPECT_EQ(rect.ToString(), w6->bounds().ToString());
387 EXPECT_EQ(rect.ToString(), w7->bounds().ToString());
388 EXPECT_EQ(rect.ToString(), w8->bounds().ToString());
390 // After the maximize mode was disabled all windows fall back into the mode
391 // they were created for.
392 DestroyMaximizeModeWindowManager();
393 EXPECT_FALSE(wm::GetWindowState(w1.get())->IsMaximized());
394 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized());
395 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
396 EXPECT_EQ(rect1.ToString(), w1->bounds().ToString());
397 EXPECT_EQ(rect2.ToString(), w2->bounds().ToString());
398 EXPECT_EQ(rect3.ToString(), w3->bounds().ToString());
399 EXPECT_EQ(rect.ToString(), w4->bounds().ToString());
400 EXPECT_EQ(rect.ToString(), w5->bounds().ToString());
401 EXPECT_EQ(rect.ToString(), w6->bounds().ToString());
402 EXPECT_EQ(rect.ToString(), w7->bounds().ToString());
403 EXPECT_EQ(rect.ToString(), w8->bounds().ToString());
406 // Test that a window which got created while the maximize mode window manager
407 // is active gets restored to a usable (non tiny) size upon switching back.
408 TEST_F(MaximizeModeWindowManagerTest,
409 CreateWindowInMaximizedModeRestoresToUsefulSize) {
410 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
411 ASSERT_TRUE(manager);
412 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
414 // We pass in an empty rectangle to simulate a window creation with no
415 // particular size.
416 gfx::Rect empty_rect(0, 0, 0, 0);
417 scoped_ptr<aura::Window> window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL,
418 empty_rect));
419 EXPECT_TRUE(wm::GetWindowState(window.get())->IsMaximized());
420 EXPECT_NE(empty_rect.ToString(), window->bounds().ToString());
421 gfx::Rect maximized_size = window->bounds();
423 // Destroy the maximize mode and check that the resulting size of the window
424 // is remaining as it is (but not maximized).
425 DestroyMaximizeModeWindowManager();
427 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized());
428 EXPECT_EQ(maximized_size.ToString(), window->bounds().ToString());
431 // Test that non-maximizable windows get properly handled when created in
432 // maximized mode.
433 TEST_F(MaximizeModeWindowManagerTest,
434 CreateNonMaximizableButResizableWindows) {
435 // Create the manager and make sure that all qualifying windows were detected
436 // and changed.
437 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
438 ASSERT_TRUE(manager);
440 gfx::Rect rect(10, 10, 200, 50);
441 gfx::Size max_size(300, 200);
442 gfx::Size empty_size;
443 scoped_ptr<aura::Window> unlimited_window(
444 CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect, empty_size));
445 scoped_ptr<aura::Window> limited_window(
446 CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect, max_size));
447 scoped_ptr<aura::Window> fixed_window(
448 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
450 gfx::Size workspace_size = ScreenUtil::GetMaximizedWindowBoundsInParent(
451 unlimited_window.get()).size();
453 // All windows should be sized now as big as possible and be centered.
454 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
455 // The unlimited window should have the size of the workspace / parent window.
456 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
457 EXPECT_EQ("0,0", unlimited_window->bounds().origin().ToString());
458 EXPECT_EQ(workspace_size.ToString(),
459 unlimited_window->bounds().size().ToString());
460 // The limited window should have the size of the upper possible bounds.
461 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
462 EXPECT_NE(rect.origin().ToString(),
463 limited_window->bounds().origin().ToString());
464 EXPECT_EQ(max_size.ToString(),
465 limited_window->bounds().size().ToString());
466 // The fixed size window should have the size of the original window.
467 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
468 EXPECT_NE(rect.origin().ToString(),
469 fixed_window->bounds().origin().ToString());
470 EXPECT_EQ(rect.size().ToString(),
471 fixed_window->bounds().size().ToString());
473 // Destroy the manager again and check that the windows return to their
474 // creation state.
475 DestroyMaximizeModeWindowManager();
477 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
478 EXPECT_EQ(rect.ToString(), unlimited_window->bounds().ToString());
479 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
480 EXPECT_EQ(rect.ToString(), limited_window->bounds().ToString());
481 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
482 EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString());
485 // Create a string which consists of the bounds and the state for comparison.
486 std::string GetPlacementString(const gfx::Rect& bounds,
487 ui::WindowShowState state) {
488 return bounds.ToString() + base::StringPrintf(" %d", state);
491 // Retrieves the window's restore state override - if any - and returns it as a
492 // string.
493 std::string GetPlacementOverride(aura::Window* window) {
494 gfx::Rect* bounds = window->GetProperty(ash::kRestoreBoundsOverrideKey);
495 if (bounds) {
496 gfx::Rect restore_bounds = *bounds;
497 ui::WindowShowState restore_state =
498 window->GetProperty(ash::kRestoreShowStateOverrideKey);
499 return GetPlacementString(restore_bounds, restore_state);
501 return std::string();
504 // Test that the restore state will be kept at its original value for
505 // session restauration purposes.
506 TEST_F(MaximizeModeWindowManagerTest, TestRestoreIntegrety) {
507 gfx::Rect bounds(10, 10, 200, 50);
508 gfx::Size empty_size;
509 gfx::Rect empty_bounds;
510 scoped_ptr<aura::Window> normal_window(
511 CreateWindowWithWidget(bounds));
512 scoped_ptr<aura::Window> maximized_window(
513 CreateWindowWithWidget(bounds));
514 wm::GetWindowState(maximized_window.get())->Maximize();
516 EXPECT_EQ(std::string(), GetPlacementOverride(normal_window.get()));
517 EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get()));
519 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
520 ASSERT_TRUE(manager);
522 // With the maximization the override states should be returned in its
523 // pre-maximized state.
524 EXPECT_EQ(GetPlacementString(bounds, ui::SHOW_STATE_NORMAL),
525 GetPlacementOverride(normal_window.get()));
526 EXPECT_EQ(GetPlacementString(bounds, ui::SHOW_STATE_MAXIMIZED),
527 GetPlacementOverride(maximized_window.get()));
529 // Changing a window's state now does not change the returned result.
530 wm::GetWindowState(maximized_window.get())->Minimize();
531 EXPECT_EQ(GetPlacementString(bounds, ui::SHOW_STATE_MAXIMIZED),
532 GetPlacementOverride(maximized_window.get()));
534 // Destroy the manager again and check that the overrides get reset.
535 DestroyMaximizeModeWindowManager();
536 EXPECT_EQ(std::string(), GetPlacementOverride(normal_window.get()));
537 EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get()));
539 // Changing a window's state now does not bring the overrides back.
540 wm::GetWindowState(maximized_window.get())->Restore();
541 gfx::Rect new_bounds(10, 10, 200, 50);
542 maximized_window->SetBounds(new_bounds);
544 EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get()));
547 // Test that windows which got created before the maximizer was created can be
548 // destroyed while the maximizer is still running.
549 TEST_F(MaximizeModeWindowManagerTest, PreCreateWindowsDeleteWhileActive) {
550 ash::MaximizeModeWindowManager* manager = NULL;
552 // Bounds for windows we know can be controlled.
553 gfx::Rect rect1(10, 10, 200, 50);
554 gfx::Rect rect2(10, 60, 200, 50);
555 gfx::Rect rect3(20, 140, 100, 100);
556 // Bounds for anything else.
557 gfx::Rect rect(80, 90, 100, 110);
558 scoped_ptr<aura::Window> w1(
559 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect1));
560 scoped_ptr<aura::Window> w2(
561 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
562 scoped_ptr<aura::Window> w3(
563 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect3));
565 // Create the manager and make sure that all qualifying windows were
566 // detected and changed.
567 manager = CreateMaximizeModeWindowManager();
568 ASSERT_TRUE(manager);
569 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
571 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
572 DestroyMaximizeModeWindowManager();
575 // Test that windows which got created while the maximizer was running can get
576 // destroyed before the maximizer gets destroyed.
577 TEST_F(MaximizeModeWindowManagerTest, CreateWindowsAndDeleteWhileActive) {
578 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
579 ASSERT_TRUE(manager);
580 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
582 // Bounds for windows we know can be controlled.
583 gfx::Rect rect1(10, 10, 200, 50);
584 gfx::Rect rect2(10, 60, 200, 50);
585 gfx::Rect rect3(20, 140, 100, 100);
586 scoped_ptr<aura::Window> w1(
587 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(10, 10, 200, 50)));
588 scoped_ptr<aura::Window> w2(
589 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(10, 60, 200, 50)));
590 scoped_ptr<aura::Window> w3(
591 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL,
592 gfx::Rect(20, 140, 100, 100)));
593 // Check that the windows got automatically maximized as well.
594 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
595 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsMaximized());
596 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized());
597 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
599 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
600 DestroyMaximizeModeWindowManager();
603 // Test that windows which were maximized stay maximized.
604 TEST_F(MaximizeModeWindowManagerTest, MaximizedShouldRemainMaximized) {
605 // Bounds for windows we know can be controlled.
606 gfx::Rect rect(10, 10, 200, 50);
607 scoped_ptr<aura::Window> window(
608 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
609 wm::GetWindowState(window.get())->Maximize();
611 // Create the manager and make sure that the window gets detected.
612 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
613 ASSERT_TRUE(manager);
614 EXPECT_EQ(1, manager->GetNumberOfManagedWindows());
615 EXPECT_TRUE(wm::GetWindowState(window.get())->IsMaximized());
617 // Destroy the manager again and check that the window will remain maximized.
618 DestroyMaximizeModeWindowManager();
619 EXPECT_TRUE(wm::GetWindowState(window.get())->IsMaximized());
620 wm::GetWindowState(window.get())->Restore();
621 EXPECT_EQ(rect.ToString(), window->bounds().ToString());
624 // Test that minimized windows do neither get maximized nor restored upon
625 // entering maximized mode and get restored to their previous state after
626 // leaving.
627 TEST_F(MaximizeModeWindowManagerTest, MinimizedWindowBehavior) {
628 // Bounds for windows we know can be controlled.
629 gfx::Rect rect(10, 10, 200, 50);
630 scoped_ptr<aura::Window> initially_minimized_window(
631 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
632 scoped_ptr<aura::Window> initially_normal_window(
633 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
634 scoped_ptr<aura::Window> initially_maximized_window(
635 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
636 wm::GetWindowState(initially_minimized_window.get())->Minimize();
637 wm::GetWindowState(initially_maximized_window.get())->Maximize();
639 // Create the manager and make sure that the window gets detected.
640 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
641 ASSERT_TRUE(manager);
642 EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
643 EXPECT_TRUE(wm::GetWindowState(
644 initially_minimized_window.get())->IsMinimized());
645 EXPECT_TRUE(wm::GetWindowState(initially_normal_window.get())->IsMaximized());
646 EXPECT_TRUE(wm::GetWindowState(
647 initially_maximized_window.get())->IsMaximized());
648 // Now minimize the second window to check that upon leaving the window
649 // will get restored to its minimized state.
650 wm::GetWindowState(initially_normal_window.get())->Minimize();
651 wm::GetWindowState(initially_maximized_window.get())->Minimize();
652 EXPECT_TRUE(wm::GetWindowState(
653 initially_minimized_window.get())->IsMinimized());
654 EXPECT_TRUE(wm::GetWindowState(
655 initially_normal_window.get())->IsMinimized());
656 EXPECT_TRUE(wm::GetWindowState(
657 initially_maximized_window.get())->IsMinimized());
659 // Destroy the manager again and check that the window will get minimized.
660 DestroyMaximizeModeWindowManager();
661 EXPECT_TRUE(wm::GetWindowState(
662 initially_minimized_window.get())->IsMinimized());
663 EXPECT_FALSE(wm::GetWindowState(
664 initially_normal_window.get())->IsMinimized());
665 EXPECT_TRUE(wm::GetWindowState(
666 initially_maximized_window.get())->IsMaximized());
669 // Check that resizing the desktop does reposition unmaximizable, unresizable &
670 // managed windows.
671 TEST_F(MaximizeModeWindowManagerTest, DesktopSizeChangeMovesUnmaximizable) {
672 UpdateDisplay("400x400");
673 // This window will move because it does not fit the new bounds.
674 gfx::Rect rect(20, 300, 100, 100);
675 scoped_ptr<aura::Window> window1(
676 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
677 EXPECT_EQ(rect.ToString(), window1->bounds().ToString());
679 // This window will not move because it does fit the new bounds.
680 gfx::Rect rect2(20, 140, 100, 100);
681 scoped_ptr<aura::Window> window2(
682 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
684 // Turning on the manager will reposition (but not resize) the window.
685 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
686 ASSERT_TRUE(manager);
687 EXPECT_EQ(2, manager->GetNumberOfManagedWindows());
688 gfx::Rect moved_bounds(window1->bounds());
689 EXPECT_NE(rect.origin().ToString(), moved_bounds.origin().ToString());
690 EXPECT_EQ(rect.size().ToString(), moved_bounds.size().ToString());
692 // Simulating a desktop resize should move the window again.
693 UpdateDisplay("300x300");
694 gfx::Rect new_moved_bounds(window1->bounds());
695 EXPECT_NE(rect.origin().ToString(), new_moved_bounds.origin().ToString());
696 EXPECT_EQ(rect.size().ToString(), new_moved_bounds.size().ToString());
697 EXPECT_NE(moved_bounds.origin().ToString(), new_moved_bounds.ToString());
699 // Turning off the mode should not restore to the initial coordinates since
700 // the new resolution is smaller and the window was on the edge.
701 DestroyMaximizeModeWindowManager();
702 EXPECT_NE(rect.ToString(), window1->bounds().ToString());
703 EXPECT_EQ(rect2.ToString(), window2->bounds().ToString());
706 // Check that windows return to original location if desktop size changes to
707 // something else and back while in maximize mode.
708 TEST_F(MaximizeModeWindowManagerTest, SizeChangeReturnWindowToOriginalPos) {
709 gfx::Rect rect(20, 140, 100, 100);
710 scoped_ptr<aura::Window> window(
711 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
713 // Turning on the manager will reposition (but not resize) the window.
714 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
715 ASSERT_TRUE(manager);
716 EXPECT_EQ(1, manager->GetNumberOfManagedWindows());
717 gfx::Rect moved_bounds(window->bounds());
718 EXPECT_NE(rect.origin().ToString(), moved_bounds.origin().ToString());
719 EXPECT_EQ(rect.size().ToString(), moved_bounds.size().ToString());
721 // Simulating a desktop resize should move the window again.
722 ResizeDesktop(-10);
723 gfx::Rect new_moved_bounds(window->bounds());
724 EXPECT_NE(rect.origin().ToString(), new_moved_bounds.origin().ToString());
725 EXPECT_EQ(rect.size().ToString(), new_moved_bounds.size().ToString());
726 EXPECT_NE(moved_bounds.origin().ToString(), new_moved_bounds.ToString());
728 // Then resize back to the original desktop size which should move windows
729 // to their original location after leaving the maximize mode.
730 ResizeDesktop(10);
731 DestroyMaximizeModeWindowManager();
732 EXPECT_EQ(rect.ToString(), window->bounds().ToString());
735 // Check that enabling of the maximize mode does not have an impact on the MRU
736 // order of windows.
737 TEST_F(MaximizeModeWindowManagerTest, ModeChangeKeepsMRUOrder) {
738 gfx::Rect rect(20, 140, 100, 100);
739 scoped_ptr<aura::Window> w1(
740 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
741 scoped_ptr<aura::Window> w2(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
742 scoped_ptr<aura::Window> w3(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
743 scoped_ptr<aura::Window> w4(
744 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
745 scoped_ptr<aura::Window> w5(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
747 // The windows should be in the reverse order of creation in the MRU list.
749 MruWindowTracker::WindowList windows = ash::Shell::GetInstance()->
750 mru_window_tracker()->BuildMruWindowList();
751 EXPECT_EQ(w1.get(), windows[4]);
752 EXPECT_EQ(w2.get(), windows[3]);
753 EXPECT_EQ(w3.get(), windows[2]);
754 EXPECT_EQ(w4.get(), windows[1]);
755 EXPECT_EQ(w5.get(), windows[0]);
758 // Activating the window manager should keep the order.
759 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
760 ASSERT_TRUE(manager);
761 EXPECT_EQ(5, manager->GetNumberOfManagedWindows());
763 MruWindowTracker::WindowList windows = ash::Shell::GetInstance()->
764 mru_window_tracker()->BuildMruWindowList();
765 // We do not test maximization here again since that was done already.
766 EXPECT_EQ(w1.get(), windows[4]);
767 EXPECT_EQ(w2.get(), windows[3]);
768 EXPECT_EQ(w3.get(), windows[2]);
769 EXPECT_EQ(w4.get(), windows[1]);
770 EXPECT_EQ(w5.get(), windows[0]);
773 // Destroying should still keep the order.
774 DestroyMaximizeModeWindowManager();
776 MruWindowTracker::WindowList windows = ash::Shell::GetInstance()->
777 mru_window_tracker()->BuildMruWindowList();
778 // We do not test maximization here again since that was done already.
779 EXPECT_EQ(w1.get(), windows[4]);
780 EXPECT_EQ(w2.get(), windows[3]);
781 EXPECT_EQ(w3.get(), windows[2]);
782 EXPECT_EQ(w4.get(), windows[1]);
783 EXPECT_EQ(w5.get(), windows[0]);
787 // Check that a restore state change does always restore to maximized.
788 TEST_F(MaximizeModeWindowManagerTest, IgnoreRestoreStateChages) {
789 gfx::Rect rect(20, 140, 100, 100);
790 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
791 wm::WindowState* window_state = wm::GetWindowState(w1.get());
792 CreateMaximizeModeWindowManager();
793 EXPECT_TRUE(window_state->IsMaximized());
794 window_state->Minimize();
795 EXPECT_TRUE(window_state->IsMinimized());
796 window_state->Restore();
797 EXPECT_TRUE(window_state->IsMaximized());
798 window_state->Restore();
799 EXPECT_TRUE(window_state->IsMaximized());
800 DestroyMaximizeModeWindowManager();
803 // Check that minimize and restore do the right thing.
804 TEST_F(MaximizeModeWindowManagerTest, TestMinimize) {
805 gfx::Rect rect(10, 10, 100, 100);
806 scoped_ptr<aura::Window> window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL,
807 rect));
808 wm::WindowState* window_state = wm::GetWindowState(window.get());
809 EXPECT_EQ(rect.ToString(), window->bounds().ToString());
810 ash::Shell::GetInstance()->maximize_mode_controller()->
811 EnableMaximizeModeWindowManager(true);
812 EXPECT_TRUE(window_state->IsMaximized());
813 EXPECT_FALSE(window_state->IsMinimized());
814 EXPECT_TRUE(window->IsVisible());
816 window_state->Minimize();
817 EXPECT_FALSE(window_state->IsMaximized());
818 EXPECT_TRUE(window_state->IsMinimized());
819 EXPECT_FALSE(window->IsVisible());
821 window_state->Maximize();
822 EXPECT_TRUE(window_state->IsMaximized());
823 EXPECT_FALSE(window_state->IsMinimized());
824 EXPECT_TRUE(window->IsVisible());
826 ash::Shell::GetInstance()->maximize_mode_controller()->
827 EnableMaximizeModeWindowManager(false);
828 EXPECT_FALSE(window_state->IsMaximized());
829 EXPECT_FALSE(window_state->IsMinimized());
830 EXPECT_TRUE(window->IsVisible());
833 // Check that a full screen window is staying full screen in maximize mode,
834 // and that it returns to full screen thereafter (if left).
835 TEST_F(MaximizeModeWindowManagerTest, KeepFullScreenModeOn) {
836 gfx::Rect rect(20, 140, 100, 100);
837 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
838 wm::WindowState* window_state = wm::GetWindowState(w1.get());
840 ShelfLayoutManager* shelf =
841 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
843 // Allow the shelf to hide.
844 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
845 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
847 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
848 window_state->OnWMEvent(&event);
850 // With full screen, the shelf should get hidden.
851 EXPECT_TRUE(window_state->IsFullscreen());
852 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
854 CreateMaximizeModeWindowManager();
856 // The Full screen mode should continue to be on.
857 EXPECT_TRUE(window_state->IsFullscreen());
858 EXPECT_FALSE(window_state->IsMaximized());
859 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
861 // With leaving the fullscreen mode, the maximized mode should return and the
862 // shelf should maintain its state from before maximize mode.
863 window_state->OnWMEvent(&event);
864 EXPECT_FALSE(window_state->IsFullscreen());
865 EXPECT_TRUE(window_state->IsMaximized());
866 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
868 // Ending the maximize mode should return to full screen and the shelf should
869 // be hidden again.
870 DestroyMaximizeModeWindowManager();
871 EXPECT_TRUE(window_state->IsFullscreen());
872 EXPECT_FALSE(window_state->IsMaximized());
873 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
876 // Check that full screen mode can be turned on in maximized mode and remains
877 // upon coming back.
878 TEST_F(MaximizeModeWindowManagerTest, AllowFullScreenMode) {
879 gfx::Rect rect(20, 140, 100, 100);
880 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
881 wm::WindowState* window_state = wm::GetWindowState(w1.get());
883 ShelfLayoutManager* shelf =
884 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
886 // Allow the shelf to hide.
887 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
889 EXPECT_FALSE(window_state->IsFullscreen());
890 EXPECT_FALSE(window_state->IsMaximized());
891 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
893 CreateMaximizeModeWindowManager();
895 // Fullscreen mode should still be off and the shelf should maintain its
896 // state.
897 EXPECT_FALSE(window_state->IsFullscreen());
898 EXPECT_TRUE(window_state->IsMaximized());
899 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
901 // After going into fullscreen mode, the shelf should be hidden.
902 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
903 window_state->OnWMEvent(&event);
904 EXPECT_TRUE(window_state->IsFullscreen());
905 EXPECT_FALSE(window_state->IsMaximized());
906 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
908 // With the destruction of the manager we should remain in full screen.
909 DestroyMaximizeModeWindowManager();
910 EXPECT_TRUE(window_state->IsFullscreen());
911 EXPECT_FALSE(window_state->IsMaximized());
912 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
915 // Check that the full screen mode will stay active when the maximize mode is
916 // ended.
917 TEST_F(MaximizeModeWindowManagerTest,
918 FullScreenModeRemainsWhenCreatedInMaximizedMode) {
919 CreateMaximizeModeWindowManager();
921 gfx::Rect rect(20, 140, 100, 100);
922 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
923 wm::WindowState* window_state = wm::GetWindowState(w1.get());
924 wm::WMEvent event_full_screen(wm::WM_EVENT_TOGGLE_FULLSCREEN);
925 window_state->OnWMEvent(&event_full_screen);
926 EXPECT_TRUE(window_state->IsFullscreen());
928 // After the maximize mode manager is ended, full screen will remain.
929 DestroyMaximizeModeWindowManager();
930 EXPECT_TRUE(window_state->IsFullscreen());
933 // Check that the full screen mode will stay active throughout a maximzied mode
934 // session.
935 TEST_F(MaximizeModeWindowManagerTest,
936 FullScreenModeRemainsThroughMaximizeModeSwitch) {
937 gfx::Rect rect(20, 140, 100, 100);
938 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
939 wm::WindowState* window_state = wm::GetWindowState(w1.get());
940 wm::WMEvent event_full_screen(wm::WM_EVENT_TOGGLE_FULLSCREEN);
941 window_state->OnWMEvent(&event_full_screen);
942 EXPECT_TRUE(window_state->IsFullscreen());
944 CreateMaximizeModeWindowManager();
945 EXPECT_TRUE(window_state->IsFullscreen());
946 DestroyMaximizeModeWindowManager();
947 EXPECT_TRUE(window_state->IsFullscreen());
950 // Check that an empty window does not get restored to a tiny size.
951 TEST_F(MaximizeModeWindowManagerTest,
952 CreateAndMaximizeInMaximizeModeShouldRetoreToGoodSizeGoingToDefault) {
953 CreateMaximizeModeWindowManager();
954 gfx::Rect rect;
955 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
956 w1->Show();
957 wm::WindowState* window_state = wm::GetWindowState(w1.get());
958 EXPECT_TRUE(window_state->IsMaximized());
960 // There is a calling order in which the restore bounds can get set to an
961 // empty rectangle. We simulate this here.
962 window_state->SetRestoreBoundsInScreen(rect);
963 EXPECT_TRUE(window_state->GetRestoreBoundsInScreen().IsEmpty());
965 // Setting the window to a new size will physically not change the window,
966 // but the restore size should get updated so that a restore later on will
967 // return to this size.
968 gfx::Rect requested_bounds(10, 20, 50, 70);
969 w1->SetBounds(requested_bounds);
970 EXPECT_TRUE(window_state->IsMaximized());
971 EXPECT_EQ(requested_bounds.ToString(),
972 window_state->GetRestoreBoundsInScreen().ToString());
974 DestroyMaximizeModeWindowManager();
976 EXPECT_FALSE(window_state->IsMaximized());
977 EXPECT_EQ(w1->bounds().ToString(), requested_bounds.ToString());
980 // Check that snapping operations get ignored.
981 TEST_F(MaximizeModeWindowManagerTest, SnapModeTests) {
982 gfx::Rect rect(20, 140, 100, 100);
983 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
984 wm::WindowState* window_state = wm::GetWindowState(w1.get());
985 wm::WMEvent event_left(wm::WM_EVENT_SNAP_LEFT);
986 wm::WMEvent event_right(wm::WM_EVENT_SNAP_RIGHT);
987 window_state->OnWMEvent(&event_left);
988 EXPECT_TRUE(window_state->IsSnapped());
990 CreateMaximizeModeWindowManager();
992 // Fullscreen mode should now be off and it should not come back while in
993 // maximize mode.
994 EXPECT_FALSE(window_state->IsSnapped());
995 EXPECT_TRUE(window_state->IsMaximized());
996 window_state->OnWMEvent(&event_left);
997 EXPECT_FALSE(window_state->IsSnapped());
998 EXPECT_TRUE(window_state->IsMaximized());
999 window_state->OnWMEvent(&event_right);
1000 EXPECT_FALSE(window_state->IsSnapped());
1001 EXPECT_TRUE(window_state->IsMaximized());
1003 DestroyMaximizeModeWindowManager();
1004 EXPECT_TRUE(window_state->IsSnapped());
1007 // Check that non maximizable windows cannot be dragged by the user.
1008 TEST_F(MaximizeModeWindowManagerTest, TryToDesktopSizeDragUnmaximizable) {
1009 gfx::Rect rect(10, 10, 100, 100);
1010 scoped_ptr<aura::Window> window(
1011 CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1012 EXPECT_EQ(rect.ToString(), window->bounds().ToString());
1014 // 1. Move the mouse over the caption and check that dragging the window does
1015 // change the location.
1016 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1017 generator.MoveMouseTo(gfx::Point(rect.x() + 2, rect.y() + 2));
1018 generator.PressLeftButton();
1019 generator.MoveMouseBy(10, 5);
1020 RunAllPendingInMessageLoop();
1021 generator.ReleaseLeftButton();
1022 gfx::Point first_dragged_origin = window->bounds().origin();
1023 EXPECT_EQ(rect.x() + 10, first_dragged_origin.x());
1024 EXPECT_EQ(rect.y() + 5, first_dragged_origin.y());
1026 // 2. Check that turning on the manager will stop allowing the window from
1027 // dragging.
1028 ash::Shell::GetInstance()->maximize_mode_controller()->
1029 EnableMaximizeModeWindowManager(true);
1030 gfx::Rect center_bounds(window->bounds());
1031 EXPECT_NE(rect.origin().ToString(), center_bounds.origin().ToString());
1032 generator.MoveMouseTo(gfx::Point(center_bounds.x() + 1,
1033 center_bounds.y() + 1));
1034 generator.PressLeftButton();
1035 generator.MoveMouseBy(10, 5);
1036 RunAllPendingInMessageLoop();
1037 generator.ReleaseLeftButton();
1038 EXPECT_EQ(center_bounds.x(), window->bounds().x());
1039 EXPECT_EQ(center_bounds.y(), window->bounds().y());
1040 ash::Shell::GetInstance()->maximize_mode_controller()->
1041 EnableMaximizeModeWindowManager(false);
1043 // 3. Releasing the mazimize manager again will restore the window to its
1044 // previous bounds and
1045 generator.MoveMouseTo(gfx::Point(first_dragged_origin.x() + 1,
1046 first_dragged_origin.y() + 1));
1047 generator.PressLeftButton();
1048 generator.MoveMouseBy(10, 5);
1049 RunAllPendingInMessageLoop();
1050 generator.ReleaseLeftButton();
1051 EXPECT_EQ(first_dragged_origin.x() + 10, window->bounds().x());
1052 EXPECT_EQ(first_dragged_origin.y() + 5, window->bounds().y());
1055 // Test that overview is exited before entering / exiting maximize mode so that
1056 // the window changes made by MaximizeModeWindowManager do not conflict with
1057 // those made in WindowOverview.
1058 TEST_F(MaximizeModeWindowManagerTest, ExitsOverview) {
1059 // Bounds for windows we know can be controlled.
1060 gfx::Rect rect1(10, 10, 200, 50);
1061 gfx::Rect rect2(10, 60, 200, 50);
1062 scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect1));
1063 scoped_ptr<aura::Window> w2(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
1065 WindowSelectorController* window_selector_controller =
1066 Shell::GetInstance()->window_selector_controller();
1067 window_selector_controller->ToggleOverview();
1068 ASSERT_TRUE(window_selector_controller->IsSelecting());
1069 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
1070 ASSERT_TRUE(manager);
1071 EXPECT_FALSE(window_selector_controller->IsSelecting());
1073 window_selector_controller->ToggleOverview();
1074 ASSERT_TRUE(window_selector_controller->IsSelecting());
1075 // Destroy the manager again and check that the windows return to their
1076 // previous state.
1077 DestroyMaximizeModeWindowManager();
1078 EXPECT_FALSE(window_selector_controller->IsSelecting());
1081 // Test that an edge swipe from the top will end full screen mode.
1082 TEST_F(MaximizeModeWindowManagerTest, ExitFullScreenWithEdgeSwipeFromTop) {
1083 gfx::Rect rect(10, 10, 200, 50);
1084 scoped_ptr<aura::Window>
1085 background_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1086 scoped_ptr<aura::Window>
1087 foreground_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1088 wm::WindowState* background_window_state =
1089 wm::GetWindowState(background_window.get());
1090 wm::WindowState* foreground_window_state =
1091 wm::GetWindowState(foreground_window.get());
1092 wm::ActivateWindow(foreground_window.get());
1093 CreateMaximizeModeWindowManager();
1095 // Fullscreen both windows.
1096 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
1097 background_window_state->OnWMEvent(&event);
1098 foreground_window_state->OnWMEvent(&event);
1099 EXPECT_TRUE(background_window_state->IsFullscreen());
1100 EXPECT_TRUE(foreground_window_state->IsFullscreen());
1101 EXPECT_EQ(foreground_window.get(), wm::GetActiveWindow());
1103 // Do an edge swipe top into screen.
1104 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1105 generator.GestureScrollSequence(gfx::Point(50, 0),
1106 gfx::Point(50, 100),
1107 base::TimeDelta::FromMilliseconds(20),
1108 10);
1110 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1111 EXPECT_TRUE(background_window_state->IsFullscreen());
1113 // Do a second edge swipe top into screen.
1114 generator.GestureScrollSequence(gfx::Point(50, 0),
1115 gfx::Point(50, 100),
1116 base::TimeDelta::FromMilliseconds(20),
1117 10);
1119 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1120 EXPECT_TRUE(background_window_state->IsFullscreen());
1122 DestroyMaximizeModeWindowManager();
1125 // Test that an edge swipe from the bottom will end full screen mode.
1126 TEST_F(MaximizeModeWindowManagerTest, ExitFullScreenWithEdgeSwipeFromBottom) {
1127 gfx::Rect rect(10, 10, 200, 50);
1128 scoped_ptr<aura::Window>
1129 background_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1130 scoped_ptr<aura::Window>
1131 foreground_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1132 wm::WindowState* background_window_state =
1133 wm::GetWindowState(background_window.get());
1134 wm::WindowState* foreground_window_state =
1135 wm::GetWindowState(foreground_window.get());
1136 wm::ActivateWindow(foreground_window.get());
1137 CreateMaximizeModeWindowManager();
1139 // Fullscreen both windows.
1140 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
1141 background_window_state->OnWMEvent(&event);
1142 foreground_window_state->OnWMEvent(&event);
1143 EXPECT_TRUE(background_window_state->IsFullscreen());
1144 EXPECT_TRUE(foreground_window_state->IsFullscreen());
1145 EXPECT_EQ(foreground_window.get(), wm::GetActiveWindow());
1147 // Do an edge swipe bottom into screen.
1148 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1149 int y = Shell::GetPrimaryRootWindow()->bounds().bottom();
1150 generator.GestureScrollSequence(gfx::Point(50, y),
1151 gfx::Point(50, y - 100),
1152 base::TimeDelta::FromMilliseconds(20),
1153 10);
1155 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1156 EXPECT_TRUE(background_window_state->IsFullscreen());
1158 DestroyMaximizeModeWindowManager();
1161 // Test that an edge touch press at the top will end full screen mode.
1162 TEST_F(MaximizeModeWindowManagerTest, ExitFullScreenWithEdgeTouchAtTop) {
1163 gfx::Rect rect(10, 10, 200, 50);
1164 scoped_ptr<aura::Window>
1165 background_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1166 scoped_ptr<aura::Window>
1167 foreground_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1168 wm::WindowState* background_window_state =
1169 wm::GetWindowState(background_window.get());
1170 wm::WindowState* foreground_window_state =
1171 wm::GetWindowState(foreground_window.get());
1172 wm::ActivateWindow(foreground_window.get());
1173 CreateMaximizeModeWindowManager();
1175 // Fullscreen both windows.
1176 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
1177 background_window_state->OnWMEvent(&event);
1178 foreground_window_state->OnWMEvent(&event);
1179 EXPECT_TRUE(background_window_state->IsFullscreen());
1180 EXPECT_TRUE(foreground_window_state->IsFullscreen());
1181 EXPECT_EQ(foreground_window.get(), wm::GetActiveWindow());
1183 // Touch tap on the top edge.
1184 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1185 generator.GestureTapAt(gfx::Point(100, 0));
1186 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1187 EXPECT_TRUE(background_window_state->IsFullscreen());
1189 // Try the same again and see that nothing changes.
1190 generator.GestureTapAt(gfx::Point(100, 0));
1191 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1192 EXPECT_TRUE(background_window_state->IsFullscreen());
1194 DestroyMaximizeModeWindowManager();
1197 // Test that an edge touch press at the bottom will end full screen mode.
1198 TEST_F(MaximizeModeWindowManagerTest, ExitFullScreenWithEdgeTouchAtBottom) {
1199 gfx::Rect rect(10, 10, 200, 50);
1200 scoped_ptr<aura::Window>
1201 background_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1202 scoped_ptr<aura::Window>
1203 foreground_window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1204 wm::WindowState* background_window_state =
1205 wm::GetWindowState(background_window.get());
1206 wm::WindowState* foreground_window_state =
1207 wm::GetWindowState(foreground_window.get());
1208 wm::ActivateWindow(foreground_window.get());
1209 CreateMaximizeModeWindowManager();
1211 // Fullscreen both windows.
1212 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
1213 background_window_state->OnWMEvent(&event);
1214 foreground_window_state->OnWMEvent(&event);
1215 EXPECT_TRUE(background_window_state->IsFullscreen());
1216 EXPECT_TRUE(foreground_window_state->IsFullscreen());
1217 EXPECT_EQ(foreground_window.get(), wm::GetActiveWindow());
1219 // Touch tap on the bottom edge.
1220 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1221 generator.GestureTapAt(
1222 gfx::Point(100, Shell::GetPrimaryRootWindow()->bounds().bottom() - 1));
1223 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1224 EXPECT_TRUE(background_window_state->IsFullscreen());
1226 // Try the same again and see that nothing changes.
1227 generator.GestureTapAt(
1228 gfx::Point(100, Shell::GetPrimaryRootWindow()->bounds().bottom() - 1));
1229 EXPECT_FALSE(foreground_window_state->IsFullscreen());
1230 EXPECT_TRUE(background_window_state->IsFullscreen());
1232 DestroyMaximizeModeWindowManager();
1235 // Test that an edge swipe from the top on an immersive mode window will not end
1236 // full screen mode.
1237 TEST_F(MaximizeModeWindowManagerTest, NoExitImmersiveModeWithEdgeSwipeFromTop) {
1238 scoped_ptr<aura::Window> window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL,
1239 gfx::Rect(10, 10, 200, 50)));
1240 wm::WindowState* window_state = wm::GetWindowState(window.get());
1241 wm::ActivateWindow(window.get());
1242 CreateMaximizeModeWindowManager();
1244 // Fullscreen the window.
1245 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
1246 window_state->OnWMEvent(&event);
1247 EXPECT_TRUE(window_state->IsFullscreen());
1248 EXPECT_FALSE(window_state->in_immersive_fullscreen());
1249 EXPECT_EQ(window.get(), wm::GetActiveWindow());
1251 window_state->set_in_immersive_fullscreen(true);
1253 // Do an edge swipe top into screen.
1254 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1255 generator.GestureScrollSequence(gfx::Point(50, 0),
1256 gfx::Point(50, 100),
1257 base::TimeDelta::FromMilliseconds(20),
1258 10);
1260 // It should have not exited full screen or immersive mode.
1261 EXPECT_TRUE(window_state->IsFullscreen());
1262 EXPECT_TRUE(window_state->in_immersive_fullscreen());
1264 DestroyMaximizeModeWindowManager();
1267 // Test that an edge swipe from the bottom will not end immersive mode.
1268 TEST_F(MaximizeModeWindowManagerTest,
1269 NoExitImmersiveModeWithEdgeSwipeFromBottom) {
1270 scoped_ptr<aura::Window> window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL,
1271 gfx::Rect(10, 10, 200, 50)));
1272 wm::WindowState* window_state = wm::GetWindowState(window.get());
1273 wm::ActivateWindow(window.get());
1274 CreateMaximizeModeWindowManager();
1276 // Fullscreen the window.
1277 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
1278 window_state->OnWMEvent(&event);
1279 EXPECT_TRUE(window_state->IsFullscreen());
1280 EXPECT_FALSE(window_state->in_immersive_fullscreen());
1281 EXPECT_EQ(window.get(), wm::GetActiveWindow());
1282 window_state->set_in_immersive_fullscreen(true);
1283 EXPECT_TRUE(window_state->in_immersive_fullscreen());
1285 // Do an edge swipe bottom into screen.
1286 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1287 int y = Shell::GetPrimaryRootWindow()->bounds().bottom();
1288 generator.GestureScrollSequence(gfx::Point(50, y),
1289 gfx::Point(50, y - 100),
1290 base::TimeDelta::FromMilliseconds(20),
1291 10);
1293 // The window should still be full screen and immersive.
1294 EXPECT_TRUE(window_state->IsFullscreen());
1295 EXPECT_TRUE(window_state->in_immersive_fullscreen());
1297 DestroyMaximizeModeWindowManager();
1300 #endif // OS_WIN
1302 } // namespace ash