| 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 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 // Test for http://crbug.com/263599. Virtual keyboard should be able to receive | 611 // Test for http://crbug.com/263599. Virtual keyboard should be able to receive |
| 640 // events at blocked user session. | 612 // events at blocked user session. |
| 641 TEST_F(VirtualKeyboardRootWindowControllerTest, | 613 TEST_F(VirtualKeyboardRootWindowControllerTest, |
| 642 ClickVirtualKeyboardInBlockedWindow) { | 614 ClickVirtualKeyboardInBlockedWindow) { |
| 643 aura::Window* root_window = Shell::GetPrimaryRootWindow(); | 615 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 644 aura::Window* keyboard_container = Shell::GetContainer(root_window, | 616 aura::Window* keyboard_container = Shell::GetContainer(root_window, |
| 645 internal::kShellWindowId_VirtualKeyboardContainer); | 617 internal::kShellWindowId_VirtualKeyboardContainer); |
| 646 ASSERT_TRUE(keyboard_container); | 618 ASSERT_TRUE(keyboard_container); |
| 647 keyboard_container->Show(); | 619 keyboard_container->Show(); |
| 648 | 620 |
| 649 ClickTestWindow* main_delegate = new ClickTestWindow(); | 621 aura::Window* keyboard_window = Shell::GetInstance()->keyboard_controller()-> |
| 650 scoped_ptr<aura::Window> keyboard_window( | 622 proxy()->GetKeyboardWindow(); |
| 651 main_delegate->CreateTestWindowWithParent(keyboard_container)); | 623 keyboard_container->AddChild(keyboard_window); |
| 652 keyboard_container->layout_manager()->OnWindowResized(); | 624 keyboard_window->SetBounds(gfx::Rect()); |
| 653 keyboard_window->Show(); | 625 keyboard_window->Show(); |
| 654 aura::test::EventGenerator event_generator(root_window, | 626 |
| 655 keyboard_window.get()); | 627 aura::test::TestEventHandler* handler = new aura::test::TestEventHandler; |
| 628 root_window->SetEventFilter(handler); |
| 629 |
| 630 aura::test::EventGenerator event_generator(root_window, keyboard_window); |
| 656 event_generator.ClickLeftButton(); | 631 event_generator.ClickLeftButton(); |
| 657 int expected_mouse_presses = 1; | 632 int expected_mouse_presses = 1; |
| 658 EXPECT_EQ(expected_mouse_presses, main_delegate->mouse_presses()); | 633 EXPECT_EQ(expected_mouse_presses, handler->num_mouse_events() / 2); |
| 659 | 634 |
| 660 for (int block_reason = FIRST_BLOCK_REASON; | 635 for (int block_reason = FIRST_BLOCK_REASON; |
| 661 block_reason < NUMBER_OF_BLOCK_REASONS; | 636 block_reason < NUMBER_OF_BLOCK_REASONS; |
| 662 ++block_reason) { | 637 ++block_reason) { |
| 663 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); | 638 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 664 event_generator.ClickLeftButton(); | 639 event_generator.ClickLeftButton(); |
| 665 expected_mouse_presses++; | 640 expected_mouse_presses++; |
| 666 EXPECT_EQ(expected_mouse_presses, main_delegate->mouse_presses()); | 641 EXPECT_EQ(expected_mouse_presses, handler->num_mouse_events() / 2); |
| 667 UnblockUserSession(); | 642 UnblockUserSession(); |
| 668 } | 643 } |
| 669 } | 644 } |
| 670 | 645 |
| 671 // Test for http://crbug.com/299787. RootWindowController should delete | 646 // Test for http://crbug.com/299787. RootWindowController should delete |
| 672 // the old container since the keyboard controller creates a new window in | 647 // the old container since the keyboard controller creates a new window in |
| 673 // GetWindowContainer(). | 648 // GetWindowContainer(). |
| 674 TEST_F(VirtualKeyboardRootWindowControllerTest, | 649 TEST_F(VirtualKeyboardRootWindowControllerTest, |
| 675 DeleteOldContainerOnVirtualKeyboardInit) { | 650 DeleteOldContainerOnVirtualKeyboardInit) { |
| 676 aura::Window* root_window = ash::Shell::GetPrimaryRootWindow(); | 651 aura::Window* root_window = ash::Shell::GetPrimaryRootWindow(); |
| 677 aura::Window* keyboard_container = Shell::GetContainer(root_window, | 652 aura::Window* keyboard_container = Shell::GetContainer(root_window, |
| 678 internal::kShellWindowId_VirtualKeyboardContainer); | 653 internal::kShellWindowId_VirtualKeyboardContainer); |
| 679 ASSERT_TRUE(keyboard_container); | 654 ASSERT_TRUE(keyboard_container); |
| 680 // Track the keyboard container window. | 655 // Track the keyboard container window. |
| 681 aura::WindowTracker tracker; | 656 aura::WindowTracker tracker; |
| 682 tracker.Add(keyboard_container); | 657 tracker.Add(keyboard_container); |
| 683 // Mock a login user profile change to reinitialize the keyboard. | 658 // Mock a login user profile change to reinitialize the keyboard. |
| 684 ash::Shell::GetInstance()->OnLoginUserProfilePrepared(); | 659 ash::Shell::GetInstance()->OnLoginUserProfilePrepared(); |
| 685 // keyboard_container should no longer be present. | 660 // keyboard_container should no longer be present. |
| 686 EXPECT_FALSE(tracker.Contains(keyboard_container)); | 661 EXPECT_FALSE(tracker.Contains(keyboard_container)); |
| 687 } | 662 } |
| 688 | 663 |
| 689 } // namespace test | 664 } // namespace test |
| 690 } // namespace ash | 665 } // namespace ash |
| OLD | NEW |