Chromium Code Reviews| Index: ash/wm/custom_frame_view_ash_unittest.cc |
| diff --git a/ash/wm/custom_frame_view_ash_unittest.cc b/ash/wm/custom_frame_view_ash_unittest.cc |
| index f7af09a7ea3c2e15fccd7645002ca93255fa6f42..e7440d3f453b5eb3b524669b8138ea577df34f11 100644 |
| --- a/ash/wm/custom_frame_view_ash_unittest.cc |
| +++ b/ash/wm/custom_frame_view_ash_unittest.cc |
| @@ -12,6 +12,7 @@ |
| #include "ash/wm/workspace/snap_sizer.h" |
| #include "base/command_line.h" |
| #include "ui/aura/aura_switches.h" |
| +#include "ui/aura/client/aura_constants.h" |
| #include "ui/aura/focus_manager.h" |
| #include "ui/aura/test/event_generator.h" |
| #include "ui/aura/root_window.h" |
| @@ -483,5 +484,131 @@ TEST_F(CustomFrameViewAshTest, OnlyLeftButtonMaximizes) { |
| EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); |
| } |
| +void ClickMaxButton(ash::FrameMaximizeButton* maximize_button, |
|
sky
2012/08/27 22:18:16
Wrap maximize_button to next line so that it lines
Mr4D (OOO till 08-26)
2012/08/28 01:30:25
Done.
|
| + aura::Window* window, |
| + SnapType snap_type) { |
| + gfx::Point button_pos = maximize_button->GetBoundsInScreen().CenterPoint(); |
| + gfx::Point off_pos(button_pos.x() + 100, button_pos.y() + 100); |
| + |
| + aura::test::EventGenerator generator(window->GetRootWindow(), off_pos); |
| + generator.MoveMouseTo(off_pos); |
| + EXPECT_FALSE(maximize_button->maximizer()); |
| + EXPECT_FALSE(maximize_button->phantom_window_open()); |
| + |
| + // Move the mouse cursor over the button. |
| + generator.MoveMouseTo(button_pos); |
| + EXPECT_TRUE(maximize_button->maximizer()); |
| + EXPECT_FALSE(maximize_button->phantom_window_open()); |
| + |
| + if (snap_type != SNAP_NONE) { |
| + gfx::Point left_max_pos = maximize_button->maximizer()-> |
| + GetButtonForUnitTest(snap_type)->GetBoundsInScreen().CenterPoint(); |
| + generator.MoveMouseTo(left_max_pos); |
| + EXPECT_TRUE(maximize_button->phantom_window_open()); |
| + } |
| + // After pressing the left button the button should get triggered. |
| + generator.ClickLeftButton(); |
| + EXPECT_FALSE(maximize_button->maximizer()); |
| +} |
| + |
| +// Test that the restore from left/right maximize is properly done. |
| +TEST_F(CustomFrameViewAshTest, MaximizeLeftRestore) { |
| + views::Widget* widget = CreateWidget(); |
| + aura::Window* window = widget->GetNativeWindow(); |
| + widget->SetBounds(gfx::Rect(10, 10, 100, 100)); |
| + gfx::Rect initial_bounds = widget->GetWindowBoundsInScreen(); |
| + CustomFrameViewAsh* frame = custom_frame_view_ash(widget); |
| + CustomFrameViewAsh::TestApi test(frame); |
| + ash::FrameMaximizeButton* maximize_button = test.maximize_button(); |
| + maximize_button->set_bubble_appearance_delay_ms(0); |
| + |
| + ClickMaxButton(maximize_button, window, SNAP_LEFT); |
| + RunAllPendingInMessageLoop(); |
|
sky
2012/08/27 22:18:16
Why do you need to explicitly run the message loop
Mr4D (OOO till 08-26)
2012/08/28 01:30:25
I have seen that other tests were doing this, so I
|
| + // The window should not be maximized. |
| + EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); |
| + // But the bounds should be different. |
| + gfx::Rect new_bounds = widget->GetWindowBoundsInScreen(); |
| + EXPECT_EQ(0, new_bounds.x()); |
| + EXPECT_EQ(0, new_bounds.y()); |
| + |
| + // Now click the same button again to see that it restores. |
| + ClickMaxButton(maximize_button, window, SNAP_LEFT); |
| + RunAllPendingInMessageLoop(); |
| + // But the bounds should be restored. |
| + new_bounds = widget->GetWindowBoundsInScreen(); |
| + EXPECT_EQ(new_bounds.x(), initial_bounds.x()); |
| + EXPECT_EQ(new_bounds.y(), initial_bounds.x()); |
| + EXPECT_EQ(new_bounds.width(), initial_bounds.width()); |
| + EXPECT_EQ(new_bounds.height(), initial_bounds.height()); |
| + // Make sure that there is no restore rectangle left. |
| + EXPECT_EQ(NULL, window->GetProperty(aura::client::kRestoreBoundsKey)); |
| +} |
| + |
| +// Maximize, left/right maximize and then restore should works. |
| +TEST_F(CustomFrameViewAshTest, MaximizeMaximizeLeftRestore) { |
| + views::Widget* widget = CreateWidget(); |
| + aura::Window* window = widget->GetNativeWindow(); |
| + widget->SetBounds(gfx::Rect(10, 10, 100, 100)); |
| + gfx::Rect initial_bounds = widget->GetWindowBoundsInScreen(); |
| + CustomFrameViewAsh* frame = custom_frame_view_ash(widget); |
| + CustomFrameViewAsh::TestApi test(frame); |
| + ash::FrameMaximizeButton* maximize_button = test.maximize_button(); |
| + maximize_button->set_bubble_appearance_delay_ms(0); |
| + |
| + ClickMaxButton(maximize_button, window, SNAP_NONE); |
| + RunAllPendingInMessageLoop(); |
| + EXPECT_TRUE(ash::wm::IsWindowMaximized(window)); |
| + |
| + ClickMaxButton(maximize_button, window, SNAP_LEFT); |
| + RunAllPendingInMessageLoop(); |
| + EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); |
| + gfx::Rect new_bounds = widget->GetWindowBoundsInScreen(); |
| + EXPECT_EQ(0, new_bounds.x()); |
| + EXPECT_EQ(0, new_bounds.y()); |
| + |
| + // Now click the same button again to see that it restores. |
| + ClickMaxButton(maximize_button, window, SNAP_LEFT); |
| + RunAllPendingInMessageLoop(); |
| + // But the bounds should be restored. |
| + new_bounds = widget->GetWindowBoundsInScreen(); |
| + EXPECT_EQ(new_bounds.x(), initial_bounds.x()); |
| + EXPECT_EQ(new_bounds.y(), initial_bounds.x()); |
| + EXPECT_EQ(new_bounds.width(), initial_bounds.width()); |
| + EXPECT_EQ(new_bounds.height(), initial_bounds.height()); |
| + // Make sure that there is no restore rectangle left. |
| + EXPECT_EQ(NULL, window->GetProperty(aura::client::kRestoreBoundsKey)); |
| +} |
| + |
| +// Left/right maximize, maximize and then restore should work. |
| +TEST_F(CustomFrameViewAshTest, MaximizeLeftMaximizeRestore) { |
| + views::Widget* widget = CreateWidget(); |
| + aura::Window* window = widget->GetNativeWindow(); |
| + widget->SetBounds(gfx::Rect(10, 10, 100, 100)); |
| + gfx::Rect initial_bounds = widget->GetWindowBoundsInScreen(); |
| + CustomFrameViewAsh* frame = custom_frame_view_ash(widget); |
| + CustomFrameViewAsh::TestApi test(frame); |
| + ash::FrameMaximizeButton* maximize_button = test.maximize_button(); |
| + maximize_button->set_bubble_appearance_delay_ms(0); |
| + |
| + ClickMaxButton(maximize_button, window, SNAP_LEFT); |
| + RunAllPendingInMessageLoop(); |
| + EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); |
| + |
| + ClickMaxButton(maximize_button, window, SNAP_NONE); |
| + RunAllPendingInMessageLoop(); |
| + EXPECT_TRUE(ash::wm::IsWindowMaximized(window)); |
| + |
| + ClickMaxButton(maximize_button, window, SNAP_NONE); |
| + RunAllPendingInMessageLoop(); |
| + EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); |
| + gfx::Rect new_bounds = widget->GetWindowBoundsInScreen(); |
| + EXPECT_EQ(new_bounds.x(), initial_bounds.x()); |
| + EXPECT_EQ(new_bounds.y(), initial_bounds.x()); |
| + EXPECT_EQ(new_bounds.width(), initial_bounds.width()); |
| + EXPECT_EQ(new_bounds.height(), initial_bounds.height()); |
| + // Make sure that there is no restore rectangle left. |
| + EXPECT_EQ(NULL, window->GetProperty(aura::client::kRestoreBoundsKey)); |
| +} |
| + |
| } // namespace internal |
| } // namespace ash |