OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/wm/workspace_controller.h" | 5 #include "ash/wm/workspace_controller.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
11 #include "ash/screen_ash.h" | 11 #include "ash/screen_ash.h" |
12 #include "ash/shelf/shelf_layout_manager.h" | 12 #include "ash/shelf/shelf_layout_manager.h" |
13 #include "ash/shelf/shelf_widget.h" | 13 #include "ash/shelf/shelf_widget.h" |
14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
15 #include "ash/shell_window_ids.h" | 15 #include "ash/shell_window_ids.h" |
16 #include "ash/system/status_area_widget.h" | 16 #include "ash/system/status_area_widget.h" |
17 #include "ash/test/ash_test_base.h" | 17 #include "ash/test/ash_test_base.h" |
18 #include "ash/test/shell_test_api.h" | 18 #include "ash/test/shell_test_api.h" |
19 #include "ash/wm/property_util.h" | 19 #include "ash/wm/window_state.h" |
20 #include "ash/wm/window_settings.h" | |
21 #include "ash/wm/window_util.h" | 20 #include "ash/wm/window_util.h" |
22 #include "base/command_line.h" | 21 #include "base/command_line.h" |
23 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
24 #include "ui/aura/client/aura_constants.h" | 23 #include "ui/aura/client/aura_constants.h" |
25 #include "ui/aura/root_window.h" | 24 #include "ui/aura/root_window.h" |
26 #include "ui/aura/test/event_generator.h" | 25 #include "ui/aura/test/event_generator.h" |
27 #include "ui/aura/test/test_window_delegate.h" | 26 #include "ui/aura/test/test_window_delegate.h" |
28 #include "ui/aura/test/test_windows.h" | 27 #include "ui/aura/test/test_windows.h" |
29 #include "ui/aura/window.h" | 28 #include "ui/aura/window.h" |
30 #include "ui/base/hit_test.h" | 29 #include "ui/base/hit_test.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 95 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
97 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | 96 window->SetType(aura::client::WINDOW_TYPE_NORMAL); |
98 window->Init(ui::LAYER_TEXTURED); | 97 window->Init(ui::LAYER_TEXTURED); |
99 SetDefaultParentByPrimaryRootWindow(window); | 98 SetDefaultParentByPrimaryRootWindow(window); |
100 return window; | 99 return window; |
101 } | 100 } |
102 | 101 |
103 aura::Window* CreateBrowserLikeWindow(const gfx::Rect& bounds) { | 102 aura::Window* CreateBrowserLikeWindow(const gfx::Rect& bounds) { |
104 aura::Window* window = CreateTestWindow(); | 103 aura::Window* window = CreateTestWindow(); |
105 window->SetBounds(bounds); | 104 window->SetBounds(bounds); |
106 wm::WindowSettings* settings = wm::GetWindowSettings(window); | 105 wm::WindowState* window_state = wm::GetWindowState(window); |
107 settings->SetTrackedByWorkspace(true); | 106 window_state->SetTrackedByWorkspace(true); |
108 settings->set_window_position_managed(true); | 107 window_state->set_window_position_managed(true); |
109 window->Show(); | 108 window->Show(); |
110 return window; | 109 return window; |
111 } | 110 } |
112 | 111 |
113 aura::Window* CreatePopupLikeWindow(const gfx::Rect& bounds) { | 112 aura::Window* CreatePopupLikeWindow(const gfx::Rect& bounds) { |
114 aura::Window* window = CreateTestWindowInShellWithBounds(bounds); | 113 aura::Window* window = CreateTestWindowInShellWithBounds(bounds); |
115 window->Show(); | 114 window->Show(); |
116 return window; | 115 return window; |
117 } | 116 } |
118 | 117 |
(...skipping 20 matching lines...) Expand all Loading... | |
139 | 138 |
140 private: | 139 private: |
141 DISALLOW_COPY_AND_ASSIGN(WorkspaceControllerTest); | 140 DISALLOW_COPY_AND_ASSIGN(WorkspaceControllerTest); |
142 }; | 141 }; |
143 | 142 |
144 // Assertions around adding a normal window. | 143 // Assertions around adding a normal window. |
145 TEST_F(WorkspaceControllerTest, AddNormalWindowWhenEmpty) { | 144 TEST_F(WorkspaceControllerTest, AddNormalWindowWhenEmpty) { |
146 scoped_ptr<Window> w1(CreateTestWindow()); | 145 scoped_ptr<Window> w1(CreateTestWindow()); |
147 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); | 146 w1->SetBounds(gfx::Rect(0, 0, 250, 251)); |
148 | 147 |
149 EXPECT_TRUE(GetRestoreBoundsInScreen(w1.get()) == NULL); | 148 wm::WindowState* window_state = wm::GetWindowState(w1.get()); |
149 | |
150 EXPECT_FALSE(window_state->HasRestoreBounds()); | |
150 | 151 |
151 w1->Show(); | 152 w1->Show(); |
152 | 153 |
153 EXPECT_TRUE(GetRestoreBoundsInScreen(w1.get()) == NULL); | 154 EXPECT_FALSE(window_state->HasRestoreBounds()); |
154 | 155 |
155 ASSERT_TRUE(w1->layer() != NULL); | 156 ASSERT_TRUE(w1->layer() != NULL); |
156 EXPECT_TRUE(w1->layer()->visible()); | 157 EXPECT_TRUE(w1->layer()->visible()); |
157 | 158 |
158 EXPECT_EQ("0,0 250x251", w1->bounds().ToString()); | 159 EXPECT_EQ("0,0 250x251", w1->bounds().ToString()); |
159 | 160 |
160 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); | 161 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); |
161 } | 162 } |
162 | 163 |
163 // Assertions around maximizing/unmaximizing. | 164 // Assertions around maximizing/unmaximizing. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 | 269 |
269 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); | 270 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); |
270 EXPECT_EQ(250, w1->bounds().width()); | 271 EXPECT_EQ(250, w1->bounds().width()); |
271 EXPECT_EQ(251, w1->bounds().height()); | 272 EXPECT_EQ(251, w1->bounds().height()); |
272 | 273 |
273 // Back to fullscreen. | 274 // Back to fullscreen. |
274 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 275 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
275 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); | 276 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); |
276 EXPECT_EQ(GetFullscreenBounds(w1.get()).width(), w1->bounds().width()); | 277 EXPECT_EQ(GetFullscreenBounds(w1.get()).width(), w1->bounds().width()); |
277 EXPECT_EQ(GetFullscreenBounds(w1.get()).height(), w1->bounds().height()); | 278 EXPECT_EQ(GetFullscreenBounds(w1.get()).height(), w1->bounds().height()); |
278 ASSERT_TRUE(GetRestoreBoundsInScreen(w1.get())); | 279 wm::WindowState* window_state = wm::GetWindowState(w1.get()); |
279 EXPECT_EQ("0,0 250x251", GetRestoreBoundsInScreen(w1.get())->ToString()); | 280 |
281 ASSERT_TRUE(window_state->HasRestoreBounds()); | |
282 EXPECT_EQ("0,0 250x251", window_state->GetRestoreBoundsInScreen().ToString()); | |
280 } | 283 } |
281 | 284 |
282 // Assertions around minimizing a single window. | 285 // Assertions around minimizing a single window. |
283 TEST_F(WorkspaceControllerTest, MinimizeSingleWindow) { | 286 TEST_F(WorkspaceControllerTest, MinimizeSingleWindow) { |
284 scoped_ptr<Window> w1(CreateTestWindow()); | 287 scoped_ptr<Window> w1(CreateTestWindow()); |
285 | 288 |
286 w1->Show(); | 289 w1->Show(); |
287 | 290 |
288 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 291 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
289 EXPECT_FALSE(w1->layer()->IsDrawn()); | 292 EXPECT_FALSE(w1->layer()->IsDrawn()); |
290 | 293 |
291 // Show the window. | 294 // Show the window. |
292 w1->Show(); | 295 w1->Show(); |
293 EXPECT_TRUE(wm::IsWindowNormal(w1.get())); | 296 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsNormal()); |
294 EXPECT_TRUE(w1->layer()->IsDrawn()); | 297 EXPECT_TRUE(w1->layer()->IsDrawn()); |
295 } | 298 } |
296 | 299 |
297 // Assertions around minimizing a fullscreen window. | 300 // Assertions around minimizing a fullscreen window. |
298 TEST_F(WorkspaceControllerTest, MinimizeFullscreenWindow) { | 301 TEST_F(WorkspaceControllerTest, MinimizeFullscreenWindow) { |
299 // Two windows, w1 normal, w2 fullscreen. | 302 // Two windows, w1 normal, w2 fullscreen. |
300 scoped_ptr<Window> w1(CreateTestWindow()); | 303 scoped_ptr<Window> w1(CreateTestWindow()); |
301 scoped_ptr<Window> w2(CreateTestWindow()); | 304 scoped_ptr<Window> w2(CreateTestWindow()); |
302 w1->Show(); | 305 w1->Show(); |
303 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 306 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
304 w2->Show(); | 307 w2->Show(); |
305 wm::ActivateWindow(w2.get()); | 308 |
309 wm::WindowState* w1_state = wm::GetWindowState(w1.get()); | |
310 wm::WindowState* w2_state = wm::GetWindowState(w2.get()); | |
311 | |
312 w2_state->Activate(); | |
306 | 313 |
307 // Minimize w2. | 314 // Minimize w2. |
308 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 315 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
309 EXPECT_TRUE(w1->layer()->IsDrawn()); | 316 EXPECT_TRUE(w1->layer()->IsDrawn()); |
310 EXPECT_FALSE(w2->layer()->IsDrawn()); | 317 EXPECT_FALSE(w2->layer()->IsDrawn()); |
311 | 318 |
312 // Show the window, which should trigger unminimizing. | 319 // Show the window, which should trigger unminimizing. |
313 w2->Show(); | 320 w2->Show(); |
314 wm::ActivateWindow(w2.get()); | 321 w2_state->Activate(); |
315 | 322 |
316 EXPECT_TRUE(wm::IsWindowFullscreen(w2.get())); | 323 EXPECT_TRUE(w2_state->IsFullscreen()); |
317 EXPECT_TRUE(w1->layer()->IsDrawn()); | 324 EXPECT_TRUE(w1->layer()->IsDrawn()); |
318 EXPECT_TRUE(w2->layer()->IsDrawn()); | 325 EXPECT_TRUE(w2->layer()->IsDrawn()); |
319 | 326 |
320 // Minimize the window, which should hide the window. | 327 // Minimize the window, which should hide the window. |
321 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 328 EXPECT_TRUE(w2_state->IsActive()); |
322 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 329 w2_state->Minimize(); |
323 EXPECT_FALSE(wm::IsActiveWindow(w2.get())); | 330 EXPECT_FALSE(w2_state->IsActive()); |
324 EXPECT_FALSE(w2->layer()->IsDrawn()); | 331 EXPECT_FALSE(w2->layer()->IsDrawn()); |
325 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 332 EXPECT_TRUE(w1_state->IsActive()); |
326 | 333 |
327 // Make the window normal. | 334 // Make the window normal. |
328 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 335 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
329 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); | 336 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); |
330 EXPECT_EQ(w2.get(), GetDesktop()->children()[1]); | 337 EXPECT_EQ(w2.get(), GetDesktop()->children()[1]); |
331 EXPECT_TRUE(w2->layer()->IsDrawn()); | 338 EXPECT_TRUE(w2->layer()->IsDrawn()); |
332 } | 339 } |
333 | 340 |
334 // Verifies ShelfLayoutManager's visibility/auto-hide state is correctly | 341 // Verifies ShelfLayoutManager's visibility/auto-hide state is correctly |
335 // updated. | 342 // updated. |
(...skipping 10 matching lines...) Expand all Loading... | |
346 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 353 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
347 const gfx::Rect touches_shelf_bounds( | 354 const gfx::Rect touches_shelf_bounds( |
348 0, shelf->GetIdealBounds().y() - 10, 101, 102); | 355 0, shelf->GetIdealBounds().y() - 10, 101, 102); |
349 // Move |w1| to overlap the shelf. | 356 // Move |w1| to overlap the shelf. |
350 w1->SetBounds(touches_shelf_bounds); | 357 w1->SetBounds(touches_shelf_bounds); |
351 EXPECT_FALSE(GetWindowOverlapsShelf()); | 358 EXPECT_FALSE(GetWindowOverlapsShelf()); |
352 | 359 |
353 // A visible ignored window should not trigger the overlap. | 360 // A visible ignored window should not trigger the overlap. |
354 scoped_ptr<Window> w_ignored(CreateTestWindow()); | 361 scoped_ptr<Window> w_ignored(CreateTestWindow()); |
355 w_ignored->SetBounds(touches_shelf_bounds); | 362 w_ignored->SetBounds(touches_shelf_bounds); |
356 wm::GetWindowSettings(&(*w_ignored))->set_ignored_by_shelf(true); | 363 wm::GetWindowState(&(*w_ignored))->set_ignored_by_shelf(true); |
357 w_ignored->Show(); | 364 w_ignored->Show(); |
358 EXPECT_FALSE(GetWindowOverlapsShelf()); | 365 EXPECT_FALSE(GetWindowOverlapsShelf()); |
359 | 366 |
360 // Make it visible, since visible shelf overlaps should be true. | 367 // Make it visible, since visible shelf overlaps should be true. |
361 w1->Show(); | 368 w1->Show(); |
362 EXPECT_TRUE(GetWindowOverlapsShelf()); | 369 EXPECT_TRUE(GetWindowOverlapsShelf()); |
363 | 370 |
364 wm::ActivateWindow(w1.get()); | 371 wm::ActivateWindow(w1.get()); |
365 w1->SetBounds(w1_bounds); | 372 w1->SetBounds(w1_bounds); |
366 w1->Show(); | 373 w1->Show(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | 408 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
402 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 409 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
403 | 410 |
404 // Minimize. | 411 // Minimize. |
405 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 412 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
406 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | 413 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
407 | 414 |
408 // Since the restore from minimize will restore to the pre-minimize | 415 // Since the restore from minimize will restore to the pre-minimize |
409 // state (tested elsewhere), we abandon the current size and restore | 416 // state (tested elsewhere), we abandon the current size and restore |
410 // rect and set them to the window. | 417 // rect and set them to the window. |
411 gfx::Rect restore = *GetRestoreBoundsInScreen(w1.get()); | 418 wm::WindowState* controller = wm::GetWindowState(w1.get()); |
419 | |
420 gfx::Rect restore = controller->GetRestoreBoundsInScreen(); | |
412 EXPECT_EQ("0,0 800x597", w1->bounds().ToString()); | 421 EXPECT_EQ("0,0 800x597", w1->bounds().ToString()); |
413 EXPECT_EQ("0,1 101x102", restore.ToString()); | 422 EXPECT_EQ("0,1 101x102", restore.ToString()); |
414 ClearRestoreBounds(w1.get()); | 423 controller->ClearRestoreBounds(); |
415 w1->SetBounds(restore); | 424 w1->SetBounds(restore); |
416 | 425 |
417 // Restore. | 426 // Restore. |
418 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 427 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
419 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | 428 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
420 EXPECT_EQ("0,1 101x102", w1->bounds().ToString()); | 429 EXPECT_EQ("0,1 101x102", w1->bounds().ToString()); |
421 | 430 |
422 // Create another window, maximized. | 431 // Create another window, maximized. |
423 scoped_ptr<Window> w2(CreateTestWindow()); | 432 scoped_ptr<Window> w2(CreateTestWindow()); |
424 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); | 433 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
634 TEST_F(WorkspaceControllerTest, DontCrashOnChangeAndActivate) { | 643 TEST_F(WorkspaceControllerTest, DontCrashOnChangeAndActivate) { |
635 // Force the shelf | 644 // Force the shelf |
636 ShelfLayoutManager* shelf = shelf_layout_manager(); | 645 ShelfLayoutManager* shelf = shelf_layout_manager(); |
637 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 646 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
638 | 647 |
639 DontCrashOnChangeAndActivateDelegate delegate; | 648 DontCrashOnChangeAndActivateDelegate delegate; |
640 scoped_ptr<Window> w1(CreateTestWindowInShellWithDelegate( | 649 scoped_ptr<Window> w1(CreateTestWindowInShellWithDelegate( |
641 &delegate, 1000, gfx::Rect(10, 11, 250, 251))); | 650 &delegate, 1000, gfx::Rect(10, 11, 250, 251))); |
642 | 651 |
643 w1->Show(); | 652 w1->Show(); |
644 wm::ActivateWindow(w1.get()); | 653 wm::WindowState* w1_state = wm::GetWindowState(w1.get()); |
645 wm::MaximizeWindow(w1.get()); | 654 w1_state->Activate(); |
646 wm::MinimizeWindow(w1.get()); | 655 w1_state->Maximize(); |
656 w1_state->Minimize(); | |
647 | 657 |
648 w1->parent()->RemoveChild(w1.get()); | 658 w1->parent()->RemoveChild(w1.get()); |
649 | 659 |
650 // Do this so that when we Show() the window a resize occurs and we make the | 660 // Do this so that when we Show() the window a resize occurs and we make the |
651 // window active. | 661 // window active. |
652 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 662 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
653 | 663 |
654 SetDefaultParentByPrimaryRootWindow(w1.get()); | 664 SetDefaultParentByPrimaryRootWindow(w1.get()); |
655 delegate.set_window(w1.get()); | 665 delegate.set_window(w1.get()); |
656 w1->Show(); | 666 w1->Show(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
688 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 698 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
689 EXPECT_TRUE(w1->IsVisible()); | 699 EXPECT_TRUE(w1->IsVisible()); |
690 | 700 |
691 // Create a second fullscreen window and mark it not tracked by workspace | 701 // Create a second fullscreen window and mark it not tracked by workspace |
692 // manager. | 702 // manager. |
693 scoped_ptr<Window> w2(CreateTestWindowUnparented()); | 703 scoped_ptr<Window> w2(CreateTestWindowUnparented()); |
694 w2->SetBounds(gfx::Rect(1, 6, 25, 30)); | 704 w2->SetBounds(gfx::Rect(1, 6, 25, 30)); |
695 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 705 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
696 SetDefaultParentByPrimaryRootWindow(w2.get()); | 706 SetDefaultParentByPrimaryRootWindow(w2.get()); |
697 w2->Show(); | 707 w2->Show(); |
698 wm::GetWindowSettings(w2.get())->SetTrackedByWorkspace(false); | 708 wm::GetWindowState(w2.get())->SetTrackedByWorkspace(false); |
699 wm::ActivateWindow(w2.get()); | 709 wm::ActivateWindow(w2.get()); |
700 | 710 |
701 // Activating |w2| should force it to have the same parent as |w1|. | 711 // Activating |w2| should force it to have the same parent as |w1|. |
702 EXPECT_EQ(w1->parent(), w2->parent()); | 712 EXPECT_EQ(w1->parent(), w2->parent()); |
703 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 713 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
704 EXPECT_TRUE(w1->IsVisible()); | 714 EXPECT_TRUE(w1->IsVisible()); |
705 EXPECT_TRUE(w2->IsVisible()); | 715 EXPECT_TRUE(w2->IsVisible()); |
706 | 716 |
707 // Because |w2| isn't tracked we should be able to set the bounds of it. | 717 // Because |w2| isn't tracked we should be able to set the bounds of it. |
708 gfx::Rect bounds(w2->bounds()); | 718 gfx::Rect bounds(w2->bounds()); |
709 bounds.Offset(4, 5); | 719 bounds.Offset(4, 5); |
710 w2->SetBounds(bounds); | 720 w2->SetBounds(bounds); |
711 EXPECT_EQ(bounds.ToString(), w2->bounds().ToString()); | 721 EXPECT_EQ(bounds.ToString(), w2->bounds().ToString()); |
712 | 722 |
713 // Transition it to tracked by worskpace. It should end up in the desktop | 723 // Transition it to tracked by worskpace. It should end up in the desktop |
714 // workspace. | 724 // workspace. |
715 wm::GetWindowSettings(w2.get())->SetTrackedByWorkspace(true); | 725 wm::GetWindowState(w2.get())->SetTrackedByWorkspace(true); |
716 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 726 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
717 EXPECT_TRUE(w1->IsVisible()); | 727 EXPECT_TRUE(w1->IsVisible()); |
718 EXPECT_TRUE(w2->IsVisible()); | 728 EXPECT_TRUE(w2->IsVisible()); |
719 EXPECT_EQ(w1->parent(), w2->parent()); | 729 EXPECT_EQ(w1->parent(), w2->parent()); |
720 } | 730 } |
721 | 731 |
722 // Test the placement of newly created windows. | 732 // Test the placement of newly created windows. |
723 TEST_F(WorkspaceControllerTest, BasicAutoPlacingOnCreate) { | 733 TEST_F(WorkspaceControllerTest, BasicAutoPlacingOnCreate) { |
724 if (!SupportsHostWindowResize()) | 734 if (!SupportsHostWindowResize()) |
725 return; | 735 return; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
792 | 802 |
793 // Check the initial position of the windows is unchanged. | 803 // Check the initial position of the windows is unchanged. |
794 EXPECT_EQ("16,32 640x320", window1->bounds().ToString()); | 804 EXPECT_EQ("16,32 640x320", window1->bounds().ToString()); |
795 EXPECT_EQ("32,48 256x512", window2->bounds().ToString()); | 805 EXPECT_EQ("32,48 256x512", window2->bounds().ToString()); |
796 | 806 |
797 // Remove the second window and make sure that the first window | 807 // Remove the second window and make sure that the first window |
798 // does NOT get centered. | 808 // does NOT get centered. |
799 window2.reset(); | 809 window2.reset(); |
800 EXPECT_EQ("16,32 640x320", window1->bounds().ToString()); | 810 EXPECT_EQ("16,32 640x320", window1->bounds().ToString()); |
801 | 811 |
812 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | |
802 // Test 2: Set up two managed windows and check their auto positioning. | 813 // Test 2: Set up two managed windows and check their auto positioning. |
803 wm::GetWindowSettings(window1.get())->set_window_position_managed(true); | 814 window1_state->set_window_position_managed(true); |
804 | 815 |
805 scoped_ptr<aura::Window> window3(CreateTestWindowInShellWithId(2)); | 816 scoped_ptr<aura::Window> window3(CreateTestWindowInShellWithId(2)); |
806 wm::GetWindowSettings(window3.get())->set_window_position_managed(true); | 817 wm::GetWindowState(window3.get())->set_window_position_managed(true); |
807 // To avoid any auto window manager changes due to SetBounds, the window | 818 // To avoid any auto window manager changes due to SetBounds, the window |
808 // gets first hidden and then shown again. | 819 // gets first hidden and then shown again. |
809 window3->Hide(); | 820 window3->Hide(); |
810 window3->SetBounds(gfx::Rect(32, 48, 256, 512)); | 821 window3->SetBounds(gfx::Rect(32, 48, 256, 512)); |
811 window3->Show(); | 822 window3->Show(); |
812 // |window1| should be flush left and |window3| flush right. | 823 // |window1| should be flush left and |window3| flush right. |
813 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); | 824 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); |
814 EXPECT_EQ(base::IntToString( | 825 EXPECT_EQ(base::IntToString( |
815 desktop_area.width() - window3->bounds().width()) + | 826 desktop_area.width() - window3->bounds().width()) + |
816 ",48 256x512", window3->bounds().ToString()); | 827 ",48 256x512", window3->bounds().ToString()); |
(...skipping 16 matching lines...) Expand all Loading... | |
833 window1->Show(); | 844 window1->Show(); |
834 // |window1| should be centered and |window4| untouched. | 845 // |window1| should be centered and |window4| untouched. |
835 EXPECT_EQ( | 846 EXPECT_EQ( |
836 base::IntToString( | 847 base::IntToString( |
837 (desktop_area.width() - window1->bounds().width()) / 2) + | 848 (desktop_area.width() - window1->bounds().width()) / 2) + |
838 ",32 640x320", window1->bounds().ToString()); | 849 ",32 640x320", window1->bounds().ToString()); |
839 EXPECT_EQ("32,48 256x512", window4->bounds().ToString()); | 850 EXPECT_EQ("32,48 256x512", window4->bounds().ToString()); |
840 | 851 |
841 // Test4: A single manageable window should get centered. | 852 // Test4: A single manageable window should get centered. |
842 window4.reset(); | 853 window4.reset(); |
843 wm::GetWindowSettings(window1.get())->set_bounds_changed_by_user(false); | 854 window1_state->set_bounds_changed_by_user(false); |
844 // Trigger the auto window placement function by showing (and hiding) it. | 855 // Trigger the auto window placement function by showing (and hiding) it. |
845 window1->Hide(); | 856 window1->Hide(); |
846 window1->Show(); | 857 window1->Show(); |
847 // |window1| should be centered. | 858 // |window1| should be centered. |
848 EXPECT_EQ( | 859 EXPECT_EQ( |
849 base::IntToString( | 860 base::IntToString( |
850 (desktop_area.width() - window1->bounds().width()) / 2) + | 861 (desktop_area.width() - window1->bounds().width()) / 2) + |
851 ",32 640x320", window1->bounds().ToString()); | 862 ",32 640x320", window1->bounds().ToString()); |
852 } | 863 } |
853 | 864 |
854 // Test the proper usage of user window movement interaction. | 865 // Test the proper usage of user window movement interaction. |
855 TEST_F(WorkspaceControllerTest, TestUserMovedWindowRepositioning) { | 866 TEST_F(WorkspaceControllerTest, TestUserMovedWindowRepositioning) { |
856 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 867 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
857 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); | 868 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
858 gfx::Rect desktop_area = window1->parent()->bounds(); | 869 gfx::Rect desktop_area = window1->parent()->bounds(); |
859 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 870 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
860 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); | 871 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
861 window1->Hide(); | 872 window1->Hide(); |
862 window2->Hide(); | 873 window2->Hide(); |
863 wm::GetWindowSettings(window1.get())->set_window_position_managed(true); | 874 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
864 wm::GetWindowSettings(window2.get())->set_window_position_managed(true); | 875 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); |
865 EXPECT_FALSE(wm::GetWindowSettings(window1.get())->bounds_changed_by_user()); | 876 |
866 EXPECT_FALSE(wm::GetWindowSettings(window2.get())->bounds_changed_by_user()); | 877 window1_state->set_window_position_managed(true); |
878 window2_state->set_window_position_managed(true); | |
879 EXPECT_FALSE(window1_state->bounds_changed_by_user()); | |
880 EXPECT_FALSE(window2_state->bounds_changed_by_user()); | |
867 | 881 |
868 // Check that the current location gets preserved if the user has | 882 // Check that the current location gets preserved if the user has |
869 // positioned it previously. | 883 // positioned it previously. |
870 wm::GetWindowSettings(window1.get())->set_bounds_changed_by_user(true); | 884 window1_state->set_bounds_changed_by_user(true); |
871 window1->Show(); | 885 window1->Show(); |
872 EXPECT_EQ("16,32 640x320", window1->bounds().ToString()); | 886 EXPECT_EQ("16,32 640x320", window1->bounds().ToString()); |
873 // Flag should be still set. | 887 // Flag should be still set. |
874 EXPECT_TRUE(wm::GetWindowSettings(window1.get())->bounds_changed_by_user()); | 888 EXPECT_TRUE(window1_state->bounds_changed_by_user()); |
875 EXPECT_FALSE(wm::GetWindowSettings(window2.get())->bounds_changed_by_user()); | 889 EXPECT_FALSE(window2_state->bounds_changed_by_user()); |
876 | 890 |
877 // Turn on the second window and make sure that both windows are now | 891 // Turn on the second window and make sure that both windows are now |
878 // positionable again (user movement cleared). | 892 // positionable again (user movement cleared). |
879 window2->Show(); | 893 window2->Show(); |
880 | 894 |
881 // |window1| should be flush left and |window2| flush right. | 895 // |window1| should be flush left and |window2| flush right. |
882 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); | 896 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); |
883 EXPECT_EQ( | 897 EXPECT_EQ( |
884 base::IntToString(desktop_area.width() - window2->bounds().width()) + | 898 base::IntToString(desktop_area.width() - window2->bounds().width()) + |
885 ",48 256x512", window2->bounds().ToString()); | 899 ",48 256x512", window2->bounds().ToString()); |
886 // FLag should now be reset. | 900 // FLag should now be reset. |
887 EXPECT_FALSE(wm::GetWindowSettings(window1.get())->bounds_changed_by_user()); | 901 EXPECT_FALSE(window1_state->bounds_changed_by_user()); |
888 EXPECT_FALSE(wm::GetWindowSettings(window2.get())->bounds_changed_by_user()); | 902 EXPECT_FALSE(window2_state->bounds_changed_by_user()); |
889 | 903 |
890 // Going back to one shown window should keep the state. | 904 // Going back to one shown window should keep the state. |
891 wm::GetWindowSettings(window1.get())->set_bounds_changed_by_user(true); | 905 window1_state->set_bounds_changed_by_user(true); |
892 window2->Hide(); | 906 window2->Hide(); |
893 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); | 907 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); |
894 EXPECT_TRUE(wm::GetWindowSettings(window1.get())->bounds_changed_by_user()); | 908 EXPECT_TRUE(window1_state->bounds_changed_by_user()); |
895 } | 909 } |
896 | 910 |
897 // Test if the single window will be restored at original position. | 911 // Test if the single window will be restored at original position. |
898 TEST_F(WorkspaceControllerTest, TestSingleWindowsRestoredBounds) { | 912 TEST_F(WorkspaceControllerTest, TestSingleWindowsRestoredBounds) { |
899 scoped_ptr<aura::Window> window1( | 913 scoped_ptr<aura::Window> window1( |
900 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); | 914 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); |
901 scoped_ptr<aura::Window> window2( | 915 scoped_ptr<aura::Window> window2( |
902 CreateTestWindowInShellWithBounds(gfx::Rect(110, 110, 100, 100))); | 916 CreateTestWindowInShellWithBounds(gfx::Rect(110, 110, 100, 100))); |
903 scoped_ptr<aura::Window> window3( | 917 scoped_ptr<aura::Window> window3( |
904 CreateTestWindowInShellWithBounds(gfx::Rect(120, 120, 100, 100))); | 918 CreateTestWindowInShellWithBounds(gfx::Rect(120, 120, 100, 100))); |
905 window1->Hide(); | 919 window1->Hide(); |
906 window2->Hide(); | 920 window2->Hide(); |
907 window3->Hide(); | 921 window3->Hide(); |
908 wm::GetWindowSettings(window1.get())->set_window_position_managed(true); | 922 wm::GetWindowState(window1.get())->set_window_position_managed(true); |
909 wm::GetWindowSettings(window2.get())->set_window_position_managed(true); | 923 wm::GetWindowState(window2.get())->set_window_position_managed(true); |
910 wm::GetWindowSettings(window3.get())->set_window_position_managed(true); | 924 wm::GetWindowState(window3.get())->set_window_position_managed(true); |
911 | 925 |
912 window1->Show(); | 926 window1->Show(); |
913 wm::ActivateWindow(window1.get()); | 927 wm::ActivateWindow(window1.get()); |
914 window2->Show(); | 928 window2->Show(); |
915 wm::ActivateWindow(window2.get()); | 929 wm::ActivateWindow(window2.get()); |
916 window3->Show(); | 930 window3->Show(); |
917 wm::ActivateWindow(window3.get()); | 931 wm::ActivateWindow(window3.get()); |
918 EXPECT_EQ(0, window1->bounds().x()); | 932 EXPECT_EQ(0, window1->bounds().x()); |
919 EXPECT_EQ(window2->GetRootWindow()->bounds().right(), | 933 EXPECT_EQ(window2->GetRootWindow()->bounds().right(), |
920 window2->bounds().right()); | 934 window2->bounds().right()); |
(...skipping 20 matching lines...) Expand all Loading... | |
941 window2->Hide(); | 955 window2->Hide(); |
942 EXPECT_EQ("120,120 100x100", window3->bounds().ToString()); | 956 EXPECT_EQ("120,120 100x100", window3->bounds().ToString()); |
943 } | 957 } |
944 | 958 |
945 // Test that user placed windows go back to their user placement after the user | 959 // Test that user placed windows go back to their user placement after the user |
946 // closes all other windows. | 960 // closes all other windows. |
947 TEST_F(WorkspaceControllerTest, TestUserHandledWindowRestore) { | 961 TEST_F(WorkspaceControllerTest, TestUserHandledWindowRestore) { |
948 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 962 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
949 gfx::Rect user_pos = gfx::Rect(16, 42, 640, 320); | 963 gfx::Rect user_pos = gfx::Rect(16, 42, 640, 320); |
950 window1->SetBounds(user_pos); | 964 window1->SetBounds(user_pos); |
951 ash::wm::SetPreAutoManageWindowBounds(window1.get(), user_pos); | 965 wm::WindowState* controller1 = |
James Cook
2013/09/18 20:44:17
controller1 -> window1_state to be consistent with
oshima
2013/09/19 01:52:01
Done.
| |
966 wm::GetWindowState(window1.get()); | |
967 | |
968 controller1->SetPreAutoManageWindowBounds(user_pos); | |
952 gfx::Rect desktop_area = window1->parent()->bounds(); | 969 gfx::Rect desktop_area = window1->parent()->bounds(); |
953 | 970 |
954 // Create a second window to let the auto manager kick in. | 971 // Create a second window to let the auto manager kick in. |
955 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 972 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
956 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); | 973 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
957 window1->Hide(); | 974 window1->Hide(); |
958 window2->Hide(); | 975 window2->Hide(); |
959 wm::GetWindowSettings(window1.get())->set_window_position_managed(true); | 976 wm::GetWindowState(window1.get())->set_window_position_managed(true); |
960 wm::GetWindowSettings(window2.get())->set_window_position_managed(true); | 977 wm::GetWindowState(window2.get())->set_window_position_managed(true); |
961 window1->Show(); | 978 window1->Show(); |
962 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString()); | 979 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString()); |
963 window2->Show(); | 980 window2->Show(); |
964 | 981 |
965 // |window1| should be flush left and |window2| flush right. | 982 // |window1| should be flush left and |window2| flush right. |
966 EXPECT_EQ("0," + base::IntToString(user_pos.y()) + | 983 EXPECT_EQ("0," + base::IntToString(user_pos.y()) + |
967 " 640x320", window1->bounds().ToString()); | 984 " 640x320", window1->bounds().ToString()); |
968 EXPECT_EQ( | 985 EXPECT_EQ( |
969 base::IntToString(desktop_area.width() - window2->bounds().width()) + | 986 base::IntToString(desktop_area.width() - window2->bounds().width()) + |
970 ",48 256x512", window2->bounds().ToString()); | 987 ",48 256x512", window2->bounds().ToString()); |
971 window2->Hide(); | 988 window2->Hide(); |
972 | 989 |
973 // After the other window get hidden the window has to move back to the | 990 // After the other window get hidden the window has to move back to the |
974 // previous position and the bounds should still be set and unchanged. | 991 // previous position and the bounds should still be set and unchanged. |
975 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString()); | 992 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString()); |
976 ASSERT_TRUE(ash::wm::GetPreAutoManageWindowBounds(window1.get())); | 993 ASSERT_TRUE(controller1->pre_auto_manage_window_bounds()); |
977 EXPECT_EQ(user_pos.ToString(), | 994 EXPECT_EQ(user_pos.ToString(), |
978 ash::wm::GetPreAutoManageWindowBounds(window1.get())->ToString()); | 995 controller1->pre_auto_manage_window_bounds()->ToString()); |
979 } | 996 } |
980 | 997 |
981 // Test that a window from normal to minimize will repos the remaining. | 998 // Test that a window from normal to minimize will repos the remaining. |
982 TEST_F(WorkspaceControllerTest, ToMinimizeRepositionsRemaining) { | 999 TEST_F(WorkspaceControllerTest, ToMinimizeRepositionsRemaining) { |
983 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 1000 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
984 wm::GetWindowSettings(window1.get())->set_window_position_managed(true); | 1001 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
1002 window1_state->set_window_position_managed(true); | |
985 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); | 1003 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
986 gfx::Rect desktop_area = window1->parent()->bounds(); | 1004 gfx::Rect desktop_area = window1->parent()->bounds(); |
987 | 1005 |
988 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 1006 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
989 wm::GetWindowSettings(window2.get())->set_window_position_managed(true); | 1007 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); |
1008 window2_state->set_window_position_managed(true); | |
990 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); | 1009 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
991 | 1010 |
992 ash::wm::MinimizeWindow(window1.get()); | 1011 window1_state->Minimize(); |
993 | 1012 |
994 // |window2| should be centered now. | 1013 // |window2| should be centered now. |
995 EXPECT_TRUE(window2->IsVisible()); | 1014 EXPECT_TRUE(window2->IsVisible()); |
996 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get())); | 1015 EXPECT_TRUE(window2_state->IsNormal()); |
997 EXPECT_EQ(base::IntToString( | 1016 EXPECT_EQ(base::IntToString( |
998 (desktop_area.width() - window2->bounds().width()) / 2) + | 1017 (desktop_area.width() - window2->bounds().width()) / 2) + |
999 ",48 256x512", window2->bounds().ToString()); | 1018 ",48 256x512", window2->bounds().ToString()); |
1000 | 1019 |
1001 ash::wm::RestoreWindow(window1.get()); | 1020 window1_state->Restore(); |
1002 // |window1| should be flush right and |window3| flush left. | 1021 // |window1| should be flush right and |window3| flush left. |
1003 EXPECT_EQ(base::IntToString( | 1022 EXPECT_EQ(base::IntToString( |
1004 desktop_area.width() - window1->bounds().width()) + | 1023 desktop_area.width() - window1->bounds().width()) + |
1005 ",32 640x320", window1->bounds().ToString()); | 1024 ",32 640x320", window1->bounds().ToString()); |
1006 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); | 1025 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); |
1007 } | 1026 } |
1008 | 1027 |
1009 // Test that minimizing an initially maximized window will repos the remaining. | 1028 // Test that minimizing an initially maximized window will repos the remaining. |
1010 TEST_F(WorkspaceControllerTest, MaxToMinRepositionsRemaining) { | 1029 TEST_F(WorkspaceControllerTest, MaxToMinRepositionsRemaining) { |
1011 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 1030 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
1012 wm::GetWindowSettings(window1.get())->set_window_position_managed(true); | 1031 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
1032 window1_state->set_window_position_managed(true); | |
1013 gfx::Rect desktop_area = window1->parent()->bounds(); | 1033 gfx::Rect desktop_area = window1->parent()->bounds(); |
1014 | 1034 |
1015 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 1035 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
1016 wm::GetWindowSettings(window2.get())->set_window_position_managed(true); | 1036 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); |
1037 window2_state->set_window_position_managed(true); | |
1017 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); | 1038 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
1018 | 1039 |
1019 ash::wm::MaximizeWindow(window1.get()); | 1040 window1_state->Maximize(); |
1020 ash::wm::MinimizeWindow(window1.get()); | 1041 window1_state->Minimize(); |
1021 | 1042 |
1022 // |window2| should be centered now. | 1043 // |window2| should be centered now. |
1023 EXPECT_TRUE(window2->IsVisible()); | 1044 EXPECT_TRUE(window2->IsVisible()); |
1024 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get())); | 1045 EXPECT_TRUE(window2_state->IsNormal()); |
1025 EXPECT_EQ(base::IntToString( | 1046 EXPECT_EQ(base::IntToString( |
1026 (desktop_area.width() - window2->bounds().width()) / 2) + | 1047 (desktop_area.width() - window2->bounds().width()) / 2) + |
1027 ",48 256x512", window2->bounds().ToString()); | 1048 ",48 256x512", window2->bounds().ToString()); |
1028 } | 1049 } |
1029 | 1050 |
1030 // Test that nomral, maximize, minimizing will repos the remaining. | 1051 // Test that nomral, maximize, minimizing will repos the remaining. |
1031 TEST_F(WorkspaceControllerTest, NormToMaxToMinRepositionsRemaining) { | 1052 TEST_F(WorkspaceControllerTest, NormToMaxToMinRepositionsRemaining) { |
1032 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 1053 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
1033 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); | 1054 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
1034 wm::GetWindowSettings(window1.get())->set_window_position_managed(true); | 1055 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
1056 window1_state->set_window_position_managed(true); | |
1035 gfx::Rect desktop_area = window1->parent()->bounds(); | 1057 gfx::Rect desktop_area = window1->parent()->bounds(); |
1036 | 1058 |
1037 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 1059 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
1038 wm::GetWindowSettings(window2.get())->set_window_position_managed(true); | 1060 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); |
1061 window2_state->set_window_position_managed(true); | |
1039 window2->SetBounds(gfx::Rect(32, 40, 256, 512)); | 1062 window2->SetBounds(gfx::Rect(32, 40, 256, 512)); |
1040 | 1063 |
1041 // Trigger the auto window placement function by showing (and hiding) it. | 1064 // Trigger the auto window placement function by showing (and hiding) it. |
1042 window1->Hide(); | 1065 window1->Hide(); |
1043 window1->Show(); | 1066 window1->Show(); |
1044 | 1067 |
1045 // |window1| should be flush right and |window3| flush left. | 1068 // |window1| should be flush right and |window3| flush left. |
1046 EXPECT_EQ(base::IntToString( | 1069 EXPECT_EQ(base::IntToString( |
1047 desktop_area.width() - window1->bounds().width()) + | 1070 desktop_area.width() - window1->bounds().width()) + |
1048 ",32 640x320", window1->bounds().ToString()); | 1071 ",32 640x320", window1->bounds().ToString()); |
1049 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); | 1072 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); |
1050 | 1073 |
1051 ash::wm::MaximizeWindow(window1.get()); | 1074 window1_state->Maximize(); |
1052 ash::wm::MinimizeWindow(window1.get()); | 1075 window1_state->Minimize(); |
1053 | 1076 |
1054 // |window2| should be centered now. | 1077 // |window2| should be centered now. |
1055 EXPECT_TRUE(window2->IsVisible()); | 1078 EXPECT_TRUE(window2->IsVisible()); |
1056 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get())); | 1079 EXPECT_TRUE(window2_state->IsNormal()); |
1057 EXPECT_EQ(base::IntToString( | 1080 EXPECT_EQ(base::IntToString( |
1058 (desktop_area.width() - window2->bounds().width()) / 2) + | 1081 (desktop_area.width() - window2->bounds().width()) / 2) + |
1059 ",40 256x512", window2->bounds().ToString()); | 1082 ",40 256x512", window2->bounds().ToString()); |
1060 } | 1083 } |
1061 | 1084 |
1062 // Test that nomral, maximize, normal will repos the remaining. | 1085 // Test that nomral, maximize, normal will repos the remaining. |
1063 TEST_F(WorkspaceControllerTest, NormToMaxToNormRepositionsRemaining) { | 1086 TEST_F(WorkspaceControllerTest, NormToMaxToNormRepositionsRemaining) { |
1064 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 1087 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
1065 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); | 1088 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
1066 wm::GetWindowSettings(window1.get())->set_window_position_managed(true); | 1089 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
1090 window1_state->set_window_position_managed(true); | |
1067 gfx::Rect desktop_area = window1->parent()->bounds(); | 1091 gfx::Rect desktop_area = window1->parent()->bounds(); |
1068 | 1092 |
1069 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 1093 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
1070 wm::GetWindowSettings(window2.get())->set_window_position_managed(true); | 1094 wm::GetWindowState(window2.get())->set_window_position_managed(true); |
1071 window2->SetBounds(gfx::Rect(32, 40, 256, 512)); | 1095 window2->SetBounds(gfx::Rect(32, 40, 256, 512)); |
1072 | 1096 |
1073 // Trigger the auto window placement function by showing (and hiding) it. | 1097 // Trigger the auto window placement function by showing (and hiding) it. |
1074 window1->Hide(); | 1098 window1->Hide(); |
1075 window1->Show(); | 1099 window1->Show(); |
1076 | 1100 |
1077 // |window1| should be flush right and |window3| flush left. | 1101 // |window1| should be flush right and |window3| flush left. |
1078 EXPECT_EQ(base::IntToString( | 1102 EXPECT_EQ(base::IntToString( |
1079 desktop_area.width() - window1->bounds().width()) + | 1103 desktop_area.width() - window1->bounds().width()) + |
1080 ",32 640x320", window1->bounds().ToString()); | 1104 ",32 640x320", window1->bounds().ToString()); |
1081 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); | 1105 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); |
1082 | 1106 |
1083 ash::wm::MaximizeWindow(window1.get()); | 1107 window1_state->Maximize(); |
1084 ash::wm::RestoreWindow(window1.get()); | 1108 window1_state->Restore(); |
1085 | 1109 |
1086 // |window1| should be flush right and |window2| flush left. | 1110 // |window1| should be flush right and |window2| flush left. |
1087 EXPECT_EQ(base::IntToString( | 1111 EXPECT_EQ(base::IntToString( |
1088 desktop_area.width() - window1->bounds().width()) + | 1112 desktop_area.width() - window1->bounds().width()) + |
1089 ",32 640x320", window1->bounds().ToString()); | 1113 ",32 640x320", window1->bounds().ToString()); |
1090 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); | 1114 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); |
1091 } | 1115 } |
1092 | 1116 |
1093 // Test that animations are triggered. | 1117 // Test that animations are triggered. |
1094 TEST_F(WorkspaceControllerTest, AnimatedNormToMaxToNormRepositionsRemaining) { | 1118 TEST_F(WorkspaceControllerTest, AnimatedNormToMaxToNormRepositionsRemaining) { |
1095 ui::ScopedAnimationDurationScaleMode normal_duration_mode( | 1119 ui::ScopedAnimationDurationScaleMode normal_duration_mode( |
1096 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 1120 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
1097 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 1121 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
1098 window1->Hide(); | 1122 window1->Hide(); |
1099 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); | 1123 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
1100 gfx::Rect desktop_area = window1->parent()->bounds(); | 1124 gfx::Rect desktop_area = window1->parent()->bounds(); |
1101 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 1125 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
1102 window2->Hide(); | 1126 window2->Hide(); |
1103 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); | 1127 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
1104 | 1128 |
1105 wm::GetWindowSettings(window1.get())->set_window_position_managed(true); | 1129 wm::GetWindowState(window1.get())->set_window_position_managed(true); |
1106 wm::GetWindowSettings(window2.get())->set_window_position_managed(true); | 1130 wm::GetWindowState(window2.get())->set_window_position_managed(true); |
1107 // Make sure nothing is animating. | 1131 // Make sure nothing is animating. |
1108 window1->layer()->GetAnimator()->StopAnimating(); | 1132 window1->layer()->GetAnimator()->StopAnimating(); |
1109 window2->layer()->GetAnimator()->StopAnimating(); | 1133 window2->layer()->GetAnimator()->StopAnimating(); |
1110 window2->Show(); | 1134 window2->Show(); |
1111 | 1135 |
1112 // The second window should now animate. | 1136 // The second window should now animate. |
1113 EXPECT_FALSE(window1->layer()->GetAnimator()->is_animating()); | 1137 EXPECT_FALSE(window1->layer()->GetAnimator()->is_animating()); |
1114 EXPECT_TRUE(window2->layer()->GetAnimator()->is_animating()); | 1138 EXPECT_TRUE(window2->layer()->GetAnimator()->is_animating()); |
1115 window2->layer()->GetAnimator()->StopAnimating(); | 1139 window2->layer()->GetAnimator()->StopAnimating(); |
1116 | 1140 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1270 generator.PressLeftButton(); | 1294 generator.PressLeftButton(); |
1271 generator.MoveMouseTo(100, 100); | 1295 generator.MoveMouseTo(100, 100); |
1272 // The bounds shouldn't change (drag should result in nothing happening | 1296 // The bounds shouldn't change (drag should result in nothing happening |
1273 // now. | 1297 // now. |
1274 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString()); | 1298 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString()); |
1275 | 1299 |
1276 generator.ReleaseLeftButton(); | 1300 generator.ReleaseLeftButton(); |
1277 EXPECT_EQ(0, observer.change_count()); | 1301 EXPECT_EQ(0, observer.change_count()); |
1278 | 1302 |
1279 // Set tracked to false and repeat, now the window should move. | 1303 // Set tracked to false and repeat, now the window should move. |
1280 wm::GetWindowSettings(w1.get())->SetTrackedByWorkspace(false); | 1304 wm::GetWindowState(w1.get())->SetTrackedByWorkspace(false); |
1281 generator.MoveMouseTo(5, 5); | 1305 generator.MoveMouseTo(5, 5); |
1282 generator.PressLeftButton(); | 1306 generator.PressLeftButton(); |
1283 generator.MoveMouseBy(100, 100); | 1307 generator.MoveMouseBy(100, 100); |
1284 EXPECT_EQ(gfx::Rect(max_bounds.x() + 100, max_bounds.y() + 100, | 1308 EXPECT_EQ(gfx::Rect(max_bounds.x() + 100, max_bounds.y() + 100, |
1285 max_bounds.width(), max_bounds.height()).ToString(), | 1309 max_bounds.width(), max_bounds.height()).ToString(), |
1286 w1->bounds().ToString()); | 1310 w1->bounds().ToString()); |
1287 | 1311 |
1288 generator.ReleaseLeftButton(); | 1312 generator.ReleaseLeftButton(); |
1289 wm::GetWindowSettings(w1.get())->SetTrackedByWorkspace(true); | 1313 wm::GetWindowState(w1.get())->SetTrackedByWorkspace(true); |
1290 // Marking the window tracked again should snap back to origin. | 1314 // Marking the window tracked again should snap back to origin. |
1291 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString()); | 1315 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString()); |
1292 EXPECT_EQ(0, observer.change_count()); | 1316 EXPECT_EQ(0, observer.change_count()); |
1293 | 1317 |
1294 w1->parent()->parent()->RemoveObserver(&observer); | 1318 w1->parent()->parent()->RemoveObserver(&observer); |
1295 } | 1319 } |
1296 | 1320 |
1297 // Verifies setting tracked by workspace to false and then dragging a maximized | 1321 // Verifies setting tracked by workspace to false and then dragging a maximized |
1298 // window can change the bound. | 1322 // window can change the bound. |
1299 TEST_F(WorkspaceControllerTest, DragMaximizedNonTrackedWindow) { | 1323 TEST_F(WorkspaceControllerTest, DragMaximizedNonTrackedWindow) { |
(...skipping 19 matching lines...) Expand all Loading... | |
1319 generator.PressLeftButton(); | 1343 generator.PressLeftButton(); |
1320 generator.MoveMouseTo(100, 100); | 1344 generator.MoveMouseTo(100, 100); |
1321 // The bounds shouldn't change (drag should result in nothing happening | 1345 // The bounds shouldn't change (drag should result in nothing happening |
1322 // now. | 1346 // now. |
1323 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString()); | 1347 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString()); |
1324 | 1348 |
1325 generator.ReleaseLeftButton(); | 1349 generator.ReleaseLeftButton(); |
1326 EXPECT_EQ(0, observer.change_count()); | 1350 EXPECT_EQ(0, observer.change_count()); |
1327 | 1351 |
1328 // Set tracked to false and repeat, now the window should move. | 1352 // Set tracked to false and repeat, now the window should move. |
1329 wm::GetWindowSettings(w1.get())->SetTrackedByWorkspace(false); | 1353 wm::GetWindowState(w1.get())->SetTrackedByWorkspace(false); |
1330 generator.MoveMouseTo(5, 5); | 1354 generator.MoveMouseTo(5, 5); |
1331 generator.PressLeftButton(); | 1355 generator.PressLeftButton(); |
1332 generator.MoveMouseBy(100, 100); | 1356 generator.MoveMouseBy(100, 100); |
1333 EXPECT_EQ(gfx::Rect(max_bounds.x() + 100, max_bounds.y() + 100, | 1357 EXPECT_EQ(gfx::Rect(max_bounds.x() + 100, max_bounds.y() + 100, |
1334 max_bounds.width(), max_bounds.height()).ToString(), | 1358 max_bounds.width(), max_bounds.height()).ToString(), |
1335 w1->bounds().ToString()); | 1359 w1->bounds().ToString()); |
1336 | 1360 |
1337 generator.ReleaseLeftButton(); | 1361 generator.ReleaseLeftButton(); |
1338 wm::GetWindowSettings(w1.get())->SetTrackedByWorkspace(true); | 1362 wm::GetWindowState(w1.get())->SetTrackedByWorkspace(true); |
1339 // Marking the window tracked again should snap back to origin. | 1363 // Marking the window tracked again should snap back to origin. |
1340 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString()); | 1364 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString()); |
1341 EXPECT_EQ(0, observer.change_count()); | 1365 EXPECT_EQ(0, observer.change_count()); |
1342 | 1366 |
1343 w1->parent()->parent()->RemoveObserver(&observer); | 1367 w1->parent()->parent()->RemoveObserver(&observer); |
1344 } | 1368 } |
1345 | 1369 |
1346 // Verifies that a new maximized window becomes visible after its activation | 1370 // Verifies that a new maximized window becomes visible after its activation |
1347 // is requested, even though it does not become activated because a system | 1371 // is requested, even though it does not become activated because a system |
1348 // modal window is active. | 1372 // modal window is active. |
1349 TEST_F(WorkspaceControllerTest, SwitchFromModal) { | 1373 TEST_F(WorkspaceControllerTest, SwitchFromModal) { |
1350 scoped_ptr<Window> modal_window(CreateTestWindowUnparented()); | 1374 scoped_ptr<Window> modal_window(CreateTestWindowUnparented()); |
1351 modal_window->SetBounds(gfx::Rect(10, 11, 21, 22)); | 1375 modal_window->SetBounds(gfx::Rect(10, 11, 21, 22)); |
1352 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); | 1376 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); |
1353 SetDefaultParentByPrimaryRootWindow(modal_window.get()); | 1377 SetDefaultParentByPrimaryRootWindow(modal_window.get()); |
1354 modal_window->Show(); | 1378 modal_window->Show(); |
1355 wm::ActivateWindow(modal_window.get()); | 1379 wm::ActivateWindow(modal_window.get()); |
1356 | 1380 |
1357 scoped_ptr<Window> maximized_window(CreateTestWindow()); | 1381 scoped_ptr<Window> maximized_window(CreateTestWindow()); |
1358 maximized_window->SetProperty( | 1382 maximized_window->SetProperty( |
1359 aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 1383 aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
1360 maximized_window->Show(); | 1384 maximized_window->Show(); |
1361 wm::ActivateWindow(maximized_window.get()); | 1385 wm::ActivateWindow(maximized_window.get()); |
1362 EXPECT_TRUE(maximized_window->IsVisible()); | 1386 EXPECT_TRUE(maximized_window->IsVisible()); |
1363 } | 1387 } |
1364 | 1388 |
1365 } // namespace internal | 1389 } // namespace internal |
1366 } // namespace ash | 1390 } // namespace ash |
OLD | NEW |