OLD | NEW |
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_manager2.h" | 5 #include "ash/wm/workspace/workspace_manager2.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 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 w2->Show(); | 1100 w2->Show(); |
1101 wm::ActivateWindow(w2.get()); | 1101 wm::ActivateWindow(w2.get()); |
1102 EXPECT_EQ(w1->parent(), w2->parent()); | 1102 EXPECT_EQ(w1->parent(), w2->parent()); |
1103 ASSERT_EQ("0 M2 active=1", StateString()); | 1103 ASSERT_EQ("0 M2 active=1", StateString()); |
1104 | 1104 |
1105 // Activate |w1|, should result in dropping |w2| to the desktop. | 1105 // Activate |w1|, should result in dropping |w2| to the desktop. |
1106 wm::ActivateWindow(w1.get()); | 1106 wm::ActivateWindow(w1.get()); |
1107 ASSERT_EQ("1 M1 active=1", StateString()); | 1107 ASSERT_EQ("1 M1 active=1", StateString()); |
1108 } | 1108 } |
1109 | 1109 |
| 1110 // Test the basic auto placement of one and or two windows in a "simulated |
| 1111 // session" of sequential window operations. |
| 1112 TEST_F(WorkspaceManager2Test, BasicAutoPlacing) { |
| 1113 // Test 1: In case there is no manageable window, no window should shift. |
| 1114 |
| 1115 scoped_ptr<aura::Window> window1( |
| 1116 aura::test::CreateTestWindowWithId(0, NULL)); |
| 1117 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 1118 gfx::Rect desktop_area = window1->parent()->bounds(); |
| 1119 |
| 1120 scoped_ptr<aura::Window> window2( |
| 1121 aura::test::CreateTestWindowWithId(1, NULL)); |
| 1122 // Trigger the auto window placement function by making it visible. |
| 1123 // Note that the bounds are getting changed while it is invisible. |
| 1124 window2->Hide(); |
| 1125 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
| 1126 window2->Show(); |
| 1127 |
| 1128 // Check the initial position of the windows is unchanged. |
| 1129 EXPECT_EQ("16,32 640x320", window1->bounds().ToString()); |
| 1130 EXPECT_EQ("32,48 256x512", window2->bounds().ToString()); |
| 1131 |
| 1132 // Remove the second window and make sure that the first window |
| 1133 // does NOT get centered. |
| 1134 window2.reset(); |
| 1135 EXPECT_EQ("16,32 640x320", window1->bounds().ToString()); |
| 1136 |
| 1137 // Test 2: Set up two managed windows and check their auto positioning. |
| 1138 ash::wm::SetWindowPositionManaged(window1.get(), true); |
| 1139 scoped_ptr<aura::Window> window3( |
| 1140 aura::test::CreateTestWindowWithId(2, NULL)); |
| 1141 ash::wm::SetWindowPositionManaged(window3.get(), true); |
| 1142 // To avoid any auto window manager changes due to SetBounds, the window |
| 1143 // gets first hidden and then shown again. |
| 1144 window3->Hide(); |
| 1145 window3->SetBounds(gfx::Rect(32, 48, 256, 512)); |
| 1146 window3->Show(); |
| 1147 // |window1| should be flush right and |window3| flush left. |
| 1148 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); |
| 1149 EXPECT_EQ(base::IntToString( |
| 1150 desktop_area.width() - window3->bounds().width()) + |
| 1151 ",48 256x512", window3->bounds().ToString()); |
| 1152 |
| 1153 // After removing |window3|, |window1| should be centered again. |
| 1154 window3.reset(); |
| 1155 EXPECT_EQ( |
| 1156 base::IntToString( |
| 1157 (desktop_area.width() - window1->bounds().width()) / 2) + |
| 1158 ",32 640x320", window1->bounds().ToString()); |
| 1159 |
| 1160 // Test 3: Set up a manageable and a non manageable window and check |
| 1161 // positioning. |
| 1162 scoped_ptr<aura::Window> window4( |
| 1163 aura::test::CreateTestWindowWithId(3, NULL)); |
| 1164 // To avoid any auto window manager changes due to SetBounds, the window |
| 1165 // gets first hidden and then shown again. |
| 1166 window1->Hide(); |
| 1167 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 1168 window4->SetBounds(gfx::Rect(32, 48, 256, 512)); |
| 1169 window1->Show(); |
| 1170 // |window1| should be centered and |window4| untouched. |
| 1171 EXPECT_EQ( |
| 1172 base::IntToString( |
| 1173 (desktop_area.width() - window1->bounds().width()) / 2) + |
| 1174 ",32 640x320", window1->bounds().ToString()); |
| 1175 EXPECT_EQ("32,48 256x512", window4->bounds().ToString()); |
| 1176 |
| 1177 // Test4: A single manageable window should get centered. |
| 1178 window4.reset(); |
| 1179 ash::wm::SetUserHasChangedWindowPositionOrSize(window1.get(), false); |
| 1180 // Trigger the auto window placement function by showing (and hiding) it. |
| 1181 window1->Hide(); |
| 1182 window1->Show(); |
| 1183 // |window1| should be centered. |
| 1184 EXPECT_EQ( |
| 1185 base::IntToString( |
| 1186 (desktop_area.width() - window1->bounds().width()) / 2) + |
| 1187 ",32 640x320", window1->bounds().ToString()); |
| 1188 } |
| 1189 |
| 1190 // Test the proper usage of user window movement interaction. |
| 1191 TEST_F(WorkspaceManager2Test, TestUserMovedWindowRepositioning) { |
| 1192 scoped_ptr<aura::Window> window1( |
| 1193 aura::test::CreateTestWindowWithId(0, NULL)); |
| 1194 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 1195 gfx::Rect desktop_area = window1->parent()->bounds(); |
| 1196 scoped_ptr<aura::Window> window2( |
| 1197 aura::test::CreateTestWindowWithId(1, NULL)); |
| 1198 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
| 1199 window1->Hide(); |
| 1200 window2->Hide(); |
| 1201 ash::wm::SetWindowPositionManaged(window1.get(), true); |
| 1202 ash::wm::SetWindowPositionManaged(window2.get(), true); |
| 1203 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get())); |
| 1204 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window2.get())); |
| 1205 |
| 1206 // Check that the current location gets preserved if the user has |
| 1207 // positioned it previously. |
| 1208 ash::wm::SetUserHasChangedWindowPositionOrSize(window1.get(), true); |
| 1209 window1->Show(); |
| 1210 EXPECT_EQ("16,32 640x320", window1->bounds().ToString()); |
| 1211 // Flag should be still set. |
| 1212 EXPECT_TRUE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get())); |
| 1213 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window2.get())); |
| 1214 |
| 1215 // Turn on the second window and make sure that both windows are now |
| 1216 // positionable again (user movement cleared). |
| 1217 window2->Show(); |
| 1218 |
| 1219 // |window1| should be flush right and |window3| flush left. |
| 1220 EXPECT_EQ(base::IntToString( |
| 1221 desktop_area.width() - window1->bounds().width()) + |
| 1222 ",32 640x320", window1->bounds().ToString()); |
| 1223 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); |
| 1224 // FLag should now be reset. |
| 1225 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get())); |
| 1226 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get())); |
| 1227 |
| 1228 // Going back to one shown window should keep the state. |
| 1229 ash::wm::SetUserHasChangedWindowPositionOrSize(window1.get(), true); |
| 1230 window2->Hide(); |
| 1231 EXPECT_EQ(base::IntToString( |
| 1232 desktop_area.width() - window1->bounds().width()) + |
| 1233 ",32 640x320", window1->bounds().ToString()); |
| 1234 EXPECT_TRUE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get())); |
| 1235 } |
| 1236 |
| 1237 // Test that a window from normal to minimize will repos the remaining. |
| 1238 TEST_F(WorkspaceManager2Test, ToMinimizeRepositionsRemaining) { |
| 1239 scoped_ptr<aura::Window> window1( |
| 1240 aura::test::CreateTestWindowWithId(0, NULL)); |
| 1241 ash::wm::SetWindowPositionManaged(window1.get(), true); |
| 1242 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 1243 gfx::Rect desktop_area = window1->parent()->bounds(); |
| 1244 |
| 1245 scoped_ptr<aura::Window> window2( |
| 1246 aura::test::CreateTestWindowWithId(1, NULL)); |
| 1247 ash::wm::SetWindowPositionManaged(window2.get(), true); |
| 1248 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
| 1249 |
| 1250 ash::wm::MinimizeWindow(window1.get()); |
| 1251 |
| 1252 // |window2| should be centered now. |
| 1253 EXPECT_TRUE(window2->IsVisible()); |
| 1254 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get())); |
| 1255 EXPECT_EQ(base::IntToString( |
| 1256 (desktop_area.width() - window2->bounds().width()) / 2) + |
| 1257 ",48 256x512", window2->bounds().ToString()); |
| 1258 |
| 1259 ash::wm::RestoreWindow(window1.get()); |
| 1260 // |window1| should be flush right and |window3| flush left. |
| 1261 EXPECT_EQ(base::IntToString( |
| 1262 desktop_area.width() - window1->bounds().width()) + |
| 1263 ",32 640x320", window1->bounds().ToString()); |
| 1264 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); |
| 1265 } |
| 1266 |
| 1267 // Test that minimizing an initially maximized window will repos the remaining. |
| 1268 TEST_F(WorkspaceManager2Test, MaxToMinRepositionsRemaining) { |
| 1269 scoped_ptr<aura::Window> window1( |
| 1270 aura::test::CreateTestWindowWithId(0, NULL)); |
| 1271 ash::wm::SetWindowPositionManaged(window1.get(), true); |
| 1272 gfx::Rect desktop_area = window1->parent()->bounds(); |
| 1273 |
| 1274 scoped_ptr<aura::Window> window2( |
| 1275 aura::test::CreateTestWindowWithId(1, NULL)); |
| 1276 ash::wm::SetWindowPositionManaged(window2.get(), true); |
| 1277 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
| 1278 |
| 1279 ash::wm::MaximizeWindow(window1.get()); |
| 1280 ash::wm::MinimizeWindow(window1.get()); |
| 1281 |
| 1282 // |window2| should be centered now. |
| 1283 EXPECT_TRUE(window2->IsVisible()); |
| 1284 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get())); |
| 1285 EXPECT_EQ(base::IntToString( |
| 1286 (desktop_area.width() - window2->bounds().width()) / 2) + |
| 1287 ",48 256x512", window2->bounds().ToString()); |
| 1288 } |
| 1289 |
| 1290 // Test that nomral, maximize, minimizing will repos the remaining. |
| 1291 TEST_F(WorkspaceManager2Test, NormToMaxToMinRepositionsRemaining) { |
| 1292 scoped_ptr<aura::Window> window1( |
| 1293 aura::test::CreateTestWindowWithId(0, NULL)); |
| 1294 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 1295 ash::wm::SetWindowPositionManaged(window1.get(), true); |
| 1296 gfx::Rect desktop_area = window1->parent()->bounds(); |
| 1297 |
| 1298 scoped_ptr<aura::Window> window2( |
| 1299 aura::test::CreateTestWindowWithId(1, NULL)); |
| 1300 ash::wm::SetWindowPositionManaged(window2.get(), true); |
| 1301 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
| 1302 |
| 1303 // Trigger the auto window placement function by showing (and hiding) it. |
| 1304 window1->Hide(); |
| 1305 window1->Show(); |
| 1306 |
| 1307 // |window1| should be flush right and |window3| flush left. |
| 1308 EXPECT_EQ(base::IntToString( |
| 1309 desktop_area.width() - window1->bounds().width()) + |
| 1310 ",32 640x320", window1->bounds().ToString()); |
| 1311 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); |
| 1312 |
| 1313 ash::wm::MaximizeWindow(window1.get()); |
| 1314 ash::wm::MinimizeWindow(window1.get()); |
| 1315 |
| 1316 // |window2| should be centered now. |
| 1317 EXPECT_TRUE(window2->IsVisible()); |
| 1318 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get())); |
| 1319 EXPECT_EQ(base::IntToString( |
| 1320 (desktop_area.width() - window2->bounds().width()) / 2) + |
| 1321 ",48 256x512", window2->bounds().ToString()); |
| 1322 } |
| 1323 |
| 1324 // Test that nomral, maximize, normal will repos the remaining. |
| 1325 TEST_F(WorkspaceManager2Test, NormToMaxToNormRepositionsRemaining) { |
| 1326 scoped_ptr<aura::Window> window1( |
| 1327 aura::test::CreateTestWindowWithId(0, NULL)); |
| 1328 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 1329 ash::wm::SetWindowPositionManaged(window1.get(), true); |
| 1330 gfx::Rect desktop_area = window1->parent()->bounds(); |
| 1331 |
| 1332 scoped_ptr<aura::Window> window2( |
| 1333 aura::test::CreateTestWindowWithId(1, NULL)); |
| 1334 ash::wm::SetWindowPositionManaged(window2.get(), true); |
| 1335 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
| 1336 |
| 1337 // Trigger the auto window placement function by showing (and hiding) it. |
| 1338 window1->Hide(); |
| 1339 window1->Show(); |
| 1340 |
| 1341 // |window1| should be flush right and |window3| flush left. |
| 1342 EXPECT_EQ(base::IntToString( |
| 1343 desktop_area.width() - window1->bounds().width()) + |
| 1344 ",32 640x320", window1->bounds().ToString()); |
| 1345 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); |
| 1346 |
| 1347 ash::wm::MaximizeWindow(window1.get()); |
| 1348 ash::wm::RestoreWindow(window1.get()); |
| 1349 |
| 1350 // |window1| should be flush right and |window2| flush left. |
| 1351 EXPECT_EQ(base::IntToString( |
| 1352 desktop_area.width() - window1->bounds().width()) + |
| 1353 ",32 640x320", window1->bounds().ToString()); |
| 1354 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); |
| 1355 } |
| 1356 |
| 1357 // Test that animations are triggered. |
| 1358 TEST_F(WorkspaceManager2Test, AnimatedNormToMaxToNormRepositionsRemaining) { |
| 1359 ui::LayerAnimator::set_disable_animations_for_test(false); |
| 1360 scoped_ptr<aura::Window> window1( |
| 1361 aura::test::CreateTestWindowWithId(0, NULL)); |
| 1362 window1->Hide(); |
| 1363 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 1364 gfx::Rect desktop_area = window1->parent()->bounds(); |
| 1365 scoped_ptr<aura::Window> window2( |
| 1366 aura::test::CreateTestWindowWithId(1, NULL)); |
| 1367 window2->Hide(); |
| 1368 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
| 1369 |
| 1370 ash::wm::SetWindowPositionManaged(window1.get(), true); |
| 1371 ash::wm::SetWindowPositionManaged(window2.get(), true); |
| 1372 // Make sure nothing is animating. |
| 1373 window1->layer()->GetAnimator()->StopAnimating(); |
| 1374 window2->layer()->GetAnimator()->StopAnimating(); |
| 1375 window2->Show(); |
| 1376 |
| 1377 // The second window should now animate. |
| 1378 EXPECT_FALSE(window1->layer()->GetAnimator()->is_animating()); |
| 1379 EXPECT_TRUE(window2->layer()->GetAnimator()->is_animating()); |
| 1380 window2->layer()->GetAnimator()->StopAnimating(); |
| 1381 |
| 1382 window1->Show(); |
| 1383 EXPECT_TRUE(window1->layer()->GetAnimator()->is_animating()); |
| 1384 EXPECT_TRUE(window2->layer()->GetAnimator()->is_animating()); |
| 1385 |
| 1386 window1->layer()->GetAnimator()->StopAnimating(); |
| 1387 window2->layer()->GetAnimator()->StopAnimating(); |
| 1388 // |window1| should be flush right and |window2| flush left. |
| 1389 EXPECT_EQ(base::IntToString( |
| 1390 desktop_area.width() - window1->bounds().width()) + |
| 1391 ",32 640x320", window1->bounds().ToString()); |
| 1392 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); |
| 1393 } |
| 1394 |
1110 } // namespace internal | 1395 } // namespace internal |
1111 } // namespace ash | 1396 } // namespace ash |
OLD | NEW |