| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/common/wm/dock/docked_window_layout_manager.h" | 5 #include "ash/common/wm/dock/docked_window_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_window_aura.h" | 7 #include "ash/aura/wm_window_aura.h" |
| 8 #include "ash/common/shelf/wm_shelf.h" | 8 #include "ash/common/shelf/wm_shelf.h" |
| 9 #include "ash/common/shell_window_ids.h" | 9 #include "ash/common/shell_window_ids.h" |
| 10 #include "ash/common/wm/panels/panel_layout_manager.h" | 10 #include "ash/common/wm/panels/panel_layout_manager.h" |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 201 |
| 202 // Location at start of the drag in |window->parent()|'s coordinates. | 202 // Location at start of the drag in |window->parent()|'s coordinates. |
| 203 gfx::Point initial_location_in_parent_; | 203 gfx::Point initial_location_in_parent_; |
| 204 | 204 |
| 205 DISALLOW_COPY_AND_ASSIGN(DockedWindowLayoutManagerTest); | 205 DISALLOW_COPY_AND_ASSIGN(DockedWindowLayoutManagerTest); |
| 206 }; | 206 }; |
| 207 | 207 |
| 208 // Tests that a created window is successfully added to the dock | 208 // Tests that a created window is successfully added to the dock |
| 209 // layout manager. | 209 // layout manager. |
| 210 TEST_P(DockedWindowLayoutManagerTest, AddOneWindow) { | 210 TEST_P(DockedWindowLayoutManagerTest, AddOneWindow) { |
| 211 if (!SupportsHostWindowResize()) | |
| 212 return; | |
| 213 | |
| 214 gfx::Rect bounds(0, 0, 201, 201); | 211 gfx::Rect bounds(0, 0, 201, 201); |
| 215 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); | 212 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); |
| 216 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); | 213 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); |
| 217 | 214 |
| 218 // The window should be attached and docked at the right edge. | 215 // The window should be attached and docked at the right edge. |
| 219 // Its width should shrink or grow to ideal width. | 216 // Its width should shrink or grow to ideal width. |
| 220 EXPECT_EQ(window->GetRootWindow()->bounds().right(), | 217 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| 221 window->GetBoundsInScreen().right()); | 218 window->GetBoundsInScreen().right()); |
| 222 EXPECT_EQ(ideal_width(), window->bounds().width()); | 219 EXPECT_EQ(ideal_width(), window->bounds().width()); |
| 223 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | 220 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); |
| 224 } | 221 } |
| 225 | 222 |
| 226 // Tests that a docked window's bounds cannot be changed programmatically. | 223 // Tests that a docked window's bounds cannot be changed programmatically. |
| 227 TEST_P(DockedWindowLayoutManagerTest, DockedWindowBoundsDontChange) { | 224 TEST_P(DockedWindowLayoutManagerTest, DockedWindowBoundsDontChange) { |
| 228 if (!SupportsHostWindowResize()) | |
| 229 return; | |
| 230 | |
| 231 gfx::Rect bounds(0, 0, 201, 201); | 225 gfx::Rect bounds(0, 0, 201, 201); |
| 232 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); | 226 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); |
| 233 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); | 227 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); |
| 234 | 228 |
| 235 // The window should be attached and docked at the right edge. | 229 // The window should be attached and docked at the right edge. |
| 236 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | 230 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); |
| 237 | 231 |
| 238 bounds = window->GetBoundsInScreen(); | 232 bounds = window->GetBoundsInScreen(); |
| 239 window->SetBounds(gfx::Rect(210, 210, 210, 210)); | 233 window->SetBounds(gfx::Rect(210, 210, 210, 210)); |
| 240 EXPECT_EQ(bounds.ToString(), window->GetBoundsInScreen().ToString()); | 234 EXPECT_EQ(bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 241 } | 235 } |
| 242 | 236 |
| 243 // Tests that with a window docked on the left the auto-placing logic in | 237 // Tests that with a window docked on the left the auto-placing logic in |
| 244 // RearrangeVisibleWindowOnShow places windows flush with work area edges. | 238 // RearrangeVisibleWindowOnShow places windows flush with work area edges. |
| 245 TEST_P(DockedWindowLayoutManagerTest, AutoPlacingLeft) { | 239 TEST_P(DockedWindowLayoutManagerTest, AutoPlacingLeft) { |
| 246 if (!SupportsHostWindowResize()) | |
| 247 return; | |
| 248 | |
| 249 gfx::Rect bounds(0, 0, 201, 201); | 240 gfx::Rect bounds(0, 0, 201, 201); |
| 250 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); | 241 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); |
| 251 DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), 0); | 242 DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), 0); |
| 252 | 243 |
| 253 // The window should be attached and snapped to the right side of the screen. | 244 // The window should be attached and snapped to the right side of the screen. |
| 254 EXPECT_EQ(window->GetRootWindow()->bounds().x(), | 245 EXPECT_EQ(window->GetRootWindow()->bounds().x(), |
| 255 window->GetBoundsInScreen().x()); | 246 window->GetBoundsInScreen().x()); |
| 256 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | 247 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); |
| 257 | 248 |
| 258 DockedWindowLayoutManager* manager = | 249 DockedWindowLayoutManager* manager = |
| (...skipping 28 matching lines...) Expand all Loading... |
| 287 window1->bounds().ToString()); | 278 window1->bounds().ToString()); |
| 288 EXPECT_EQ( | 279 EXPECT_EQ( |
| 289 base::IntToString(desktop_area.width() - window2->bounds().width()) + | 280 base::IntToString(desktop_area.width() - window2->bounds().width()) + |
| 290 ",48 150x300", | 281 ",48 150x300", |
| 291 window2->bounds().ToString()); | 282 window2->bounds().ToString()); |
| 292 } | 283 } |
| 293 | 284 |
| 294 // Tests that with a window docked on the right the auto-placing logic in | 285 // Tests that with a window docked on the right the auto-placing logic in |
| 295 // RearrangeVisibleWindowOnShow places windows flush with work area edges. | 286 // RearrangeVisibleWindowOnShow places windows flush with work area edges. |
| 296 TEST_P(DockedWindowLayoutManagerTest, AutoPlacingRight) { | 287 TEST_P(DockedWindowLayoutManagerTest, AutoPlacingRight) { |
| 297 if (!SupportsHostWindowResize()) | |
| 298 return; | |
| 299 | |
| 300 gfx::Rect bounds(0, 0, 201, 201); | 288 gfx::Rect bounds(0, 0, 201, 201); |
| 301 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); | 289 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); |
| 302 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); | 290 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); |
| 303 | 291 |
| 304 // The window should be attached and snapped to the right side of the screen. | 292 // The window should be attached and snapped to the right side of the screen. |
| 305 EXPECT_EQ(window->GetRootWindow()->bounds().right(), | 293 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| 306 window->GetBoundsInScreen().right()); | 294 window->GetBoundsInScreen().right()); |
| 307 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | 295 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); |
| 308 | 296 |
| 309 DockedWindowLayoutManager* manager = | 297 DockedWindowLayoutManager* manager = |
| (...skipping 27 matching lines...) Expand all Loading... |
| 337 EXPECT_EQ(base::IntToString(desktop_area.width() - window2->bounds().width() - | 325 EXPECT_EQ(base::IntToString(desktop_area.width() - window2->bounds().width() - |
| 338 docked_width(manager) - min_dock_gap()) + | 326 docked_width(manager) - min_dock_gap()) + |
| 339 ",48 256x512", | 327 ",48 256x512", |
| 340 window2->bounds().ToString()); | 328 window2->bounds().ToString()); |
| 341 } | 329 } |
| 342 | 330 |
| 343 // Tests that with a window docked on the right the auto-placing logic in | 331 // Tests that with a window docked on the right the auto-placing logic in |
| 344 // RearrangeVisibleWindowOnShow places windows flush with work area edges. | 332 // RearrangeVisibleWindowOnShow places windows flush with work area edges. |
| 345 // Test case for the secondary screen. | 333 // Test case for the secondary screen. |
| 346 TEST_P(DockedWindowLayoutManagerTest, AutoPlacingRightSecondScreen) { | 334 TEST_P(DockedWindowLayoutManagerTest, AutoPlacingRightSecondScreen) { |
| 347 if (!SupportsMultipleDisplays() || !SupportsHostWindowResize()) | 335 if (!SupportsMultipleDisplays()) |
| 348 return; | 336 return; |
| 349 | 337 |
| 350 // Create a dual screen layout. | 338 // Create a dual screen layout. |
| 351 UpdateDisplay("600x600,600x600"); | 339 UpdateDisplay("600x600,600x600"); |
| 352 | 340 |
| 353 gfx::Rect bounds(600, 0, 201, 201); | 341 gfx::Rect bounds(600, 0, 201, 201); |
| 354 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); | 342 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); |
| 355 // Drag pointer to the right edge of the second screen. | 343 // Drag pointer to the right edge of the second screen. |
| 356 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); | 344 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); |
| 357 | 345 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 EXPECT_EQ("600,32 231x320", window1->GetBoundsInScreen().ToString()); | 381 EXPECT_EQ("600,32 231x320", window1->GetBoundsInScreen().ToString()); |
| 394 EXPECT_EQ( | 382 EXPECT_EQ( |
| 395 base::IntToString(600 + desktop_area.width() - window2->bounds().width() - | 383 base::IntToString(600 + desktop_area.width() - window2->bounds().width() - |
| 396 docked_width(manager) - min_dock_gap()) + | 384 docked_width(manager) - min_dock_gap()) + |
| 397 ",48 256x512", | 385 ",48 256x512", |
| 398 window2->GetBoundsInScreen().ToString()); | 386 window2->GetBoundsInScreen().ToString()); |
| 399 } | 387 } |
| 400 | 388 |
| 401 // Adds two windows and tests that the gaps are evenly distributed. | 389 // Adds two windows and tests that the gaps are evenly distributed. |
| 402 TEST_P(DockedWindowLayoutManagerTest, AddTwoWindows) { | 390 TEST_P(DockedWindowLayoutManagerTest, AddTwoWindows) { |
| 403 if (!SupportsHostWindowResize()) | |
| 404 return; | |
| 405 | |
| 406 std::unique_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 391 std::unique_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 407 std::unique_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 202))); | 392 std::unique_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 202))); |
| 408 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 393 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 409 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 300); | 394 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 300); |
| 410 | 395 |
| 411 // The windows should be attached and snapped to the right side of the screen. | 396 // The windows should be attached and snapped to the right side of the screen. |
| 412 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), | 397 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| 413 w1->GetBoundsInScreen().right()); | 398 w1->GetBoundsInScreen().right()); |
| 414 EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id()); | 399 EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id()); |
| 415 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), | 400 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), |
| 416 w2->GetBoundsInScreen().right()); | 401 w2->GetBoundsInScreen().right()); |
| 417 EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id()); | 402 EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id()); |
| 418 | 403 |
| 419 // Test that the gaps differ at most by a single pixel. | 404 // Test that the gaps differ at most by a single pixel. |
| 420 gfx::Rect work_area = display::Screen::GetScreen() | 405 gfx::Rect work_area = display::Screen::GetScreen() |
| 421 ->GetDisplayNearestWindow(w1.get()) | 406 ->GetDisplayNearestWindow(w1.get()) |
| 422 .work_area(); | 407 .work_area(); |
| 423 int gap1 = w1->GetBoundsInScreen().y(); | 408 int gap1 = w1->GetBoundsInScreen().y(); |
| 424 int gap2 = w2->GetBoundsInScreen().y() - w1->GetBoundsInScreen().bottom(); | 409 int gap2 = w2->GetBoundsInScreen().y() - w1->GetBoundsInScreen().bottom(); |
| 425 int gap3 = work_area.bottom() - w2->GetBoundsInScreen().bottom(); | 410 int gap3 = work_area.bottom() - w2->GetBoundsInScreen().bottom(); |
| 426 EXPECT_EQ(0, gap1); | 411 EXPECT_EQ(0, gap1); |
| 427 EXPECT_NEAR(gap2, min_dock_gap(), 1); | 412 EXPECT_NEAR(gap2, min_dock_gap(), 1); |
| 428 EXPECT_EQ(0, gap3); | 413 EXPECT_EQ(0, gap3); |
| 429 } | 414 } |
| 430 | 415 |
| 431 // Adds two non-overlapping windows and tests layout after a drag. | 416 // Adds two non-overlapping windows and tests layout after a drag. |
| 432 TEST_P(DockedWindowLayoutManagerTest, TwoWindowsDragging) { | 417 TEST_P(DockedWindowLayoutManagerTest, TwoWindowsDragging) { |
| 433 if (!SupportsHostWindowResize()) | |
| 434 return; | |
| 435 | |
| 436 std::unique_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 418 std::unique_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 437 std::unique_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 202))); | 419 std::unique_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 202))); |
| 438 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 420 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 439 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 300); | 421 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 300); |
| 440 | 422 |
| 441 // The windows should be attached and snapped to the right side of the screen. | 423 // The windows should be attached and snapped to the right side of the screen. |
| 442 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), | 424 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| 443 w1->GetBoundsInScreen().right()); | 425 w1->GetBoundsInScreen().right()); |
| 444 EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id()); | 426 EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id()); |
| 445 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), | 427 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 458 int gap1 = w2->GetBoundsInScreen().y() - work_area.y(); | 440 int gap1 = w2->GetBoundsInScreen().y() - work_area.y(); |
| 459 int gap2 = w1->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); | 441 int gap2 = w1->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); |
| 460 int gap3 = work_area.bottom() - w1->GetBoundsInScreen().bottom(); | 442 int gap3 = work_area.bottom() - w1->GetBoundsInScreen().bottom(); |
| 461 EXPECT_EQ(0, gap1); | 443 EXPECT_EQ(0, gap1); |
| 462 EXPECT_NEAR(gap2, min_dock_gap(), 1); | 444 EXPECT_NEAR(gap2, min_dock_gap(), 1); |
| 463 EXPECT_EQ(0, gap3); | 445 EXPECT_EQ(0, gap3); |
| 464 } | 446 } |
| 465 | 447 |
| 466 // Adds three overlapping windows and tests layout after a drag. | 448 // Adds three overlapping windows and tests layout after a drag. |
| 467 TEST_P(DockedWindowLayoutManagerTest, ThreeWindowsDragging) { | 449 TEST_P(DockedWindowLayoutManagerTest, ThreeWindowsDragging) { |
| 468 if (!SupportsHostWindowResize()) | |
| 469 return; | |
| 470 UpdateDisplay("600x1000"); | 450 UpdateDisplay("600x1000"); |
| 471 | 451 |
| 472 std::unique_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 310))); | 452 std::unique_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 310))); |
| 473 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 453 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 474 std::unique_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 310))); | 454 std::unique_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 310))); |
| 475 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 500); | 455 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 500); |
| 476 std::unique_ptr<aura::Window> w3(CreateTestWindow(gfx::Rect(0, 0, 220, 310))); | 456 std::unique_ptr<aura::Window> w3(CreateTestWindow(gfx::Rect(0, 0, 220, 310))); |
| 477 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w3.get(), 600); | 457 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w3.get(), 600); |
| 478 | 458 |
| 479 // All windows should be attached and snapped to the right side of the screen. | 459 // All windows should be attached and snapped to the right side of the screen. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 gap3 = w3->GetBoundsInScreen().y() - w1->GetBoundsInScreen().bottom(); | 501 gap3 = w3->GetBoundsInScreen().y() - w1->GetBoundsInScreen().bottom(); |
| 522 gap4 = work_area.bottom() - w3->GetBoundsInScreen().bottom(); | 502 gap4 = work_area.bottom() - w3->GetBoundsInScreen().bottom(); |
| 523 EXPECT_EQ(0, gap1); | 503 EXPECT_EQ(0, gap1); |
| 524 EXPECT_NEAR(gap2, min_dock_gap(), 1); | 504 EXPECT_NEAR(gap2, min_dock_gap(), 1); |
| 525 EXPECT_NEAR(gap3, min_dock_gap(), 1); | 505 EXPECT_NEAR(gap3, min_dock_gap(), 1); |
| 526 EXPECT_EQ(0, gap4); | 506 EXPECT_EQ(0, gap4); |
| 527 } | 507 } |
| 528 | 508 |
| 529 // Adds three windows in bottom display and tests layout after a drag. | 509 // Adds three windows in bottom display and tests layout after a drag. |
| 530 TEST_P(DockedWindowLayoutManagerTest, ThreeWindowsDraggingSecondScreen) { | 510 TEST_P(DockedWindowLayoutManagerTest, ThreeWindowsDraggingSecondScreen) { |
| 531 if (!SupportsMultipleDisplays() || !SupportsHostWindowResize()) | 511 if (!SupportsMultipleDisplays()) |
| 532 return; | 512 return; |
| 533 | 513 |
| 534 // Create two screen vertical layout. | 514 // Create two screen vertical layout. |
| 535 UpdateDisplay("600x1000,600x1000"); | 515 UpdateDisplay("600x1000,600x1000"); |
| 536 // Layout the secondary display to the bottom of the primary. | 516 // Layout the secondary display to the bottom of the primary. |
| 537 ASSERT_GT(display::Screen::GetScreen()->GetNumDisplays(), 1); | 517 ASSERT_GT(display::Screen::GetScreen()->GetNumDisplays(), 1); |
| 538 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays( | 518 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays( |
| 539 test::CreateDisplayLayout(display::DisplayPlacement::BOTTOM, 0)); | 519 test::CreateDisplayLayout(display::DisplayPlacement::BOTTOM, 0)); |
| 540 | 520 |
| 541 std::unique_ptr<aura::Window> w1( | 521 std::unique_ptr<aura::Window> w1( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 gap3 = w3->GetBoundsInScreen().y() - w1->GetBoundsInScreen().bottom(); | 573 gap3 = w3->GetBoundsInScreen().y() - w1->GetBoundsInScreen().bottom(); |
| 594 gap4 = work_area.bottom() - w3->GetBoundsInScreen().bottom(); | 574 gap4 = work_area.bottom() - w3->GetBoundsInScreen().bottom(); |
| 595 EXPECT_EQ(0, gap1); | 575 EXPECT_EQ(0, gap1); |
| 596 EXPECT_NEAR(gap2, min_dock_gap(), 1); | 576 EXPECT_NEAR(gap2, min_dock_gap(), 1); |
| 597 EXPECT_NEAR(gap3, min_dock_gap(), 1); | 577 EXPECT_NEAR(gap3, min_dock_gap(), 1); |
| 598 EXPECT_EQ(0, gap4); | 578 EXPECT_EQ(0, gap4); |
| 599 } | 579 } |
| 600 | 580 |
| 601 // Tests that a second window added to the dock is resized to match. | 581 // Tests that a second window added to the dock is resized to match. |
| 602 TEST_P(DockedWindowLayoutManagerTest, TwoWindowsWidthNew) { | 582 TEST_P(DockedWindowLayoutManagerTest, TwoWindowsWidthNew) { |
| 603 if (!SupportsHostWindowResize()) | |
| 604 return; | |
| 605 | |
| 606 std::unique_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 583 std::unique_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 607 std::unique_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 280, 202))); | 584 std::unique_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 280, 202))); |
| 608 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 585 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 609 // The first window should get resized to ideal width. | 586 // The first window should get resized to ideal width. |
| 610 EXPECT_EQ(ideal_width(), w1->bounds().width()); | 587 EXPECT_EQ(ideal_width(), w1->bounds().width()); |
| 611 | 588 |
| 612 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 300); | 589 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 300); |
| 613 // The second window should get resized to the existing dock. | 590 // The second window should get resized to the existing dock. |
| 614 EXPECT_EQ(ideal_width(), w2->bounds().width()); | 591 EXPECT_EQ(ideal_width(), w2->bounds().width()); |
| 615 } | 592 } |
| 616 | 593 |
| 617 // Tests that a first non-resizable window added to the dock is not resized. | 594 // Tests that a first non-resizable window added to the dock is not resized. |
| 618 TEST_P(DockedWindowLayoutManagerTest, TwoWindowsWidthNonResizableFirst) { | 595 TEST_P(DockedWindowLayoutManagerTest, TwoWindowsWidthNonResizableFirst) { |
| 619 if (!SupportsHostWindowResize()) | |
| 620 return; | |
| 621 | |
| 622 std::unique_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 596 std::unique_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 623 w1->SetProperty(aura::client::kCanResizeKey, false); | 597 w1->SetProperty(aura::client::kCanResizeKey, false); |
| 624 std::unique_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 280, 202))); | 598 std::unique_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 280, 202))); |
| 625 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 599 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 626 // The first window should not get resized. | 600 // The first window should not get resized. |
| 627 EXPECT_EQ(201, w1->bounds().width()); | 601 EXPECT_EQ(201, w1->bounds().width()); |
| 628 | 602 |
| 629 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 300); | 603 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 300); |
| 630 // The second window should get resized to the first window's width. | 604 // The second window should get resized to the first window's width. |
| 631 EXPECT_EQ(w1->bounds().width(), w2->bounds().width()); | 605 EXPECT_EQ(w1->bounds().width(), w2->bounds().width()); |
| 632 } | 606 } |
| 633 | 607 |
| 634 // Tests that a second non-resizable window added to the dock is not resized. | 608 // Tests that a second non-resizable window added to the dock is not resized. |
| 635 TEST_P(DockedWindowLayoutManagerTest, TwoWindowsWidthNonResizableSecond) { | 609 TEST_P(DockedWindowLayoutManagerTest, TwoWindowsWidthNonResizableSecond) { |
| 636 if (!SupportsHostWindowResize()) | |
| 637 return; | |
| 638 | |
| 639 std::unique_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 610 std::unique_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 640 std::unique_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 280, 202))); | 611 std::unique_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 280, 202))); |
| 641 w2->SetProperty(aura::client::kCanResizeKey, false); | 612 w2->SetProperty(aura::client::kCanResizeKey, false); |
| 642 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 613 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 643 // The first window should get resized to ideal width. | 614 // The first window should get resized to ideal width. |
| 644 EXPECT_EQ(ideal_width(), w1->bounds().width()); | 615 EXPECT_EQ(ideal_width(), w1->bounds().width()); |
| 645 | 616 |
| 646 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 300); | 617 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 300); |
| 647 // The second window should not get resized. | 618 // The second window should not get resized. |
| 648 EXPECT_EQ(280, w2->bounds().width()); | 619 EXPECT_EQ(280, w2->bounds().width()); |
| 649 | 620 |
| 650 // The first window should get resized again - to match the second window. | 621 // The first window should get resized again - to match the second window. |
| 651 EXPECT_EQ(w1->bounds().width(), w2->bounds().width()); | 622 EXPECT_EQ(w1->bounds().width(), w2->bounds().width()); |
| 652 } | 623 } |
| 653 | 624 |
| 654 // Test that restrictions on minimum and maximum width of windows are honored. | 625 // Test that restrictions on minimum and maximum width of windows are honored. |
| 655 TEST_P(DockedWindowLayoutManagerTest, TwoWindowsWidthRestrictions) { | 626 TEST_P(DockedWindowLayoutManagerTest, TwoWindowsWidthRestrictions) { |
| 656 if (!SupportsHostWindowResize()) | |
| 657 return; | |
| 658 | |
| 659 aura::test::TestWindowDelegate delegate1; | 627 aura::test::TestWindowDelegate delegate1; |
| 660 delegate1.set_maximum_size(gfx::Size(240, 0)); | 628 delegate1.set_maximum_size(gfx::Size(240, 0)); |
| 661 std::unique_ptr<aura::Window> w1( | 629 std::unique_ptr<aura::Window> w1( |
| 662 CreateTestWindowWithDelegate(gfx::Rect(0, 0, 201, 201), &delegate1)); | 630 CreateTestWindowWithDelegate(gfx::Rect(0, 0, 201, 201), &delegate1)); |
| 663 aura::test::TestWindowDelegate delegate2; | 631 aura::test::TestWindowDelegate delegate2; |
| 664 delegate2.set_minimum_size(gfx::Size(260, 0)); | 632 delegate2.set_minimum_size(gfx::Size(260, 0)); |
| 665 std::unique_ptr<aura::Window> w2( | 633 std::unique_ptr<aura::Window> w2( |
| 666 CreateTestWindowWithDelegate(gfx::Rect(0, 0, 280, 202), &delegate2)); | 634 CreateTestWindowWithDelegate(gfx::Rect(0, 0, 280, 202), &delegate2)); |
| 667 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 635 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 668 // The first window should get resized to its maximum width. | 636 // The first window should get resized to its maximum width. |
| 669 EXPECT_EQ(240, w1->bounds().width()); | 637 EXPECT_EQ(240, w1->bounds().width()); |
| 670 | 638 |
| 671 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 300); | 639 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 300); |
| 672 // The second window should get resized to its minimum width. | 640 // The second window should get resized to its minimum width. |
| 673 EXPECT_EQ(260, w2->bounds().width()); | 641 EXPECT_EQ(260, w2->bounds().width()); |
| 674 | 642 |
| 675 // The first window should be centered relative to the second. | 643 // The first window should be centered relative to the second. |
| 676 EXPECT_EQ(w1->bounds().CenterPoint().x(), w2->bounds().CenterPoint().x()); | 644 EXPECT_EQ(w1->bounds().CenterPoint().x(), w2->bounds().CenterPoint().x()); |
| 677 } | 645 } |
| 678 | 646 |
| 679 // Test that restrictions on minimum width of windows are honored. | 647 // Test that restrictions on minimum width of windows are honored. |
| 680 TEST_P(DockedWindowLayoutManagerTest, WidthMoreThanMax) { | 648 TEST_P(DockedWindowLayoutManagerTest, WidthMoreThanMax) { |
| 681 if (!SupportsHostWindowResize()) | |
| 682 return; | |
| 683 | |
| 684 aura::test::TestWindowDelegate delegate; | 649 aura::test::TestWindowDelegate delegate; |
| 685 delegate.set_minimum_size(gfx::Size(400, 0)); | 650 delegate.set_minimum_size(gfx::Size(400, 0)); |
| 686 std::unique_ptr<aura::Window> window( | 651 std::unique_ptr<aura::Window> window( |
| 687 CreateTestWindowWithDelegate(gfx::Rect(0, 0, 400, 201), &delegate)); | 652 CreateTestWindowWithDelegate(gfx::Rect(0, 0, 400, 201), &delegate)); |
| 688 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, window.get(), 20); | 653 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, window.get(), 20); |
| 689 | 654 |
| 690 // Secondary drag ensures that we are testing the minimum size restriction | 655 // Secondary drag ensures that we are testing the minimum size restriction |
| 691 // and not just failure to get past the tiling step in SnapSizer. | 656 // and not just failure to get past the tiling step in SnapSizer. |
| 692 ASSERT_NO_FATAL_FAILURE( | 657 ASSERT_NO_FATAL_FAILURE( |
| 693 DragStartAtOffsetFromwindowOrigin(window.get(), 25, 5)); | 658 DragStartAtOffsetFromwindowOrigin(window.get(), 25, 5)); |
| 694 DragMove(150, 0); | 659 DragMove(150, 0); |
| 695 DragEnd(); | 660 DragEnd(); |
| 696 | 661 |
| 697 // The window should not get docked even though it is dragged past the edge. | 662 // The window should not get docked even though it is dragged past the edge. |
| 698 EXPECT_NE(window->GetRootWindow()->bounds().right(), | 663 EXPECT_NE(window->GetRootWindow()->bounds().right(), |
| 699 window->GetBoundsInScreen().right()); | 664 window->GetBoundsInScreen().right()); |
| 700 EXPECT_NE(kShellWindowId_DockedContainer, window->parent()->id()); | 665 EXPECT_NE(kShellWindowId_DockedContainer, window->parent()->id()); |
| 701 } | 666 } |
| 702 | 667 |
| 703 // Docks three windows and tests that the very first window gets minimized. | 668 // Docks three windows and tests that the very first window gets minimized. |
| 704 TEST_P(DockedWindowLayoutManagerTest, ThreeWindowsMinimize) { | 669 TEST_P(DockedWindowLayoutManagerTest, ThreeWindowsMinimize) { |
| 705 if (!SupportsHostWindowResize()) | |
| 706 return; | |
| 707 | |
| 708 std::unique_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 670 std::unique_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 709 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 671 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 710 std::unique_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 202))); | 672 std::unique_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 202))); |
| 711 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 200); | 673 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 200); |
| 712 std::unique_ptr<aura::Window> w3(CreateTestWindow(gfx::Rect(0, 0, 220, 204))); | 674 std::unique_ptr<aura::Window> w3(CreateTestWindow(gfx::Rect(0, 0, 220, 204))); |
| 713 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w3.get(), 300); | 675 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w3.get(), 300); |
| 714 | 676 |
| 715 // The last two windows should be attached and snapped to the right edge. | 677 // The last two windows should be attached and snapped to the right edge. |
| 716 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), | 678 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), |
| 717 w2->GetBoundsInScreen().right()); | 679 w2->GetBoundsInScreen().right()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 731 // The other two windows should be still docked. | 693 // The other two windows should be still docked. |
| 732 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMinimized()); | 694 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMinimized()); |
| 733 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsDocked()); | 695 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsDocked()); |
| 734 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMinimized()); | 696 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMinimized()); |
| 735 EXPECT_TRUE(wm::GetWindowState(w3.get())->IsDocked()); | 697 EXPECT_TRUE(wm::GetWindowState(w3.get())->IsDocked()); |
| 736 EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id()); | 698 EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id()); |
| 737 } | 699 } |
| 738 | 700 |
| 739 // Docks up to three windows and tests that they split vertical space. | 701 // Docks up to three windows and tests that they split vertical space. |
| 740 TEST_P(DockedWindowLayoutManagerTest, ThreeWindowsSplitHeightEvenly) { | 702 TEST_P(DockedWindowLayoutManagerTest, ThreeWindowsSplitHeightEvenly) { |
| 741 if (!SupportsHostWindowResize()) | |
| 742 return; | |
| 743 | |
| 744 UpdateDisplay("600x1000"); | 703 UpdateDisplay("600x1000"); |
| 745 std::unique_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 704 std::unique_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 746 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 705 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 747 std::unique_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 202))); | 706 std::unique_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 202))); |
| 748 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 200); | 707 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 200); |
| 749 | 708 |
| 750 // The two windows should be attached and snapped to the right edge. | 709 // The two windows should be attached and snapped to the right edge. |
| 751 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), | 710 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| 752 w1->GetBoundsInScreen().right()); | 711 w1->GetBoundsInScreen().right()); |
| 753 EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id()); | 712 EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 777 EXPECT_NEAR(w1->GetBoundsInScreen().height(), | 736 EXPECT_NEAR(w1->GetBoundsInScreen().height(), |
| 778 w2->GetBoundsInScreen().height(), 1); | 737 w2->GetBoundsInScreen().height(), 1); |
| 779 EXPECT_NEAR(w2->GetBoundsInScreen().height(), | 738 EXPECT_NEAR(w2->GetBoundsInScreen().height(), |
| 780 w3->GetBoundsInScreen().height(), 1); | 739 w3->GetBoundsInScreen().height(), 1); |
| 781 EXPECT_NEAR(work_area.height() / 3, w1->GetBoundsInScreen().height(), | 740 EXPECT_NEAR(work_area.height() / 3, w1->GetBoundsInScreen().height(), |
| 782 min_dock_gap() * 2); | 741 min_dock_gap() * 2); |
| 783 } | 742 } |
| 784 | 743 |
| 785 // Docks two windows and tests that restrictions on vertical size are honored. | 744 // Docks two windows and tests that restrictions on vertical size are honored. |
| 786 TEST_P(DockedWindowLayoutManagerTest, TwoWindowsHeightRestrictions) { | 745 TEST_P(DockedWindowLayoutManagerTest, TwoWindowsHeightRestrictions) { |
| 787 if (!SupportsHostWindowResize()) | |
| 788 return; | |
| 789 | |
| 790 // The first window is fixed height. | 746 // The first window is fixed height. |
| 791 aura::test::TestWindowDelegate delegate1; | 747 aura::test::TestWindowDelegate delegate1; |
| 792 delegate1.set_minimum_size(gfx::Size(0, 300)); | 748 delegate1.set_minimum_size(gfx::Size(0, 300)); |
| 793 delegate1.set_maximum_size(gfx::Size(0, 300)); | 749 delegate1.set_maximum_size(gfx::Size(0, 300)); |
| 794 std::unique_ptr<aura::Window> w1( | 750 std::unique_ptr<aura::Window> w1( |
| 795 CreateTestWindowWithDelegate(gfx::Rect(0, 0, 201, 300), &delegate1)); | 751 CreateTestWindowWithDelegate(gfx::Rect(0, 0, 201, 300), &delegate1)); |
| 796 // The second window has maximum height. | 752 // The second window has maximum height. |
| 797 aura::test::TestWindowDelegate delegate2; | 753 aura::test::TestWindowDelegate delegate2; |
| 798 delegate2.set_maximum_size(gfx::Size(0, 100)); | 754 delegate2.set_maximum_size(gfx::Size(0, 100)); |
| 799 std::unique_ptr<aura::Window> w2( | 755 std::unique_ptr<aura::Window> w2( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 819 gfx::Rect work_area = display::Screen::GetScreen() | 775 gfx::Rect work_area = display::Screen::GetScreen() |
| 820 ->GetDisplayNearestWindow(w1.get()) | 776 ->GetDisplayNearestWindow(w1.get()) |
| 821 .work_area(); | 777 .work_area(); |
| 822 EXPECT_GT(w1->GetBoundsInScreen().height(), work_area.height() / 2 + 10); | 778 EXPECT_GT(w1->GetBoundsInScreen().height(), work_area.height() / 2 + 10); |
| 823 EXPECT_LT(w2->GetBoundsInScreen().height(), work_area.height() / 2 - 10); | 779 EXPECT_LT(w2->GetBoundsInScreen().height(), work_area.height() / 2 - 10); |
| 824 } | 780 } |
| 825 | 781 |
| 826 // Tests that a docked window is moved to primary display when secondary display | 782 // Tests that a docked window is moved to primary display when secondary display |
| 827 // is disconnected and that it stays docked and properly positioned. | 783 // is disconnected and that it stays docked and properly positioned. |
| 828 TEST_P(DockedWindowLayoutManagerTest, DisplayDisconnectionMovesDocked) { | 784 TEST_P(DockedWindowLayoutManagerTest, DisplayDisconnectionMovesDocked) { |
| 829 if (!SupportsMultipleDisplays() || !SupportsHostWindowResize()) | 785 if (!SupportsMultipleDisplays()) |
| 830 return; | 786 return; |
| 831 | 787 |
| 832 // Create a dual screen layout. | 788 // Create a dual screen layout. |
| 833 UpdateDisplay("600x700,800x600"); | 789 UpdateDisplay("600x700,800x600"); |
| 834 | 790 |
| 835 gfx::Rect bounds(600, 0, 201, 201); | 791 gfx::Rect bounds(600, 0, 201, 201); |
| 836 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); | 792 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); |
| 837 // Drag pointer to the right edge of the second screen. | 793 // Drag pointer to the right edge of the second screen. |
| 838 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); | 794 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); |
| 839 | 795 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 852 EXPECT_EQ(work_area.height(), window->GetBoundsInScreen().height()); | 808 EXPECT_EQ(work_area.height(), window->GetBoundsInScreen().height()); |
| 853 } | 809 } |
| 854 | 810 |
| 855 // Tests run twice - on both panels and normal windows | 811 // Tests run twice - on both panels and normal windows |
| 856 INSTANTIATE_TEST_CASE_P(NormalOrPanel, | 812 INSTANTIATE_TEST_CASE_P(NormalOrPanel, |
| 857 DockedWindowLayoutManagerTest, | 813 DockedWindowLayoutManagerTest, |
| 858 testing::Values(ui::wm::WINDOW_TYPE_NORMAL, | 814 testing::Values(ui::wm::WINDOW_TYPE_NORMAL, |
| 859 ui::wm::WINDOW_TYPE_PANEL)); | 815 ui::wm::WINDOW_TYPE_PANEL)); |
| 860 | 816 |
| 861 } // namespace ash | 817 } // namespace ash |
| OLD | NEW |