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

Side by Side Diff: ash/root_window_controller_unittest.cc

Issue 565373002: Move virtual keyboard behind context menus. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code cleanup. Created 6 years, 3 months 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
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 "ash/session/session_state_delegate.h" 7 #include "ash/session/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 "base/memory/scoped_ptr.h"
18 #include "ui/aura/client/focus_change_observer.h" 19 #include "ui/aura/client/focus_change_observer.h"
19 #include "ui/aura/client/focus_client.h" 20 #include "ui/aura/client/focus_client.h"
20 #include "ui/aura/client/window_tree_client.h" 21 #include "ui/aura/client/window_tree_client.h"
21 #include "ui/aura/env.h" 22 #include "ui/aura/env.h"
22 #include "ui/aura/test/test_window_delegate.h" 23 #include "ui/aura/test/test_window_delegate.h"
23 #include "ui/aura/test/test_windows.h" 24 #include "ui/aura/test/test_windows.h"
24 #include "ui/aura/window.h" 25 #include "ui/aura/window.h"
25 #include "ui/aura/window_event_dispatcher.h" 26 #include "ui/aura/window_event_dispatcher.h"
26 #include "ui/aura/window_tracker.h" 27 #include "ui/aura/window_tracker.h"
27 #include "ui/base/ime/dummy_text_input_client.h" 28 #include "ui/base/ime/dummy_text_input_client.h"
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 const gfx::Rect& visible_rect() const { 641 const gfx::Rect& visible_rect() const {
641 return visible_rect_; 642 return visible_rect_;
642 } 643 }
643 644
644 private: 645 private:
645 gfx::Rect visible_rect_; 646 gfx::Rect visible_rect_;
646 647
647 DISALLOW_COPY_AND_ASSIGN(MockTextInputClient); 648 DISALLOW_COPY_AND_ASSIGN(MockTextInputClient);
648 }; 649 };
649 650
651 class TargetHitTestEventHandler : public ui::test::TestEventHandler {
652 public:
653 TargetHitTestEventHandler() {}
654
655 // ui::test::TestEventHandler overrides.
656 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
657 if (event->type() == ui::ET_MOUSE_PRESSED)
658 ui::test::TestEventHandler::OnMouseEvent(event);
659 event->StopPropagation();
660 }
661
662 private:
663 DISALLOW_COPY_AND_ASSIGN(TargetHitTestEventHandler);
664 };
665
650 // Test for http://crbug.com/297858. Virtual keyboard container should only show 666 // Test for http://crbug.com/297858. Virtual keyboard container should only show
651 // on primary root window. 667 // on primary root window.
652 TEST_F(VirtualKeyboardRootWindowControllerTest, 668 TEST_F(VirtualKeyboardRootWindowControllerTest,
653 VirtualKeyboardOnPrimaryRootWindowOnly) { 669 VirtualKeyboardOnPrimaryRootWindowOnly) {
654 if (!SupportsMultipleDisplays()) 670 if (!SupportsMultipleDisplays())
655 return; 671 return;
656 672
657 UpdateDisplay("500x500,500x500"); 673 UpdateDisplay("500x500,500x500");
658 674
659 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 675 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 text_input_client.visible_rect().height()); 850 text_input_client.visible_rect().height());
835 851
836 if (switches::IsTextInputFocusManagerEnabled()) { 852 if (switches::IsTextInputFocusManagerEnabled()) {
837 ui::TextInputFocusManager::GetInstance()->BlurTextInputClient( 853 ui::TextInputFocusManager::GetInstance()->BlurTextInputClient(
838 &text_input_client); 854 &text_input_client);
839 } else { 855 } else {
840 input_method->SetFocusedTextInputClient(NULL); 856 input_method->SetFocusedTextInputClient(NULL);
841 } 857 }
842 } 858 }
843 859
860 // Tests that the virtual keyboard does not block context menus. The virtual
861 // keyboard should appear in front of most content, but not context menus. See
862 // crbug/377180.
863 TEST_F(VirtualKeyboardRootWindowControllerTest, ZOrderTest) {
864 UpdateDisplay("800x600");
865 keyboard::KeyboardController* keyboard_controller =
866 keyboard::KeyboardController::GetInstance();
867 keyboard::KeyboardControllerProxy* proxy = keyboard_controller->proxy();
868
869 aura::Window* root_window = Shell::GetPrimaryRootWindow();
870 aura::Window* keyboard_container =
871 Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
872 ASSERT_TRUE(keyboard_container);
873 keyboard_container->Show();
874
875 const int keyboard_height = 200;
876 aura::Window* keyboard_window = proxy->GetKeyboardWindow();
877 keyboard_container->AddChild(keyboard_window);
878 keyboard_window->set_owned_by_parent(false);
879 gfx::Rect keyboard_bounds = keyboard::KeyboardBoundsFromWindowBounds(
880 keyboard_container->bounds(), keyboard_height);
881 keyboard_window->SetBounds(keyboard_bounds);
882 keyboard_window->Show();
883
884 ui::test::EventGenerator generator(root_window);
885
886 // Cover the screen with two windows: a normal window on the left side and a
887 // context menu on the right side. When the virtual keyboard is displayed it
888 // partially occludes the normal window, but not the context menu. Compute
889 // positions for generating synthetic click events to perform hit tests,
890 // ensuring the correct window layering. 'top' is above the VK, whereas
891 // 'bottom' lies within the VK. 'left' is centered in the normal window, and
892 // 'right' is centered in the context menu.
James Cook 2014/09/15 17:45:20 Very helpful, thanks!
893 int window_height = keyboard_bounds.bottom();
894 int window_width = keyboard_bounds.width() / 2;
895 int left = window_width / 2;
896 int right = 3 * window_width / 2;
897 int top = keyboard_bounds.y() / 2;
898 int bottom = window_height - keyboard_height / 2;
899
900 // Normal window is partially occluded by the virtual keyboard.
901 aura::test::TestWindowDelegate delegate;
902 scoped_ptr<aura::Window> normal(CreateTestWindowInShellWithDelegateAndType(
903 &delegate,
904 ui::wm::WINDOW_TYPE_NORMAL,
905 0,
906 gfx::Rect(0, 0, window_width, window_height)));
907 normal->set_owned_by_parent(false);
908 normal->Show();
909 TargetHitTestEventHandler normal_handler;
910 normal->AddPreTargetHandler(&normal_handler);
911
912 // Test that only the click on the top portion of the window is picked up. The
913 // click on the bottom hits the virtual keyboard instead.
914 generator.MoveMouseTo(left, top);
915 generator.ClickLeftButton();
916 EXPECT_EQ(1, normal_handler.num_mouse_events());
917 generator.MoveMouseTo(left, bottom);
918 generator.ClickLeftButton();
919 EXPECT_EQ(1, normal_handler.num_mouse_events());
920
921 // Menu overlaps virtual keyboard.
922 aura::test::TestWindowDelegate delegate2;
923 scoped_ptr<aura::Window> menu(CreateTestWindowInShellWithDelegateAndType(
924 &delegate2,
925 ui::wm::WINDOW_TYPE_MENU,
926 0,
927 gfx::Rect(window_width, 0, window_width, window_height)));
928 menu->set_owned_by_parent(false);
929 menu->Show();
930 TargetHitTestEventHandler menu_handler;
931 menu->AddPreTargetHandler(&menu_handler);
932
933 // Test that both clicks register.
934 generator.MoveMouseTo(right, top);
935 generator.ClickLeftButton();
936 EXPECT_EQ(1, menu_handler.num_mouse_events());
937 generator.MoveMouseTo(right, bottom);
938 generator.ClickLeftButton();
939 EXPECT_EQ(2, menu_handler.num_mouse_events());
940
941 // Cleanup to ensure that the test windows are destroyed before their
942 // delegates.
943 normal.reset();
944 menu.reset();
James Cook 2014/09/15 17:45:20 You don't need these, they clean up themselves and
kevers 2014/09/15 18:13:04 Without the explicit resets, the test crashes. My
James Cook 2014/09/15 20:00:05 Ah. I should have read the comments in more detail
945 }
946
844 } // namespace test 947 } // namespace test
845 } // namespace ash 948 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698