| 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 "chrome/browser/ui/window_sizer/window_sizer.h" | 5 #include "chrome/browser/ui/window_sizer/window_sizer.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 TEST_F(WindowSizerTest, LastWindowBoundsCase) { | 212 TEST_F(WindowSizerTest, LastWindowBoundsCase) { |
| 213 { // normal, in the middle of the screen somewhere. | 213 { // normal, in the middle of the screen somewhere. |
| 214 gfx::Rect window_bounds; | 214 gfx::Rect window_bounds; |
| 215 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 215 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 216 gfx::Rect(WindowSizer::kDesktopBorderSize, | 216 gfx::Rect(WindowSizer::kDesktopBorderSize, |
| 217 WindowSizer::kDesktopBorderSize, 500, 400), | 217 WindowSizer::kDesktopBorderSize, 500, 400), |
| 218 gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL, | 218 gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL, |
| 219 gfx::Rect()); | 219 gfx::Rect()); |
| 220 EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, | 220 EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, |
| 221 kWindowTilePixels + WindowSizer::kDesktopBorderSize, | 221 kWindowTilePixels + WindowSizer::kDesktopBorderSize, |
| 222 500, 400), | 222 500, 400).ToString(), |
| 223 window_bounds); | 223 window_bounds.ToString()); |
| 224 } | 224 } |
| 225 | 225 |
| 226 { // taskbar on top. | 226 { // taskbar on top. |
| 227 gfx::Rect window_bounds; | 227 gfx::Rect window_bounds; |
| 228 GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(), | 228 GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(), |
| 229 gfx::Rect(WindowSizer::kDesktopBorderSize, | 229 gfx::Rect(WindowSizer::kDesktopBorderSize, |
| 230 WindowSizer::kDesktopBorderSize, 500, 400), | 230 WindowSizer::kDesktopBorderSize, 500, 400), |
| 231 gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL, | 231 gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL, |
| 232 gfx::Rect()); | 232 gfx::Rect()); |
| 233 EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, | 233 EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, |
| 234 std::max(kWindowTilePixels + | 234 std::max(kWindowTilePixels + |
| 235 WindowSizer::kDesktopBorderSize, | 235 WindowSizer::kDesktopBorderSize, |
| 236 34 /* toolbar height */), | 236 34 /* toolbar height */), |
| 237 500, 400), window_bounds); | 237 500, 400).ToString(), window_bounds.ToString()); |
| 238 } | 238 } |
| 239 | 239 |
| 240 { // Too small to satisify the minimum visibility condition. | 240 { // Too small to satisify the minimum visibility condition. |
| 241 gfx::Rect window_bounds; | 241 gfx::Rect window_bounds; |
| 242 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 242 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 243 gfx::Rect(WindowSizer::kDesktopBorderSize, | 243 gfx::Rect(WindowSizer::kDesktopBorderSize, |
| 244 WindowSizer::kDesktopBorderSize, 29, 29), | 244 WindowSizer::kDesktopBorderSize, 29, 29), |
| 245 gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL, | 245 gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL, |
| 246 gfx::Rect()); | 246 gfx::Rect()); |
| 247 EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, | 247 EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, |
| 248 kWindowTilePixels + WindowSizer::kDesktopBorderSize, | 248 kWindowTilePixels + WindowSizer::kDesktopBorderSize, |
| 249 30 /* not 29 */, | 249 30 /* not 29 */, |
| 250 30 /* not 29 */), | 250 30 /* not 29 */).ToString(), |
| 251 window_bounds); | 251 window_bounds.ToString()); |
| 252 } | 252 } |
| 253 | 253 |
| 254 | 254 |
| 255 { // Normal. | 255 { // Normal. |
| 256 gfx::Rect window_bounds; | 256 gfx::Rect window_bounds; |
| 257 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 257 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 258 gfx::Rect(WindowSizer::kDesktopBorderSize, | 258 gfx::Rect(WindowSizer::kDesktopBorderSize, |
| 259 WindowSizer::kDesktopBorderSize, 500, 400), | 259 WindowSizer::kDesktopBorderSize, 500, 400), |
| 260 gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL, | 260 gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL, |
| 261 gfx::Rect()); | 261 gfx::Rect()); |
| 262 EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, | 262 EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, |
| 263 kWindowTilePixels + WindowSizer::kDesktopBorderSize, | 263 kWindowTilePixels + WindowSizer::kDesktopBorderSize, |
| 264 500, 400), | 264 500, 400).ToString(), |
| 265 window_bounds); | 265 window_bounds.ToString()); |
| 266 } | 266 } |
| 267 } | 267 } |
| 268 | 268 |
| 269 // Test that the window opened is sized appropriately given persisted sizes. | 269 // Test that the window opened is sized appropriately given persisted sizes. |
| 270 TEST_F(WindowSizerTest, PersistedBoundsCase) { | 270 TEST_F(WindowSizerTest, PersistedBoundsCase) { |
| 271 { // normal, in the middle of the screen somewhere. | 271 { // normal, in the middle of the screen somewhere. |
| 272 gfx::Rect initial_bounds(WindowSizer::kDesktopBorderSize, | 272 gfx::Rect initial_bounds(WindowSizer::kDesktopBorderSize, |
| 273 WindowSizer::kDesktopBorderSize, 500, 400); | 273 WindowSizer::kDesktopBorderSize, 500, 400); |
| 274 | 274 |
| 275 gfx::Rect window_bounds; | 275 gfx::Rect window_bounds; |
| 276 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds, | 276 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds, |
| 277 gfx::Rect(), PERSISTED, &window_bounds, NULL, gfx::Rect()); | 277 gfx::Rect(), PERSISTED, &window_bounds, NULL, gfx::Rect()); |
| 278 EXPECT_EQ(initial_bounds, window_bounds); | 278 EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString()); |
| 279 } | 279 } |
| 280 | 280 |
| 281 { // Normal. | 281 { // Normal. |
| 282 gfx::Rect initial_bounds(0, 0, 1024, 768); | 282 gfx::Rect initial_bounds(0, 0, 1024, 768); |
| 283 | 283 |
| 284 gfx::Rect window_bounds; | 284 gfx::Rect window_bounds; |
| 285 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds, | 285 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds, |
| 286 gfx::Rect(), PERSISTED, &window_bounds, NULL, gfx::Rect()); | 286 gfx::Rect(), PERSISTED, &window_bounds, NULL, gfx::Rect()); |
| 287 EXPECT_EQ(initial_bounds, window_bounds); | 287 EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString()); |
| 288 } | 288 } |
| 289 | 289 |
| 290 { // normal, on non-primary monitor in negative coords. | 290 { // normal, on non-primary monitor in negative coords. |
| 291 gfx::Rect initial_bounds(-600, 10, 500, 400); | 291 gfx::Rect initial_bounds(-600, 10, 500, 400); |
| 292 | 292 |
| 293 gfx::Rect window_bounds; | 293 gfx::Rect window_bounds; |
| 294 GetWindowBounds(tentwentyfour, tentwentyfour, left_nonprimary, | 294 GetWindowBounds(tentwentyfour, tentwentyfour, left_nonprimary, |
| 295 initial_bounds, gfx::Rect(), PERSISTED, &window_bounds, | 295 initial_bounds, gfx::Rect(), PERSISTED, &window_bounds, |
| 296 NULL, gfx::Rect()); | 296 NULL, gfx::Rect()); |
| 297 EXPECT_EQ(initial_bounds, window_bounds); | 297 EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString()); |
| 298 } | 298 } |
| 299 | 299 |
| 300 { // normal, on non-primary monitor in negative coords. | 300 { // normal, on non-primary monitor in negative coords. |
| 301 gfx::Rect initial_bounds(-1024, 0, 1024, 768); | 301 gfx::Rect initial_bounds(-1024, 0, 1024, 768); |
| 302 | 302 |
| 303 gfx::Rect window_bounds; | 303 gfx::Rect window_bounds; |
| 304 GetWindowBounds(tentwentyfour, tentwentyfour, left_nonprimary, | 304 GetWindowBounds(tentwentyfour, tentwentyfour, left_nonprimary, |
| 305 initial_bounds, gfx::Rect(), PERSISTED, &window_bounds, | 305 initial_bounds, gfx::Rect(), PERSISTED, &window_bounds, |
| 306 NULL, gfx::Rect()); | 306 NULL, gfx::Rect()); |
| 307 EXPECT_EQ(initial_bounds, window_bounds); | 307 EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString()); |
| 308 } | 308 } |
| 309 | 309 |
| 310 { // Non-primary monitor resoultion has changed, but the monitor still | 310 { // Non-primary monitor resoultion has changed, but the monitor still |
| 311 // completely contains the window. | 311 // completely contains the window. |
| 312 | 312 |
| 313 gfx::Rect initial_bounds(1074, 50, 600, 500); | 313 gfx::Rect initial_bounds(1074, 50, 600, 500); |
| 314 | 314 |
| 315 gfx::Rect window_bounds; | 315 gfx::Rect window_bounds; |
| 316 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600), | 316 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600), |
| 317 initial_bounds, right_nonprimary, PERSISTED, | 317 initial_bounds, right_nonprimary, PERSISTED, |
| 318 &window_bounds, NULL, gfx::Rect()); | 318 &window_bounds, NULL, gfx::Rect()); |
| 319 EXPECT_EQ(initial_bounds, window_bounds); | 319 EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString()); |
| 320 } | 320 } |
| 321 | 321 |
| 322 { // Non-primary monitor resoultion has changed, and the window is partially | 322 { // Non-primary monitor resoultion has changed, and the window is partially |
| 323 // off-screen. | 323 // off-screen. |
| 324 | 324 |
| 325 gfx::Rect initial_bounds(1274, 50, 600, 500); | 325 gfx::Rect initial_bounds(1274, 50, 600, 500); |
| 326 | 326 |
| 327 gfx::Rect window_bounds; | 327 gfx::Rect window_bounds; |
| 328 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600), | 328 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600), |
| 329 initial_bounds, right_nonprimary, PERSISTED, | 329 initial_bounds, right_nonprimary, PERSISTED, |
| 330 &window_bounds, NULL, gfx::Rect()); | 330 &window_bounds, NULL, gfx::Rect()); |
| 331 EXPECT_EQ(gfx::Rect(1224, 50, 600, 500), window_bounds); | 331 EXPECT_EQ("1224,50 600x500", window_bounds.ToString()); |
| 332 } | 332 } |
| 333 | 333 |
| 334 { // Non-primary monitor resoultion has changed, and the window is now too | 334 { // Non-primary monitor resoultion has changed, and the window is now too |
| 335 // large for the monitor. | 335 // large for the monitor. |
| 336 | 336 |
| 337 gfx::Rect initial_bounds(1274, 50, 900, 700); | 337 gfx::Rect initial_bounds(1274, 50, 900, 700); |
| 338 | 338 |
| 339 gfx::Rect window_bounds; | 339 gfx::Rect window_bounds; |
| 340 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600), | 340 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600), |
| 341 initial_bounds, right_nonprimary, PERSISTED, | 341 initial_bounds, right_nonprimary, PERSISTED, |
| 342 &window_bounds, NULL, gfx::Rect()); | 342 &window_bounds, NULL, gfx::Rect()); |
| 343 EXPECT_EQ(gfx::Rect(1024, 0, 800, 600), window_bounds); | 343 EXPECT_EQ("1024,0 800x600", window_bounds.ToString()); |
| 344 } | 344 } |
| 345 | 345 |
| 346 { // width and height too small | 346 { // width and height too small |
| 347 gfx::Rect window_bounds; | 347 gfx::Rect window_bounds; |
| 348 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 348 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 349 gfx::Rect(WindowSizer::kDesktopBorderSize, | 349 gfx::Rect(WindowSizer::kDesktopBorderSize, |
| 350 WindowSizer::kDesktopBorderSize, 29, 29), | 350 WindowSizer::kDesktopBorderSize, 29, 29), |
| 351 gfx::Rect(), PERSISTED, &window_bounds, NULL, gfx::Rect()); | 351 gfx::Rect(), PERSISTED, &window_bounds, NULL, gfx::Rect()); |
| 352 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | 352 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, |
| 353 WindowSizer::kDesktopBorderSize, | 353 WindowSizer::kDesktopBorderSize, |
| 354 30 /* not 29 */, 30 /* not 29 */), | 354 30 /* not 29 */, 30 /* not 29 */).ToString(), |
| 355 window_bounds); | 355 window_bounds.ToString()); |
| 356 } | 356 } |
| 357 } | 357 } |
| 358 | 358 |
| 359 ////////////////////////////////////////////////////////////////////////////// | 359 ////////////////////////////////////////////////////////////////////////////// |
| 360 // The following unittests have different results on Mac/non-Mac because we | 360 // The following unittests have different results on Mac/non-Mac because we |
| 361 // reposition windows aggressively on Mac. The *WithAggressiveReposition tests | 361 // reposition windows aggressively on Mac. The *WithAggressiveReposition tests |
| 362 // are run on Mac, and the *WithNonAggressiveRepositioning tests are run on | 362 // are run on Mac, and the *WithNonAggressiveRepositioning tests are run on |
| 363 // other platforms. | 363 // other platforms. |
| 364 | 364 |
| 365 TEST_F(WindowSizerTest, LastWindowOffscreenWithNonAggressiveRepositioning) { | 365 TEST_F(WindowSizerTest, LastWindowOffscreenWithNonAggressiveRepositioning) { |
| 366 { // taskbar on left. | 366 { // taskbar on left. |
| 367 gfx::Rect window_bounds; | 367 gfx::Rect window_bounds; |
| 368 GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(), | 368 GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(), |
| 369 gfx::Rect(WindowSizer::kDesktopBorderSize, | 369 gfx::Rect(WindowSizer::kDesktopBorderSize, |
| 370 WindowSizer::kDesktopBorderSize, 500, 400), | 370 WindowSizer::kDesktopBorderSize, 500, 400), |
| 371 gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL, | 371 gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL, |
| 372 gfx::Rect()); | 372 gfx::Rect()); |
| 373 EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, | 373 EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, |
| 374 kWindowTilePixels + WindowSizer::kDesktopBorderSize, | 374 kWindowTilePixels + WindowSizer::kDesktopBorderSize, |
| 375 500, 400), | 375 500, 400).ToString(), |
| 376 window_bounds); | 376 window_bounds.ToString()); |
| 377 } | 377 } |
| 378 | 378 |
| 379 { // offset would put the new window offscreen at the bottom but the minimum | 379 { // offset would put the new window offscreen at the bottom but the minimum |
| 380 // visibility condition is barely satisfied without relocation. | 380 // visibility condition is barely satisfied without relocation. |
| 381 gfx::Rect window_bounds; | 381 gfx::Rect window_bounds; |
| 382 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 382 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 383 gfx::Rect(10, 728, 500, 400), gfx::Rect(), LAST_ACTIVE, | 383 gfx::Rect(10, 728, 500, 400), gfx::Rect(), LAST_ACTIVE, |
| 384 &window_bounds, NULL, gfx::Rect()); | 384 &window_bounds, NULL, gfx::Rect()); |
| 385 EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738, | 385 EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738, 500, 400).ToString(), |
| 386 500, 400), window_bounds); | 386 window_bounds.ToString()); |
| 387 } | 387 } |
| 388 | 388 |
| 389 { // offset would put the new window offscreen at the bottom and the minimum | 389 { // offset would put the new window offscreen at the bottom and the minimum |
| 390 // visibility condition is satisified by relocation. | 390 // visibility condition is satisified by relocation. |
| 391 gfx::Rect window_bounds; | 391 gfx::Rect window_bounds; |
| 392 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 392 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 393 gfx::Rect(10, 729, 500, 400), gfx::Rect(), LAST_ACTIVE, | 393 gfx::Rect(10, 729, 500, 400), gfx::Rect(), LAST_ACTIVE, |
| 394 &window_bounds, NULL, gfx::Rect()); | 394 &window_bounds, NULL, gfx::Rect()); |
| 395 EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738 /* not 739 */, 500, 400), | 395 EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, |
| 396 window_bounds); | 396 738 /* not 739 */, |
| 397 500, |
| 398 400).ToString(), |
| 399 window_bounds.ToString()); |
| 397 } | 400 } |
| 398 | 401 |
| 399 { // offset would put the new window offscreen at the right but the minimum | 402 { // offset would put the new window offscreen at the right but the minimum |
| 400 // visibility condition is barely satisfied without relocation. | 403 // visibility condition is barely satisfied without relocation. |
| 401 gfx::Rect window_bounds; | 404 gfx::Rect window_bounds; |
| 402 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 405 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 403 gfx::Rect(984, 10, 500, 400), gfx::Rect(), LAST_ACTIVE, | 406 gfx::Rect(984, 10, 500, 400), gfx::Rect(), LAST_ACTIVE, |
| 404 &window_bounds, NULL, gfx::Rect()); | 407 &window_bounds, NULL, gfx::Rect()); |
| 405 EXPECT_EQ(gfx::Rect(994, 10 + kWindowTilePixels, 500, 400), window_bounds); | 408 EXPECT_EQ(gfx::Rect(994, 10 + kWindowTilePixels, 500, 400).ToString(), |
| 409 window_bounds.ToString()); |
| 406 } | 410 } |
| 407 | 411 |
| 408 { // offset would put the new window offscreen at the right and the minimum | 412 { // offset would put the new window offscreen at the right and the minimum |
| 409 // visibility condition is satisified by relocation. | 413 // visibility condition is satisified by relocation. |
| 410 gfx::Rect window_bounds; | 414 gfx::Rect window_bounds; |
| 411 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 415 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 412 gfx::Rect(985, 10, 500, 400), gfx::Rect(), LAST_ACTIVE, | 416 gfx::Rect(985, 10, 500, 400), gfx::Rect(), LAST_ACTIVE, |
| 413 &window_bounds, NULL, gfx::Rect()); | 417 &window_bounds, NULL, gfx::Rect()); |
| 414 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 10 + kWindowTilePixels, | 418 EXPECT_EQ(gfx::Rect(994 /* not 995 */, |
| 415 500, 400), window_bounds); | 419 10 + kWindowTilePixels, |
| 420 500, |
| 421 400).ToString(), |
| 422 window_bounds.ToString()); |
| 416 } | 423 } |
| 417 | 424 |
| 418 { // offset would put the new window offscreen at the bottom right and the | 425 { // offset would put the new window offscreen at the bottom right and the |
| 419 // minimum visibility condition is satisified by relocation. | 426 // minimum visibility condition is satisified by relocation. |
| 420 gfx::Rect window_bounds; | 427 gfx::Rect window_bounds; |
| 421 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 428 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 422 gfx::Rect(985, 729, 500, 400), gfx::Rect(), LAST_ACTIVE, | 429 gfx::Rect(985, 729, 500, 400), gfx::Rect(), LAST_ACTIVE, |
| 423 &window_bounds, NULL, gfx::Rect()); | 430 &window_bounds, NULL, gfx::Rect()); |
| 424 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 738 /* not 739 */, 500, 400), | 431 EXPECT_EQ(gfx::Rect(994 /* not 995 */, |
| 425 window_bounds); | 432 738 /* not 739 */, |
| 433 500, |
| 434 400).ToString(), |
| 435 window_bounds.ToString()); |
| 426 } | 436 } |
| 427 } | 437 } |
| 428 | 438 |
| 429 TEST_F(WindowSizerTest, | 439 TEST_F(WindowSizerTest, |
| 430 PersistedWindowOffscreenWithNonAggressiveRepositioning) { | 440 PersistedWindowOffscreenWithNonAggressiveRepositioning) { |
| 431 { // off the left but the minimum visibility condition is barely satisfied | 441 { // off the left but the minimum visibility condition is barely satisfied |
| 432 // without relocaiton. | 442 // without relocaiton. |
| 433 gfx::Rect initial_bounds(-470, 50, 500, 400); | 443 gfx::Rect initial_bounds(-470, 50, 500, 400); |
| 434 | 444 |
| 435 gfx::Rect window_bounds; | 445 gfx::Rect window_bounds; |
| 436 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 446 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 437 initial_bounds, gfx::Rect(), PERSISTED, | 447 initial_bounds, gfx::Rect(), PERSISTED, |
| 438 &window_bounds, NULL, gfx::Rect()); | 448 &window_bounds, NULL, gfx::Rect()); |
| 439 EXPECT_EQ(initial_bounds, window_bounds); | 449 EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString()); |
| 440 } | 450 } |
| 441 | 451 |
| 442 { // off the left and the minimum visibility condition is satisfied by | 452 { // off the left and the minimum visibility condition is satisfied by |
| 443 // relocation. | 453 // relocation. |
| 444 gfx::Rect window_bounds; | 454 gfx::Rect window_bounds; |
| 445 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 455 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 446 gfx::Rect(-471, 50, 500, 400), gfx::Rect(), PERSISTED, | 456 gfx::Rect(-471, 50, 500, 400), gfx::Rect(), PERSISTED, |
| 447 &window_bounds, NULL, gfx::Rect()); | 457 &window_bounds, NULL, gfx::Rect()); |
| 448 EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 50, 500, 400), window_bounds); | 458 EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 50, 500, 400).ToString(), |
| 459 window_bounds.ToString()); |
| 449 } | 460 } |
| 450 | 461 |
| 451 { // off the top | 462 { // off the top |
| 452 gfx::Rect initial_bounds(50, -370, 500, 400); | 463 gfx::Rect initial_bounds(50, -370, 500, 400); |
| 453 | 464 |
| 454 gfx::Rect window_bounds; | 465 gfx::Rect window_bounds; |
| 455 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 466 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 456 gfx::Rect(50, -370, 500, 400), gfx::Rect(), PERSISTED, | 467 gfx::Rect(50, -370, 500, 400), gfx::Rect(), PERSISTED, |
| 457 &window_bounds, NULL, gfx::Rect()); | 468 &window_bounds, NULL, gfx::Rect()); |
| 458 EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds); | 469 EXPECT_EQ("50,0 500x400", window_bounds.ToString()); |
| 459 } | 470 } |
| 460 | 471 |
| 461 { // off the right but the minimum visibility condition is barely satisified | 472 { // off the right but the minimum visibility condition is barely satisified |
| 462 // without relocation. | 473 // without relocation. |
| 463 gfx::Rect initial_bounds(994, 50, 500, 400); | 474 gfx::Rect initial_bounds(994, 50, 500, 400); |
| 464 | 475 |
| 465 gfx::Rect window_bounds; | 476 gfx::Rect window_bounds; |
| 466 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 477 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 467 initial_bounds, gfx::Rect(), PERSISTED, | 478 initial_bounds, gfx::Rect(), PERSISTED, |
| 468 &window_bounds, NULL, gfx::Rect()); | 479 &window_bounds, NULL, gfx::Rect()); |
| 469 EXPECT_EQ(initial_bounds, window_bounds); | 480 EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString()); |
| 470 } | 481 } |
| 471 | 482 |
| 472 { // off the right and the minimum visibility condition is satisified by | 483 { // off the right and the minimum visibility condition is satisified by |
| 473 // relocation. | 484 // relocation. |
| 474 gfx::Rect window_bounds; | 485 gfx::Rect window_bounds; |
| 475 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 486 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 476 gfx::Rect(995, 50, 500, 400), gfx::Rect(), PERSISTED, | 487 gfx::Rect(995, 50, 500, 400), gfx::Rect(), PERSISTED, |
| 477 &window_bounds, NULL, gfx::Rect()); | 488 &window_bounds, NULL, gfx::Rect()); |
| 478 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 50, 500, 400), window_bounds); | 489 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 50, 500, 400).ToString(), |
| 490 window_bounds.ToString()); |
| 479 } | 491 } |
| 480 | 492 |
| 481 { // off the bottom but the minimum visibility condition is barely satisified | 493 { // off the bottom but the minimum visibility condition is barely satisified |
| 482 // without relocation. | 494 // without relocation. |
| 483 gfx::Rect initial_bounds(50, 738, 500, 400); | 495 gfx::Rect initial_bounds(50, 738, 500, 400); |
| 484 | 496 |
| 485 gfx::Rect window_bounds; | 497 gfx::Rect window_bounds; |
| 486 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 498 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 487 initial_bounds, gfx::Rect(), PERSISTED, | 499 initial_bounds, gfx::Rect(), PERSISTED, |
| 488 &window_bounds, NULL, gfx::Rect()); | 500 &window_bounds, NULL, gfx::Rect()); |
| 489 EXPECT_EQ(initial_bounds, window_bounds); | 501 EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString()); |
| 490 } | 502 } |
| 491 | 503 |
| 492 { // off the bottom and the minimum visibility condition is satisified by | 504 { // off the bottom and the minimum visibility condition is satisified by |
| 493 // relocation. | 505 // relocation. |
| 494 gfx::Rect window_bounds; | 506 gfx::Rect window_bounds; |
| 495 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 507 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 496 gfx::Rect(50, 739, 500, 400), gfx::Rect(), PERSISTED, | 508 gfx::Rect(50, 739, 500, 400), gfx::Rect(), PERSISTED, |
| 497 &window_bounds, NULL, gfx::Rect()); | 509 &window_bounds, NULL, gfx::Rect()); |
| 498 EXPECT_EQ(gfx::Rect(50, 738 /* not 739 */, 500, 400), window_bounds); | 510 EXPECT_EQ(gfx::Rect(50, 738 /* not 739 */, 500, 400).ToString(), |
| 511 window_bounds.ToString()); |
| 499 } | 512 } |
| 500 | 513 |
| 501 { // off the topleft | 514 { // off the topleft |
| 502 gfx::Rect window_bounds; | 515 gfx::Rect window_bounds; |
| 503 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 516 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 504 gfx::Rect(-471, -371, 500, 400), gfx::Rect(), PERSISTED, | 517 gfx::Rect(-471, -371, 500, 400), gfx::Rect(), PERSISTED, |
| 505 &window_bounds, NULL, gfx::Rect()); | 518 &window_bounds, NULL, gfx::Rect()); |
| 506 EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 0, 500, 400), | 519 EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 0, 500, 400).ToString(), |
| 507 window_bounds); | 520 window_bounds.ToString()); |
| 508 } | 521 } |
| 509 | 522 |
| 510 { // off the topright and the minimum visibility condition is satisified by | 523 { // off the topright and the minimum visibility condition is satisified by |
| 511 // relocation. | 524 // relocation. |
| 512 gfx::Rect window_bounds; | 525 gfx::Rect window_bounds; |
| 513 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 526 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 514 gfx::Rect(995, -371, 500, 400), gfx::Rect(), PERSISTED, | 527 gfx::Rect(995, -371, 500, 400), gfx::Rect(), PERSISTED, |
| 515 &window_bounds, NULL, gfx::Rect()); | 528 &window_bounds, NULL, gfx::Rect()); |
| 516 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 0, 500, 400), | 529 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 0, 500, 400).ToString(), |
| 517 window_bounds); | 530 window_bounds.ToString()); |
| 518 } | 531 } |
| 519 | 532 |
| 520 { // off the bottomleft and the minimum visibility condition is satisified by | 533 { // off the bottomleft and the minimum visibility condition is satisified by |
| 521 // relocation. | 534 // relocation. |
| 522 gfx::Rect window_bounds; | 535 gfx::Rect window_bounds; |
| 523 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 536 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 524 gfx::Rect(-471, 739, 500, 400), gfx::Rect(), PERSISTED, | 537 gfx::Rect(-471, 739, 500, 400), gfx::Rect(), PERSISTED, |
| 525 &window_bounds, NULL, gfx::Rect()); | 538 &window_bounds, NULL, gfx::Rect()); |
| 526 EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 738 /* not 739 */, 500, 400), | 539 EXPECT_EQ(gfx::Rect(-470 /* not -471 */, |
| 527 window_bounds); | 540 738 /* not 739 */, |
| 541 500, |
| 542 400).ToString(), |
| 543 window_bounds.ToString()); |
| 528 } | 544 } |
| 529 | 545 |
| 530 { // off the bottomright and the minimum visibility condition is satisified by | 546 { // off the bottomright and the minimum visibility condition is satisified by |
| 531 // relocation. | 547 // relocation. |
| 532 gfx::Rect window_bounds; | 548 gfx::Rect window_bounds; |
| 533 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 549 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 534 gfx::Rect(995, 739, 500, 400), gfx::Rect(), PERSISTED, | 550 gfx::Rect(995, 739, 500, 400), gfx::Rect(), PERSISTED, |
| 535 &window_bounds, NULL, gfx::Rect()); | 551 &window_bounds, NULL, gfx::Rect()); |
| 536 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 738 /* not 739 */, 500, 400), | 552 EXPECT_EQ(gfx::Rect(994 /* not 995 */, |
| 537 window_bounds); | 553 738 /* not 739 */, |
| 554 500, |
| 555 400).ToString(), |
| 556 window_bounds.ToString()); |
| 538 } | 557 } |
| 539 | 558 |
| 540 { // entirely off left | 559 { // entirely off left |
| 541 gfx::Rect window_bounds; | 560 gfx::Rect window_bounds; |
| 542 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 561 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 543 gfx::Rect(-700, 50, 500, 400), gfx::Rect(), PERSISTED, | 562 gfx::Rect(-700, 50, 500, 400), gfx::Rect(), PERSISTED, |
| 544 &window_bounds, NULL, gfx::Rect()); | 563 &window_bounds, NULL, gfx::Rect()); |
| 545 EXPECT_EQ(gfx::Rect(-470 /* not -700 */, 50, 500, 400), window_bounds); | 564 EXPECT_EQ(gfx::Rect(-470 /* not -700 */, 50, 500, 400).ToString(), |
| 565 window_bounds.ToString()); |
| 546 } | 566 } |
| 547 | 567 |
| 548 { // entirely off left (monitor was detached since last run) | 568 { // entirely off left (monitor was detached since last run) |
| 549 gfx::Rect window_bounds; | 569 gfx::Rect window_bounds; |
| 550 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 570 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 551 gfx::Rect(-700, 50, 500, 400), left_nonprimary, PERSISTED, | 571 gfx::Rect(-700, 50, 500, 400), left_nonprimary, PERSISTED, |
| 552 &window_bounds, NULL, gfx::Rect()); | 572 &window_bounds, NULL, gfx::Rect()); |
| 553 EXPECT_EQ(gfx::Rect(0, 50, 500, 400), window_bounds); | 573 EXPECT_EQ("0,50 500x400", window_bounds.ToString()); |
| 554 } | 574 } |
| 555 | 575 |
| 556 { // entirely off top | 576 { // entirely off top |
| 557 gfx::Rect window_bounds; | 577 gfx::Rect window_bounds; |
| 558 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 578 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 559 gfx::Rect(50, -500, 500, 400), gfx::Rect(), PERSISTED, | 579 gfx::Rect(50, -500, 500, 400), gfx::Rect(), PERSISTED, |
| 560 &window_bounds, NULL, gfx::Rect()); | 580 &window_bounds, NULL, gfx::Rect()); |
| 561 EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds); | 581 EXPECT_EQ("50,0 500x400", window_bounds.ToString()); |
| 562 } | 582 } |
| 563 | 583 |
| 564 { // entirely off top (monitor was detached since last run) | 584 { // entirely off top (monitor was detached since last run) |
| 565 gfx::Rect window_bounds; | 585 gfx::Rect window_bounds; |
| 566 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 586 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 567 gfx::Rect(50, -500, 500, 400), top_nonprimary, | 587 gfx::Rect(50, -500, 500, 400), top_nonprimary, |
| 568 PERSISTED, &window_bounds, NULL, gfx::Rect()); | 588 PERSISTED, &window_bounds, NULL, gfx::Rect()); |
| 569 EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds); | 589 EXPECT_EQ("50,0 500x400", window_bounds.ToString()); |
| 570 } | 590 } |
| 571 | 591 |
| 572 { // entirely off right | 592 { // entirely off right |
| 573 gfx::Rect window_bounds; | 593 gfx::Rect window_bounds; |
| 574 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 594 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 575 gfx::Rect(1200, 50, 500, 400), gfx::Rect(), PERSISTED, | 595 gfx::Rect(1200, 50, 500, 400), gfx::Rect(), PERSISTED, |
| 576 &window_bounds, NULL, gfx::Rect()); | 596 &window_bounds, NULL, gfx::Rect()); |
| 577 EXPECT_EQ(gfx::Rect(994 /* not 1200 */, 50, 500, 400), window_bounds); | 597 EXPECT_EQ(gfx::Rect(994 /* not 1200 */, 50, 500, 400).ToString(), |
| 598 window_bounds.ToString()); |
| 578 } | 599 } |
| 579 | 600 |
| 580 { // entirely off right (monitor was detached since last run) | 601 { // entirely off right (monitor was detached since last run) |
| 581 gfx::Rect window_bounds; | 602 gfx::Rect window_bounds; |
| 582 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 603 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 583 gfx::Rect(1200, 50, 500, 400), right_nonprimary, | 604 gfx::Rect(1200, 50, 500, 400), right_nonprimary, |
| 584 PERSISTED, &window_bounds, NULL, gfx::Rect()); | 605 PERSISTED, &window_bounds, NULL, gfx::Rect()); |
| 585 EXPECT_EQ(gfx::Rect(524, 50, 500, 400), window_bounds); | 606 EXPECT_EQ("524,50 500x400", window_bounds.ToString()); |
| 586 } | 607 } |
| 587 | 608 |
| 588 { // entirely off bottom | 609 { // entirely off bottom |
| 589 gfx::Rect window_bounds; | 610 gfx::Rect window_bounds; |
| 590 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 611 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 591 gfx::Rect(50, 800, 500, 400), gfx::Rect(), PERSISTED, | 612 gfx::Rect(50, 800, 500, 400), gfx::Rect(), PERSISTED, |
| 592 &window_bounds, NULL, gfx::Rect()); | 613 &window_bounds, NULL, gfx::Rect()); |
| 593 EXPECT_EQ(gfx::Rect(50, 738 /* not 800 */, 500, 400), window_bounds); | 614 EXPECT_EQ(gfx::Rect(50, 738 /* not 800 */, 500, 400).ToString(), |
| 615 window_bounds.ToString()); |
| 594 } | 616 } |
| 595 | 617 |
| 596 { // entirely off bottom (monitor was detached since last run) | 618 { // entirely off bottom (monitor was detached since last run) |
| 597 gfx::Rect window_bounds; | 619 gfx::Rect window_bounds; |
| 598 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 620 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 599 gfx::Rect(50, 800, 500, 400), bottom_nonprimary, | 621 gfx::Rect(50, 800, 500, 400), bottom_nonprimary, |
| 600 PERSISTED, &window_bounds, NULL, gfx::Rect()); | 622 PERSISTED, &window_bounds, NULL, gfx::Rect()); |
| 601 EXPECT_EQ(gfx::Rect(50, 368, 500, 400), window_bounds); | 623 EXPECT_EQ("50,368 500x400", window_bounds.ToString()); |
| 602 } | 624 } |
| 603 } | 625 } |
| 604 | 626 |
| 605 // Test that a newly created window gets positioned over a previously created | 627 // Test the placement of newly created windows. |
| 606 // window. | 628 TEST_F(WindowSizerTestWithBrowser, PlaceNewWindows) { |
| 607 TEST_F(WindowSizerTestWithBrowser, PlaceNewWindowOverOldWindow) { | |
| 608 // Create a dummy window. | 629 // Create a dummy window. |
| 609 scoped_ptr<aura::Window> window( | 630 scoped_ptr<aura::Window> window( |
| 610 aura::test::CreateTestWindowWithId(0, NULL)); | 631 aura::test::CreateTestWindowWithId(0, NULL)); |
| 611 window->SetBounds(gfx::Rect(16, 32, 640, 320)); | 632 window->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 612 | 633 |
| 613 scoped_ptr<aura::Window> popup( | 634 scoped_ptr<aura::Window> popup( |
| 614 aura::test::CreateTestWindowWithId(1, NULL)); | 635 aura::test::CreateTestWindowWithId(1, NULL)); |
| 615 popup->SetBounds(gfx::Rect(16, 32, 128, 256)); | 636 popup->SetBounds(gfx::Rect(16, 32, 128, 256)); |
| 616 | 637 |
| 617 scoped_ptr<aura::Window> panel( | 638 scoped_ptr<aura::Window> panel( |
| 618 aura::test::CreateTestWindowWithId(2, NULL)); | 639 aura::test::CreateTestWindowWithId(2, NULL)); |
| 619 panel->SetBounds(gfx::Rect(32, 48, 256, 512)); | 640 panel->SetBounds(gfx::Rect(32, 48, 256, 512)); |
| 620 | 641 |
| 621 // Create a browser which we can use to pass into the GetWindowBounds | 642 // Create a browser which we can use to pass into the GetWindowBounds |
| 622 // function. | 643 // function. |
| 623 scoped_ptr<TestingProfile> profile(new TestingProfile()); | 644 scoped_ptr<TestingProfile> profile(new TestingProfile()); |
| 624 // Creating a popup handler here to make sure it does not interfere with the | 645 // Creating a popup handler here to make sure it does not interfere with the |
| 625 // existing windows. | 646 // existing windows. |
| 626 scoped_ptr<Browser> browser( | 647 scoped_ptr<Browser> browser( |
| 627 chrome::CreateBrowserWithTestWindowForProfile(profile.get())); | 648 chrome::CreateBrowserWithTestWindowForProfile(profile.get())); |
| 628 | 649 |
| 629 // Creating a popup handler here to make sure it does not interfere with the | 650 // Creating a popup handler here to make sure it does not interfere with the |
| 630 // existing windows. | 651 // existing windows. |
| 631 scoped_ptr<BrowserWindow> browser_window( | 652 scoped_ptr<BrowserWindow> browser_window( |
| 632 new TestBrowserWindowAura(window.get())); | 653 new TestBrowserWindowAura(window.get())); |
| 633 Browser::CreateParams window_params(profile.get()); | 654 Browser::CreateParams window_params(profile.get()); |
| 634 window_params.window = browser_window.get(); | 655 window_params.window = browser_window.get(); |
| 635 scoped_ptr<Browser> window_owning_browser(new Browser(window_params)); | 656 scoped_ptr<Browser> window_owning_browser(new Browser(window_params)); |
| 657 window_owning_browser->window()->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 636 | 658 |
| 637 // Creating a popup to make sure it does not interfere with the positioning. | 659 // Creating a popup to make sure it does not interfere with the positioning. |
| 638 scoped_ptr<BrowserWindow> browser_popup( | 660 scoped_ptr<BrowserWindow> browser_popup( |
| 639 new TestBrowserWindowAura(popup.get())); | 661 new TestBrowserWindowAura(popup.get())); |
| 640 Browser::CreateParams popup_params(Browser::TYPE_POPUP, profile.get()); | 662 Browser::CreateParams popup_params(Browser::TYPE_POPUP, profile.get()); |
| 641 popup_params.window = browser_popup.get(); | 663 popup_params.window = browser_popup.get(); |
| 642 scoped_ptr<Browser> popup_owning_browser(new Browser(popup_params)); | 664 scoped_ptr<Browser> popup_owning_browser(new Browser(popup_params)); |
| 665 popup_owning_browser->window()->SetBounds(gfx::Rect(16, 32, 128, 256)); |
| 643 | 666 |
| 644 // Creating a panel to make sure it does not interfere with the positioning. | 667 // Creating a panel to make sure it does not interfere with the positioning. |
| 645 scoped_ptr<BrowserWindow> browser_panel( | 668 scoped_ptr<BrowserWindow> browser_panel( |
| 646 new TestBrowserWindowAura(panel.get())); | 669 new TestBrowserWindowAura(panel.get())); |
| 647 Browser::CreateParams panel_params(Browser::TYPE_POPUP, profile.get()); | 670 Browser::CreateParams panel_params(Browser::TYPE_POPUP, profile.get()); |
| 648 panel_params.window = browser_panel.get(); | 671 panel_params.window = browser_panel.get(); |
| 649 scoped_ptr<Browser> panel_owning_browser(new Browser(panel_params)); | 672 scoped_ptr<Browser> panel_owning_browser(new Browser(panel_params)); |
| 673 panel_owning_browser->window()->SetBounds(gfx::Rect(32, 48, 256, 512)); |
| 650 | 674 |
| 651 window->Show(); | 675 window->Show(); |
| 652 { // With a shown window it's size should get returned. | 676 { // With a shown window it's size should get returned. |
| 653 gfx::Rect window_bounds; | 677 gfx::Rect window_bounds; |
| 654 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 678 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 655 gfx::Rect(50, 100, 300, 150), bottom_nonprimary, | 679 gfx::Rect(50, 100, 300, 150), bottom_nonprimary, |
| 656 PERSISTED, &window_bounds, browser.get(), gfx::Rect()); | 680 PERSISTED, &window_bounds, browser.get(), gfx::Rect()); |
| 657 EXPECT_EQ(gfx::Rect(16, 32, 640, 320), window_bounds); | 681 // The position should be right flush. |
| 682 EXPECT_EQ("384,32 640x320", window_bounds.ToString()); |
| 683 // In addition the other window should have moved left flush. |
| 684 EXPECT_EQ("0,32 640x320", window->bounds().ToString()); |
| 685 } |
| 686 |
| 687 { // With the window shown - but more on the right side then on the left |
| 688 // side (and partially out of the screen), it should default to the other |
| 689 // side and inside the screen. |
| 690 window->SetBounds(gfx::Rect(350, 600, 640, 320)); |
| 691 gfx::Rect window_bounds; |
| 692 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 693 gfx::Rect(50, 100, 300, 150), bottom_nonprimary, |
| 694 PERSISTED, &window_bounds, browser.get(), gfx::Rect()); |
| 695 // The position should be left & bottom flush. |
| 696 EXPECT_EQ("0,448 640x320", window_bounds.ToString()); |
| 697 // In addition the other window should have moved right flush. |
| 698 EXPECT_EQ("384,600 640x320", window->bounds().ToString()); |
| 699 } |
| 700 |
| 701 { // If the second windows right side is already over the right side of the |
| 702 // screen, it will not move back into the screen. |
| 703 window->SetBounds(gfx::Rect(1000, 600, 640, 320)); |
| 704 gfx::Rect window_bounds; |
| 705 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 706 gfx::Rect(50, 100, 300, 150), bottom_nonprimary, |
| 707 PERSISTED, &window_bounds, browser.get(), gfx::Rect()); |
| 708 // The position should be left & bottom flush. |
| 709 EXPECT_EQ("0,448 640x320", window_bounds.ToString()); |
| 710 // If the other window was already beyond the point to get right flush |
| 711 // it will remain where it is. |
| 712 EXPECT_EQ("1000,600 640x320", window->bounds().ToString()); |
| 658 } | 713 } |
| 659 | 714 |
| 660 { // Make sure that popups do not get changed. | 715 { // Make sure that popups do not get changed. |
| 661 gfx::Rect window_bounds; | 716 gfx::Rect window_bounds; |
| 662 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 717 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 663 gfx::Rect(50, 100, 300, 150), bottom_nonprimary, | 718 gfx::Rect(50, 100, 300, 150), bottom_nonprimary, |
| 664 PERSISTED, &window_bounds, popup_owning_browser.get(), | 719 PERSISTED, &window_bounds, popup_owning_browser.get(), |
| 665 gfx::Rect()); | 720 gfx::Rect()); |
| 666 EXPECT_EQ(gfx::Rect(50, 100, 300, 150), window_bounds); | 721 EXPECT_EQ("50,100 300x150", window_bounds.ToString()); |
| 667 } | 722 } |
| 668 | 723 |
| 669 window->SetBounds(gfx::Rect(816, 720, 640, 320)); | 724 window->Hide(); |
| 670 // Verifies newly created windows appear on screen. | 725 { // If a window is there but not shown the persisted default should be used. |
| 671 { | |
| 672 gfx::Rect window_bounds; | 726 gfx::Rect window_bounds; |
| 673 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 727 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 674 gfx::Rect(50, 100, 300, 150), bottom_nonprimary, | 728 gfx::Rect(50, 100, 300, 150), bottom_nonprimary, |
| 675 PERSISTED, &window_bounds, browser.get(), gfx::Rect()); | 729 PERSISTED, &window_bounds, browser.get(), gfx::Rect()); |
| 676 EXPECT_EQ("384,448 640x320", window_bounds.ToString()); | 730 EXPECT_EQ("50,100 300x150", window_bounds.ToString()); |
| 677 } | 731 } |
| 678 | 732 |
| 679 window->Hide(); | |
| 680 { // If a window is there but not shown the default should be returned. | 733 { // If a window is there but not shown the default should be returned. |
| 681 // The existing popup should not have any impact as well. | |
| 682 gfx::Rect window_bounds; | 734 gfx::Rect window_bounds; |
| 683 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 735 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
| 684 gfx::Rect(50, 100, 300, 150), bottom_nonprimary, | 736 gfx::Rect(), bottom_nonprimary, |
| 685 PERSISTED, &window_bounds, browser.get(), gfx::Rect()); | 737 DEFAULT, &window_bounds, browser.get(), gfx::Rect()); |
| 686 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | 738 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, |
| 687 WindowSizer::kDesktopBorderSize, | 739 WindowSizer::kDesktopBorderSize, |
| 688 1024 - 2 * WindowSizer::kDesktopBorderSize, | 740 1024 - 2 * WindowSizer::kDesktopBorderSize, |
| 689 768 - WindowSizer::kDesktopBorderSize), | 741 768 - WindowSizer::kDesktopBorderSize).ToString(), |
| 690 window_bounds); | 742 window_bounds.ToString()); |
| 691 } | 743 } |
| 692 } | 744 } |
| 693 | 745 |
| 694 // Test that the window is sized appropriately for the first run experience | 746 // Test that the window is sized appropriately for the first run experience |
| 695 // where the default window bounds calculation is invoked. | 747 // where the default window bounds calculation is invoked. |
| 696 TEST_F(WindowSizerTest, AdjustFitSize) { | 748 TEST_F(WindowSizerTest, AdjustFitSize) { |
| 697 { // Check that the window gets resized to the screen. | 749 { // Check that the window gets resized to the screen. |
| 698 gfx::Rect window_bounds; | 750 gfx::Rect window_bounds; |
| 699 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), | 751 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), |
| 700 gfx::Rect(), DEFAULT, &window_bounds, NULL, | 752 gfx::Rect(), DEFAULT, &window_bounds, NULL, |
| 701 gfx::Rect(-10, -10, 1024 + 20, 768 + 20)); | 753 gfx::Rect(-10, -10, 1024 + 20, 768 + 20)); |
| 702 EXPECT_EQ(gfx::Rect(0, 0, 1024, 768), window_bounds); | 754 EXPECT_EQ("0,0 1024x768", window_bounds.ToString()); |
| 703 } | 755 } |
| 704 | 756 |
| 705 { // Check that a window which hangs out of the screen get moved back in. | 757 { // Check that a window which hangs out of the screen get moved back in. |
| 706 gfx::Rect window_bounds; | 758 gfx::Rect window_bounds; |
| 707 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), | 759 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), |
| 708 gfx::Rect(), DEFAULT, &window_bounds, NULL, | 760 gfx::Rect(), DEFAULT, &window_bounds, NULL, |
| 709 gfx::Rect(1020, 700, 100, 100)); | 761 gfx::Rect(1020, 700, 100, 100)); |
| 710 EXPECT_EQ(gfx::Rect(924, 668, 100, 100), window_bounds); | 762 EXPECT_EQ("924,668 100x100", window_bounds.ToString()); |
| 711 } | 763 } |
| 712 } | 764 } |
| OLD | NEW |