Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: ash/root_window_controller_unittest.cc

Issue 2445293002: Make the virtual keyboard show up on the display with input focus. (Closed)
Patch Set: address the comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/mus/keyboard_ui_mus.cc ('k') | ash/shell.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 7 #include <memory>
8 8
9 #include "ash/aura/wm_window_aura.h" 9 #include "ash/aura/wm_window_aura.h"
10 #include "ash/common/material_design/material_design_controller.h" 10 #include "ash/common/material_design/material_design_controller.h"
(...skipping 19 matching lines...) Expand all
30 #include "ui/aura/env.h" 30 #include "ui/aura/env.h"
31 #include "ui/aura/test/test_window_delegate.h" 31 #include "ui/aura/test/test_window_delegate.h"
32 #include "ui/aura/test/test_windows.h" 32 #include "ui/aura/test/test_windows.h"
33 #include "ui/aura/window.h" 33 #include "ui/aura/window.h"
34 #include "ui/aura/window_event_dispatcher.h" 34 #include "ui/aura/window_event_dispatcher.h"
35 #include "ui/aura/window_tracker.h" 35 #include "ui/aura/window_tracker.h"
36 #include "ui/base/ime/dummy_text_input_client.h" 36 #include "ui/base/ime/dummy_text_input_client.h"
37 #include "ui/base/ime/input_method.h" 37 #include "ui/base/ime/input_method.h"
38 #include "ui/base/ime/text_input_client.h" 38 #include "ui/base/ime/text_input_client.h"
39 #include "ui/display/manager/display_manager.h" 39 #include "ui/display/manager/display_manager.h"
40 #include "ui/display/test/display_manager_test_api.h"
41 #include "ui/events/devices/device_data_manager.h"
42 #include "ui/events/devices/touchscreen_device.h"
40 #include "ui/events/test/event_generator.h" 43 #include "ui/events/test/event_generator.h"
41 #include "ui/events/test/test_event_handler.h" 44 #include "ui/events/test/test_event_handler.h"
42 #include "ui/keyboard/keyboard_controller.h" 45 #include "ui/keyboard/keyboard_controller.h"
43 #include "ui/keyboard/keyboard_switches.h" 46 #include "ui/keyboard/keyboard_switches.h"
44 #include "ui/keyboard/keyboard_ui.h" 47 #include "ui/keyboard/keyboard_ui.h"
45 #include "ui/keyboard/keyboard_util.h" 48 #include "ui/keyboard/keyboard_util.h"
46 #include "ui/views/controls/menu/menu_controller.h" 49 #include "ui/views/controls/menu/menu_controller.h"
47 #include "ui/views/widget/widget.h" 50 #include "ui/views/widget/widget.h"
48 #include "ui/views/widget/widget_delegate.h" 51 #include "ui/views/widget/widget_delegate.h"
49 52
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 class VirtualKeyboardRootWindowControllerTest 699 class VirtualKeyboardRootWindowControllerTest
697 : public RootWindowControllerTest { 700 : public RootWindowControllerTest {
698 public: 701 public:
699 VirtualKeyboardRootWindowControllerTest() {} 702 VirtualKeyboardRootWindowControllerTest() {}
700 ~VirtualKeyboardRootWindowControllerTest() override {} 703 ~VirtualKeyboardRootWindowControllerTest() override {}
701 704
702 void SetUp() override { 705 void SetUp() override {
703 base::CommandLine::ForCurrentProcess()->AppendSwitch( 706 base::CommandLine::ForCurrentProcess()->AppendSwitch(
704 keyboard::switches::kEnableVirtualKeyboard); 707 keyboard::switches::kEnableVirtualKeyboard);
705 test::AshTestBase::SetUp(); 708 test::AshTestBase::SetUp();
706 Shell::GetPrimaryRootWindowController()->ActivateKeyboard( 709 keyboard::SetTouchKeyboardEnabled(true);
707 keyboard::KeyboardController::GetInstance()); 710 Shell::GetInstance()->CreateKeyboard();
711 }
712
713 void TearDown() override {
714 keyboard::SetTouchKeyboardEnabled(false);
715 test::AshTestBase::TearDown();
708 } 716 }
709 717
710 private: 718 private:
711 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest); 719 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest);
712 }; 720 };
713 721
714 class MockTextInputClient : public ui::DummyTextInputClient { 722 class MockTextInputClient : public ui::DummyTextInputClient {
715 public: 723 public:
716 MockTextInputClient() : ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT) {} 724 MockTextInputClient() : ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT) {}
717 725
(...skipping 18 matching lines...) Expand all
736 if (event->type() == ui::ET_MOUSE_PRESSED) 744 if (event->type() == ui::ET_MOUSE_PRESSED)
737 ui::test::TestEventHandler::OnMouseEvent(event); 745 ui::test::TestEventHandler::OnMouseEvent(event);
738 event->StopPropagation(); 746 event->StopPropagation();
739 } 747 }
740 748
741 private: 749 private:
742 DISALLOW_COPY_AND_ASSIGN(TargetHitTestEventHandler); 750 DISALLOW_COPY_AND_ASSIGN(TargetHitTestEventHandler);
743 }; 751 };
744 752
745 // Test for http://crbug.com/297858. Virtual keyboard container should only show 753 // Test for http://crbug.com/297858. Virtual keyboard container should only show
746 // on primary root window. 754 // on primary root window if no window has touch capability.
747 TEST_F(VirtualKeyboardRootWindowControllerTest, 755 TEST_F(VirtualKeyboardRootWindowControllerTest,
748 VirtualKeyboardOnPrimaryRootWindowOnly) { 756 VirtualKeyboardOnPrimaryRootWindowDefault) {
749 if (!SupportsMultipleDisplays()) 757 if (!SupportsMultipleDisplays())
750 return; 758 return;
751 759
752 UpdateDisplay("500x500,500x500"); 760 UpdateDisplay("500x500,500x500");
753 761
754 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 762 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
755 aura::Window* primary_root_window = Shell::GetPrimaryRootWindow(); 763 aura::Window* primary_root_window = Shell::GetPrimaryRootWindow();
756 aura::Window* secondary_root_window = root_windows[0] == primary_root_window 764 aura::Window* secondary_root_window = root_windows[0] == primary_root_window
757 ? root_windows[1] 765 ? root_windows[1]
758 : root_windows[0]; 766 : root_windows[0];
759 767
760 ASSERT_TRUE(Shell::GetContainer(primary_root_window, 768 ASSERT_TRUE(Shell::GetContainer(primary_root_window,
761 kShellWindowId_VirtualKeyboardContainer)); 769 kShellWindowId_VirtualKeyboardContainer));
762 ASSERT_FALSE(Shell::GetContainer(secondary_root_window, 770 ASSERT_FALSE(Shell::GetContainer(secondary_root_window,
763 kShellWindowId_VirtualKeyboardContainer)); 771 kShellWindowId_VirtualKeyboardContainer));
764 } 772 }
765 773
774 // Test for http://crbug.com/303429. Virtual keyboard container should show on
775 // a display which has touch capability.
776 TEST_F(VirtualKeyboardRootWindowControllerTest,
777 VirtualKeyboardOnTouchableDisplayOnly) {
778 if (!SupportsMultipleDisplays())
779 return;
780
781 UpdateDisplay("500x500,500x500");
782 display::Display secondary_display =
783 Shell::GetInstance()->display_manager()->GetSecondaryDisplay();
784 display::test::DisplayManagerTestApi(Shell::GetInstance()->display_manager())
785 .SetTouchSupport(secondary_display.id(),
786 display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE);
787
788 // The primary display doesn't have touch capability and the secondary display
789 // does.
790 ASSERT_NE(display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE,
791 display::Screen::GetScreen()->GetPrimaryDisplay().touch_support());
792 ASSERT_EQ(display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE,
793 Shell::GetInstance()
794 ->display_manager()
795 ->GetSecondaryDisplay()
796 .touch_support());
797
798 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
799 aura::Window* primary_root_window = Shell::GetPrimaryRootWindow();
800 aura::Window* secondary_root_window = root_windows[0] == primary_root_window
801 ? root_windows[1]
802 : root_windows[0];
803
804 keyboard::KeyboardController::GetInstance()->ShowKeyboard(false);
805 ASSERT_FALSE(Shell::GetContainer(primary_root_window,
806 kShellWindowId_VirtualKeyboardContainer));
807 ASSERT_TRUE(Shell::GetContainer(secondary_root_window,
808 kShellWindowId_VirtualKeyboardContainer));
809
810 // Move the focus to the primary display.
811 aura::Window* focusable_window_in_primary_display =
812 CreateTestWindowInShellWithBounds(
813 primary_root_window->GetBoundsInScreen());
814 ASSERT_EQ(primary_root_window,
815 focusable_window_in_primary_display->GetRootWindow());
816 focusable_window_in_primary_display->Focus();
817 ASSERT_TRUE(focusable_window_in_primary_display->HasFocus());
818
819 // Virtual keyboard shows up on the secondary display even if a window in the
820 // primary screen has the focus.
821 keyboard::KeyboardController::GetInstance()->ShowKeyboard(false);
822 ASSERT_FALSE(Shell::GetContainer(primary_root_window,
oshima 2016/11/16 22:05:02 nit: EXPECT_
yhanada 2016/11/16 22:22:10 Done.
823 kShellWindowId_VirtualKeyboardContainer));
824 ASSERT_TRUE(Shell::GetContainer(secondary_root_window,
825 kShellWindowId_VirtualKeyboardContainer));
oshima 2016/11/16 22:05:02 ditto
yhanada 2016/11/16 22:22:10 Done.
826 }
827
828 // Test for http://crbug.com/303429. If both of displays have touch capability,
829 // virtual keyboard follows the input focus.
830 TEST_F(VirtualKeyboardRootWindowControllerTest, FollowInputFocus) {
831 if (!SupportsMultipleDisplays())
832 return;
833
834 UpdateDisplay("500x500,500x500");
835 const int64_t primary_display_id =
836 display::Screen::GetScreen()->GetPrimaryDisplay().id();
837 display::test::DisplayManagerTestApi(Shell::GetInstance()->display_manager())
838 .SetTouchSupport(primary_display_id,
839 display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE);
840 const int64_t secondary_display_id =
841 Shell::GetInstance()->display_manager()->GetSecondaryDisplay().id();
842 display::test::DisplayManagerTestApi(Shell::GetInstance()->display_manager())
843 .SetTouchSupport(secondary_display_id,
844 display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE);
845
846 // Both of displays have touch capability.
847 ASSERT_EQ(display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE,
848 display::Screen::GetScreen()->GetPrimaryDisplay().touch_support());
849 ASSERT_EQ(display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE,
850 Shell::GetInstance()
851 ->display_manager()
852 ->GetSecondaryDisplay()
853 .touch_support());
854
855 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
856 aura::Window* primary_root_window = Shell::GetPrimaryRootWindow();
857 aura::Window* secondary_root_window = root_windows[0] == primary_root_window
858 ? root_windows[1]
859 : root_windows[0];
860 aura::Window* focusable_window_in_primary_display =
861 CreateTestWindowInShellWithBounds(
862 primary_root_window->GetBoundsInScreen());
863 ASSERT_EQ(primary_root_window,
864 focusable_window_in_primary_display->GetRootWindow());
865 aura::Window* focusable_window_in_secondary_display =
866 CreateTestWindowInShellWithBounds(
867 secondary_root_window->GetBoundsInScreen());
868 ASSERT_EQ(secondary_root_window,
869 focusable_window_in_secondary_display->GetRootWindow());
870
871 keyboard::KeyboardController::GetInstance()->ShowKeyboard(false);
872 ASSERT_TRUE(Shell::GetContainer(primary_root_window,
873 kShellWindowId_VirtualKeyboardContainer));
oshima 2016/11/16 22:05:02 ditto
yhanada 2016/11/16 22:22:10 Done.
874 ASSERT_FALSE(Shell::GetContainer(secondary_root_window,
875 kShellWindowId_VirtualKeyboardContainer));
oshima 2016/11/16 22:05:02 ditto
yhanada 2016/11/16 22:22:10 Done.
876
877 // Move the focus to the secondary display.
878 focusable_window_in_secondary_display->Focus();
879 ASSERT_TRUE(focusable_window_in_secondary_display->HasFocus());
880
881 keyboard::KeyboardController::GetInstance()->ShowKeyboard(false);
882 ASSERT_FALSE(Shell::GetContainer(primary_root_window,
883 kShellWindowId_VirtualKeyboardContainer));
884 ASSERT_TRUE(Shell::GetContainer(secondary_root_window,
885 kShellWindowId_VirtualKeyboardContainer));
886
887 // Move back focus to the primary display.
888 focusable_window_in_primary_display->Focus();
889 ASSERT_TRUE(focusable_window_in_primary_display->HasFocus());
890
891 keyboard::KeyboardController::GetInstance()->ShowKeyboard(false);
892 ASSERT_TRUE(Shell::GetContainer(primary_root_window,
893 kShellWindowId_VirtualKeyboardContainer));
oshima 2016/11/16 22:05:02 ditto
yhanada 2016/11/16 22:22:10 Done.
894 ASSERT_FALSE(Shell::GetContainer(secondary_root_window,
895 kShellWindowId_VirtualKeyboardContainer));
oshima 2016/11/16 22:05:02 ditto
yhanada 2016/11/16 22:22:10 Done.
896 }
897
898 // Test for http://crbug.com/303429. Even if both of display don't have touch
899 // capability, the virtual keyboard shows up on the specified display.
900 TEST_F(VirtualKeyboardRootWindowControllerTest,
901 VirtualKeyboardShowOnSpecifiedDisplay) {
902 if (!SupportsMultipleDisplays())
903 return;
904
905 UpdateDisplay("500x500,500x500");
906 display::Display secondary_display =
907 Shell::GetInstance()->display_manager()->GetSecondaryDisplay();
908
909 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
910 aura::Window* primary_root_window = Shell::GetPrimaryRootWindow();
911 aura::Window* secondary_root_window = root_windows[0] == primary_root_window
912 ? root_windows[1]
913 : root_windows[0];
914
915 ASSERT_TRUE(Shell::GetContainer(primary_root_window,
916 kShellWindowId_VirtualKeyboardContainer));
917 ASSERT_FALSE(Shell::GetContainer(secondary_root_window,
918 kShellWindowId_VirtualKeyboardContainer));
919
920 const int64_t secondary_display_id = secondary_display.id();
921 keyboard::KeyboardController::GetInstance()->ShowKeyboardInDisplay(
922 secondary_display_id);
923
924 ASSERT_FALSE(Shell::GetContainer(primary_root_window,
925 kShellWindowId_VirtualKeyboardContainer));
oshima 2016/11/16 22:05:02 dotto
yhanada 2016/11/16 22:22:10 Done.
926 ASSERT_TRUE(Shell::GetContainer(secondary_root_window,
927 kShellWindowId_VirtualKeyboardContainer));
oshima 2016/11/16 22:05:02 ditto
yhanada 2016/11/16 22:22:10 Done.
928 }
929
766 // Test for http://crbug.com/263599. Virtual keyboard should be able to receive 930 // Test for http://crbug.com/263599. Virtual keyboard should be able to receive
767 // events at blocked user session. 931 // events at blocked user session.
768 TEST_F(VirtualKeyboardRootWindowControllerTest, 932 TEST_F(VirtualKeyboardRootWindowControllerTest,
769 ClickVirtualKeyboardInBlockedWindow) { 933 ClickVirtualKeyboardInBlockedWindow) {
770 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 934 aura::Window* root_window = Shell::GetPrimaryRootWindow();
771 aura::Window* keyboard_container = 935 aura::Window* keyboard_container =
772 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); 936 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
773 ASSERT_TRUE(keyboard_container); 937 ASSERT_TRUE(keyboard_container);
774 keyboard_container->Show(); 938 keyboard_container->Show();
775 939
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 keyboard_controller->ui()->GetKeyboardWindow()->SetBounds( 1195 keyboard_controller->ui()->GetKeyboardWindow()->SetBounds(
1032 gfx::Rect(0, 400, 800, 200)); 1196 gfx::Rect(0, 400, 800, 200));
1033 EXPECT_EQ("0,400 800x200", keyboard_container->bounds().ToString()); 1197 EXPECT_EQ("0,400 800x200", keyboard_container->bounds().ToString());
1034 1198
1035 UpdateDisplay("600x800"); 1199 UpdateDisplay("600x800");
1036 EXPECT_EQ("0,600 600x200", keyboard_container->bounds().ToString()); 1200 EXPECT_EQ("0,600 600x200", keyboard_container->bounds().ToString());
1037 } 1201 }
1038 1202
1039 } // namespace test 1203 } // namespace test
1040 } // namespace ash 1204 } // namespace ash
OLDNEW
« no previous file with comments | « ash/mus/keyboard_ui_mus.cc ('k') | ash/shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698