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/custom_frame_view_ash.h" | 5 #include "ash/wm/custom_frame_view_ash.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 9 #include "ash/wm/maximize_bubble_controller.h" |
9 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
| 11 #include "ash/wm/workspace/frame_maximize_button.h" |
10 #include "ash/wm/workspace/snap_sizer.h" | 12 #include "ash/wm/workspace/snap_sizer.h" |
11 #include "base/command_line.h" | 13 #include "base/command_line.h" |
12 #include "ui/aura/aura_switches.h" | 14 #include "ui/aura/aura_switches.h" |
13 #include "ui/aura/test/event_generator.h" | 15 #include "ui/aura/test/event_generator.h" |
14 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
15 #include "ui/views/controls/button/image_button.h" | 17 #include "ui/views/controls/button/image_button.h" |
16 #include "ui/views/test/test_views_delegate.h" | 18 #include "ui/views/test/test_views_delegate.h" |
17 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
18 #include "ui/views/widget/widget_delegate.h" | 20 #include "ui/views/widget/widget_delegate.h" |
19 | 21 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 RunAllPendingInMessageLoop(); | 250 RunAllPendingInMessageLoop(); |
249 | 251 |
250 EXPECT_TRUE(ash::wm::IsWindowMinimized(window)); | 252 EXPECT_TRUE(ash::wm::IsWindowMinimized(window)); |
251 } | 253 } |
252 | 254 |
253 // Test with gesture events. | 255 // Test with gesture events. |
254 | 256 |
255 widget->Close(); | 257 widget->Close(); |
256 } | 258 } |
257 | 259 |
| 260 // Test that closing the (browser) window with an opened balloon does not |
| 261 // crash the system. In other words: Make sure that shutting down the frame |
| 262 // destroys the opened balloon in an orderly fashion. |
| 263 TEST_F(CustomFrameViewAshTest, MaximizeButtonExternalShutDown) { |
| 264 views::Widget* widget = CreateWidget(); |
| 265 aura::Window* window = widget->GetNativeWindow(); |
| 266 CustomFrameViewAsh* frame = custom_frame_view_ash(widget); |
| 267 CustomFrameViewAsh::TestApi test(frame); |
| 268 ash::FrameMaximizeButton* maximize_button = test.maximize_button(); |
| 269 maximize_button->set_bubble_appearance_delay_ms(0); |
| 270 gfx::Point button_pos = maximize_button->GetBoundsInScreen().CenterPoint(); |
| 271 gfx::Point off_pos(button_pos.x() + 100, button_pos.y() + 100); |
| 272 |
| 273 aura::test::EventGenerator generator(window->GetRootWindow(), off_pos); |
| 274 EXPECT_FALSE(maximize_button->maximizer()); |
| 275 EXPECT_TRUE(ash::wm::IsWindowNormal(window)); |
| 276 |
| 277 // Move the mouse cursor over the button to bring up the maximizer bubble. |
| 278 generator.MoveMouseTo(button_pos); |
| 279 EXPECT_TRUE(maximize_button->maximizer()); |
| 280 |
| 281 // Even though the widget is closing the bubble menu should not crash upon |
| 282 // its delayed destruction. |
| 283 widget->CloseNow(); |
| 284 } |
| 285 |
| 286 // Test that hovering over a button in the balloon dialog will show the phantom |
| 287 // window. Moving then away from the button will hide it again. Then check that |
| 288 // pressing and dragging the button itself off the button will also release the |
| 289 // phantom window. |
| 290 TEST_F(CustomFrameViewAshTest, MaximizeLeftButtonDragOut) { |
| 291 views::Widget* widget = CreateWidget(); |
| 292 aura::Window* window = widget->GetNativeWindow(); |
| 293 CustomFrameViewAsh* frame = custom_frame_view_ash(widget); |
| 294 CustomFrameViewAsh::TestApi test(frame); |
| 295 ash::FrameMaximizeButton* maximize_button = test.maximize_button(); |
| 296 maximize_button->set_bubble_appearance_delay_ms(0); |
| 297 gfx::Point button_pos = maximize_button->GetBoundsInScreen().CenterPoint(); |
| 298 gfx::Point off_pos(button_pos.x() + 100, button_pos.y() + 100); |
| 299 |
| 300 aura::test::EventGenerator generator(window->GetRootWindow(), off_pos); |
| 301 EXPECT_FALSE(maximize_button->maximizer()); |
| 302 EXPECT_TRUE(ash::wm::IsWindowNormal(window)); |
| 303 EXPECT_FALSE(maximize_button->phantom_window_open()); |
| 304 |
| 305 // Move the mouse cursor over the button to bring up the maximizer bubble. |
| 306 generator.MoveMouseTo(button_pos); |
| 307 EXPECT_TRUE(maximize_button->maximizer()); |
| 308 |
| 309 // Move the mouse over the left maximize button. |
| 310 gfx::Point left_max_pos = maximize_button->maximizer()-> |
| 311 GetButtonForUnitTest(SNAP_LEFT)->GetBoundsInScreen().CenterPoint(); |
| 312 |
| 313 generator.MoveMouseTo(left_max_pos); |
| 314 // Expect the phantom window to be open. |
| 315 EXPECT_TRUE(maximize_button->phantom_window_open()); |
| 316 |
| 317 // Move away to see the window being destroyed. |
| 318 generator.MoveMouseTo(off_pos); |
| 319 EXPECT_FALSE(maximize_button->phantom_window_open()); |
| 320 |
| 321 // Move back over the button. |
| 322 generator.MoveMouseTo(button_pos); |
| 323 generator.MoveMouseTo(left_max_pos); |
| 324 EXPECT_TRUE(maximize_button->phantom_window_open()); |
| 325 |
| 326 // Press button and drag out of dialog. |
| 327 generator.PressLeftButton(); |
| 328 generator.MoveMouseTo(off_pos); |
| 329 generator.ReleaseLeftButton(); |
| 330 |
| 331 // Check that the phantom window is also gone. |
| 332 EXPECT_FALSE(maximize_button->phantom_window_open()); |
| 333 } |
| 334 |
| 335 // Test that clicking a button in the maximizer bubble (in this case the |
| 336 // maximize left button) will do the requested action. |
| 337 TEST_F(CustomFrameViewAshTest, MaximizeLeftByButton) { |
| 338 const int kGridSize = ash::Shell::GetInstance()->GetGridSize(); |
| 339 views::Widget* widget = CreateWidget(); |
| 340 aura::Window* window = widget->GetNativeWindow(); |
| 341 CustomFrameViewAsh* frame = custom_frame_view_ash(widget); |
| 342 CustomFrameViewAsh::TestApi test(frame); |
| 343 ash::FrameMaximizeButton* maximize_button = test.maximize_button(); |
| 344 maximize_button->set_bubble_appearance_delay_ms(0); |
| 345 gfx::Point button_pos = maximize_button->GetBoundsInScreen().CenterPoint(); |
| 346 gfx::Point off_pos(button_pos.x() + 100, button_pos.y() + 100); |
| 347 |
| 348 aura::test::EventGenerator generator(window->GetRootWindow(), off_pos); |
| 349 EXPECT_FALSE(maximize_button->maximizer()); |
| 350 EXPECT_TRUE(ash::wm::IsWindowNormal(window)); |
| 351 EXPECT_FALSE(maximize_button->phantom_window_open()); |
| 352 |
| 353 // Move the mouse cursor over the button to bring up the maximizer bubble. |
| 354 generator.MoveMouseTo(button_pos); |
| 355 EXPECT_TRUE(maximize_button->maximizer()); |
| 356 |
| 357 // Move the mouse over the left maximize button. |
| 358 gfx::Point left_max_pos = maximize_button->maximizer()-> |
| 359 GetButtonForUnitTest(SNAP_LEFT)->GetBoundsInScreen().CenterPoint(); |
| 360 generator.MoveMouseTo(left_max_pos); |
| 361 EXPECT_TRUE(maximize_button->phantom_window_open()); |
| 362 generator.ClickLeftButton(); |
| 363 |
| 364 EXPECT_FALSE(maximize_button->maximizer()); |
| 365 EXPECT_FALSE(maximize_button->phantom_window_open()); |
| 366 |
| 367 EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); |
| 368 EXPECT_FALSE(ash::wm::IsWindowMinimized(window)); |
| 369 internal::SnapSizer sizer(window, button_pos, |
| 370 internal::SnapSizer::LEFT_EDGE, kGridSize); |
| 371 EXPECT_EQ(sizer.target_bounds().ToString(), window->bounds().ToString()); |
| 372 } |
| 373 |
258 } // namespace internal | 374 } // namespace internal |
259 } // namespace ash | 375 } // namespace ash |
OLD | NEW |