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