Chromium Code Reviews| 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 #if !defined(OS_CHROMEOS) | 894 #if !defined(OS_CHROMEOS) |
| 895 // Test that a synthetic mouse exit is sent to the widget which was handling | |
| 896 // mouse events when a different widget grabs capture. | |
| 897 // TODO(pkotwicz): Make test pass on CrOS. | |
|
sadrul
2014/06/26 12:59:35
I guess you need to create multiple WindowTreeHost
| |
| 898 TEST_F(WidgetCaptureTest, MouseExitOnCaptureGrab) { | |
| 899 Widget widget1; | |
| 900 Widget::InitParams params1 = | |
| 901 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 902 params1.native_widget = CreateNativeWidget(true, &widget1); | |
| 903 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 904 widget1.Init(params1); | |
| 905 MouseView* mouse_view1 = new MouseView; | |
| 906 widget1.SetContentsView(mouse_view1); | |
| 907 widget1.Show(); | |
| 908 widget1.SetBounds(gfx::Rect(300, 300)); | |
| 909 | |
| 910 Widget widget2; | |
| 911 Widget::InitParams params2 = | |
| 912 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 913 params2.native_widget = CreateNativeWidget(true, &widget2); | |
| 914 params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 915 widget2.Init(params2); | |
| 916 widget2.Show(); | |
| 917 widget2.SetBounds(gfx::Rect(400, 0, 300, 300)); | |
| 918 | |
| 919 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(100, 100), | |
| 920 gfx::Point(100, 100), ui::EF_NONE, ui::EF_NONE); | |
| 921 ui::EventDispatchDetails details = widget1.GetNativeWindow()->GetHost()-> | |
| 922 event_processor()->OnEventFromSource(&mouse_move_event); | |
| 923 ASSERT_FALSE(details.dispatcher_destroyed); | |
| 924 EXPECT_EQ(1, mouse_view1->EnteredCalls()); | |
| 925 EXPECT_EQ(0, mouse_view1->ExitedCalls()); | |
| 926 | |
| 927 widget2.SetCapture(NULL); | |
| 928 EXPECT_EQ(0, mouse_view1->EnteredCalls()); | |
| 929 // Grabbing native capture on Windows generates a ui::ET_MOUSE_EXITED event | |
| 930 // in addition to the one generated by Chrome. | |
| 931 EXPECT_LT(0, mouse_view1->ExitedCalls()); | |
| 932 } | |
| 933 #endif | |
| 934 | |
| 935 #if !defined(OS_CHROMEOS) | |
| 895 namespace { | 936 namespace { |
| 896 | 937 |
| 897 // Used to veirfy OnMouseEvent() has been invoked. | 938 // Used to veirfy OnMouseEvent() has been invoked. |
| 898 class MouseEventTrackingWidget : public Widget { | 939 class MouseEventTrackingWidget : public Widget { |
| 899 public: | 940 public: |
| 900 MouseEventTrackingWidget() : got_mouse_event_(false) {} | 941 MouseEventTrackingWidget() : got_mouse_event_(false) {} |
| 901 virtual ~MouseEventTrackingWidget() {} | 942 virtual ~MouseEventTrackingWidget() {} |
| 902 | 943 |
| 903 bool GetAndClearGotMouseEvent() { | 944 bool GetAndClearGotMouseEvent() { |
| 904 bool value = got_mouse_event_; | 945 bool value = got_mouse_event_; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 962 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> | 1003 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> |
| 963 GetHost()->event_processor()->OnEventFromSource(&mouse_event); | 1004 GetHost()->event_processor()->OnEventFromSource(&mouse_event); |
| 964 ASSERT_FALSE(details.dispatcher_destroyed); | 1005 ASSERT_FALSE(details.dispatcher_destroyed); |
| 965 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); | 1006 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); |
| 966 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); | 1007 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); |
| 967 } | 1008 } |
| 968 #endif | 1009 #endif |
| 969 | 1010 |
| 970 } // namespace test | 1011 } // namespace test |
| 971 } // namespace views | 1012 } // namespace views |
| OLD | NEW |