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/system_modal_container_layout_manager.h" | 5 #include "ash/wm/system_modal_container_layout_manager.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "ash/common/session/session_state_delegate.h" | 9 #include "ash/common/session/session_state_delegate.h" |
10 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
11 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
12 #include "ash/root_window_controller.h" | 12 #include "ash/root_window_controller.h" |
13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "ash/test/ash_test_base.h" | 14 #include "ash/test/ash_test_base.h" |
15 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
19 #include "ui/aura/client/aura_constants.h" | 19 #include "ui/aura/client/aura_constants.h" |
20 #include "ui/aura/test/test_window_delegate.h" | 20 #include "ui/aura/test/test_window_delegate.h" |
21 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
22 #include "ui/aura/window_event_dispatcher.h" | 22 #include "ui/aura/window_event_dispatcher.h" |
| 23 #include "ui/base/hit_test.h" |
23 #include "ui/compositor/layer.h" | 24 #include "ui/compositor/layer.h" |
24 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 25 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
25 #include "ui/compositor/test/layer_animator_test_controller.h" | 26 #include "ui/compositor/test/layer_animator_test_controller.h" |
26 #include "ui/events/test/event_generator.h" | 27 #include "ui/events/test/event_generator.h" |
27 #include "ui/keyboard/keyboard_controller.h" | 28 #include "ui/keyboard/keyboard_controller.h" |
28 #include "ui/keyboard/keyboard_switches.h" | 29 #include "ui/keyboard/keyboard_switches.h" |
29 #include "ui/keyboard/keyboard_ui.h" | 30 #include "ui/keyboard/keyboard_ui.h" |
30 #include "ui/keyboard/keyboard_util.h" | 31 #include "ui/keyboard/keyboard_util.h" |
31 #include "ui/views/test/capture_tracking_view.h" | 32 #include "ui/views/test/capture_tracking_view.h" |
32 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 e1.ClickLeftButton(); | 368 e1.ClickLeftButton(); |
368 // Verify that none of the other containers received any more mouse presses. | 369 // Verify that none of the other containers received any more mouse presses. |
369 EXPECT_EQ(1, lock_modal_delegate->mouse_presses()); | 370 EXPECT_EQ(1, lock_modal_delegate->mouse_presses()); |
370 EXPECT_EQ(1, lock_delegate->mouse_presses()); | 371 EXPECT_EQ(1, lock_delegate->mouse_presses()); |
371 EXPECT_EQ(1, main_delegate->mouse_presses()); | 372 EXPECT_EQ(1, main_delegate->mouse_presses()); |
372 EXPECT_EQ(1, transient_delegate->mouse_presses()); | 373 EXPECT_EQ(1, transient_delegate->mouse_presses()); |
373 UnblockUserSession(); | 374 UnblockUserSession(); |
374 } | 375 } |
375 } | 376 } |
376 | 377 |
| 378 TEST_F(SystemModalContainerLayoutManagerTest, ModalTransientChildEvents) { |
| 379 // Create a normal window and attempt to receive a click event. |
| 380 EventTestWindow* main_delegate = new EventTestWindow(false); |
| 381 std::unique_ptr<aura::Window> main( |
| 382 main_delegate->OpenTestWindowWithContext(CurrentContext())); |
| 383 EXPECT_TRUE(wm::IsActiveWindow(main.get())); |
| 384 ui::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), main.get()); |
| 385 e1.ClickLeftButton(); |
| 386 EXPECT_EQ(1, main_delegate->mouse_presses()); |
| 387 |
| 388 // Create a modal window for the main window and verify that the main window |
| 389 // no longer receives mouse events. |
| 390 EventTestWindow* modal1_delegate = new EventTestWindow(true); |
| 391 aura::Window* modal1 = modal1_delegate->OpenTestWindowWithParent(main.get()); |
| 392 EXPECT_TRUE(wm::IsActiveWindow(modal1)); |
| 393 e1.ClickLeftButton(); |
| 394 EXPECT_EQ(1, modal1_delegate->mouse_presses()); |
| 395 EXPECT_EQ(1, main_delegate->mouse_presses()); |
| 396 |
| 397 // Create a non-modal transient child of modal1 and verify it receives mouse |
| 398 // events instead of main and modal1. |
| 399 EventTestWindow* modal1_transient_delegate = new EventTestWindow(false); |
| 400 aura::Window* modal1_transient = |
| 401 modal1_transient_delegate->OpenTestWindowWithParent(modal1); |
| 402 EXPECT_TRUE(wm::IsActiveWindow(modal1_transient)); |
| 403 e1.ClickLeftButton(); |
| 404 EXPECT_EQ(1, modal1_transient_delegate->mouse_presses()); |
| 405 EXPECT_EQ(1, modal1_delegate->mouse_presses()); |
| 406 EXPECT_EQ(1, main_delegate->mouse_presses()); |
| 407 |
| 408 // Create a child control for modal1_transient and it receives mouse events. |
| 409 aura::test::EventCountDelegate control_delegate; |
| 410 control_delegate.set_window_component(HTCLIENT); |
| 411 std::unique_ptr<aura::Window> child(new aura::Window(&control_delegate)); |
| 412 child->SetType(ui::wm::WINDOW_TYPE_CONTROL); |
| 413 child->Init(ui::LAYER_TEXTURED); |
| 414 modal1_transient->AddChild(child.get()); |
| 415 child->SetBounds(gfx::Rect(100, 100)); |
| 416 child->Show(); |
| 417 e1.ClickLeftButton(); |
| 418 EXPECT_EQ("1 1", control_delegate.GetMouseButtonCountsAndReset()); |
| 419 EXPECT_EQ(1, modal1_transient_delegate->mouse_presses()); |
| 420 EXPECT_EQ(1, modal1_delegate->mouse_presses()); |
| 421 EXPECT_EQ(1, main_delegate->mouse_presses()); |
| 422 |
| 423 // Create another modal window for the main window and it receives mouse |
| 424 // events instead of all others. |
| 425 EventTestWindow* modal2_delegate = new EventTestWindow(true); |
| 426 aura::Window* modal2 = modal2_delegate->OpenTestWindowWithParent(main.get()); |
| 427 EXPECT_TRUE(wm::IsActiveWindow(modal2)); |
| 428 e1.ClickLeftButton(); |
| 429 EXPECT_EQ(1, modal2_delegate->mouse_presses()); |
| 430 EXPECT_EQ("0 0", control_delegate.GetMouseButtonCountsAndReset()); |
| 431 EXPECT_EQ(1, modal1_transient_delegate->mouse_presses()); |
| 432 EXPECT_EQ(1, modal1_delegate->mouse_presses()); |
| 433 EXPECT_EQ(1, main_delegate->mouse_presses()); |
| 434 |
| 435 // Create a non-modal transient child of modal2 and it receives events. |
| 436 EventTestWindow* modal2_transient_delegate = new EventTestWindow(false); |
| 437 aura::Window* modal2_transient = |
| 438 modal2_transient_delegate->OpenTestWindowWithParent(modal2); |
| 439 EXPECT_TRUE(wm::IsActiveWindow(modal2_transient)); |
| 440 e1.ClickLeftButton(); |
| 441 EXPECT_EQ(1, modal2_transient_delegate->mouse_presses()); |
| 442 EXPECT_EQ(1, modal2_delegate->mouse_presses()); |
| 443 EXPECT_EQ("0 0", control_delegate.GetMouseButtonCountsAndReset()); |
| 444 EXPECT_EQ(1, modal1_transient_delegate->mouse_presses()); |
| 445 EXPECT_EQ(1, modal1_delegate->mouse_presses()); |
| 446 EXPECT_EQ(1, main_delegate->mouse_presses()); |
| 447 |
| 448 // Create a non-modal transient grandchild of modal2 and it receives events. |
| 449 EventTestWindow* modal2_transient_grandchild_delegate = |
| 450 new EventTestWindow(false); |
| 451 aura::Window* modal2_transient_grandchild = |
| 452 modal2_transient_grandchild_delegate->OpenTestWindowWithParent( |
| 453 modal2_transient); |
| 454 EXPECT_TRUE(wm::IsActiveWindow(modal2_transient_grandchild)); |
| 455 e1.ClickLeftButton(); |
| 456 EXPECT_EQ(1, modal2_transient_grandchild_delegate->mouse_presses()); |
| 457 EXPECT_EQ(1, modal2_transient_delegate->mouse_presses()); |
| 458 EXPECT_EQ(1, modal2_delegate->mouse_presses()); |
| 459 EXPECT_EQ("0 0", control_delegate.GetMouseButtonCountsAndReset()); |
| 460 EXPECT_EQ(1, modal1_transient_delegate->mouse_presses()); |
| 461 EXPECT_EQ(1, modal1_delegate->mouse_presses()); |
| 462 EXPECT_EQ(1, main_delegate->mouse_presses()); |
| 463 } |
| 464 |
377 // Makes sure we don't crash if a modal window is shown while the parent window | 465 // Makes sure we don't crash if a modal window is shown while the parent window |
378 // is hidden. | 466 // is hidden. |
379 TEST_F(SystemModalContainerLayoutManagerTest, ShowModalWhileHidden) { | 467 TEST_F(SystemModalContainerLayoutManagerTest, ShowModalWhileHidden) { |
380 // Hide the lock screen. | 468 // Hide the lock screen. |
381 Shell::GetPrimaryRootWindowController() | 469 Shell::GetPrimaryRootWindowController() |
382 ->GetContainer(kShellWindowId_SystemModalContainer) | 470 ->GetContainer(kShellWindowId_SystemModalContainer) |
383 ->layer() | 471 ->layer() |
384 ->SetOpacity(0); | 472 ->SetOpacity(0); |
385 | 473 |
386 // Create a modal window. | 474 // Create a modal window. |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 if (!SupportsMultipleDisplays()) | 884 if (!SupportsMultipleDisplays()) |
797 return; | 885 return; |
798 | 886 |
799 UpdateDisplay("500x500, 500x500"); | 887 UpdateDisplay("500x500, 500x500"); |
800 InputTestDelegate delegate; | 888 InputTestDelegate delegate; |
801 delegate.RunTest(this); | 889 delegate.RunTest(this); |
802 } | 890 } |
803 | 891 |
804 } // namespace test | 892 } // namespace test |
805 } // namespace ash | 893 } // namespace ash |
OLD | NEW |