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

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

Issue 23205027: Correctly restore the auto managed window to the original bounds when becoming single window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 aura::Window* CreateTestWindow() { 95 aura::Window* CreateTestWindow() {
96 aura::Window* window = new aura::Window(NULL); 96 aura::Window* window = new aura::Window(NULL);
97 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 97 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
98 window->SetType(aura::client::WINDOW_TYPE_NORMAL); 98 window->SetType(aura::client::WINDOW_TYPE_NORMAL);
99 window->Init(ui::LAYER_TEXTURED); 99 window->Init(ui::LAYER_TEXTURED);
100 SetDefaultParentByPrimaryRootWindow(window); 100 SetDefaultParentByPrimaryRootWindow(window);
101 return window; 101 return window;
102 } 102 }
103 103
104 aura::Window* CreateAppTestWindow(aura::Window* parent) { 104 aura::Window* CreateBrowserLikeWindow(const gfx::Rect& bounds) {
105 aura::Window* window = new aura::Window(NULL); 105 aura::Window* window = CreateTestWindow();
106 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 106 window->SetBounds(bounds);
107 window->SetType(aura::client::WINDOW_TYPE_POPUP); 107 SetTrackedByWorkspace(window, true);
108 window->Init(ui::LAYER_TEXTURED); 108 wm::SetWindowPositionManaged(window, true);
109 if (!parent) 109 window->Show();
110 SetDefaultParentByPrimaryRootWindow(window);
111 else
112 parent->AddChild(window);
113 return window; 110 return window;
114 } 111 }
115 112
113 aura::Window* CreatePopupLikeWindow(const gfx::Rect& bounds) {
114 aura::Window* window = CreateTestWindowInShellWithBounds(bounds);
115 window->Show();
116 return window;
117 }
118
116 aura::Window* GetDesktop() { 119 aura::Window* GetDesktop() {
117 return Shell::GetContainer(Shell::GetPrimaryRootWindow(), 120 return Shell::GetContainer(Shell::GetPrimaryRootWindow(),
118 kShellWindowId_DefaultContainer); 121 kShellWindowId_DefaultContainer);
119 } 122 }
120 123
121 gfx::Rect GetFullscreenBounds(aura::Window* window) { 124 gfx::Rect GetFullscreenBounds(aura::Window* window) {
122 return Shell::GetScreen()->GetDisplayNearestWindow(window).bounds(); 125 return Shell::GetScreen()->GetDisplayNearestWindow(window).bounds();
123 } 126 }
124 127
125 ShelfWidget* shelf_widget() { 128 ShelfWidget* shelf_widget() {
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 714
712 // Transition it to tracked by worskpace. It should end up in the desktop 715 // Transition it to tracked by worskpace. It should end up in the desktop
713 // workspace. 716 // workspace.
714 SetTrackedByWorkspace(w2.get(), true); 717 SetTrackedByWorkspace(w2.get(), true);
715 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 718 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
716 EXPECT_TRUE(w1->IsVisible()); 719 EXPECT_TRUE(w1->IsVisible());
717 EXPECT_TRUE(w2->IsVisible()); 720 EXPECT_TRUE(w2->IsVisible());
718 EXPECT_EQ(w1->parent(), w2->parent()); 721 EXPECT_EQ(w1->parent(), w2->parent());
719 } 722 }
720 723
724 // Test the placement of newly created windows.
725 TEST_F(WorkspaceControllerTest, BasicAutoPlacingOnCreate) {
726 if (!SupportsHostWindowResize())
727 return;
728 UpdateDisplay("1600x1200");
729 // Creating a popup handler here to make sure it does not interfere with the
730 // existing windows.
731 gfx::Rect source_browser_bounds(16, 32, 640, 320);
732 scoped_ptr<aura::Window> browser_window(CreateBrowserLikeWindow(
733 source_browser_bounds));
734
735 // Creating a popup to make sure it does not interfere with the positioning.
736 scoped_ptr<aura::Window> browser_popup(CreatePopupLikeWindow(
737 gfx::Rect(16, 32, 128, 256)));
738
739 browser_window->Show();
740 browser_popup->Show();
741
742 { // With a shown window it's size should get returned.
743 scoped_ptr<aura::Window> new_browser_window(CreateBrowserLikeWindow(
744 source_browser_bounds));
745 // The position should be right flush.
746 EXPECT_EQ("960,32 640x320", new_browser_window->bounds().ToString());
747 }
748
749 { // With the window shown - but more on the right side then on the left
750 // side (and partially out of the screen), it should default to the other
751 // side and inside the screen.
752 gfx::Rect source_browser_bounds(gfx::Rect(1000, 600, 640, 320));
753 browser_window->SetBounds(source_browser_bounds);
754
755 scoped_ptr<aura::Window> new_browser_window(CreateBrowserLikeWindow(
756 source_browser_bounds));
757 // The position should be left & bottom flush.
758 EXPECT_EQ("0,600 640x320", new_browser_window->bounds().ToString());
759
760 // If the other window was already beyond the point to get right flush
761 // it will remain where it is.
762 EXPECT_EQ("1000,600 640x320", browser_window->bounds().ToString());
763 }
764
765 { // Make sure that popups do not get changed.
766 scoped_ptr<aura::Window> new_popup_window(CreatePopupLikeWindow(
767 gfx::Rect(50, 100, 300, 150)));
768 EXPECT_EQ("50,100 300x150", new_popup_window->bounds().ToString());
769 }
770
771 browser_window->Hide();
772 { // If a window is there but not shown the default should be centered.
773 scoped_ptr<aura::Window> new_browser_window(CreateBrowserLikeWindow(
774 gfx::Rect(50, 100, 300, 150)));
775 EXPECT_EQ("650,100 300x150", new_browser_window->bounds().ToString());
776 }
777 }
778
721 // Test the basic auto placement of one and or two windows in a "simulated 779 // Test the basic auto placement of one and or two windows in a "simulated
722 // session" of sequential window operations. 780 // session" of sequential window operations.
723 TEST_F(WorkspaceControllerTest, BasicAutoPlacing) { 781 TEST_F(WorkspaceControllerTest, BasicAutoPlacingOnShowHide) {
724 // Test 1: In case there is no manageable window, no window should shift. 782 // Test 1: In case there is no manageable window, no window should shift.
725 783
726 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); 784 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
727 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 785 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
728 gfx::Rect desktop_area = window1->parent()->bounds(); 786 gfx::Rect desktop_area = window1->parent()->bounds();
729 787
730 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); 788 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
731 // Trigger the auto window placement function by making it visible. 789 // Trigger the auto window placement function by making it visible.
732 // Note that the bounds are getting changed while it is invisible. 790 // Note that the bounds are getting changed while it is invisible.
733 window2->Hide(); 791 window2->Hide();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 window1->Show(); 872 window1->Show();
815 EXPECT_EQ("16,32 640x320", window1->bounds().ToString()); 873 EXPECT_EQ("16,32 640x320", window1->bounds().ToString());
816 // Flag should be still set. 874 // Flag should be still set.
817 EXPECT_TRUE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get())); 875 EXPECT_TRUE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get()));
818 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window2.get())); 876 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window2.get()));
819 877
820 // Turn on the second window and make sure that both windows are now 878 // Turn on the second window and make sure that both windows are now
821 // positionable again (user movement cleared). 879 // positionable again (user movement cleared).
822 window2->Show(); 880 window2->Show();
823 881
824 // |window1| should be flush left and |window3| flush right. 882 // |window1| should be flush left and |window2| flush right.
825 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); 883 EXPECT_EQ("0,32 640x320", window1->bounds().ToString());
826 EXPECT_EQ( 884 EXPECT_EQ(
827 base::IntToString(desktop_area.width() - window2->bounds().width()) + 885 base::IntToString(desktop_area.width() - window2->bounds().width()) +
828 ",48 256x512", window2->bounds().ToString()); 886 ",48 256x512", window2->bounds().ToString());
829 // FLag should now be reset. 887 // FLag should now be reset.
830 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get())); 888 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get()));
831 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get())); 889 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get()));
832 890
833 // Going back to one shown window should keep the state. 891 // Going back to one shown window should keep the state.
834 ash::wm::SetUserHasChangedWindowPositionOrSize(window1.get(), true); 892 ash::wm::SetUserHasChangedWindowPositionOrSize(window1.get(), true);
835 window2->Hide(); 893 window2->Hide();
836 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); 894 EXPECT_EQ("0,32 640x320", window1->bounds().ToString());
837 EXPECT_TRUE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get())); 895 EXPECT_TRUE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get()));
838 } 896 }
839 897
898 // Test if the single window will be restored at original position.
899 TEST_F(WorkspaceControllerTest, TestSingleWindowsRestoredBounds) {
900 scoped_ptr<aura::Window> window1(
901 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100)));
902 scoped_ptr<aura::Window> window2(
903 CreateTestWindowInShellWithBounds(gfx::Rect(110, 110, 100, 100)));
904 scoped_ptr<aura::Window> window3(
905 CreateTestWindowInShellWithBounds(gfx::Rect(120, 120, 100, 100)));
906 window1->Hide();
907 window2->Hide();
908 window3->Hide();
909 ash::wm::SetWindowPositionManaged(window1.get(), true);
910 ash::wm::SetWindowPositionManaged(window2.get(), true);
911 ash::wm::SetWindowPositionManaged(window3.get(), true);
912
913 window1->Show();
914 wm::ActivateWindow(window1.get());
915 window2->Show();
916 wm::ActivateWindow(window2.get());
917 window3->Show();
918 wm::ActivateWindow(window3.get());
919 EXPECT_EQ(0, window1->bounds().x());
920 EXPECT_EQ(window2->GetRootWindow()->bounds().right(),
921 window2->bounds().right());
922 EXPECT_EQ(0, window3->bounds().x());
923
924 window1->Hide();
925 EXPECT_EQ(window2->GetRootWindow()->bounds().right(),
926 window2->bounds().right());
927 EXPECT_EQ(0, window3->bounds().x());
928
929 // Being a single window will retore the original location.
930 window3->Hide();
931 wm::ActivateWindow(window2.get());
932 EXPECT_EQ("110,110 100x100", window2->bounds().ToString());
933
934 // Showing the 3rd will push the 2nd window left.
935 window3->Show();
936 wm::ActivateWindow(window3.get());
937 EXPECT_EQ(0, window2->bounds().x());
938 EXPECT_EQ(window3->GetRootWindow()->bounds().right(),
939 window3->bounds().right());
940
941 // Being a single window will retore the original location.
942 window2->Hide();
943 EXPECT_EQ("120,120 100x100", window3->bounds().ToString());
944 }
945
840 // Test that user placed windows go back to their user placement after the user 946 // Test that user placed windows go back to their user placement after the user
841 // closes all other windows. 947 // closes all other windows.
842 TEST_F(WorkspaceControllerTest, TestUserHandledWindowRestore) { 948 TEST_F(WorkspaceControllerTest, TestUserHandledWindowRestore) {
843 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); 949 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
844 gfx::Rect user_pos = gfx::Rect(16, 42, 640, 320); 950 gfx::Rect user_pos = gfx::Rect(16, 42, 640, 320);
845 window1->SetBounds(user_pos); 951 window1->SetBounds(user_pos);
846 ash::wm::SetPreAutoManageWindowBounds(window1.get(), user_pos); 952 ash::wm::SetPreAutoManageWindowBounds(window1.get(), user_pos);
847 gfx::Rect desktop_area = window1->parent()->bounds(); 953 gfx::Rect desktop_area = window1->parent()->bounds();
848 954
849 // Create a second window to let the auto manager kick in. 955 // Create a second window to let the auto manager kick in.
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 scoped_ptr<Window> maximized_window(CreateTestWindow()); 1358 scoped_ptr<Window> maximized_window(CreateTestWindow());
1253 maximized_window->SetProperty( 1359 maximized_window->SetProperty(
1254 aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 1360 aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1255 maximized_window->Show(); 1361 maximized_window->Show();
1256 wm::ActivateWindow(maximized_window.get()); 1362 wm::ActivateWindow(maximized_window.get());
1257 EXPECT_TRUE(maximized_window->IsVisible()); 1363 EXPECT_TRUE(maximized_window->IsVisible());
1258 } 1364 }
1259 1365
1260 } // namespace internal 1366 } // namespace internal
1261 } // namespace ash 1367 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698