| 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 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 | 983 |
| 984 widget.Show(); | 984 widget.Show(); |
| 985 ui::test::EventGenerator generator(GetContext(), widget.GetNativeWindow()); | 985 ui::test::EventGenerator generator(GetContext(), widget.GetNativeWindow()); |
| 986 generator.set_current_location(gfx::Point(300, 10)); | 986 generator.set_current_location(gfx::Point(300, 10)); |
| 987 generator.PressLeftButton(); | 987 generator.PressLeftButton(); |
| 988 | 988 |
| 989 EXPECT_FALSE(mouse_view1->pressed()); | 989 EXPECT_FALSE(mouse_view1->pressed()); |
| 990 EXPECT_TRUE(mouse_view2->pressed()); | 990 EXPECT_TRUE(mouse_view2->pressed()); |
| 991 } | 991 } |
| 992 | 992 |
| 993 #if !defined(OS_CHROMEOS) && !defined(OS_WIN) | 993 // Regression test for http://crbug.com/382421 (Linux-Aura issue). |
| 994 // TODO(pkotwicz): Make test pass on CrOS and Windows. |
| 995 // TODO(tapted): Investigate for toolkit-views on Mac http;//crbug.com/441064. |
| 996 #if defined(OS_CHROMEOS) || defined(OS_WIN) || defined(OS_MACOSX) |
| 997 #define MAYBE_MouseExitOnCaptureGrab DISABLED_MouseExitOnCaptureGrab |
| 998 #else |
| 999 #define MAYBE_MouseExitOnCaptureGrab MouseExitOnCaptureGrab |
| 1000 #endif |
| 1001 |
| 994 // Test that a synthetic mouse exit is sent to the widget which was handling | 1002 // Test that a synthetic mouse exit is sent to the widget which was handling |
| 995 // mouse events when a different widget grabs capture. | 1003 // mouse events when a different widget grabs capture. |
| 996 // TODO(pkotwicz): Make test pass on CrOS and Windows. | 1004 TEST_F(WidgetCaptureTest, MAYBE_MouseExitOnCaptureGrab) { |
| 997 TEST_F(WidgetCaptureTest, MouseExitOnCaptureGrab) { | |
| 998 Widget widget1; | 1005 Widget widget1; |
| 999 Widget::InitParams params1 = | 1006 Widget::InitParams params1 = |
| 1000 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 1007 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 1001 params1.native_widget = CreateNativeWidget(true, &widget1); | 1008 params1.native_widget = CreateNativeWidget(true, &widget1); |
| 1002 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 1009 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 1003 widget1.Init(params1); | 1010 widget1.Init(params1); |
| 1004 MouseView* mouse_view1 = new MouseView; | 1011 MouseView* mouse_view1 = new MouseView; |
| 1005 widget1.SetContentsView(mouse_view1); | 1012 widget1.SetContentsView(mouse_view1); |
| 1006 widget1.Show(); | 1013 widget1.Show(); |
| 1007 widget1.SetBounds(gfx::Rect(300, 300)); | 1014 widget1.SetBounds(gfx::Rect(300, 300)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1021 | 1028 |
| 1022 EXPECT_EQ(1, mouse_view1->EnteredCalls()); | 1029 EXPECT_EQ(1, mouse_view1->EnteredCalls()); |
| 1023 EXPECT_EQ(0, mouse_view1->ExitedCalls()); | 1030 EXPECT_EQ(0, mouse_view1->ExitedCalls()); |
| 1024 | 1031 |
| 1025 widget2.SetCapture(NULL); | 1032 widget2.SetCapture(NULL); |
| 1026 EXPECT_EQ(0, mouse_view1->EnteredCalls()); | 1033 EXPECT_EQ(0, mouse_view1->EnteredCalls()); |
| 1027 // Grabbing native capture on Windows generates a ui::ET_MOUSE_EXITED event | 1034 // Grabbing native capture on Windows generates a ui::ET_MOUSE_EXITED event |
| 1028 // in addition to the one generated by Chrome. | 1035 // in addition to the one generated by Chrome. |
| 1029 EXPECT_LT(0, mouse_view1->ExitedCalls()); | 1036 EXPECT_LT(0, mouse_view1->ExitedCalls()); |
| 1030 } | 1037 } |
| 1031 #endif // !defined(OS_CHROMEOS) | |
| 1032 | 1038 |
| 1033 namespace { | 1039 namespace { |
| 1034 | 1040 |
| 1035 // Widget observer which grabs capture when the widget is activated. | 1041 // Widget observer which grabs capture when the widget is activated. |
| 1036 class CaptureOnActivationObserver : public WidgetObserver { | 1042 class CaptureOnActivationObserver : public WidgetObserver { |
| 1037 public: | 1043 public: |
| 1038 CaptureOnActivationObserver() { | 1044 CaptureOnActivationObserver() : activation_observed_(false) {} |
| 1039 } | |
| 1040 ~CaptureOnActivationObserver() override {} | 1045 ~CaptureOnActivationObserver() override {} |
| 1041 | 1046 |
| 1042 // WidgetObserver: | 1047 // WidgetObserver: |
| 1043 void OnWidgetActivationChanged(Widget* widget, bool active) override { | 1048 void OnWidgetActivationChanged(Widget* widget, bool active) override { |
| 1044 if (active) | 1049 if (active) { |
| 1045 widget->SetCapture(NULL); | 1050 widget->SetCapture(nullptr); |
| 1051 activation_observed_ = true; |
| 1052 } |
| 1046 } | 1053 } |
| 1047 | 1054 |
| 1055 bool activation_observed() const { return activation_observed_; } |
| 1056 |
| 1048 private: | 1057 private: |
| 1058 bool activation_observed_; |
| 1059 |
| 1049 DISALLOW_COPY_AND_ASSIGN(CaptureOnActivationObserver); | 1060 DISALLOW_COPY_AND_ASSIGN(CaptureOnActivationObserver); |
| 1050 }; | 1061 }; |
| 1051 | 1062 |
| 1052 } // namespace | 1063 } // namespace |
| 1053 | 1064 |
| 1054 // Test that setting capture on widget activation of a non-toplevel widget | 1065 // Test that setting capture on widget activation of a non-toplevel widget |
| 1055 // (e.g. a bubble on Linux) succeeds. | 1066 // (e.g. a bubble on Linux) succeeds. |
| 1056 TEST_F(WidgetCaptureTest, SetCaptureToNonToplevel) { | 1067 TEST_F(WidgetCaptureTest, SetCaptureToNonToplevel) { |
| 1057 Widget toplevel; | 1068 Widget toplevel; |
| 1058 Widget::InitParams toplevel_params = | 1069 Widget::InitParams toplevel_params = |
| 1059 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 1070 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 1060 toplevel_params.native_widget = CreateNativeWidget(true, &toplevel); | 1071 toplevel_params.native_widget = CreateNativeWidget(true, &toplevel); |
| 1061 toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 1072 toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 1062 toplevel.Init(toplevel_params); | 1073 toplevel.Init(toplevel_params); |
| 1063 toplevel.Show(); | 1074 toplevel.Show(); |
| 1064 | 1075 |
| 1065 Widget* child = new Widget; | 1076 Widget* child = new Widget; |
| 1066 Widget::InitParams child_params = | 1077 Widget::InitParams child_params = |
| 1067 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 1078 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 1068 child_params.parent = toplevel.GetNativeView(); | 1079 child_params.parent = toplevel.GetNativeView(); |
| 1069 child_params.context = toplevel.GetNativeWindow(); | 1080 child_params.context = toplevel.GetNativeWindow(); |
| 1070 child->Init(child_params); | 1081 child->Init(child_params); |
| 1071 | 1082 |
| 1072 CaptureOnActivationObserver observer; | 1083 CaptureOnActivationObserver observer; |
| 1073 child->AddObserver(&observer); | 1084 child->AddObserver(&observer); |
| 1074 child->Show(); | 1085 child->Show(); |
| 1075 | 1086 |
| 1087 #if defined(OS_MACOSX) && !defined(USE_AURA) |
| 1088 // On Mac, activation is asynchronous. A single trip to the runloop should be |
| 1089 // sufficient. On Aura platforms, note that since the child widget isn't top- |
| 1090 // level, the aura window manager gets asked whether the widget is active, not |
| 1091 // the OS. |
| 1092 base::RunLoop().RunUntilIdle(); |
| 1093 #endif |
| 1094 |
| 1095 EXPECT_TRUE(observer.activation_observed()); |
| 1076 EXPECT_TRUE(child->HasCapture()); | 1096 EXPECT_TRUE(child->HasCapture()); |
| 1077 } | 1097 } |
| 1078 | 1098 |
| 1079 | 1099 |
| 1080 #if defined(OS_WIN) | 1100 #if defined(OS_WIN) |
| 1081 namespace { | 1101 namespace { |
| 1082 | 1102 |
| 1083 // Used to verify OnMouseEvent() has been invoked. | 1103 // Used to verify OnMouseEvent() has been invoked. |
| 1084 class MouseEventTrackingWidget : public Widget { | 1104 class MouseEventTrackingWidget : public Widget { |
| 1085 public: | 1105 public: |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1140 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> | 1160 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> |
| 1141 GetHost()->event_processor()->OnEventFromSource(&mouse_event); | 1161 GetHost()->event_processor()->OnEventFromSource(&mouse_event); |
| 1142 ASSERT_FALSE(details.dispatcher_destroyed); | 1162 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1143 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); | 1163 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); |
| 1144 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); | 1164 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); |
| 1145 } | 1165 } |
| 1146 #endif // defined(OS_WIN) | 1166 #endif // defined(OS_WIN) |
| 1147 | 1167 |
| 1148 } // namespace test | 1168 } // namespace test |
| 1149 } // namespace views | 1169 } // namespace views |
| OLD | NEW |