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" |
11 #include "ash/system/tray/system_tray_delegate.h" | 11 #include "ash/system/tray/system_tray_delegate.h" |
12 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
13 #include "ash/wm/system_modal_container_layout_manager.h" | 13 #include "ash/wm/system_modal_container_layout_manager.h" |
14 #include "ash/wm/window_properties.h" | 14 #include "ash/wm/window_properties.h" |
15 #include "ash/wm/window_state.h" | 15 #include "ash/wm/window_state.h" |
16 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "ui/aura/client/focus_change_observer.h" | 18 #include "ui/aura/client/focus_change_observer.h" |
19 #include "ui/aura/client/focus_client.h" | 19 #include "ui/aura/client/focus_client.h" |
20 #include "ui/aura/client/window_tree_client.h" | 20 #include "ui/aura/client/window_tree_client.h" |
21 #include "ui/aura/env.h" | 21 #include "ui/aura/env.h" |
22 #include "ui/aura/root_window.h" | 22 #include "ui/aura/root_window.h" |
23 #include "ui/aura/test/event_generator.h" | 23 #include "ui/aura/test/event_generator.h" |
| 24 #include "ui/aura/test/test_event_handler.h" |
24 #include "ui/aura/test/test_window_delegate.h" | 25 #include "ui/aura/test/test_window_delegate.h" |
25 #include "ui/aura/test/test_windows.h" | 26 #include "ui/aura/test/test_windows.h" |
26 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
27 #include "ui/aura/window_tracker.h" | 28 #include "ui/aura/window_tracker.h" |
| 29 #include "ui/keyboard/keyboard_controller_proxy.h" |
28 #include "ui/keyboard/keyboard_switches.h" | 30 #include "ui/keyboard/keyboard_switches.h" |
29 #include "ui/views/controls/menu/menu_controller.h" | 31 #include "ui/views/controls/menu/menu_controller.h" |
30 #include "ui/views/widget/widget.h" | 32 #include "ui/views/widget/widget.h" |
31 #include "ui/views/widget/widget_delegate.h" | 33 #include "ui/views/widget/widget_delegate.h" |
32 | 34 |
33 using aura::Window; | 35 using aura::Window; |
34 using views::Widget; | 36 using views::Widget; |
35 | 37 |
36 namespace ash { | 38 namespace ash { |
37 namespace { | 39 namespace { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 aura::Window* lost_focus) OVERRIDE { | 80 aura::Window* lost_focus) OVERRIDE { |
79 if (window_ == lost_focus) | 81 if (window_ == lost_focus) |
80 delete window_; | 82 delete window_; |
81 } | 83 } |
82 | 84 |
83 aura::Window* window_; | 85 aura::Window* window_; |
84 | 86 |
85 DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate); | 87 DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate); |
86 }; | 88 }; |
87 | 89 |
88 class ClickTestWindow : public views::WidgetDelegateView { | |
89 public: | |
90 ClickTestWindow() : mouse_presses_(0) {} | |
91 virtual ~ClickTestWindow() {} | |
92 | |
93 // Overridden from views::WidgetDelegate: | |
94 virtual views::View* GetContentsView() OVERRIDE { | |
95 return this; | |
96 } | |
97 | |
98 aura::Window* CreateTestWindowWithParent(aura::Window* parent) { | |
99 DCHECK(parent); | |
100 views::Widget* widget = Widget::CreateWindowWithParent(this, parent); | |
101 return widget->GetNativeView(); | |
102 } | |
103 | |
104 // Overridden from views::View: | |
105 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE { | |
106 mouse_presses_++; | |
107 return false; | |
108 } | |
109 | |
110 int mouse_presses() const { return mouse_presses_; } | |
111 | |
112 private: | |
113 int mouse_presses_; | |
114 | |
115 DISALLOW_COPY_AND_ASSIGN(ClickTestWindow); | |
116 }; | |
117 | |
118 } // namespace | 90 } // namespace |
119 | 91 |
120 namespace test { | 92 namespace test { |
121 | 93 |
122 class RootWindowControllerTest : public test::AshTestBase { | 94 class RootWindowControllerTest : public test::AshTestBase { |
123 public: | 95 public: |
124 views::Widget* CreateTestWidget(const gfx::Rect& bounds) { | 96 views::Widget* CreateTestWidget(const gfx::Rect& bounds) { |
125 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( | 97 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
126 NULL, CurrentContext(), bounds); | 98 NULL, CurrentContext(), bounds); |
127 widget->Show(); | 99 widget->Show(); |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 // Test for http://crbug.com/263599. Virtual keyboard should be able to receive | 627 // Test for http://crbug.com/263599. Virtual keyboard should be able to receive |
656 // events at blocked user session. | 628 // events at blocked user session. |
657 TEST_F(VirtualKeyboardRootWindowControllerTest, | 629 TEST_F(VirtualKeyboardRootWindowControllerTest, |
658 ClickVirtualKeyboardInBlockedWindow) { | 630 ClickVirtualKeyboardInBlockedWindow) { |
659 aura::Window* root_window = Shell::GetPrimaryRootWindow(); | 631 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
660 aura::Window* keyboard_container = Shell::GetContainer(root_window, | 632 aura::Window* keyboard_container = Shell::GetContainer(root_window, |
661 internal::kShellWindowId_VirtualKeyboardContainer); | 633 internal::kShellWindowId_VirtualKeyboardContainer); |
662 ASSERT_TRUE(keyboard_container); | 634 ASSERT_TRUE(keyboard_container); |
663 keyboard_container->Show(); | 635 keyboard_container->Show(); |
664 | 636 |
665 ClickTestWindow* main_delegate = new ClickTestWindow(); | 637 aura::Window* keyboard_window = Shell::GetInstance()->keyboard_controller() |
666 scoped_ptr<aura::Window> keyboard_window( | 638 ->proxy()->GetKeyboardWindow(); |
667 main_delegate->CreateTestWindowWithParent(keyboard_container)); | 639 keyboard_container->AddChild(keyboard_window); |
668 keyboard_container->layout_manager()->OnWindowResized(); | 640 keyboard_window->SetBounds(gfx::Rect()); |
669 keyboard_window->Show(); | 641 keyboard_window->Show(); |
670 aura::test::EventGenerator event_generator(root_window, | 642 |
671 keyboard_window.get()); | 643 aura::test::TestEventHandler* handler = new aura::test::TestEventHandler; |
| 644 root_window->SetEventFilter(handler); |
| 645 |
| 646 aura::test::EventGenerator event_generator(root_window, keyboard_window); |
672 event_generator.ClickLeftButton(); | 647 event_generator.ClickLeftButton(); |
673 int expected_mouse_presses = 1; | 648 int expected_mouse_presses = 1; |
674 EXPECT_EQ(expected_mouse_presses, main_delegate->mouse_presses()); | 649 EXPECT_EQ(expected_mouse_presses, handler->num_mouse_events() / 2); |
675 | 650 |
676 for (int block_reason = FIRST_BLOCK_REASON; | 651 for (int block_reason = FIRST_BLOCK_REASON; |
677 block_reason < NUMBER_OF_BLOCK_REASONS; | 652 block_reason < NUMBER_OF_BLOCK_REASONS; |
678 ++block_reason) { | 653 ++block_reason) { |
679 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); | 654 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
680 event_generator.ClickLeftButton(); | 655 event_generator.ClickLeftButton(); |
681 expected_mouse_presses++; | 656 expected_mouse_presses++; |
682 EXPECT_EQ(expected_mouse_presses, main_delegate->mouse_presses()); | 657 EXPECT_EQ(expected_mouse_presses, handler->num_mouse_events() / 2); |
683 UnblockUserSession(); | 658 UnblockUserSession(); |
684 } | 659 } |
685 } | 660 } |
686 | 661 |
687 // Test for http://crbug.com/299787. RootWindowController should delete | 662 // Test for http://crbug.com/299787. RootWindowController should delete |
688 // the old container since the keyboard controller creates a new window in | 663 // the old container since the keyboard controller creates a new window in |
689 // GetWindowContainer(). | 664 // GetWindowContainer(). |
690 TEST_F(VirtualKeyboardRootWindowControllerTest, | 665 TEST_F(VirtualKeyboardRootWindowControllerTest, |
691 DeleteOldContainerOnVirtualKeyboardInit) { | 666 DeleteOldContainerOnVirtualKeyboardInit) { |
692 aura::Window* root_window = ash::Shell::GetPrimaryRootWindow(); | 667 aura::Window* root_window = ash::Shell::GetPrimaryRootWindow(); |
693 aura::Window* keyboard_container = Shell::GetContainer(root_window, | 668 aura::Window* keyboard_container = Shell::GetContainer(root_window, |
694 internal::kShellWindowId_VirtualKeyboardContainer); | 669 internal::kShellWindowId_VirtualKeyboardContainer); |
695 ASSERT_TRUE(keyboard_container); | 670 ASSERT_TRUE(keyboard_container); |
696 // Track the keyboard container window. | 671 // Track the keyboard container window. |
697 aura::WindowTracker tracker; | 672 aura::WindowTracker tracker; |
698 tracker.Add(keyboard_container); | 673 tracker.Add(keyboard_container); |
699 // Mock a login user profile change to reinitialize the keyboard. | 674 // Mock a login user profile change to reinitialize the keyboard. |
700 ash::Shell::GetInstance()->OnLoginUserProfilePrepared(); | 675 ash::Shell::GetInstance()->OnLoginUserProfilePrepared(); |
701 // keyboard_container should no longer be present. | 676 // keyboard_container should no longer be present. |
702 EXPECT_FALSE(tracker.Contains(keyboard_container)); | 677 EXPECT_FALSE(tracker.Contains(keyboard_container)); |
703 } | 678 } |
704 | 679 |
705 } // namespace test | 680 } // namespace test |
706 } // namespace ash | 681 } // namespace ash |
OLD | NEW |