Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1814)

Unified Diff: ash/wm/custom_frame_view_ash_unittest.cc

Issue 10825327: Adding unit tests for maximize menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 ebdc94681b6e2c003be37b04f010158f23a25b70..8cefb4906ac86f74d3d1522c14a56b5651b6adbd 100644
--- a/ash/wm/custom_frame_view_ash_unittest.cc
+++ b/ash/wm/custom_frame_view_ash_unittest.cc
@@ -6,7 +6,9 @@
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
+#include "ash/wm/maximize_bubble_controller.h"
#include "ash/wm/window_util.h"
+#include "ash/wm/workspace/frame_maximize_button.h"
#include "ash/wm/workspace/snap_sizer.h"
#include "base/command_line.h"
#include "ui/aura/aura_switches.h"
@@ -255,5 +257,135 @@ TEST_F(CustomFrameViewAshTest, ResizeButtonDrag) {
widget->Close();
}
+TEST_F(CustomFrameViewAshTest, MaximizeButtonCrashOnExternalShutDown) {
sky 2012/08/13 21:17:14 Add a small description as to what each test is te
Mr4D (OOO till 08-26) 2012/08/13 23:01:03 Done.
+ views::Widget* widget = CreateWidget();
+ aura::Window* window = widget->GetNativeWindow();
+ CustomFrameViewAsh* frame = custom_frame_view_ash(widget);
+ CustomFrameViewAsh::TestApi test(frame);
+ ash::FrameMaximizeButton* maximize_button = test.maximize_button();
+ test.maximize_button()->set_bubble_appearance_delay_ms(0);
+ gfx::Point center = maximize_button->GetBoundsInScreen().CenterPoint();
+ // Move the location off the button.
+ center.set_y(center.y() - 100);
+
+ aura::test::EventGenerator generator(window->GetRootWindow(), center);
+
+ EXPECT_TRUE(ash::wm::IsWindowNormal(window));
+
+ // Move the mouse cursor over the button to bring up the maximizer bubble.
+ center = maximize_button->GetBoundsInScreen().CenterPoint();
+ generator.MoveMouseTo(center);
+ EXPECT_TRUE(maximize_button->maximizer());
+
+ // Even though the widget is closing the bubble menu should not crash upon
+ // its delayed destruction.
+ widget->Close();
sky 2012/08/13 21:17:14 Can you make this is a CloseNow() and in all other
Mr4D (OOO till 08-26) 2012/08/13 23:01:03 Done.
+}
+
+TEST_F(CustomFrameViewAshTest, MaximizeButtonExternalShutDown) {
+ views::Widget* widget = CreateWidget();
+ aura::Window* window = widget->GetNativeWindow();
+ 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);
+ 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);
+ EXPECT_FALSE(maximize_button->maximizer());
+ EXPECT_TRUE(ash::wm::IsWindowNormal(window));
+
+ // Move the mouse cursor over the button to bring up the maximizer bubble.
+ generator.MoveMouseTo(button_pos);
+ EXPECT_TRUE(maximize_button->maximizer());
+
+ // Even though the widget is closing the bubble menu should not crash upon
+ // its delayed destruction.
+ widget->Close();
+}
+
+TEST_F(CustomFrameViewAshTest, MaximizeLeftButtonDragOut) {
+ views::Widget* widget = CreateWidget();
+ aura::Window* window = widget->GetNativeWindow();
+ 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);
+ 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);
+ EXPECT_FALSE(maximize_button->maximizer());
+ EXPECT_TRUE(ash::wm::IsWindowNormal(window));
+ EXPECT_FALSE(maximize_button->phantom_window_open());
+
+ // Move the mouse cursor over the button to bring up the maximizer bubble.
+ generator.MoveMouseTo(button_pos);
+ EXPECT_TRUE(maximize_button->maximizer());
+
+ // Move the mouse over the left maximize button.
+ gfx::Point left_max_pos = maximize_button->maximizer()->
+ GetButtonForUnitTest(SNAP_LEFT)->GetBoundsInScreen().CenterPoint();
+
+ generator.MoveMouseTo(left_max_pos);
+ // Expect the phantom window to be open.
+ EXPECT_TRUE(maximize_button->phantom_window_open());
+
+ // Move away to see the window being destroyed.
+ generator.MoveMouseTo(off_pos);
+ EXPECT_FALSE(maximize_button->phantom_window_open());
+
+ // Move back over the button.
+ generator.MoveMouseTo(button_pos);
+ generator.MoveMouseTo(left_max_pos);
+ EXPECT_TRUE(maximize_button->phantom_window_open());
+
+ // Press button and drag out of dialog.
+ generator.PressLeftButton();
+ generator.MoveMouseTo(off_pos);
+ generator.ReleaseLeftButton();
+
+ // Check that the phantom window is also gone.
+ EXPECT_FALSE(maximize_button->phantom_window_open());
+}
+
+TEST_F(CustomFrameViewAshTest, MaximizeLeftByButton) {
+ const int kGridSize = ash::Shell::GetInstance()->GetGridSize();
+ views::Widget* widget = CreateWidget();
+ aura::Window* window = widget->GetNativeWindow();
+ 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);
+ 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);
+ EXPECT_FALSE(maximize_button->maximizer());
+ EXPECT_TRUE(ash::wm::IsWindowNormal(window));
+ EXPECT_FALSE(maximize_button->phantom_window_open());
+
+ // Move the mouse cursor over the button to bring up the maximizer bubble.
+ generator.MoveMouseTo(button_pos);
+ EXPECT_TRUE(maximize_button->maximizer());
+
+ // Move the mouse over the left maximize button.
+ gfx::Point left_max_pos = maximize_button->maximizer()->
+ GetButtonForUnitTest(SNAP_LEFT)->GetBoundsInScreen().CenterPoint();
+ generator.MoveMouseTo(left_max_pos);
+ EXPECT_TRUE(maximize_button->phantom_window_open());
+ generator.ClickLeftButton();
+
+ EXPECT_FALSE(maximize_button->maximizer());
+ EXPECT_FALSE(maximize_button->phantom_window_open());
+
+ EXPECT_FALSE(ash::wm::IsWindowMaximized(window));
+ EXPECT_FALSE(ash::wm::IsWindowMinimized(window));
+ internal::SnapSizer sizer(window, button_pos,
+ internal::SnapSizer::LEFT_EDGE, kGridSize);
+ EXPECT_EQ(sizer.target_bounds().ToString(), window->bounds().ToString());
+}
+
} // namespace internal
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698