| Index: ash/wm/workspace/workspace_manager2_unittest.cc
|
| diff --git a/ash/wm/workspace/workspace_manager2_unittest.cc b/ash/wm/workspace/workspace_manager2_unittest.cc
|
| index 70a39e6cbf3d1c0747f10349778f924b3e4b7f99..29e92321f242eaf39299959d54c9d97a6f4e929e 100644
|
| --- a/ash/wm/workspace/workspace_manager2_unittest.cc
|
| +++ b/ash/wm/workspace/workspace_manager2_unittest.cc
|
| @@ -1107,5 +1107,290 @@ TEST_F(WorkspaceManager2Test, DeactivateDropsToDesktop) {
|
| ASSERT_EQ("1 M1 active=1", StateString());
|
| }
|
|
|
| +// Test the basic auto placement of one and or two windows in a "simulated
|
| +// session" of sequential window operations.
|
| +TEST_F(WorkspaceManager2Test, BasicAutoPlacing) {
|
| + // Test 1: In case there is no manageable window, no window should shift.
|
| +
|
| + scoped_ptr<aura::Window> window1(
|
| + aura::test::CreateTestWindowWithId(0, NULL));
|
| + window1->SetBounds(gfx::Rect(16, 32, 640, 320));
|
| + gfx::Rect desktop_area = window1->parent()->bounds();
|
| +
|
| + scoped_ptr<aura::Window> window2(
|
| + aura::test::CreateTestWindowWithId(1, NULL));
|
| + // Trigger the auto window placement function by making it visible.
|
| + // Note that the bounds are getting changed while it is invisible.
|
| + window2->Hide();
|
| + window2->SetBounds(gfx::Rect(32, 48, 256, 512));
|
| + window2->Show();
|
| +
|
| + // Check the initial position of the windows is unchanged.
|
| + EXPECT_EQ("16,32 640x320", window1->bounds().ToString());
|
| + EXPECT_EQ("32,48 256x512", window2->bounds().ToString());
|
| +
|
| + // Remove the second window and make sure that the first window
|
| + // does NOT get centered.
|
| + window2.reset();
|
| + EXPECT_EQ("16,32 640x320", window1->bounds().ToString());
|
| +
|
| + // Test 2: Set up two managed windows and check their auto positioning.
|
| + ash::wm::SetWindowPositionManaged(window1.get(), true);
|
| + scoped_ptr<aura::Window> window3(
|
| + aura::test::CreateTestWindowWithId(2, NULL));
|
| + ash::wm::SetWindowPositionManaged(window3.get(), true);
|
| + // To avoid any auto window manager changes due to SetBounds, the window
|
| + // gets first hidden and then shown again.
|
| + window3->Hide();
|
| + window3->SetBounds(gfx::Rect(32, 48, 256, 512));
|
| + window3->Show();
|
| + // |window1| should be flush right and |window3| flush left.
|
| + EXPECT_EQ("0,32 640x320", window1->bounds().ToString());
|
| + EXPECT_EQ(base::IntToString(
|
| + desktop_area.width() - window3->bounds().width()) +
|
| + ",48 256x512", window3->bounds().ToString());
|
| +
|
| + // After removing |window3|, |window1| should be centered again.
|
| + window3.reset();
|
| + EXPECT_EQ(
|
| + base::IntToString(
|
| + (desktop_area.width() - window1->bounds().width()) / 2) +
|
| + ",32 640x320", window1->bounds().ToString());
|
| +
|
| + // Test 3: Set up a manageable and a non manageable window and check
|
| + // positioning.
|
| + scoped_ptr<aura::Window> window4(
|
| + aura::test::CreateTestWindowWithId(3, NULL));
|
| + // To avoid any auto window manager changes due to SetBounds, the window
|
| + // gets first hidden and then shown again.
|
| + window1->Hide();
|
| + window1->SetBounds(gfx::Rect(16, 32, 640, 320));
|
| + window4->SetBounds(gfx::Rect(32, 48, 256, 512));
|
| + window1->Show();
|
| + // |window1| should be centered and |window4| untouched.
|
| + EXPECT_EQ(
|
| + base::IntToString(
|
| + (desktop_area.width() - window1->bounds().width()) / 2) +
|
| + ",32 640x320", window1->bounds().ToString());
|
| + EXPECT_EQ("32,48 256x512", window4->bounds().ToString());
|
| +
|
| + // Test4: A single manageable window should get centered.
|
| + window4.reset();
|
| + ash::wm::SetUserHasChangedWindowPositionOrSize(window1.get(), false);
|
| + // Trigger the auto window placement function by showing (and hiding) it.
|
| + window1->Hide();
|
| + window1->Show();
|
| + // |window1| should be centered.
|
| + EXPECT_EQ(
|
| + base::IntToString(
|
| + (desktop_area.width() - window1->bounds().width()) / 2) +
|
| + ",32 640x320", window1->bounds().ToString());
|
| +}
|
| +
|
| +// Test the proper usage of user window movement interaction.
|
| +TEST_F(WorkspaceManager2Test, TestUserMovedWindowRepositioning) {
|
| + scoped_ptr<aura::Window> window1(
|
| + aura::test::CreateTestWindowWithId(0, NULL));
|
| + window1->SetBounds(gfx::Rect(16, 32, 640, 320));
|
| + gfx::Rect desktop_area = window1->parent()->bounds();
|
| + scoped_ptr<aura::Window> window2(
|
| + aura::test::CreateTestWindowWithId(1, NULL));
|
| + window2->SetBounds(gfx::Rect(32, 48, 256, 512));
|
| + window1->Hide();
|
| + window2->Hide();
|
| + ash::wm::SetWindowPositionManaged(window1.get(), true);
|
| + ash::wm::SetWindowPositionManaged(window2.get(), true);
|
| + EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get()));
|
| + EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window2.get()));
|
| +
|
| + // Check that the current location gets preserved if the user has
|
| + // positioned it previously.
|
| + ash::wm::SetUserHasChangedWindowPositionOrSize(window1.get(), true);
|
| + window1->Show();
|
| + EXPECT_EQ("16,32 640x320", window1->bounds().ToString());
|
| + // Flag should be still set.
|
| + EXPECT_TRUE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get()));
|
| + EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window2.get()));
|
| +
|
| + // Turn on the second window and make sure that both windows are now
|
| + // positionable again (user movement cleared).
|
| + window2->Show();
|
| +
|
| + // |window1| should be flush right and |window3| flush left.
|
| + EXPECT_EQ(base::IntToString(
|
| + desktop_area.width() - window1->bounds().width()) +
|
| + ",32 640x320", window1->bounds().ToString());
|
| + EXPECT_EQ("0,48 256x512", window2->bounds().ToString());
|
| + // FLag should now be reset.
|
| + EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get()));
|
| + EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get()));
|
| +
|
| + // Going back to one shown window should keep the state.
|
| + ash::wm::SetUserHasChangedWindowPositionOrSize(window1.get(), true);
|
| + window2->Hide();
|
| + EXPECT_EQ(base::IntToString(
|
| + desktop_area.width() - window1->bounds().width()) +
|
| + ",32 640x320", window1->bounds().ToString());
|
| + EXPECT_TRUE(ash::wm::HasUserChangedWindowPositionOrSize(window1.get()));
|
| +}
|
| +
|
| +// Test that a window from normal to minimize will repos the remaining.
|
| +TEST_F(WorkspaceManager2Test, ToMinimizeRepositionsRemaining) {
|
| + scoped_ptr<aura::Window> window1(
|
| + aura::test::CreateTestWindowWithId(0, NULL));
|
| + ash::wm::SetWindowPositionManaged(window1.get(), true);
|
| + window1->SetBounds(gfx::Rect(16, 32, 640, 320));
|
| + gfx::Rect desktop_area = window1->parent()->bounds();
|
| +
|
| + scoped_ptr<aura::Window> window2(
|
| + aura::test::CreateTestWindowWithId(1, NULL));
|
| + ash::wm::SetWindowPositionManaged(window2.get(), true);
|
| + window2->SetBounds(gfx::Rect(32, 48, 256, 512));
|
| +
|
| + ash::wm::MinimizeWindow(window1.get());
|
| +
|
| + // |window2| should be centered now.
|
| + EXPECT_TRUE(window2->IsVisible());
|
| + EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get()));
|
| + EXPECT_EQ(base::IntToString(
|
| + (desktop_area.width() - window2->bounds().width()) / 2) +
|
| + ",48 256x512", window2->bounds().ToString());
|
| +
|
| + ash::wm::RestoreWindow(window1.get());
|
| + // |window1| should be flush right and |window3| flush left.
|
| + EXPECT_EQ(base::IntToString(
|
| + desktop_area.width() - window1->bounds().width()) +
|
| + ",32 640x320", window1->bounds().ToString());
|
| + EXPECT_EQ("0,48 256x512", window2->bounds().ToString());
|
| +}
|
| +
|
| +// Test that minimizing an initially maximized window will repos the remaining.
|
| +TEST_F(WorkspaceManager2Test, MaxToMinRepositionsRemaining) {
|
| + scoped_ptr<aura::Window> window1(
|
| + aura::test::CreateTestWindowWithId(0, NULL));
|
| + ash::wm::SetWindowPositionManaged(window1.get(), true);
|
| + gfx::Rect desktop_area = window1->parent()->bounds();
|
| +
|
| + scoped_ptr<aura::Window> window2(
|
| + aura::test::CreateTestWindowWithId(1, NULL));
|
| + ash::wm::SetWindowPositionManaged(window2.get(), true);
|
| + window2->SetBounds(gfx::Rect(32, 48, 256, 512));
|
| +
|
| + ash::wm::MaximizeWindow(window1.get());
|
| + ash::wm::MinimizeWindow(window1.get());
|
| +
|
| + // |window2| should be centered now.
|
| + EXPECT_TRUE(window2->IsVisible());
|
| + EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get()));
|
| + EXPECT_EQ(base::IntToString(
|
| + (desktop_area.width() - window2->bounds().width()) / 2) +
|
| + ",48 256x512", window2->bounds().ToString());
|
| +}
|
| +
|
| +// Test that nomral, maximize, minimizing will repos the remaining.
|
| +TEST_F(WorkspaceManager2Test, NormToMaxToMinRepositionsRemaining) {
|
| + scoped_ptr<aura::Window> window1(
|
| + aura::test::CreateTestWindowWithId(0, NULL));
|
| + window1->SetBounds(gfx::Rect(16, 32, 640, 320));
|
| + ash::wm::SetWindowPositionManaged(window1.get(), true);
|
| + gfx::Rect desktop_area = window1->parent()->bounds();
|
| +
|
| + scoped_ptr<aura::Window> window2(
|
| + aura::test::CreateTestWindowWithId(1, NULL));
|
| + ash::wm::SetWindowPositionManaged(window2.get(), true);
|
| + window2->SetBounds(gfx::Rect(32, 48, 256, 512));
|
| +
|
| + // Trigger the auto window placement function by showing (and hiding) it.
|
| + window1->Hide();
|
| + window1->Show();
|
| +
|
| + // |window1| should be flush right and |window3| flush left.
|
| + EXPECT_EQ(base::IntToString(
|
| + desktop_area.width() - window1->bounds().width()) +
|
| + ",32 640x320", window1->bounds().ToString());
|
| + EXPECT_EQ("0,48 256x512", window2->bounds().ToString());
|
| +
|
| + ash::wm::MaximizeWindow(window1.get());
|
| + ash::wm::MinimizeWindow(window1.get());
|
| +
|
| + // |window2| should be centered now.
|
| + EXPECT_TRUE(window2->IsVisible());
|
| + EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get()));
|
| + EXPECT_EQ(base::IntToString(
|
| + (desktop_area.width() - window2->bounds().width()) / 2) +
|
| + ",48 256x512", window2->bounds().ToString());
|
| +}
|
| +
|
| +// Test that nomral, maximize, normal will repos the remaining.
|
| +TEST_F(WorkspaceManager2Test, NormToMaxToNormRepositionsRemaining) {
|
| + scoped_ptr<aura::Window> window1(
|
| + aura::test::CreateTestWindowWithId(0, NULL));
|
| + window1->SetBounds(gfx::Rect(16, 32, 640, 320));
|
| + ash::wm::SetWindowPositionManaged(window1.get(), true);
|
| + gfx::Rect desktop_area = window1->parent()->bounds();
|
| +
|
| + scoped_ptr<aura::Window> window2(
|
| + aura::test::CreateTestWindowWithId(1, NULL));
|
| + ash::wm::SetWindowPositionManaged(window2.get(), true);
|
| + window2->SetBounds(gfx::Rect(32, 48, 256, 512));
|
| +
|
| + // Trigger the auto window placement function by showing (and hiding) it.
|
| + window1->Hide();
|
| + window1->Show();
|
| +
|
| + // |window1| should be flush right and |window3| flush left.
|
| + EXPECT_EQ(base::IntToString(
|
| + desktop_area.width() - window1->bounds().width()) +
|
| + ",32 640x320", window1->bounds().ToString());
|
| + EXPECT_EQ("0,48 256x512", window2->bounds().ToString());
|
| +
|
| + ash::wm::MaximizeWindow(window1.get());
|
| + ash::wm::RestoreWindow(window1.get());
|
| +
|
| + // |window1| should be flush right and |window2| flush left.
|
| + EXPECT_EQ(base::IntToString(
|
| + desktop_area.width() - window1->bounds().width()) +
|
| + ",32 640x320", window1->bounds().ToString());
|
| + EXPECT_EQ("0,48 256x512", window2->bounds().ToString());
|
| +}
|
| +
|
| +// Test that animations are triggered.
|
| +TEST_F(WorkspaceManager2Test, AnimatedNormToMaxToNormRepositionsRemaining) {
|
| + ui::LayerAnimator::set_disable_animations_for_test(false);
|
| + scoped_ptr<aura::Window> window1(
|
| + aura::test::CreateTestWindowWithId(0, NULL));
|
| + window1->Hide();
|
| + window1->SetBounds(gfx::Rect(16, 32, 640, 320));
|
| + gfx::Rect desktop_area = window1->parent()->bounds();
|
| + scoped_ptr<aura::Window> window2(
|
| + aura::test::CreateTestWindowWithId(1, NULL));
|
| + window2->Hide();
|
| + window2->SetBounds(gfx::Rect(32, 48, 256, 512));
|
| +
|
| + ash::wm::SetWindowPositionManaged(window1.get(), true);
|
| + ash::wm::SetWindowPositionManaged(window2.get(), true);
|
| + // Make sure nothing is animating.
|
| + window1->layer()->GetAnimator()->StopAnimating();
|
| + window2->layer()->GetAnimator()->StopAnimating();
|
| + window2->Show();
|
| +
|
| + // The second window should now animate.
|
| + EXPECT_FALSE(window1->layer()->GetAnimator()->is_animating());
|
| + EXPECT_TRUE(window2->layer()->GetAnimator()->is_animating());
|
| + window2->layer()->GetAnimator()->StopAnimating();
|
| +
|
| + window1->Show();
|
| + EXPECT_TRUE(window1->layer()->GetAnimator()->is_animating());
|
| + EXPECT_TRUE(window2->layer()->GetAnimator()->is_animating());
|
| +
|
| + window1->layer()->GetAnimator()->StopAnimating();
|
| + window2->layer()->GetAnimator()->StopAnimating();
|
| + // |window1| should be flush right and |window2| flush left.
|
| + EXPECT_EQ(base::IntToString(
|
| + desktop_area.width() - window1->bounds().width()) +
|
| + ",32 640x320", window1->bounds().ToString());
|
| + EXPECT_EQ("0,48 256x512", window2->bounds().ToString());
|
| +}
|
| +
|
| } // namespace internal
|
| } // namespace ash
|
|
|