| 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_window_resizer.h" | 5 #include "ash/wm/workspace/workspace_window_resizer.h" |
| 6 | 6 |
| 7 #include "ash/screen_ash.h" | 7 #include "ash/screen_ash.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
| 10 #include "ash/wm/property_util.h" | 10 #include "ash/wm/property_util.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate); | 43 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class WorkspaceWindowResizerTest : public test::AshTestBase { | 46 class WorkspaceWindowResizerTest : public test::AshTestBase { |
| 47 public: | 47 public: |
| 48 WorkspaceWindowResizerTest() : window_(NULL) {} | 48 WorkspaceWindowResizerTest() : window_(NULL) {} |
| 49 virtual ~WorkspaceWindowResizerTest() {} | 49 virtual ~WorkspaceWindowResizerTest() {} |
| 50 | 50 |
| 51 virtual void SetUp() OVERRIDE { | 51 virtual void SetUp() OVERRIDE { |
| 52 AshTestBase::SetUp(); | 52 AshTestBase::SetUp(); |
| 53 aura::RootWindow* root = Shell::GetInstance()->GetRootWindow(); | 53 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); |
| 54 root->SetHostSize(gfx::Size(800, kRootHeight)); | 54 root->SetHostSize(gfx::Size(800, kRootHeight)); |
| 55 | 55 |
| 56 gfx::Rect root_bounds(root->bounds()); | 56 gfx::Rect root_bounds(root->bounds()); |
| 57 EXPECT_EQ(kRootHeight, root_bounds.height()); | 57 EXPECT_EQ(kRootHeight, root_bounds.height()); |
| 58 Shell::GetInstance()->SetMonitorWorkAreaInsets(root, gfx::Insets()); | 58 Shell::GetInstance()->SetMonitorWorkAreaInsets(root, gfx::Insets()); |
| 59 window_.reset(new aura::Window(&delegate_)); | 59 window_.reset(new aura::Window(&delegate_)); |
| 60 window_->Init(ui::LAYER_NOT_DRAWN); | 60 window_->Init(ui::LAYER_NOT_DRAWN); |
| 61 window_->SetParent(root); | 61 window_->SetParent(root); |
| 62 window_->set_id(1); | 62 window_->set_id(1); |
| 63 | 63 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 78 window3_.reset(); | 78 window3_.reset(); |
| 79 AshTestBase::TearDown(); | 79 AshTestBase::TearDown(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Returns a string identifying the z-order of each of the known windows. | 82 // Returns a string identifying the z-order of each of the known windows. |
| 83 // The returned string constains the id of the known windows and is ordered | 83 // The returned string constains the id of the known windows and is ordered |
| 84 // from topmost to bottomost windows. | 84 // from topmost to bottomost windows. |
| 85 std::string WindowOrderAsString() const { | 85 std::string WindowOrderAsString() const { |
| 86 std::string result; | 86 std::string result; |
| 87 const aura::Window::Windows& windows = | 87 const aura::Window::Windows& windows = |
| 88 Shell::GetInstance()->GetRootWindow()->children(); | 88 Shell::GetPrimaryRootWindow()->children(); |
| 89 for (aura::Window::Windows::const_reverse_iterator i = windows.rbegin(); | 89 for (aura::Window::Windows::const_reverse_iterator i = windows.rbegin(); |
| 90 i != windows.rend(); ++i) { | 90 i != windows.rend(); ++i) { |
| 91 if (*i == window_.get() || *i == window2_.get() || *i == window3_.get()) { | 91 if (*i == window_.get() || *i == window2_.get() || *i == window3_.get()) { |
| 92 if (!result.empty()) | 92 if (!result.empty()) |
| 93 result += " "; | 93 result += " "; |
| 94 result += base::IntToString((*i)->id()); | 94 result += base::IntToString((*i)->id()); |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 return result; | 97 return result; |
| 98 } | 98 } |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 resizer->RevertDrag(); | 342 resizer->RevertDrag(); |
| 343 EXPECT_EQ("0,50 400x200", window_->bounds().ToString()); | 343 EXPECT_EQ("0,50 400x200", window_->bounds().ToString()); |
| 344 EXPECT_EQ("0,250 200x100", window2_->bounds().ToString()); | 344 EXPECT_EQ("0,250 200x100", window2_->bounds().ToString()); |
| 345 } | 345 } |
| 346 | 346 |
| 347 // Assertions around attached window resize dragging from the bottom with 3 | 347 // Assertions around attached window resize dragging from the bottom with 3 |
| 348 // windows. | 348 // windows. |
| 349 // TODO(oshima): Host window doesn't get a resize event after | 349 // TODO(oshima): Host window doesn't get a resize event after |
| 350 // SetHostSize on Windows trybot, which gives wrong work/monitor area. | 350 // SetHostSize on Windows trybot, which gives wrong work/monitor area. |
| 351 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_3) { | 351 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_3) { |
| 352 aura::RootWindow* root = Shell::GetInstance()->GetRootWindow(); | 352 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); |
| 353 root->SetHostSize(gfx::Size(600, 800)); | 353 root->SetHostSize(gfx::Size(600, 800)); |
| 354 LOG(ERROR) << "=== Calling OnHostResized, 600x800"; | 354 LOG(ERROR) << "=== Calling OnHostResized, 600x800"; |
| 355 | 355 |
| 356 Shell::GetInstance()->SetMonitorWorkAreaInsets(root, gfx::Insets()); | 356 Shell::GetInstance()->SetMonitorWorkAreaInsets(root, gfx::Insets()); |
| 357 | 357 |
| 358 window_->SetBounds(gfx::Rect( 300, 100, 300, 200)); | 358 window_->SetBounds(gfx::Rect( 300, 100, 300, 200)); |
| 359 window2_->SetBounds(gfx::Rect(300, 300, 200, 150)); | 359 window2_->SetBounds(gfx::Rect(300, 300, 200, 150)); |
| 360 window3_->SetBounds(gfx::Rect(300, 450, 200, 100)); | 360 window3_->SetBounds(gfx::Rect(300, 450, 200, 100)); |
| 361 delegate2_.set_min_size(gfx::Size(50, 52)); | 361 delegate2_.set_min_size(gfx::Size(50, 52)); |
| 362 delegate3_.set_min_size(gfx::Size(50, 38)); | 362 delegate3_.set_min_size(gfx::Size(50, 38)); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0); | 490 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0); |
| 491 | 491 |
| 492 // 2 should be topmost since it's initially the highest in the stack. | 492 // 2 should be topmost since it's initially the highest in the stack. |
| 493 EXPECT_EQ("2 3 1", WindowOrderAsString()); | 493 EXPECT_EQ("2 3 1", WindowOrderAsString()); |
| 494 } | 494 } |
| 495 } | 495 } |
| 496 | 496 |
| 497 // Makes sure we don't allow dragging below the work area. | 497 // Makes sure we don't allow dragging below the work area. |
| 498 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottom) { | 498 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottom) { |
| 499 Shell::GetInstance()->SetMonitorWorkAreaInsets( | 499 Shell::GetInstance()->SetMonitorWorkAreaInsets( |
| 500 Shell::GetInstance()->GetRootWindow(), gfx::Insets(0, 0, 10, 0)); | 500 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0)); |
| 501 | 501 |
| 502 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); | 502 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); |
| 503 SetGridSize(0); | 503 SetGridSize(0); |
| 504 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 504 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| 505 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | 505 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
| 506 ASSERT_TRUE(resizer.get()); | 506 ASSERT_TRUE(resizer.get()); |
| 507 resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0); | 507 resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0); |
| 508 int expected_y = | 508 int expected_y = |
| 509 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10; | 509 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10; |
| 510 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400", | 510 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400", |
| 511 window_->bounds().ToString()); | 511 window_->bounds().ToString()); |
| 512 } | 512 } |
| 513 | 513 |
| 514 // Makes sure we don't allow dragging off the top of the work area. | 514 // Makes sure we don't allow dragging off the top of the work area. |
| 515 TEST_F(WorkspaceWindowResizerTest, DontDragOffTop) { | 515 TEST_F(WorkspaceWindowResizerTest, DontDragOffTop) { |
| 516 Shell::GetInstance()->SetMonitorWorkAreaInsets( | 516 Shell::GetInstance()->SetMonitorWorkAreaInsets( |
| 517 Shell::GetInstance()->GetRootWindow(), gfx::Insets(10, 0, 0, 0)); | 517 Shell::GetPrimaryRootWindow(), gfx::Insets(10, 0, 0, 0)); |
| 518 | 518 |
| 519 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); | 519 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); |
| 520 SetGridSize(0); | 520 SetGridSize(0); |
| 521 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 521 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| 522 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | 522 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
| 523 ASSERT_TRUE(resizer.get()); | 523 ASSERT_TRUE(resizer.get()); |
| 524 resizer->Drag(CalculateDragPoint(*resizer, 0, -600), 0); | 524 resizer->Drag(CalculateDragPoint(*resizer, 0, -600), 0); |
| 525 EXPECT_EQ("100,10 300x400", window_->bounds().ToString()); | 525 EXPECT_EQ("100,10 300x400", window_->bounds().ToString()); |
| 526 } | 526 } |
| 527 | 527 |
| 528 TEST_F(WorkspaceWindowResizerTest, ResizeBottomOutsideWorkArea) { | 528 TEST_F(WorkspaceWindowResizerTest, ResizeBottomOutsideWorkArea) { |
| 529 Shell::GetInstance()->SetMonitorWorkAreaInsets( | 529 Shell::GetInstance()->SetMonitorWorkAreaInsets( |
| 530 Shell::GetInstance()->GetRootWindow(), gfx::Insets(0, 0, 50, 0)); | 530 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0)); |
| 531 | 531 |
| 532 window_->SetBounds(gfx::Rect(100, 200, 300, 380)); | 532 window_->SetBounds(gfx::Rect(100, 200, 300, 380)); |
| 533 SetGridSize(10); | 533 SetGridSize(10); |
| 534 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 534 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| 535 window_.get(), gfx::Point(), HTTOP, empty_windows())); | 535 window_.get(), gfx::Point(), HTTOP, empty_windows())); |
| 536 ASSERT_TRUE(resizer.get()); | 536 ASSERT_TRUE(resizer.get()); |
| 537 resizer->Drag(CalculateDragPoint(*resizer, 8, 0), 0); | 537 resizer->Drag(CalculateDragPoint(*resizer, 8, 0), 0); |
| 538 EXPECT_EQ("100,200 300x380", window_->bounds().ToString()); | 538 EXPECT_EQ("100,200 300x380", window_->bounds().ToString()); |
| 539 } | 539 } |
| 540 | 540 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 20), 0); | 587 resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 20), 0); |
| 588 EXPECT_EQ("96,20 320x160", window_->bounds().ToString()); | 588 EXPECT_EQ("96,20 320x160", window_->bounds().ToString()); |
| 589 resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 7), 0); | 589 resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 7), 0); |
| 590 EXPECT_EQ("96,0 320x160", window_->bounds().ToString()); | 590 EXPECT_EQ("96,0 320x160", window_->bounds().ToString()); |
| 591 // No need to test dragging < 0 as we force that to 0. | 591 // No need to test dragging < 0 as we force that to 0. |
| 592 } | 592 } |
| 593 | 593 |
| 594 // Verifies a window taller than work area height doesn't snap above the top of | 594 // Verifies a window taller than work area height doesn't snap above the top of |
| 595 // the work area. | 595 // the work area. |
| 596 TEST_F(WorkspaceWindowResizerTest, TallWindow) { | 596 TEST_F(WorkspaceWindowResizerTest, TallWindow) { |
| 597 aura::RootWindow* root = Shell::GetInstance()->GetRootWindow(); | 597 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); |
| 598 Shell::GetInstance()->SetMonitorWorkAreaInsets( | 598 Shell::GetInstance()->SetMonitorWorkAreaInsets( |
| 599 root, gfx::Insets(0, 0, 50, 0)); | 599 root, gfx::Insets(0, 0, 50, 0)); |
| 600 window_->SetBounds(gfx::Rect(0, 0, 320, 560)); | 600 window_->SetBounds(gfx::Rect(0, 0, 320, 560)); |
| 601 SetGridSize(16); | 601 SetGridSize(16); |
| 602 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 602 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| 603 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | 603 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
| 604 resizer->Drag(CalculateDragPoint(*resizer, 0, 9), 0); | 604 resizer->Drag(CalculateDragPoint(*resizer, 0, 9), 0); |
| 605 EXPECT_EQ("0,9 320x560", window_->bounds().ToString()); | 605 EXPECT_EQ("0,9 320x560", window_->bounds().ToString()); |
| 606 } | 606 } |
| 607 | 607 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0); | 653 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0); |
| 654 resizer->CompleteDrag(ui::EF_CONTROL_DOWN); | 654 resizer->CompleteDrag(ui::EF_CONTROL_DOWN); |
| 655 EXPECT_EQ("106,124 320x160", window_->bounds().ToString()); | 655 EXPECT_EQ("106,124 320x160", window_->bounds().ToString()); |
| 656 } | 656 } |
| 657 | 657 |
| 658 #endif | 658 #endif |
| 659 | 659 |
| 660 } // namespace | 660 } // namespace |
| 661 } // namespace test | 661 } // namespace test |
| 662 } // namespace ash | 662 } // namespace ash |
| OLD | NEW |