OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 EXPECT_TRUE(widget2.GetAndClearGotCaptureLost()); | 859 EXPECT_TRUE(widget2.GetAndClearGotCaptureLost()); |
860 | 860 |
861 // Release and verify no one has it. | 861 // Release and verify no one has it. |
862 widget1.ReleaseCapture(); | 862 widget1.ReleaseCapture(); |
863 EXPECT_FALSE(widget1.HasCapture()); | 863 EXPECT_FALSE(widget1.HasCapture()); |
864 EXPECT_FALSE(widget2.HasCapture()); | 864 EXPECT_FALSE(widget2.HasCapture()); |
865 EXPECT_TRUE(widget1.GetAndClearGotCaptureLost()); | 865 EXPECT_TRUE(widget1.GetAndClearGotCaptureLost()); |
866 EXPECT_FALSE(widget2.GetAndClearGotCaptureLost()); | 866 EXPECT_FALSE(widget2.GetAndClearGotCaptureLost()); |
867 } | 867 } |
868 | 868 |
869 private: | |
870 NativeWidget* CreateNativeWidget(bool create_desktop_native_widget, | 869 NativeWidget* CreateNativeWidget(bool create_desktop_native_widget, |
871 Widget* widget) { | 870 Widget* widget) { |
872 #if !defined(OS_CHROMEOS) | 871 #if !defined(OS_CHROMEOS) |
873 if (create_desktop_native_widget) | 872 if (create_desktop_native_widget) |
874 return new DesktopNativeWidgetAura(widget); | 873 return new DesktopNativeWidgetAura(widget); |
875 #endif | 874 #endif |
876 return NULL; | 875 return NULL; |
877 } | 876 } |
878 | 877 |
| 878 private: |
879 DISALLOW_COPY_AND_ASSIGN(WidgetCaptureTest); | 879 DISALLOW_COPY_AND_ASSIGN(WidgetCaptureTest); |
880 }; | 880 }; |
881 | 881 |
882 // See description in TestCapture(). | 882 // See description in TestCapture(). |
883 TEST_F(WidgetCaptureTest, Capture) { | 883 TEST_F(WidgetCaptureTest, Capture) { |
884 TestCapture(false); | 884 TestCapture(false); |
885 } | 885 } |
886 | 886 |
887 #if !defined(OS_LINUX) | 887 #if !defined(OS_LINUX) |
888 // See description in TestCapture(). Creates DesktopNativeWidget. | 888 // See description in TestCapture(). Creates DesktopNativeWidget. |
889 TEST_F(WidgetCaptureTest, CaptureDesktopNativeWidget) { | 889 TEST_F(WidgetCaptureTest, CaptureDesktopNativeWidget) { |
890 TestCapture(true); | 890 TestCapture(true); |
891 } | 891 } |
892 #endif | 892 #endif |
893 | 893 |
| 894 // Test that a synthetic mouse exit is sent to the widget which was handling |
| 895 // mouse events when a different widget grabs capture. |
| 896 TEST_F(WidgetCaptureTest, MouseExitOnCaptureGrab) { |
| 897 Widget widget1; |
| 898 Widget::InitParams params1 = |
| 899 CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 900 params1.native_widget = CreateNativeWidget(true, &widget1); |
| 901 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 902 widget1.Init(params1); |
| 903 MouseView* contents_view1 = new MouseView; |
| 904 widget1.SetContentsView(contents_view1); |
| 905 widget1.Show(); |
| 906 |
| 907 Widget widget2; |
| 908 Widget::InitParams params2 = |
| 909 CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 910 params2.native_widget = CreateNativeWidget(true, &widget2); |
| 911 params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 912 widget2.Init(params2); |
| 913 MouseView* contents_view2 = new MouseView; |
| 914 widget2.SetContentsView(contents_view2); |
| 915 widget2.Show(); |
| 916 |
| 917 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(), |
| 918 gfx::Point(), ui::EF_NONE, ui::EF_NONE); |
| 919 ui::EventDispatchDetails details = widget1.GetNativeWindow()->GetHost()-> |
| 920 event_processor()->OnEventFromSource(&mouse_move_event); |
| 921 ASSERT_FALSE(details.dispatcher_destroyed); |
| 922 EXPECT_EQ(1, contents_view1->EnteredCalls()); |
| 923 EXPECT_EQ(0, contents_view1->ExitedCalls()); |
| 924 |
| 925 widget2.SetCapture(NULL); |
| 926 EXPECT_EQ(0, contents_view1->EnteredCalls()); |
| 927 // Grabbing native capture on Windows generates a ui::ET_MOUSE_EXITED event |
| 928 // in addition to the one generated by Chrome. |
| 929 EXPECT_LT(0, contents_view1->ExitedCalls()); |
| 930 EXPECT_EQ(0, contents_view2->ExitedCalls()); |
| 931 |
| 932 } |
| 933 |
894 #if !defined(OS_CHROMEOS) | 934 #if !defined(OS_CHROMEOS) |
895 namespace { | 935 namespace { |
896 | 936 |
897 // Used to veirfy OnMouseEvent() has been invoked. | 937 // Used to veirfy OnMouseEvent() has been invoked. |
898 class MouseEventTrackingWidget : public Widget { | 938 class MouseEventTrackingWidget : public Widget { |
899 public: | 939 public: |
900 MouseEventTrackingWidget() : got_mouse_event_(false) {} | 940 MouseEventTrackingWidget() : got_mouse_event_(false) {} |
901 virtual ~MouseEventTrackingWidget() {} | 941 virtual ~MouseEventTrackingWidget() {} |
902 | 942 |
903 bool GetAndClearGotMouseEvent() { | 943 bool GetAndClearGotMouseEvent() { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> | 1002 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> |
963 GetHost()->event_processor()->OnEventFromSource(&mouse_event); | 1003 GetHost()->event_processor()->OnEventFromSource(&mouse_event); |
964 ASSERT_FALSE(details.dispatcher_destroyed); | 1004 ASSERT_FALSE(details.dispatcher_destroyed); |
965 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); | 1005 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); |
966 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); | 1006 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); |
967 } | 1007 } |
968 #endif | 1008 #endif |
969 | 1009 |
970 } // namespace test | 1010 } // namespace test |
971 } // namespace views | 1011 } // namespace views |
OLD | NEW |