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/root_window_controller.h" | 5 #include "ash/root_window_controller.h" |
6 | 6 |
7 #include "ash/session_state_delegate.h" | 7 #include "ash/session_state_delegate.h" |
8 #include "ash/shelf/shelf_layout_manager.h" | 8 #include "ash/shelf/shelf_layout_manager.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 ASSERT_TRUE(keyboard_container); | 646 ASSERT_TRUE(keyboard_container); |
647 keyboard_container->Show(); | 647 keyboard_container->Show(); |
648 | 648 |
649 aura::Window* keyboard_window = keyboard::KeyboardController::GetInstance()-> | 649 aura::Window* keyboard_window = keyboard::KeyboardController::GetInstance()-> |
650 proxy()->GetKeyboardWindow(); | 650 proxy()->GetKeyboardWindow(); |
651 keyboard_container->AddChild(keyboard_window); | 651 keyboard_container->AddChild(keyboard_window); |
652 keyboard_window->set_owned_by_parent(false); | 652 keyboard_window->set_owned_by_parent(false); |
653 keyboard_window->SetBounds(gfx::Rect()); | 653 keyboard_window->SetBounds(gfx::Rect()); |
654 keyboard_window->Show(); | 654 keyboard_window->Show(); |
655 | 655 |
656 ui::test::TestEventHandler* handler = new ui::test::TestEventHandler; | 656 ui::test::TestEventHandler handler; |
657 root_window->SetEventFilter(handler); | 657 root_window->AddPreTargetHandler(&handler); |
658 | 658 |
659 aura::test::EventGenerator event_generator(root_window, keyboard_window); | 659 aura::test::EventGenerator event_generator(root_window, keyboard_window); |
660 event_generator.ClickLeftButton(); | 660 event_generator.ClickLeftButton(); |
661 int expected_mouse_presses = 1; | 661 int expected_mouse_presses = 1; |
662 EXPECT_EQ(expected_mouse_presses, handler->num_mouse_events() / 2); | 662 EXPECT_EQ(expected_mouse_presses, handler.num_mouse_events() / 2); |
663 | 663 |
664 for (int block_reason = FIRST_BLOCK_REASON; | 664 for (int block_reason = FIRST_BLOCK_REASON; |
665 block_reason < NUMBER_OF_BLOCK_REASONS; | 665 block_reason < NUMBER_OF_BLOCK_REASONS; |
666 ++block_reason) { | 666 ++block_reason) { |
667 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); | 667 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
668 event_generator.ClickLeftButton(); | 668 event_generator.ClickLeftButton(); |
669 expected_mouse_presses++; | 669 expected_mouse_presses++; |
670 EXPECT_EQ(expected_mouse_presses, handler->num_mouse_events() / 2); | 670 EXPECT_EQ(expected_mouse_presses, handler.num_mouse_events() / 2); |
671 UnblockUserSession(); | 671 UnblockUserSession(); |
672 } | 672 } |
| 673 root_window->RemovePreTargetHandler(&handler); |
673 } | 674 } |
674 | 675 |
675 // Test for http://crbug.com/299787. RootWindowController should delete | 676 // Test for http://crbug.com/299787. RootWindowController should delete |
676 // the old container since the keyboard controller creates a new window in | 677 // the old container since the keyboard controller creates a new window in |
677 // GetWindowContainer(). | 678 // GetWindowContainer(). |
678 TEST_F(VirtualKeyboardRootWindowControllerTest, | 679 TEST_F(VirtualKeyboardRootWindowControllerTest, |
679 DeleteOldContainerOnVirtualKeyboardInit) { | 680 DeleteOldContainerOnVirtualKeyboardInit) { |
680 aura::Window* root_window = Shell::GetPrimaryRootWindow(); | 681 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
681 aura::Window* keyboard_container = | 682 aura::Window* keyboard_container = |
682 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); | 683 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 ASSERT_TRUE(keyboard_container); | 728 ASSERT_TRUE(keyboard_container); |
728 keyboard_container->Show(); | 729 keyboard_container->Show(); |
729 | 730 |
730 aura::Window* keyboard_window = keyboard::KeyboardController::GetInstance()-> | 731 aura::Window* keyboard_window = keyboard::KeyboardController::GetInstance()-> |
731 proxy()->GetKeyboardWindow(); | 732 proxy()->GetKeyboardWindow(); |
732 keyboard_container->AddChild(keyboard_window); | 733 keyboard_container->AddChild(keyboard_window); |
733 keyboard_window->set_owned_by_parent(false); | 734 keyboard_window->set_owned_by_parent(false); |
734 keyboard_window->SetBounds(gfx::Rect()); | 735 keyboard_window->SetBounds(gfx::Rect()); |
735 keyboard_window->Show(); | 736 keyboard_window->Show(); |
736 | 737 |
737 ui::test::TestEventHandler* handler = new ui::test::TestEventHandler; | 738 ui::test::TestEventHandler handler; |
738 root_window->SetEventFilter(handler); | 739 root_window->AddPreTargetHandler(&handler); |
739 aura::test::EventGenerator root_window_event_generator(root_window); | 740 aura::test::EventGenerator root_window_event_generator(root_window); |
740 aura::test::EventGenerator keyboard_event_generator(root_window, | 741 aura::test::EventGenerator keyboard_event_generator(root_window, |
741 keyboard_window); | 742 keyboard_window); |
742 | 743 |
743 views::Widget* modal_widget = | 744 views::Widget* modal_widget = |
744 CreateModalWidget(gfx::Rect(300, 10, 100, 100)); | 745 CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
745 | 746 |
746 // Verify that mouse events to the root window are block with a visble modal | 747 // Verify that mouse events to the root window are block with a visble modal |
747 // dialog. | 748 // dialog. |
748 root_window_event_generator.ClickLeftButton(); | 749 root_window_event_generator.ClickLeftButton(); |
749 EXPECT_EQ(0, handler->num_mouse_events()); | 750 EXPECT_EQ(0, handler.num_mouse_events()); |
750 | 751 |
751 // Verify that event dispatch to the virtual keyboard is unblocked. | 752 // Verify that event dispatch to the virtual keyboard is unblocked. |
752 keyboard_event_generator.ClickLeftButton(); | 753 keyboard_event_generator.ClickLeftButton(); |
753 EXPECT_EQ(1, handler->num_mouse_events() / 2); | 754 EXPECT_EQ(1, handler.num_mouse_events() / 2); |
754 | 755 |
755 modal_widget->Close(); | 756 modal_widget->Close(); |
756 | 757 |
757 // Verify that mouse events are now unblocked to the root window. | 758 // Verify that mouse events are now unblocked to the root window. |
758 root_window_event_generator.ClickLeftButton(); | 759 root_window_event_generator.ClickLeftButton(); |
759 EXPECT_EQ(2, handler->num_mouse_events() / 2); | 760 EXPECT_EQ(2, handler.num_mouse_events() / 2); |
| 761 root_window->RemovePreTargetHandler(&handler); |
760 } | 762 } |
761 | 763 |
762 } // namespace test | 764 } // namespace test |
763 } // namespace ash | 765 } // namespace ash |
OLD | NEW |