Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: ash/wm/workspace_controller_unittest.cc

Issue 24108003: [Cleanup] Rename WindowSettings to WindowState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase fix Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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())->IsNormalShowState());
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
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
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* window_state = wm::GetWindowState(w1.get());
419
420 gfx::Rect restore = window_state->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 window_state->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
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
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
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
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
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* window1_state = wm::GetWindowState(window1.get());
966
967 window1_state->SetPreAutoManageWindowBounds(user_pos);
952 gfx::Rect desktop_area = window1->parent()->bounds(); 968 gfx::Rect desktop_area = window1->parent()->bounds();
953 969
954 // Create a second window to let the auto manager kick in. 970 // Create a second window to let the auto manager kick in.
955 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); 971 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
956 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); 972 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
957 window1->Hide(); 973 window1->Hide();
958 window2->Hide(); 974 window2->Hide();
959 wm::GetWindowSettings(window1.get())->set_window_position_managed(true); 975 wm::GetWindowState(window1.get())->set_window_position_managed(true);
960 wm::GetWindowSettings(window2.get())->set_window_position_managed(true); 976 wm::GetWindowState(window2.get())->set_window_position_managed(true);
961 window1->Show(); 977 window1->Show();
962 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString()); 978 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString());
963 window2->Show(); 979 window2->Show();
964 980
965 // |window1| should be flush left and |window2| flush right. 981 // |window1| should be flush left and |window2| flush right.
966 EXPECT_EQ("0," + base::IntToString(user_pos.y()) + 982 EXPECT_EQ("0," + base::IntToString(user_pos.y()) +
967 " 640x320", window1->bounds().ToString()); 983 " 640x320", window1->bounds().ToString());
968 EXPECT_EQ( 984 EXPECT_EQ(
969 base::IntToString(desktop_area.width() - window2->bounds().width()) + 985 base::IntToString(desktop_area.width() - window2->bounds().width()) +
970 ",48 256x512", window2->bounds().ToString()); 986 ",48 256x512", window2->bounds().ToString());
971 window2->Hide(); 987 window2->Hide();
972 988
973 // After the other window get hidden the window has to move back to the 989 // 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. 990 // previous position and the bounds should still be set and unchanged.
975 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString()); 991 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString());
976 ASSERT_TRUE(ash::wm::GetPreAutoManageWindowBounds(window1.get())); 992 ASSERT_TRUE(window1_state->pre_auto_manage_window_bounds());
977 EXPECT_EQ(user_pos.ToString(), 993 EXPECT_EQ(user_pos.ToString(),
978 ash::wm::GetPreAutoManageWindowBounds(window1.get())->ToString()); 994 window1_state->pre_auto_manage_window_bounds()->ToString());
979 } 995 }
980 996
981 // Test that a window from normal to minimize will repos the remaining. 997 // Test that a window from normal to minimize will repos the remaining.
982 TEST_F(WorkspaceControllerTest, ToMinimizeRepositionsRemaining) { 998 TEST_F(WorkspaceControllerTest, ToMinimizeRepositionsRemaining) {
983 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); 999 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
984 wm::GetWindowSettings(window1.get())->set_window_position_managed(true); 1000 wm::WindowState* window1_state = wm::GetWindowState(window1.get());
1001 window1_state->set_window_position_managed(true);
985 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 1002 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
986 gfx::Rect desktop_area = window1->parent()->bounds(); 1003 gfx::Rect desktop_area = window1->parent()->bounds();
987 1004
988 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); 1005 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
989 wm::GetWindowSettings(window2.get())->set_window_position_managed(true); 1006 wm::WindowState* window2_state = wm::GetWindowState(window2.get());
1007 window2_state->set_window_position_managed(true);
990 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); 1008 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
991 1009
992 ash::wm::MinimizeWindow(window1.get()); 1010 window1_state->Minimize();
993 1011
994 // |window2| should be centered now. 1012 // |window2| should be centered now.
995 EXPECT_TRUE(window2->IsVisible()); 1013 EXPECT_TRUE(window2->IsVisible());
996 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get())); 1014 EXPECT_TRUE(window2_state->IsNormalShowState());
997 EXPECT_EQ(base::IntToString( 1015 EXPECT_EQ(base::IntToString(
998 (desktop_area.width() - window2->bounds().width()) / 2) + 1016 (desktop_area.width() - window2->bounds().width()) / 2) +
999 ",48 256x512", window2->bounds().ToString()); 1017 ",48 256x512", window2->bounds().ToString());
1000 1018
1001 ash::wm::RestoreWindow(window1.get()); 1019 window1_state->Restore();
1002 // |window1| should be flush right and |window3| flush left. 1020 // |window1| should be flush right and |window3| flush left.
1003 EXPECT_EQ(base::IntToString( 1021 EXPECT_EQ(base::IntToString(
1004 desktop_area.width() - window1->bounds().width()) + 1022 desktop_area.width() - window1->bounds().width()) +
1005 ",32 640x320", window1->bounds().ToString()); 1023 ",32 640x320", window1->bounds().ToString());
1006 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); 1024 EXPECT_EQ("0,48 256x512", window2->bounds().ToString());
1007 } 1025 }
1008 1026
1009 // Test that minimizing an initially maximized window will repos the remaining. 1027 // Test that minimizing an initially maximized window will repos the remaining.
1010 TEST_F(WorkspaceControllerTest, MaxToMinRepositionsRemaining) { 1028 TEST_F(WorkspaceControllerTest, MaxToMinRepositionsRemaining) {
1011 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); 1029 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1012 wm::GetWindowSettings(window1.get())->set_window_position_managed(true); 1030 wm::WindowState* window1_state = wm::GetWindowState(window1.get());
1031 window1_state->set_window_position_managed(true);
1013 gfx::Rect desktop_area = window1->parent()->bounds(); 1032 gfx::Rect desktop_area = window1->parent()->bounds();
1014 1033
1015 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); 1034 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1016 wm::GetWindowSettings(window2.get())->set_window_position_managed(true); 1035 wm::WindowState* window2_state = wm::GetWindowState(window2.get());
1036 window2_state->set_window_position_managed(true);
1017 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); 1037 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
1018 1038
1019 ash::wm::MaximizeWindow(window1.get()); 1039 window1_state->Maximize();
1020 ash::wm::MinimizeWindow(window1.get()); 1040 window1_state->Minimize();
1021 1041
1022 // |window2| should be centered now. 1042 // |window2| should be centered now.
1023 EXPECT_TRUE(window2->IsVisible()); 1043 EXPECT_TRUE(window2->IsVisible());
1024 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get())); 1044 EXPECT_TRUE(window2_state->IsNormalShowState());
1025 EXPECT_EQ(base::IntToString( 1045 EXPECT_EQ(base::IntToString(
1026 (desktop_area.width() - window2->bounds().width()) / 2) + 1046 (desktop_area.width() - window2->bounds().width()) / 2) +
1027 ",48 256x512", window2->bounds().ToString()); 1047 ",48 256x512", window2->bounds().ToString());
1028 } 1048 }
1029 1049
1030 // Test that nomral, maximize, minimizing will repos the remaining. 1050 // Test that nomral, maximize, minimizing will repos the remaining.
1031 TEST_F(WorkspaceControllerTest, NormToMaxToMinRepositionsRemaining) { 1051 TEST_F(WorkspaceControllerTest, NormToMaxToMinRepositionsRemaining) {
1032 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); 1052 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1033 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 1053 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
1034 wm::GetWindowSettings(window1.get())->set_window_position_managed(true); 1054 wm::WindowState* window1_state = wm::GetWindowState(window1.get());
1055 window1_state->set_window_position_managed(true);
1035 gfx::Rect desktop_area = window1->parent()->bounds(); 1056 gfx::Rect desktop_area = window1->parent()->bounds();
1036 1057
1037 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); 1058 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1038 wm::GetWindowSettings(window2.get())->set_window_position_managed(true); 1059 wm::WindowState* window2_state = wm::GetWindowState(window2.get());
1060 window2_state->set_window_position_managed(true);
1039 window2->SetBounds(gfx::Rect(32, 40, 256, 512)); 1061 window2->SetBounds(gfx::Rect(32, 40, 256, 512));
1040 1062
1041 // Trigger the auto window placement function by showing (and hiding) it. 1063 // Trigger the auto window placement function by showing (and hiding) it.
1042 window1->Hide(); 1064 window1->Hide();
1043 window1->Show(); 1065 window1->Show();
1044 1066
1045 // |window1| should be flush right and |window3| flush left. 1067 // |window1| should be flush right and |window3| flush left.
1046 EXPECT_EQ(base::IntToString( 1068 EXPECT_EQ(base::IntToString(
1047 desktop_area.width() - window1->bounds().width()) + 1069 desktop_area.width() - window1->bounds().width()) +
1048 ",32 640x320", window1->bounds().ToString()); 1070 ",32 640x320", window1->bounds().ToString());
1049 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); 1071 EXPECT_EQ("0,40 256x512", window2->bounds().ToString());
1050 1072
1051 ash::wm::MaximizeWindow(window1.get()); 1073 window1_state->Maximize();
1052 ash::wm::MinimizeWindow(window1.get()); 1074 window1_state->Minimize();
1053 1075
1054 // |window2| should be centered now. 1076 // |window2| should be centered now.
1055 EXPECT_TRUE(window2->IsVisible()); 1077 EXPECT_TRUE(window2->IsVisible());
1056 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get())); 1078 EXPECT_TRUE(window2_state->IsNormalShowState());
1057 EXPECT_EQ(base::IntToString( 1079 EXPECT_EQ(base::IntToString(
1058 (desktop_area.width() - window2->bounds().width()) / 2) + 1080 (desktop_area.width() - window2->bounds().width()) / 2) +
1059 ",40 256x512", window2->bounds().ToString()); 1081 ",40 256x512", window2->bounds().ToString());
1060 } 1082 }
1061 1083
1062 // Test that nomral, maximize, normal will repos the remaining. 1084 // Test that nomral, maximize, normal will repos the remaining.
1063 TEST_F(WorkspaceControllerTest, NormToMaxToNormRepositionsRemaining) { 1085 TEST_F(WorkspaceControllerTest, NormToMaxToNormRepositionsRemaining) {
1064 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); 1086 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1065 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 1087 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
1066 wm::GetWindowSettings(window1.get())->set_window_position_managed(true); 1088 wm::WindowState* window1_state = wm::GetWindowState(window1.get());
1089 window1_state->set_window_position_managed(true);
1067 gfx::Rect desktop_area = window1->parent()->bounds(); 1090 gfx::Rect desktop_area = window1->parent()->bounds();
1068 1091
1069 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); 1092 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1070 wm::GetWindowSettings(window2.get())->set_window_position_managed(true); 1093 wm::GetWindowState(window2.get())->set_window_position_managed(true);
1071 window2->SetBounds(gfx::Rect(32, 40, 256, 512)); 1094 window2->SetBounds(gfx::Rect(32, 40, 256, 512));
1072 1095
1073 // Trigger the auto window placement function by showing (and hiding) it. 1096 // Trigger the auto window placement function by showing (and hiding) it.
1074 window1->Hide(); 1097 window1->Hide();
1075 window1->Show(); 1098 window1->Show();
1076 1099
1077 // |window1| should be flush right and |window3| flush left. 1100 // |window1| should be flush right and |window3| flush left.
1078 EXPECT_EQ(base::IntToString( 1101 EXPECT_EQ(base::IntToString(
1079 desktop_area.width() - window1->bounds().width()) + 1102 desktop_area.width() - window1->bounds().width()) +
1080 ",32 640x320", window1->bounds().ToString()); 1103 ",32 640x320", window1->bounds().ToString());
1081 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); 1104 EXPECT_EQ("0,40 256x512", window2->bounds().ToString());
1082 1105
1083 ash::wm::MaximizeWindow(window1.get()); 1106 window1_state->Maximize();
1084 ash::wm::RestoreWindow(window1.get()); 1107 window1_state->Restore();
1085 1108
1086 // |window1| should be flush right and |window2| flush left. 1109 // |window1| should be flush right and |window2| flush left.
1087 EXPECT_EQ(base::IntToString( 1110 EXPECT_EQ(base::IntToString(
1088 desktop_area.width() - window1->bounds().width()) + 1111 desktop_area.width() - window1->bounds().width()) +
1089 ",32 640x320", window1->bounds().ToString()); 1112 ",32 640x320", window1->bounds().ToString());
1090 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); 1113 EXPECT_EQ("0,40 256x512", window2->bounds().ToString());
1091 } 1114 }
1092 1115
1093 // Test that animations are triggered. 1116 // Test that animations are triggered.
1094 TEST_F(WorkspaceControllerTest, AnimatedNormToMaxToNormRepositionsRemaining) { 1117 TEST_F(WorkspaceControllerTest, AnimatedNormToMaxToNormRepositionsRemaining) {
1095 ui::ScopedAnimationDurationScaleMode normal_duration_mode( 1118 ui::ScopedAnimationDurationScaleMode normal_duration_mode(
1096 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); 1119 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
1097 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); 1120 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1098 window1->Hide(); 1121 window1->Hide();
1099 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 1122 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
1100 gfx::Rect desktop_area = window1->parent()->bounds(); 1123 gfx::Rect desktop_area = window1->parent()->bounds();
1101 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); 1124 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1102 window2->Hide(); 1125 window2->Hide();
1103 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); 1126 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
1104 1127
1105 wm::GetWindowSettings(window1.get())->set_window_position_managed(true); 1128 wm::GetWindowState(window1.get())->set_window_position_managed(true);
1106 wm::GetWindowSettings(window2.get())->set_window_position_managed(true); 1129 wm::GetWindowState(window2.get())->set_window_position_managed(true);
1107 // Make sure nothing is animating. 1130 // Make sure nothing is animating.
1108 window1->layer()->GetAnimator()->StopAnimating(); 1131 window1->layer()->GetAnimator()->StopAnimating();
1109 window2->layer()->GetAnimator()->StopAnimating(); 1132 window2->layer()->GetAnimator()->StopAnimating();
1110 window2->Show(); 1133 window2->Show();
1111 1134
1112 // The second window should now animate. 1135 // The second window should now animate.
1113 EXPECT_FALSE(window1->layer()->GetAnimator()->is_animating()); 1136 EXPECT_FALSE(window1->layer()->GetAnimator()->is_animating());
1114 EXPECT_TRUE(window2->layer()->GetAnimator()->is_animating()); 1137 EXPECT_TRUE(window2->layer()->GetAnimator()->is_animating());
1115 window2->layer()->GetAnimator()->StopAnimating(); 1138 window2->layer()->GetAnimator()->StopAnimating();
1116 1139
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 generator.PressLeftButton(); 1293 generator.PressLeftButton();
1271 generator.MoveMouseTo(100, 100); 1294 generator.MoveMouseTo(100, 100);
1272 // The bounds shouldn't change (drag should result in nothing happening 1295 // The bounds shouldn't change (drag should result in nothing happening
1273 // now. 1296 // now.
1274 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString()); 1297 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString());
1275 1298
1276 generator.ReleaseLeftButton(); 1299 generator.ReleaseLeftButton();
1277 EXPECT_EQ(0, observer.change_count()); 1300 EXPECT_EQ(0, observer.change_count());
1278 1301
1279 // Set tracked to false and repeat, now the window should move. 1302 // Set tracked to false and repeat, now the window should move.
1280 wm::GetWindowSettings(w1.get())->SetTrackedByWorkspace(false); 1303 wm::GetWindowState(w1.get())->SetTrackedByWorkspace(false);
1281 generator.MoveMouseTo(5, 5); 1304 generator.MoveMouseTo(5, 5);
1282 generator.PressLeftButton(); 1305 generator.PressLeftButton();
1283 generator.MoveMouseBy(100, 100); 1306 generator.MoveMouseBy(100, 100);
1284 EXPECT_EQ(gfx::Rect(max_bounds.x() + 100, max_bounds.y() + 100, 1307 EXPECT_EQ(gfx::Rect(max_bounds.x() + 100, max_bounds.y() + 100,
1285 max_bounds.width(), max_bounds.height()).ToString(), 1308 max_bounds.width(), max_bounds.height()).ToString(),
1286 w1->bounds().ToString()); 1309 w1->bounds().ToString());
1287 1310
1288 generator.ReleaseLeftButton(); 1311 generator.ReleaseLeftButton();
1289 wm::GetWindowSettings(w1.get())->SetTrackedByWorkspace(true); 1312 wm::GetWindowState(w1.get())->SetTrackedByWorkspace(true);
1290 // Marking the window tracked again should snap back to origin. 1313 // Marking the window tracked again should snap back to origin.
1291 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString()); 1314 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString());
1292 EXPECT_EQ(0, observer.change_count()); 1315 EXPECT_EQ(0, observer.change_count());
1293 1316
1294 w1->parent()->parent()->RemoveObserver(&observer); 1317 w1->parent()->parent()->RemoveObserver(&observer);
1295 } 1318 }
1296 1319
1297 // Verifies setting tracked by workspace to false and then dragging a maximized 1320 // Verifies setting tracked by workspace to false and then dragging a maximized
1298 // window can change the bound. 1321 // window can change the bound.
1299 TEST_F(WorkspaceControllerTest, DragMaximizedNonTrackedWindow) { 1322 TEST_F(WorkspaceControllerTest, DragMaximizedNonTrackedWindow) {
(...skipping 19 matching lines...) Expand all
1319 generator.PressLeftButton(); 1342 generator.PressLeftButton();
1320 generator.MoveMouseTo(100, 100); 1343 generator.MoveMouseTo(100, 100);
1321 // The bounds shouldn't change (drag should result in nothing happening 1344 // The bounds shouldn't change (drag should result in nothing happening
1322 // now. 1345 // now.
1323 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString()); 1346 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString());
1324 1347
1325 generator.ReleaseLeftButton(); 1348 generator.ReleaseLeftButton();
1326 EXPECT_EQ(0, observer.change_count()); 1349 EXPECT_EQ(0, observer.change_count());
1327 1350
1328 // Set tracked to false and repeat, now the window should move. 1351 // Set tracked to false and repeat, now the window should move.
1329 wm::GetWindowSettings(w1.get())->SetTrackedByWorkspace(false); 1352 wm::GetWindowState(w1.get())->SetTrackedByWorkspace(false);
1330 generator.MoveMouseTo(5, 5); 1353 generator.MoveMouseTo(5, 5);
1331 generator.PressLeftButton(); 1354 generator.PressLeftButton();
1332 generator.MoveMouseBy(100, 100); 1355 generator.MoveMouseBy(100, 100);
1333 EXPECT_EQ(gfx::Rect(max_bounds.x() + 100, max_bounds.y() + 100, 1356 EXPECT_EQ(gfx::Rect(max_bounds.x() + 100, max_bounds.y() + 100,
1334 max_bounds.width(), max_bounds.height()).ToString(), 1357 max_bounds.width(), max_bounds.height()).ToString(),
1335 w1->bounds().ToString()); 1358 w1->bounds().ToString());
1336 1359
1337 generator.ReleaseLeftButton(); 1360 generator.ReleaseLeftButton();
1338 wm::GetWindowSettings(w1.get())->SetTrackedByWorkspace(true); 1361 wm::GetWindowState(w1.get())->SetTrackedByWorkspace(true);
1339 // Marking the window tracked again should snap back to origin. 1362 // Marking the window tracked again should snap back to origin.
1340 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString()); 1363 EXPECT_EQ(max_bounds.ToString(), w1->bounds().ToString());
1341 EXPECT_EQ(0, observer.change_count()); 1364 EXPECT_EQ(0, observer.change_count());
1342 1365
1343 w1->parent()->parent()->RemoveObserver(&observer); 1366 w1->parent()->parent()->RemoveObserver(&observer);
1344 } 1367 }
1345 1368
1346 // Verifies that a new maximized window becomes visible after its activation 1369 // Verifies that a new maximized window becomes visible after its activation
1347 // is requested, even though it does not become activated because a system 1370 // is requested, even though it does not become activated because a system
1348 // modal window is active. 1371 // modal window is active.
1349 TEST_F(WorkspaceControllerTest, SwitchFromModal) { 1372 TEST_F(WorkspaceControllerTest, SwitchFromModal) {
1350 scoped_ptr<Window> modal_window(CreateTestWindowUnparented()); 1373 scoped_ptr<Window> modal_window(CreateTestWindowUnparented());
1351 modal_window->SetBounds(gfx::Rect(10, 11, 21, 22)); 1374 modal_window->SetBounds(gfx::Rect(10, 11, 21, 22));
1352 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); 1375 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM);
1353 SetDefaultParentByPrimaryRootWindow(modal_window.get()); 1376 SetDefaultParentByPrimaryRootWindow(modal_window.get());
1354 modal_window->Show(); 1377 modal_window->Show();
1355 wm::ActivateWindow(modal_window.get()); 1378 wm::ActivateWindow(modal_window.get());
1356 1379
1357 scoped_ptr<Window> maximized_window(CreateTestWindow()); 1380 scoped_ptr<Window> maximized_window(CreateTestWindow());
1358 maximized_window->SetProperty( 1381 maximized_window->SetProperty(
1359 aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 1382 aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1360 maximized_window->Show(); 1383 maximized_window->Show();
1361 wm::ActivateWindow(maximized_window.get()); 1384 wm::ActivateWindow(maximized_window.get());
1362 EXPECT_TRUE(maximized_window->IsVisible()); 1385 EXPECT_TRUE(maximized_window->IsVisible());
1363 } 1386 }
1364 1387
1365 } // namespace internal 1388 } // namespace internal
1366 } // namespace ash 1389 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace_controller.cc ('k') | chrome/browser/chromeos/extensions/wallpaper_private_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698