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

Side by Side Diff: ash/wm/workspace/workspace_manager_unittest.cc

Issue 11421006: Desktop aura: Break aura::Window::SetParent in two. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix ash_unittests Created 8 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/workspace_manager.h" 5 #include "ash/wm/workspace/workspace_manager.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/root_window_controller.h" 8 #include "ash/root_window_controller.h"
9 #include "ash/screen_ash.h" 9 #include "ash/screen_ash.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 window->SetType(aura::client::WINDOW_TYPE_NORMAL); 47 window->SetType(aura::client::WINDOW_TYPE_NORMAL);
48 window->Init(ui::LAYER_TEXTURED); 48 window->Init(ui::LAYER_TEXTURED);
49 return window; 49 return window;
50 } 50 }
51 51
52 aura::Window* CreateTestWindow() { 52 aura::Window* CreateTestWindow() {
53 aura::Window* window = new aura::Window(NULL); 53 aura::Window* window = new aura::Window(NULL);
54 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 54 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
55 window->SetType(aura::client::WINDOW_TYPE_NORMAL); 55 window->SetType(aura::client::WINDOW_TYPE_NORMAL);
56 window->Init(ui::LAYER_TEXTURED); 56 window->Init(ui::LAYER_TEXTURED);
57 window->SetParent(NULL); 57 SetDefaultParentByPrimaryRootWindow(window);
58 return window; 58 return window;
59 } 59 }
60 60
61 aura::Window* GetViewport() { 61 aura::Window* GetViewport() {
62 return Shell::GetContainer(Shell::GetPrimaryRootWindow(), 62 return Shell::GetContainer(Shell::GetPrimaryRootWindow(),
63 kShellWindowId_DefaultContainer); 63 kShellWindowId_DefaultContainer);
64 } 64 }
65 65
66 const std::vector<Workspace*>& workspaces() const { 66 const std::vector<Workspace*>& workspaces() const {
67 return manager_->workspaces_; 67 return manager_->workspaces_;
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 // workspace. 313 // workspace.
314 w1->SetBounds(gfx::Rect(0, 0, 200, 500)); 314 w1->SetBounds(gfx::Rect(0, 0, 200, 500));
315 EXPECT_EQ(200, w1->bounds().width()); 315 EXPECT_EQ(200, w1->bounds().width());
316 EXPECT_EQ(500, w1->bounds().height()); 316 EXPECT_EQ(500, w1->bounds().height());
317 } 317 }
318 318
319 // Verifies the bounds is not altered when showing and grid is enabled. 319 // Verifies the bounds is not altered when showing and grid is enabled.
320 TEST_F(WorkspaceManagerTest, SnapToGrid) { 320 TEST_F(WorkspaceManagerTest, SnapToGrid) {
321 scoped_ptr<Window> w1(CreateTestWindowUnparented()); 321 scoped_ptr<Window> w1(CreateTestWindowUnparented());
322 w1->SetBounds(gfx::Rect(1, 6, 25, 30)); 322 w1->SetBounds(gfx::Rect(1, 6, 25, 30));
323 w1->SetParent(NULL); 323 SetDefaultParentByPrimaryRootWindow(w1.get());
324 // We are not aligning this anymore this way. When the window gets shown 324 // We are not aligning this anymore this way. When the window gets shown
325 // the window is expected to be handled differently, but this cannot be 325 // the window is expected to be handled differently, but this cannot be
326 // tested with this test. So the result of this test should be that the 326 // tested with this test. So the result of this test should be that the
327 // bounds are exactly as passed in. 327 // bounds are exactly as passed in.
328 EXPECT_EQ("1,6 25x30", w1->bounds().ToString()); 328 EXPECT_EQ("1,6 25x30", w1->bounds().ToString());
329 } 329 }
330 330
331 // Assertions around a fullscreen window. 331 // Assertions around a fullscreen window.
332 TEST_F(WorkspaceManagerTest, SingleFullscreenWindow) { 332 TEST_F(WorkspaceManagerTest, SingleFullscreenWindow) {
333 scoped_ptr<Window> w1(CreateTestWindow()); 333 scoped_ptr<Window> w1(CreateTestWindow());
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 829
830 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 830 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
831 ASSERT_EQ("0 M2 active=1", StateString()); 831 ASSERT_EQ("0 M2 active=1", StateString());
832 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 832 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
833 833
834 // Create another transient child of |w1|. We do this unparented, set up the 834 // Create another transient child of |w1|. We do this unparented, set up the
835 // transient parent then set parent. This is how NativeWidgetAura does things 835 // transient parent then set parent. This is how NativeWidgetAura does things
836 // too. 836 // too.
837 scoped_ptr<Window> w3(CreateTestWindowUnparented()); 837 scoped_ptr<Window> w3(CreateTestWindowUnparented());
838 w1->AddTransientChild(w3.get()); 838 w1->AddTransientChild(w3.get());
839 w3->SetParent(NULL); 839 SetDefaultParentByPrimaryRootWindow(w3.get());
840 w3->Show(); 840 w3->Show();
841 ASSERT_EQ("0 M3 active=1", StateString()); 841 ASSERT_EQ("0 M3 active=1", StateString());
842 842
843 // Minimize the window. All the transients are hidden as a result, so it ends 843 // Minimize the window. All the transients are hidden as a result, so it ends
844 // up in pending. 844 // up in pending.
845 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); 845 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
846 ASSERT_EQ("0 P=M3 active=0", StateString()); 846 ASSERT_EQ("0 P=M3 active=0", StateString());
847 847
848 // Restore and everything should go back to the first workspace. 848 // Restore and everything should go back to the first workspace.
849 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 849 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 // . minimize a maximized window. 1019 // . minimize a maximized window.
1020 // . remove the window (which happens when switching displays). 1020 // . remove the window (which happens when switching displays).
1021 // . add the window back. 1021 // . add the window back.
1022 // . show the window and during the bounds change activate it. 1022 // . show the window and during the bounds change activate it.
1023 TEST_F(WorkspaceManagerTest, DontCrashOnChangeAndActivate) { 1023 TEST_F(WorkspaceManagerTest, DontCrashOnChangeAndActivate) {
1024 // Force the shelf 1024 // Force the shelf
1025 ShelfLayoutManager* shelf = shelf_layout_manager(); 1025 ShelfLayoutManager* shelf = shelf_layout_manager();
1026 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 1026 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1027 1027
1028 DontCrashOnChangeAndActivateDelegate delegate; 1028 DontCrashOnChangeAndActivateDelegate delegate;
1029 scoped_ptr<Window> w1( 1029 scoped_ptr<Window> w1(CreateTestWindowInShellWithDelegate(
1030 CreateTestWindowWithDelegate(&delegate, 1000, gfx::Rect(10, 11, 250, 251), 1030 &delegate, 1000, gfx::Rect(10, 11, 250, 251)));
1031 NULL)); 1031
1032 w1->Show(); 1032 w1->Show();
1033 wm::ActivateWindow(w1.get()); 1033 wm::ActivateWindow(w1.get());
1034 wm::MaximizeWindow(w1.get()); 1034 wm::MaximizeWindow(w1.get());
1035 wm::MinimizeWindow(w1.get()); 1035 wm::MinimizeWindow(w1.get());
1036 1036
1037 w1->parent()->RemoveChild(w1.get()); 1037 w1->parent()->RemoveChild(w1.get());
1038 1038
1039 // Do this so that when we Show() the window a resize occurs and we make the 1039 // Do this so that when we Show() the window a resize occurs and we make the
1040 // window active. 1040 // window active.
1041 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 1041 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1042 1042
1043 w1->SetParent(NULL); 1043 SetDefaultParentByPrimaryRootWindow(w1.get());
1044 delegate.set_window(w1.get()); 1044 delegate.set_window(w1.get());
1045 w1->Show(); 1045 w1->Show();
1046 } 1046 }
1047 1047
1048 // Verifies a window with a transient parent not managed by workspace works. 1048 // Verifies a window with a transient parent not managed by workspace works.
1049 TEST_F(WorkspaceManagerTest, TransientParent) { 1049 TEST_F(WorkspaceManagerTest, TransientParent) {
1050 // Normal window with no transient parent. 1050 // Normal window with no transient parent.
1051 scoped_ptr<Window> w2(CreateTestWindow()); 1051 scoped_ptr<Window> w2(CreateTestWindow());
1052 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); 1052 w2->SetBounds(gfx::Rect(10, 11, 250, 251));
1053 w2->Show(); 1053 w2->Show();
1054 wm::ActivateWindow(w2.get()); 1054 wm::ActivateWindow(w2.get());
1055 1055
1056 // Window with a transient parent. We set the transient parent to the root, 1056 // Window with a transient parent. We set the transient parent to the root,
1057 // which would never happen but is enough to exercise the bug. 1057 // which would never happen but is enough to exercise the bug.
1058 scoped_ptr<Window> w1(CreateTestWindowUnparented()); 1058 scoped_ptr<Window> w1(CreateTestWindowUnparented());
1059 Shell::GetInstance()->GetPrimaryRootWindow()->AddTransientChild(w1.get()); 1059 Shell::GetInstance()->GetPrimaryRootWindow()->AddTransientChild(w1.get());
1060 w1->SetBounds(gfx::Rect(10, 11, 250, 251)); 1060 w1->SetBounds(gfx::Rect(10, 11, 250, 251));
1061 w1->SetParent(NULL); 1061 SetDefaultParentByPrimaryRootWindow(w1.get());
1062 w1->Show(); 1062 w1->Show();
1063 wm::ActivateWindow(w1.get()); 1063 wm::ActivateWindow(w1.get());
1064 1064
1065 // The window with the transient parent should get added to the same parent as 1065 // The window with the transient parent should get added to the same parent as
1066 // the normal window. 1066 // the normal window.
1067 EXPECT_EQ(w2->parent(), w1->parent()); 1067 EXPECT_EQ(w2->parent(), w1->parent());
1068 } 1068 }
1069 1069
1070 // Verifies changing TrackedByWorkspace works. 1070 // Verifies changing TrackedByWorkspace works.
1071 TEST_F(WorkspaceManagerTest, TrackedByWorkspace) { 1071 TEST_F(WorkspaceManagerTest, TrackedByWorkspace) {
1072 // Create a window maximized. 1072 // Create a window maximized.
1073 scoped_ptr<Window> w1(CreateTestWindow()); 1073 scoped_ptr<Window> w1(CreateTestWindow());
1074 w1->Show(); 1074 w1->Show();
1075 wm::ActivateWindow(w1.get()); 1075 wm::ActivateWindow(w1.get());
1076 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 1076 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1077 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 1077 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
1078 EXPECT_TRUE(w1->IsVisible()); 1078 EXPECT_TRUE(w1->IsVisible());
1079 1079
1080 // Create a second window maximized and mark it not tracked by workspace 1080 // Create a second window maximized and mark it not tracked by workspace
1081 // manager. 1081 // manager.
1082 scoped_ptr<Window> w2(CreateTestWindowUnparented()); 1082 scoped_ptr<Window> w2(CreateTestWindowUnparented());
1083 w2->SetBounds(gfx::Rect(1, 6, 25, 30)); 1083 w2->SetBounds(gfx::Rect(1, 6, 25, 30));
1084 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 1084 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1085 w2->SetParent(NULL); 1085 SetDefaultParentByPrimaryRootWindow(w2.get());
1086 w2->Show(); 1086 w2->Show();
1087 SetTrackedByWorkspace(w2.get(), false); 1087 SetTrackedByWorkspace(w2.get(), false);
1088 wm::ActivateWindow(w2.get()); 1088 wm::ActivateWindow(w2.get());
1089 1089
1090 // Activating |w2| should force it to have the same parent as |w1|. 1090 // Activating |w2| should force it to have the same parent as |w1|.
1091 EXPECT_EQ(w1->parent(), w2->parent()); 1091 EXPECT_EQ(w1->parent(), w2->parent());
1092 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 1092 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
1093 EXPECT_TRUE(w1->IsVisible()); 1093 EXPECT_TRUE(w1->IsVisible());
1094 EXPECT_TRUE(w2->IsVisible()); 1094 EXPECT_TRUE(w2->IsVisible());
1095 1095
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 // Activate |w1|, should result in dropping |w2| to the desktop. 1133 // Activate |w1|, should result in dropping |w2| to the desktop.
1134 wm::ActivateWindow(w1.get()); 1134 wm::ActivateWindow(w1.get());
1135 ASSERT_EQ("1 M1 active=1", StateString()); 1135 ASSERT_EQ("1 M1 active=1", StateString());
1136 } 1136 }
1137 1137
1138 // Test the basic auto placement of one and or two windows in a "simulated 1138 // Test the basic auto placement of one and or two windows in a "simulated
1139 // session" of sequential window operations. 1139 // session" of sequential window operations.
1140 TEST_F(WorkspaceManagerTest, BasicAutoPlacing) { 1140 TEST_F(WorkspaceManagerTest, BasicAutoPlacing) {
1141 // Test 1: In case there is no manageable window, no window should shift. 1141 // Test 1: In case there is no manageable window, no window should shift.
1142 1142
1143 scoped_ptr<aura::Window> window1( 1143 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1144 aura::test::CreateTestWindowWithId(0, NULL));
1145 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 1144 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
1146 gfx::Rect desktop_area = window1->parent()->bounds(); 1145 gfx::Rect desktop_area = window1->parent()->bounds();
1147 1146
1148 scoped_ptr<aura::Window> window2( 1147 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1149 aura::test::CreateTestWindowWithId(1, NULL));
1150 // Trigger the auto window placement function by making it visible. 1148 // Trigger the auto window placement function by making it visible.
1151 // Note that the bounds are getting changed while it is invisible. 1149 // Note that the bounds are getting changed while it is invisible.
1152 window2->Hide(); 1150 window2->Hide();
1153 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); 1151 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
1154 window2->Show(); 1152 window2->Show();
1155 1153
1156 // Check the initial position of the windows is unchanged. 1154 // Check the initial position of the windows is unchanged.
1157 EXPECT_EQ("16,32 640x320", window1->bounds().ToString()); 1155 EXPECT_EQ("16,32 640x320", window1->bounds().ToString());
1158 EXPECT_EQ("32,48 256x512", window2->bounds().ToString()); 1156 EXPECT_EQ("32,48 256x512", window2->bounds().ToString());
1159 1157
1160 // Remove the second window and make sure that the first window 1158 // Remove the second window and make sure that the first window
1161 // does NOT get centered. 1159 // does NOT get centered.
1162 window2.reset(); 1160 window2.reset();
1163 EXPECT_EQ("16,32 640x320", window1->bounds().ToString()); 1161 EXPECT_EQ("16,32 640x320", window1->bounds().ToString());
1164 1162
1165 // Test 2: Set up two managed windows and check their auto positioning. 1163 // Test 2: Set up two managed windows and check their auto positioning.
1166 ash::wm::SetWindowPositionManaged(window1.get(), true); 1164 ash::wm::SetWindowPositionManaged(window1.get(), true);
1167 scoped_ptr<aura::Window> window3( 1165 scoped_ptr<aura::Window> window3(CreateTestWindowInShellWithId(2));
1168 aura::test::CreateTestWindowWithId(2, NULL));
1169 ash::wm::SetWindowPositionManaged(window3.get(), true); 1166 ash::wm::SetWindowPositionManaged(window3.get(), true);
1170 // To avoid any auto window manager changes due to SetBounds, the window 1167 // To avoid any auto window manager changes due to SetBounds, the window
1171 // gets first hidden and then shown again. 1168 // gets first hidden and then shown again.
1172 window3->Hide(); 1169 window3->Hide();
1173 window3->SetBounds(gfx::Rect(32, 48, 256, 512)); 1170 window3->SetBounds(gfx::Rect(32, 48, 256, 512));
1174 window3->Show(); 1171 window3->Show();
1175 // |window1| should be flush right and |window3| flush left. 1172 // |window1| should be flush right and |window3| flush left.
1176 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); 1173 EXPECT_EQ("0,32 640x320", window1->bounds().ToString());
1177 EXPECT_EQ(base::IntToString( 1174 EXPECT_EQ(base::IntToString(
1178 desktop_area.width() - window3->bounds().width()) + 1175 desktop_area.width() - window3->bounds().width()) +
1179 ",48 256x512", window3->bounds().ToString()); 1176 ",48 256x512", window3->bounds().ToString());
1180 1177
1181 // After removing |window3|, |window1| should be centered again. 1178 // After removing |window3|, |window1| should be centered again.
1182 window3.reset(); 1179 window3.reset();
1183 EXPECT_EQ( 1180 EXPECT_EQ(
1184 base::IntToString( 1181 base::IntToString(
1185 (desktop_area.width() - window1->bounds().width()) / 2) + 1182 (desktop_area.width() - window1->bounds().width()) / 2) +
1186 ",32 640x320", window1->bounds().ToString()); 1183 ",32 640x320", window1->bounds().ToString());
1187 1184
1188 // Test 3: Set up a manageable and a non manageable window and check 1185 // Test 3: Set up a manageable and a non manageable window and check
1189 // positioning. 1186 // positioning.
1190 scoped_ptr<aura::Window> window4( 1187 scoped_ptr<aura::Window> window4(CreateTestWindowInShellWithId(3));
1191 aura::test::CreateTestWindowWithId(3, NULL));
1192 // To avoid any auto window manager changes due to SetBounds, the window 1188 // To avoid any auto window manager changes due to SetBounds, the window
1193 // gets first hidden and then shown again. 1189 // gets first hidden and then shown again.
1194 window1->Hide(); 1190 window1->Hide();
1195 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 1191 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
1196 window4->SetBounds(gfx::Rect(32, 48, 256, 512)); 1192 window4->SetBounds(gfx::Rect(32, 48, 256, 512));
1197 window1->Show(); 1193 window1->Show();
1198 // |window1| should be centered and |window4| untouched. 1194 // |window1| should be centered and |window4| untouched.
1199 EXPECT_EQ( 1195 EXPECT_EQ(
1200 base::IntToString( 1196 base::IntToString(
1201 (desktop_area.width() - window1->bounds().width()) / 2) + 1197 (desktop_area.width() - window1->bounds().width()) / 2) +
1202 ",32 640x320", window1->bounds().ToString()); 1198 ",32 640x320", window1->bounds().ToString());
1203 EXPECT_EQ("32,48 256x512", window4->bounds().ToString()); 1199 EXPECT_EQ("32,48 256x512", window4->bounds().ToString());
1204 1200
1205 // Test4: A single manageable window should get centered. 1201 // Test4: A single manageable window should get centered.
1206 window4.reset(); 1202 window4.reset();
1207 ash::wm::SetUserHasChangedWindowPositionOrSize(window1.get(), false); 1203 ash::wm::SetUserHasChangedWindowPositionOrSize(window1.get(), false);
1208 // Trigger the auto window placement function by showing (and hiding) it. 1204 // Trigger the auto window placement function by showing (and hiding) it.
1209 window1->Hide(); 1205 window1->Hide();
1210 window1->Show(); 1206 window1->Show();
1211 // |window1| should be centered. 1207 // |window1| should be centered.
1212 EXPECT_EQ( 1208 EXPECT_EQ(
1213 base::IntToString( 1209 base::IntToString(
1214 (desktop_area.width() - window1->bounds().width()) / 2) + 1210 (desktop_area.width() - window1->bounds().width()) / 2) +
1215 ",32 640x320", window1->bounds().ToString()); 1211 ",32 640x320", window1->bounds().ToString());
1216 } 1212 }
1217 1213
1218 // Test the proper usage of user window movement interaction. 1214 // Test the proper usage of user window movement interaction.
1219 TEST_F(WorkspaceManagerTest, TestUserMovedWindowRepositioning) { 1215 TEST_F(WorkspaceManagerTest, TestUserMovedWindowRepositioning) {
1220 scoped_ptr<aura::Window> window1( 1216 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1221 aura::test::CreateTestWindowWithId(0, NULL));
1222 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 1217 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
1223 gfx::Rect desktop_area = window1->parent()->bounds(); 1218 gfx::Rect desktop_area = window1->parent()->bounds();
1224 scoped_ptr<aura::Window> window2( 1219 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1225 aura::test::CreateTestWindowWithId(1, NULL));
1226 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); 1220 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
1227 window1->Hide(); 1221 window1->Hide();
1228 window2->Hide(); 1222 window2->Hide();
1229 ash::wm::SetWindowPositionManaged(window1.get(), true); 1223 ash::wm::SetWindowPositionManaged(window1.get(), true);
1230 ash::wm::SetWindowPositionManaged(window2.get(), true); 1224 ash::wm::SetWindowPositionManaged(window2.get(), true);
1231 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get())); 1225 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get()));
1232 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window2.get())); 1226 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window2.get()));
1233 1227
1234 // Check that the current location gets preserved if the user has 1228 // Check that the current location gets preserved if the user has
1235 // positioned it previously. 1229 // positioned it previously.
(...skipping 20 matching lines...) Expand all
1256 // Going back to one shown window should keep the state. 1250 // Going back to one shown window should keep the state.
1257 ash::wm::SetUserHasChangedWindowPositionOrSize(window1.get(), true); 1251 ash::wm::SetUserHasChangedWindowPositionOrSize(window1.get(), true);
1258 window2->Hide(); 1252 window2->Hide();
1259 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); 1253 EXPECT_EQ("0,32 640x320", window1->bounds().ToString());
1260 EXPECT_TRUE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get())); 1254 EXPECT_TRUE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get()));
1261 } 1255 }
1262 1256
1263 // Test that user placed windows go back to their user placement after the user 1257 // Test that user placed windows go back to their user placement after the user
1264 // closes all other windows. 1258 // closes all other windows.
1265 TEST_F(WorkspaceManagerTest, TestUserHandledWindowRestore) { 1259 TEST_F(WorkspaceManagerTest, TestUserHandledWindowRestore) {
1266 scoped_ptr<aura::Window> window1( 1260 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1267 aura::test::CreateTestWindowWithId(0, NULL));
1268 gfx::Rect user_pos = gfx::Rect(16, 42, 640, 320); 1261 gfx::Rect user_pos = gfx::Rect(16, 42, 640, 320);
1269 window1->SetBounds(user_pos); 1262 window1->SetBounds(user_pos);
1270 ash::wm::SetPreAutoManageWindowBounds(window1.get(), user_pos); 1263 ash::wm::SetPreAutoManageWindowBounds(window1.get(), user_pos);
1271 gfx::Rect desktop_area = window1->parent()->bounds(); 1264 gfx::Rect desktop_area = window1->parent()->bounds();
1272 1265
1273 // Create a second window to let the auto manager kick in. 1266 // Create a second window to let the auto manager kick in.
1274 scoped_ptr<aura::Window> window2( 1267 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1275 aura::test::CreateTestWindowWithId(1, NULL));
1276 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); 1268 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
1277 window1->Hide(); 1269 window1->Hide();
1278 window2->Hide(); 1270 window2->Hide();
1279 ash::wm::SetWindowPositionManaged(window1.get(), true); 1271 ash::wm::SetWindowPositionManaged(window1.get(), true);
1280 ash::wm::SetWindowPositionManaged(window2.get(), true); 1272 ash::wm::SetWindowPositionManaged(window2.get(), true);
1281 window1->Show(); 1273 window1->Show();
1282 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString()); 1274 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString());
1283 window2->Show(); 1275 window2->Show();
1284 1276
1285 // |window1| should be flush left and |window2| flush right. 1277 // |window1| should be flush left and |window2| flush right.
1286 EXPECT_EQ("0," + base::IntToString(user_pos.y()) + 1278 EXPECT_EQ("0," + base::IntToString(user_pos.y()) +
1287 " 640x320", window1->bounds().ToString()); 1279 " 640x320", window1->bounds().ToString());
1288 EXPECT_EQ( 1280 EXPECT_EQ(
1289 base::IntToString(desktop_area.width() - window2->bounds().width()) + 1281 base::IntToString(desktop_area.width() - window2->bounds().width()) +
1290 ",48 256x512", window2->bounds().ToString()); 1282 ",48 256x512", window2->bounds().ToString());
1291 window2->Hide(); 1283 window2->Hide();
1292 1284
1293 // After the other window get hidden the window has to move back to the 1285 // After the other window get hidden the window has to move back to the
1294 // previous position and the bounds should still be set and unchanged. 1286 // previous position and the bounds should still be set and unchanged.
1295 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString()); 1287 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString());
1296 ASSERT_TRUE(ash::wm::GetPreAutoManageWindowBounds(window1.get())); 1288 ASSERT_TRUE(ash::wm::GetPreAutoManageWindowBounds(window1.get()));
1297 EXPECT_EQ(user_pos.ToString(), 1289 EXPECT_EQ(user_pos.ToString(),
1298 ash::wm::GetPreAutoManageWindowBounds(window1.get())->ToString()); 1290 ash::wm::GetPreAutoManageWindowBounds(window1.get())->ToString());
1299 } 1291 }
1300 1292
1301 // Test that a window from normal to minimize will repos the remaining. 1293 // Test that a window from normal to minimize will repos the remaining.
1302 TEST_F(WorkspaceManagerTest, ToMinimizeRepositionsRemaining) { 1294 TEST_F(WorkspaceManagerTest, ToMinimizeRepositionsRemaining) {
1303 scoped_ptr<aura::Window> window1( 1295 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1304 aura::test::CreateTestWindowWithId(0, NULL));
1305 ash::wm::SetWindowPositionManaged(window1.get(), true); 1296 ash::wm::SetWindowPositionManaged(window1.get(), true);
1306 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 1297 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
1307 gfx::Rect desktop_area = window1->parent()->bounds(); 1298 gfx::Rect desktop_area = window1->parent()->bounds();
1308 1299
1309 scoped_ptr<aura::Window> window2( 1300 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1310 aura::test::CreateTestWindowWithId(1, NULL));
1311 ash::wm::SetWindowPositionManaged(window2.get(), true); 1301 ash::wm::SetWindowPositionManaged(window2.get(), true);
1312 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); 1302 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
1313 1303
1314 ash::wm::MinimizeWindow(window1.get()); 1304 ash::wm::MinimizeWindow(window1.get());
1315 1305
1316 // |window2| should be centered now. 1306 // |window2| should be centered now.
1317 EXPECT_TRUE(window2->IsVisible()); 1307 EXPECT_TRUE(window2->IsVisible());
1318 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get())); 1308 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get()));
1319 EXPECT_EQ(base::IntToString( 1309 EXPECT_EQ(base::IntToString(
1320 (desktop_area.width() - window2->bounds().width()) / 2) + 1310 (desktop_area.width() - window2->bounds().width()) / 2) +
1321 ",48 256x512", window2->bounds().ToString()); 1311 ",48 256x512", window2->bounds().ToString());
1322 1312
1323 ash::wm::RestoreWindow(window1.get()); 1313 ash::wm::RestoreWindow(window1.get());
1324 // |window1| should be flush right and |window3| flush left. 1314 // |window1| should be flush right and |window3| flush left.
1325 EXPECT_EQ(base::IntToString( 1315 EXPECT_EQ(base::IntToString(
1326 desktop_area.width() - window1->bounds().width()) + 1316 desktop_area.width() - window1->bounds().width()) +
1327 ",32 640x320", window1->bounds().ToString()); 1317 ",32 640x320", window1->bounds().ToString());
1328 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); 1318 EXPECT_EQ("0,48 256x512", window2->bounds().ToString());
1329 } 1319 }
1330 1320
1331 // Test that minimizing an initially maximized window will repos the remaining. 1321 // Test that minimizing an initially maximized window will repos the remaining.
1332 TEST_F(WorkspaceManagerTest, MaxToMinRepositionsRemaining) { 1322 TEST_F(WorkspaceManagerTest, MaxToMinRepositionsRemaining) {
1333 scoped_ptr<aura::Window> window1( 1323 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1334 aura::test::CreateTestWindowWithId(0, NULL));
1335 ash::wm::SetWindowPositionManaged(window1.get(), true); 1324 ash::wm::SetWindowPositionManaged(window1.get(), true);
1336 gfx::Rect desktop_area = window1->parent()->bounds(); 1325 gfx::Rect desktop_area = window1->parent()->bounds();
1337 1326
1338 scoped_ptr<aura::Window> window2( 1327 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1339 aura::test::CreateTestWindowWithId(1, NULL));
1340 ash::wm::SetWindowPositionManaged(window2.get(), true); 1328 ash::wm::SetWindowPositionManaged(window2.get(), true);
1341 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); 1329 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
1342 1330
1343 ash::wm::MaximizeWindow(window1.get()); 1331 ash::wm::MaximizeWindow(window1.get());
1344 ash::wm::MinimizeWindow(window1.get()); 1332 ash::wm::MinimizeWindow(window1.get());
1345 1333
1346 // |window2| should be centered now. 1334 // |window2| should be centered now.
1347 EXPECT_TRUE(window2->IsVisible()); 1335 EXPECT_TRUE(window2->IsVisible());
1348 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get())); 1336 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get()));
1349 EXPECT_EQ(base::IntToString( 1337 EXPECT_EQ(base::IntToString(
1350 (desktop_area.width() - window2->bounds().width()) / 2) + 1338 (desktop_area.width() - window2->bounds().width()) / 2) +
1351 ",48 256x512", window2->bounds().ToString()); 1339 ",48 256x512", window2->bounds().ToString());
1352 } 1340 }
1353 1341
1354 // Test that nomral, maximize, minimizing will repos the remaining. 1342 // Test that nomral, maximize, minimizing will repos the remaining.
1355 TEST_F(WorkspaceManagerTest, NormToMaxToMinRepositionsRemaining) { 1343 TEST_F(WorkspaceManagerTest, NormToMaxToMinRepositionsRemaining) {
1356 scoped_ptr<aura::Window> window1( 1344 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1357 aura::test::CreateTestWindowWithId(0, NULL));
1358 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 1345 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
1359 ash::wm::SetWindowPositionManaged(window1.get(), true); 1346 ash::wm::SetWindowPositionManaged(window1.get(), true);
1360 gfx::Rect desktop_area = window1->parent()->bounds(); 1347 gfx::Rect desktop_area = window1->parent()->bounds();
1361 1348
1362 scoped_ptr<aura::Window> window2( 1349 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1363 aura::test::CreateTestWindowWithId(1, NULL));
1364 ash::wm::SetWindowPositionManaged(window2.get(), true); 1350 ash::wm::SetWindowPositionManaged(window2.get(), true);
1365 window2->SetBounds(gfx::Rect(32, 40, 256, 512)); 1351 window2->SetBounds(gfx::Rect(32, 40, 256, 512));
1366 1352
1367 // Trigger the auto window placement function by showing (and hiding) it. 1353 // Trigger the auto window placement function by showing (and hiding) it.
1368 window1->Hide(); 1354 window1->Hide();
1369 window1->Show(); 1355 window1->Show();
1370 1356
1371 // |window1| should be flush right and |window3| flush left. 1357 // |window1| should be flush right and |window3| flush left.
1372 EXPECT_EQ(base::IntToString( 1358 EXPECT_EQ(base::IntToString(
1373 desktop_area.width() - window1->bounds().width()) + 1359 desktop_area.width() - window1->bounds().width()) +
1374 ",32 640x320", window1->bounds().ToString()); 1360 ",32 640x320", window1->bounds().ToString());
1375 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); 1361 EXPECT_EQ("0,40 256x512", window2->bounds().ToString());
1376 1362
1377 ash::wm::MaximizeWindow(window1.get()); 1363 ash::wm::MaximizeWindow(window1.get());
1378 ash::wm::MinimizeWindow(window1.get()); 1364 ash::wm::MinimizeWindow(window1.get());
1379 1365
1380 // |window2| should be centered now. 1366 // |window2| should be centered now.
1381 EXPECT_TRUE(window2->IsVisible()); 1367 EXPECT_TRUE(window2->IsVisible());
1382 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get())); 1368 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get()));
1383 EXPECT_EQ(base::IntToString( 1369 EXPECT_EQ(base::IntToString(
1384 (desktop_area.width() - window2->bounds().width()) / 2) + 1370 (desktop_area.width() - window2->bounds().width()) / 2) +
1385 ",40 256x512", window2->bounds().ToString()); 1371 ",40 256x512", window2->bounds().ToString());
1386 } 1372 }
1387 1373
1388 // Test that nomral, maximize, normal will repos the remaining. 1374 // Test that nomral, maximize, normal will repos the remaining.
1389 TEST_F(WorkspaceManagerTest, NormToMaxToNormRepositionsRemaining) { 1375 TEST_F(WorkspaceManagerTest, NormToMaxToNormRepositionsRemaining) {
1390 scoped_ptr<aura::Window> window1( 1376 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1391 aura::test::CreateTestWindowWithId(0, NULL));
1392 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 1377 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
1393 ash::wm::SetWindowPositionManaged(window1.get(), true); 1378 ash::wm::SetWindowPositionManaged(window1.get(), true);
1394 gfx::Rect desktop_area = window1->parent()->bounds(); 1379 gfx::Rect desktop_area = window1->parent()->bounds();
1395 1380
1396 scoped_ptr<aura::Window> window2( 1381 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1397 aura::test::CreateTestWindowWithId(1, NULL));
1398 ash::wm::SetWindowPositionManaged(window2.get(), true); 1382 ash::wm::SetWindowPositionManaged(window2.get(), true);
1399 window2->SetBounds(gfx::Rect(32, 40, 256, 512)); 1383 window2->SetBounds(gfx::Rect(32, 40, 256, 512));
1400 1384
1401 // Trigger the auto window placement function by showing (and hiding) it. 1385 // Trigger the auto window placement function by showing (and hiding) it.
1402 window1->Hide(); 1386 window1->Hide();
1403 window1->Show(); 1387 window1->Show();
1404 1388
1405 // |window1| should be flush right and |window3| flush left. 1389 // |window1| should be flush right and |window3| flush left.
1406 EXPECT_EQ(base::IntToString( 1390 EXPECT_EQ(base::IntToString(
1407 desktop_area.width() - window1->bounds().width()) + 1391 desktop_area.width() - window1->bounds().width()) +
1408 ",32 640x320", window1->bounds().ToString()); 1392 ",32 640x320", window1->bounds().ToString());
1409 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); 1393 EXPECT_EQ("0,40 256x512", window2->bounds().ToString());
1410 1394
1411 ash::wm::MaximizeWindow(window1.get()); 1395 ash::wm::MaximizeWindow(window1.get());
1412 ash::wm::RestoreWindow(window1.get()); 1396 ash::wm::RestoreWindow(window1.get());
1413 1397
1414 // |window1| should be flush right and |window2| flush left. 1398 // |window1| should be flush right and |window2| flush left.
1415 EXPECT_EQ(base::IntToString( 1399 EXPECT_EQ(base::IntToString(
1416 desktop_area.width() - window1->bounds().width()) + 1400 desktop_area.width() - window1->bounds().width()) +
1417 ",32 640x320", window1->bounds().ToString()); 1401 ",32 640x320", window1->bounds().ToString());
1418 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); 1402 EXPECT_EQ("0,40 256x512", window2->bounds().ToString());
1419 } 1403 }
1420 1404
1421 // Test that animations are triggered. 1405 // Test that animations are triggered.
1422 TEST_F(WorkspaceManagerTest, AnimatedNormToMaxToNormRepositionsRemaining) { 1406 TEST_F(WorkspaceManagerTest, AnimatedNormToMaxToNormRepositionsRemaining) {
1423 ui::LayerAnimator::set_disable_animations_for_test(false); 1407 ui::LayerAnimator::set_disable_animations_for_test(false);
1424 scoped_ptr<aura::Window> window1( 1408 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
1425 aura::test::CreateTestWindowWithId(0, NULL));
1426 window1->Hide(); 1409 window1->Hide();
1427 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); 1410 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
1428 gfx::Rect desktop_area = window1->parent()->bounds(); 1411 gfx::Rect desktop_area = window1->parent()->bounds();
1429 scoped_ptr<aura::Window> window2( 1412 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
1430 aura::test::CreateTestWindowWithId(1, NULL));
1431 window2->Hide(); 1413 window2->Hide();
1432 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); 1414 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
1433 1415
1434 ash::wm::SetWindowPositionManaged(window1.get(), true); 1416 ash::wm::SetWindowPositionManaged(window1.get(), true);
1435 ash::wm::SetWindowPositionManaged(window2.get(), true); 1417 ash::wm::SetWindowPositionManaged(window2.get(), true);
1436 // Make sure nothing is animating. 1418 // Make sure nothing is animating.
1437 window1->layer()->GetAnimator()->StopAnimating(); 1419 window1->layer()->GetAnimator()->StopAnimating();
1438 window2->layer()->GetAnimator()->StopAnimating(); 1420 window2->layer()->GetAnimator()->StopAnimating();
1439 window2->Show(); 1421 window2->Show();
1440 1422
(...skipping 10 matching lines...) Expand all
1451 window2->layer()->GetAnimator()->StopAnimating(); 1433 window2->layer()->GetAnimator()->StopAnimating();
1452 // |window1| should be flush right and |window2| flush left. 1434 // |window1| should be flush right and |window2| flush left.
1453 EXPECT_EQ(base::IntToString( 1435 EXPECT_EQ(base::IntToString(
1454 desktop_area.width() - window1->bounds().width()) + 1436 desktop_area.width() - window1->bounds().width()) +
1455 ",32 640x320", window1->bounds().ToString()); 1437 ",32 640x320", window1->bounds().ToString());
1456 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); 1438 EXPECT_EQ("0,48 256x512", window2->bounds().ToString());
1457 } 1439 }
1458 1440
1459 } // namespace internal 1441 } // namespace internal
1460 } // namespace ash 1442 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_manager.cc ('k') | ash/wm/workspace/workspace_window_resizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698