Chromium Code Reviews| Index: ash/accelerators/accelerator_controller_unittest.cc |
| diff --git a/ash/accelerators/accelerator_controller_unittest.cc b/ash/accelerators/accelerator_controller_unittest.cc |
| index 8030a86acb7e63b0c37a50fc80906beb6b1bd0f1..5186072e2cdf62276b836b891c3c5c445f4bcf4f 100644 |
| --- a/ash/accelerators/accelerator_controller_unittest.cc |
| +++ b/ash/accelerators/accelerator_controller_unittest.cc |
| @@ -19,10 +19,12 @@ |
| #include "ash/test/display_manager_test_api.h" |
| #include "ash/test/test_screenshot_delegate.h" |
| #include "ash/test/test_session_state_animator.h" |
| +#include "ash/test/test_shelf_delegate.h" |
| #include "ash/test/test_shell_delegate.h" |
| #include "ash/test/test_volume_control_delegate.h" |
| #include "ash/volume_control_delegate.h" |
| #include "ash/wm/lock_state_controller.h" |
| +#include "ash/wm/panels/panel_layout_manager.h" |
| #include "ash/wm/window_state.h" |
| #include "ash/wm/window_util.h" |
| #include "ash/wm/wm_event.h" |
| @@ -268,6 +270,19 @@ class AcceleratorControllerTest : public test::AshTestBase { |
| static bool is_exiting(ExitWarningHandler* ewh) { |
| return ewh->state_ == ExitWarningHandler::EXITING; |
| } |
| + aura::Window* CreatePanel() { |
| + aura::Window* window = |
| + CreateTestWindowInShellWithDelegateAndType(NULL, |
| + ui::wm::WINDOW_TYPE_PANEL, 0, gfx::Rect(5, 5, 20, 20)); |
| + test::TestShelfDelegate* shelf_delegate = |
| + test::TestShelfDelegate::instance(); |
| + shelf_delegate->AddShelfItem(window); |
| + PanelLayoutManager* manager = static_cast<PanelLayoutManager*>( |
| + Shell::GetContainer(window->GetRootWindow(), |
| + kShellWindowId_PanelContainer)->layout_manager()); |
| + manager->Relayout(); |
| + return window; |
| + } |
| private: |
| DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest); |
| @@ -435,13 +450,13 @@ TEST_F(AcceleratorControllerTest, WindowSnap) { |
| window_state->Activate(); |
| { |
| - GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy); |
| gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( |
| window.get()); |
| EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); |
| } |
| { |
| - GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_RIGHT, dummy); |
| gfx::Rect expected_bounds = wm::GetDefaultRightSnappedWindowBoundsInParent( |
| window.get()); |
| EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); |
| @@ -460,11 +475,11 @@ TEST_F(AcceleratorControllerTest, WindowSnap) { |
| EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString()); |
| GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy); |
| - GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy); |
| EXPECT_FALSE(window_state->IsMaximized()); |
| GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy); |
| - GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_RIGHT, dummy); |
| EXPECT_FALSE(window_state->IsMaximized()); |
| GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy); |
| @@ -481,6 +496,142 @@ TEST_F(AcceleratorControllerTest, WindowSnap) { |
| } |
| } |
| +TEST_F(AcceleratorControllerTest, WindowDock) { |
| + scoped_ptr<aura::Window> window0( |
| + CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); |
| + { |
| + scoped_ptr<aura::Window> window1( |
| + CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); |
| + const ui::Accelerator dummy; |
| + |
| + wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
| + window1_state->Activate(); |
| + |
| + // check snap left, dock left, restore cycle |
|
varkha
2014/09/29 21:04:34
Comments should be English sentences - capitalized
|
| + { |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy); |
| + gfx::Rect normal_bounds = window1_state->GetRestoreBoundsInParent(); |
| + gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( |
| + window1.get()); |
| + EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString()); |
| + EXPECT_TRUE(window1_state->IsSnapped()); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy); |
| + EXPECT_FALSE(window1_state->IsNormalOrSnapped()); |
| + EXPECT_TRUE(window1_state->IsDocked()); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy); |
| + EXPECT_FALSE(window1_state->IsDocked()); |
| + EXPECT_EQ(normal_bounds.ToString(), window1->bounds().ToString()); |
| + } |
| + // check snap right, dock right, restore cycle |
|
varkha
2014/09/29 21:04:34
Consider separating those into separate methods. I
dtapuska
2014/09/30 14:40:49
Done.
|
| + { |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_RIGHT, dummy); |
| + gfx::Rect normal_bounds = window1_state->GetRestoreBoundsInParent(); |
| + gfx::Rect expected_bounds = |
| + wm::GetDefaultRightSnappedWindowBoundsInParent(window1.get()); |
| + EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString()); |
| + EXPECT_TRUE(window1_state->IsSnapped()); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_RIGHT, dummy); |
| + EXPECT_FALSE(window1_state->IsNormalOrSnapped()); |
| + EXPECT_TRUE(window1_state->IsDocked()); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_RIGHT, dummy); |
| + EXPECT_FALSE(window1_state->IsDocked()); |
| + EXPECT_EQ(normal_bounds.ToString(), window1->bounds().ToString()); |
| + } |
| + |
| + // check snap left, dock left, snap right |
| + { |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy); |
| + gfx::Rect expected_bounds = |
| + wm::GetDefaultLeftSnappedWindowBoundsInParent(window1.get()); |
| + gfx::Rect expected_bounds2 = |
| + wm::GetDefaultRightSnappedWindowBoundsInParent(window1.get()); |
| + EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString()); |
| + EXPECT_TRUE(window1_state->IsSnapped()); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy); |
| + EXPECT_FALSE(window1_state->IsNormalOrSnapped()); |
| + EXPECT_TRUE(window1_state->IsDocked()); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_RIGHT, dummy); |
| + EXPECT_FALSE(window1_state->IsDocked()); |
| + EXPECT_TRUE(window1_state->IsSnapped()); |
| + EXPECT_EQ(expected_bounds2.ToString(), window1->bounds().ToString()); |
| + } |
| + |
| + // check snap left, dock left, snap right |
| + { |
| + scoped_ptr<aura::Window> window2( |
| + CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); |
| + |
| + wm::WindowState* window2_state = wm::GetWindowState(window2.get()); |
| + |
| + scoped_ptr<aura::Window> window3( |
| + CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); |
| + |
| + wm::WindowState* window3_state = wm::GetWindowState(window3.get()); |
| + window3_state->Activate(); |
| + |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy); |
| + gfx::Rect window3_docked_bounds = window3->bounds(); |
| + |
| + window2_state->Activate(); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy); |
| + window1_state->Activate(); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy); |
| + |
| + EXPECT_TRUE(window3_state->IsDocked()); |
| + EXPECT_TRUE(window2_state->IsDocked()); |
| + EXPECT_TRUE(window1_state->IsDocked()); |
| + EXPECT_TRUE(window3_state->IsMinimized()); |
| + |
| + window1_state->Activate(); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy); |
| + window2_state->Activate(); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy); |
| + window3_state->Unminimize(); |
| + EXPECT_FALSE(window1_state->IsDocked()); |
| + EXPECT_FALSE(window2_state->IsDocked()); |
| + EXPECT_TRUE(window3_state->IsDocked()); |
| + EXPECT_EQ(window3_docked_bounds.ToString(), window3->bounds().ToString()); |
| + } |
| + } |
| + |
| + // Panel docking tests |
| + { |
| + scoped_ptr<aura::Window> window(CreatePanel()); |
| + |
| + const ui::Accelerator dummy; |
| + |
| + wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| + |
| + window_state->Activate(); |
| + |
| + // check snap left (doesn't apply for panels), dock left, dock, right, |
| + // restore cycle |
| + { |
| + gfx::Rect window_restore_bounds2 = window->bounds(); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy); |
| + gfx::Rect expected_bounds = |
| + wm::GetDefaultLeftSnappedWindowBoundsInParent(window.get()); |
| + gfx::Rect window_restore_bounds = |
| + window_state->GetRestoreBoundsInScreen(); |
| + EXPECT_NE(expected_bounds.ToString(), window->bounds().ToString()); |
| + EXPECT_FALSE(window_state->IsSnapped()); |
| + EXPECT_FALSE(window_state->IsNormalOrSnapped()); |
| + EXPECT_TRUE(window_state->IsDocked()); |
| + window_state->Restore(); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_RIGHT, dummy); |
| + EXPECT_TRUE(window_state->IsDocked()); |
| + GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_RIGHT, dummy); |
| + EXPECT_FALSE(window_state->IsDocked()); |
| + EXPECT_EQ(window_restore_bounds.ToString(), |
| + window_restore_bounds2.ToString()); |
| + EXPECT_EQ(window_restore_bounds.ToString(), window->bounds().ToString()); |
| + } |
| + } |
| +} |
| + |
| TEST_F(AcceleratorControllerTest, CenterWindowAccelerator) { |
| scoped_ptr<aura::Window> window( |
| CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); |