Chromium Code Reviews| 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_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.
| |
| 261 views::Widget* widget = CreateWidget(); | |
| 262 aura::Window* window = widget->GetNativeWindow(); | |
| 263 CustomFrameViewAsh* frame = custom_frame_view_ash(widget); | |
| 264 CustomFrameViewAsh::TestApi test(frame); | |
| 265 ash::FrameMaximizeButton* maximize_button = test.maximize_button(); | |
| 266 test.maximize_button()->set_bubble_appearance_delay_ms(0); | |
| 267 gfx::Point center = maximize_button->GetBoundsInScreen().CenterPoint(); | |
| 268 // Move the location off the button. | |
| 269 center.set_y(center.y() - 100); | |
| 270 | |
| 271 aura::test::EventGenerator generator(window->GetRootWindow(), center); | |
| 272 | |
| 273 EXPECT_TRUE(ash::wm::IsWindowNormal(window)); | |
| 274 | |
| 275 // Move the mouse cursor over the button to bring up the maximizer bubble. | |
| 276 center = maximize_button->GetBoundsInScreen().CenterPoint(); | |
| 277 generator.MoveMouseTo(center); | |
| 278 EXPECT_TRUE(maximize_button->maximizer()); | |
| 279 | |
| 280 // Even though the widget is closing the bubble menu should not crash upon | |
| 281 // its delayed destruction. | |
| 282 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.
| |
| 283 } | |
| 284 | |
| 285 TEST_F(CustomFrameViewAshTest, MaximizeButtonExternalShutDown) { | |
| 286 views::Widget* widget = CreateWidget(); | |
| 287 aura::Window* window = widget->GetNativeWindow(); | |
| 288 CustomFrameViewAsh* frame = custom_frame_view_ash(widget); | |
| 289 CustomFrameViewAsh::TestApi test(frame); | |
| 290 ash::FrameMaximizeButton* maximize_button = test.maximize_button(); | |
| 291 maximize_button->set_bubble_appearance_delay_ms(0); | |
| 292 gfx::Point button_pos = maximize_button->GetBoundsInScreen().CenterPoint(); | |
| 293 gfx::Point off_pos(button_pos.x() + 100, button_pos.y() + 100); | |
| 294 | |
| 295 aura::test::EventGenerator generator(window->GetRootWindow(), off_pos); | |
| 296 EXPECT_FALSE(maximize_button->maximizer()); | |
| 297 EXPECT_TRUE(ash::wm::IsWindowNormal(window)); | |
| 298 | |
| 299 // Move the mouse cursor over the button to bring up the maximizer bubble. | |
| 300 generator.MoveMouseTo(button_pos); | |
| 301 EXPECT_TRUE(maximize_button->maximizer()); | |
| 302 | |
| 303 // Even though the widget is closing the bubble menu should not crash upon | |
| 304 // its delayed destruction. | |
| 305 widget->Close(); | |
| 306 } | |
| 307 | |
| 308 TEST_F(CustomFrameViewAshTest, MaximizeLeftButtonDragOut) { | |
| 309 views::Widget* widget = CreateWidget(); | |
| 310 aura::Window* window = widget->GetNativeWindow(); | |
| 311 CustomFrameViewAsh* frame = custom_frame_view_ash(widget); | |
| 312 CustomFrameViewAsh::TestApi test(frame); | |
| 313 ash::FrameMaximizeButton* maximize_button = test.maximize_button(); | |
| 314 maximize_button->set_bubble_appearance_delay_ms(0); | |
| 315 gfx::Point button_pos = maximize_button->GetBoundsInScreen().CenterPoint(); | |
| 316 gfx::Point off_pos(button_pos.x() + 100, button_pos.y() + 100); | |
| 317 | |
| 318 aura::test::EventGenerator generator(window->GetRootWindow(), off_pos); | |
| 319 EXPECT_FALSE(maximize_button->maximizer()); | |
| 320 EXPECT_TRUE(ash::wm::IsWindowNormal(window)); | |
| 321 EXPECT_FALSE(maximize_button->phantom_window_open()); | |
| 322 | |
| 323 // Move the mouse cursor over the button to bring up the maximizer bubble. | |
| 324 generator.MoveMouseTo(button_pos); | |
| 325 EXPECT_TRUE(maximize_button->maximizer()); | |
| 326 | |
| 327 // Move the mouse over the left maximize button. | |
| 328 gfx::Point left_max_pos = maximize_button->maximizer()-> | |
| 329 GetButtonForUnitTest(SNAP_LEFT)->GetBoundsInScreen().CenterPoint(); | |
| 330 | |
| 331 generator.MoveMouseTo(left_max_pos); | |
| 332 // Expect the phantom window to be open. | |
| 333 EXPECT_TRUE(maximize_button->phantom_window_open()); | |
| 334 | |
| 335 // Move away to see the window being destroyed. | |
| 336 generator.MoveMouseTo(off_pos); | |
| 337 EXPECT_FALSE(maximize_button->phantom_window_open()); | |
| 338 | |
| 339 // Move back over the button. | |
| 340 generator.MoveMouseTo(button_pos); | |
| 341 generator.MoveMouseTo(left_max_pos); | |
| 342 EXPECT_TRUE(maximize_button->phantom_window_open()); | |
| 343 | |
| 344 // Press button and drag out of dialog. | |
| 345 generator.PressLeftButton(); | |
| 346 generator.MoveMouseTo(off_pos); | |
| 347 generator.ReleaseLeftButton(); | |
| 348 | |
| 349 // Check that the phantom window is also gone. | |
| 350 EXPECT_FALSE(maximize_button->phantom_window_open()); | |
| 351 } | |
| 352 | |
| 353 TEST_F(CustomFrameViewAshTest, MaximizeLeftByButton) { | |
| 354 const int kGridSize = ash::Shell::GetInstance()->GetGridSize(); | |
| 355 views::Widget* widget = CreateWidget(); | |
| 356 aura::Window* window = widget->GetNativeWindow(); | |
| 357 CustomFrameViewAsh* frame = custom_frame_view_ash(widget); | |
| 358 CustomFrameViewAsh::TestApi test(frame); | |
| 359 ash::FrameMaximizeButton* maximize_button = test.maximize_button(); | |
| 360 maximize_button->set_bubble_appearance_delay_ms(0); | |
| 361 gfx::Point button_pos = maximize_button->GetBoundsInScreen().CenterPoint(); | |
| 362 gfx::Point off_pos(button_pos.x() + 100, button_pos.y() + 100); | |
| 363 | |
| 364 aura::test::EventGenerator generator(window->GetRootWindow(), off_pos); | |
| 365 EXPECT_FALSE(maximize_button->maximizer()); | |
| 366 EXPECT_TRUE(ash::wm::IsWindowNormal(window)); | |
| 367 EXPECT_FALSE(maximize_button->phantom_window_open()); | |
| 368 | |
| 369 // Move the mouse cursor over the button to bring up the maximizer bubble. | |
| 370 generator.MoveMouseTo(button_pos); | |
| 371 EXPECT_TRUE(maximize_button->maximizer()); | |
| 372 | |
| 373 // Move the mouse over the left maximize button. | |
| 374 gfx::Point left_max_pos = maximize_button->maximizer()-> | |
| 375 GetButtonForUnitTest(SNAP_LEFT)->GetBoundsInScreen().CenterPoint(); | |
| 376 generator.MoveMouseTo(left_max_pos); | |
| 377 EXPECT_TRUE(maximize_button->phantom_window_open()); | |
| 378 generator.ClickLeftButton(); | |
| 379 | |
| 380 EXPECT_FALSE(maximize_button->maximizer()); | |
| 381 EXPECT_FALSE(maximize_button->phantom_window_open()); | |
| 382 | |
| 383 EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); | |
| 384 EXPECT_FALSE(ash::wm::IsWindowMinimized(window)); | |
| 385 internal::SnapSizer sizer(window, button_pos, | |
| 386 internal::SnapSizer::LEFT_EDGE, kGridSize); | |
| 387 EXPECT_EQ(sizer.target_bounds().ToString(), window->bounds().ToString()); | |
| 388 } | |
| 389 | |
| 258 } // namespace internal | 390 } // namespace internal |
| 259 } // namespace ash | 391 } // namespace ash |
| OLD | NEW |