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

Side by Side Diff: ui/views/widget/widget_interactive_uitest.cc

Issue 789763002: MacViews: Implement capture using NSEvent local+global monitors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20140812-MacViews-LAYERS2-PRESQUASH
Patch Set: selfnits Created 6 years 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) 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
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 #if !defined(OS_CHROMEOS) && !defined(OS_WIN) && !defined(OS_MACOSX)
994 // Test that a synthetic mouse exit is sent to the widget which was handling 994 // Test that a synthetic mouse exit is sent to the widget which was handling
995 // mouse events when a different widget grabs capture. 995 // mouse events when a different widget grabs capture.
996 // TODO(pkotwicz): Make test pass on CrOS and Windows. 996 // TODO(pkotwicz): Make test pass on CrOS and Windows.
997 // TODO(tapted): Investigate for toolkit-views on Mac http;//crbug.com/441064.
997 TEST_F(WidgetCaptureTest, MouseExitOnCaptureGrab) { 998 TEST_F(WidgetCaptureTest, MouseExitOnCaptureGrab) {
998 Widget widget1; 999 Widget widget1;
999 Widget::InitParams params1 = 1000 Widget::InitParams params1 =
1000 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); 1001 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
1001 params1.native_widget = CreateNativeWidget(true, &widget1); 1002 params1.native_widget = CreateNativeWidget(true, &widget1);
1002 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 1003 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
1003 widget1.Init(params1); 1004 widget1.Init(params1);
1004 MouseView* mouse_view1 = new MouseView; 1005 MouseView* mouse_view1 = new MouseView;
1005 widget1.SetContentsView(mouse_view1); 1006 widget1.SetContentsView(mouse_view1);
1006 widget1.Show(); 1007 widget1.Show();
1007 widget1.SetBounds(gfx::Rect(300, 300)); 1008 widget1.SetBounds(gfx::Rect(300, 300));
1008 1009
1009 Widget widget2; 1010 Widget widget2;
1010 Widget::InitParams params2 = 1011 Widget::InitParams params2 =
1011 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); 1012 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
1012 params2.native_widget = CreateNativeWidget(true, &widget2); 1013 params2.native_widget = CreateNativeWidget(true, &widget2);
1013 params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 1014 params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
1014 widget2.Init(params2); 1015 widget2.Init(params2);
1015 widget2.Show(); 1016 widget2.Show();
1016 widget2.SetBounds(gfx::Rect(400, 0, 300, 300)); 1017 widget2.SetBounds(gfx::Rect(400, 0, 300, 300));
1017 1018
1018 ui::test::EventGenerator generator(widget1.GetNativeWindow()); 1019 ui::test::EventGenerator generator(GetContext(), widget1.GetNativeWindow());
1019 generator.set_current_location(gfx::Point(100, 100)); 1020 generator.set_current_location(gfx::Point(100, 100));
1020 generator.MoveMouseBy(0, 0); 1021 generator.MoveMouseBy(0, 0);
1021 1022
1022 EXPECT_EQ(1, mouse_view1->EnteredCalls()); 1023 EXPECT_EQ(1, mouse_view1->EnteredCalls());
1023 EXPECT_EQ(0, mouse_view1->ExitedCalls()); 1024 EXPECT_EQ(0, mouse_view1->ExitedCalls());
1024 1025
1025 widget2.SetCapture(NULL); 1026 widget2.SetCapture(NULL);
1026 EXPECT_EQ(0, mouse_view1->EnteredCalls()); 1027 EXPECT_EQ(0, mouse_view1->EnteredCalls());
1027 // Grabbing native capture on Windows generates a ui::ET_MOUSE_EXITED event 1028 // Grabbing native capture on Windows generates a ui::ET_MOUSE_EXITED event
1028 // in addition to the one generated by Chrome. 1029 // in addition to the one generated by Chrome.
1029 EXPECT_LT(0, mouse_view1->ExitedCalls()); 1030 EXPECT_LT(0, mouse_view1->ExitedCalls());
1030 } 1031 }
1031 #endif // !defined(OS_CHROMEOS) 1032 #endif // !defined(OS_CHROMEOS)
Andre 2014/12/12 22:57:38 Update comment or delete.
tapted 2014/12/17 03:20:51 Done (changed this into a MAYBE_ test [neater, kee
1032 1033
1033 namespace { 1034 namespace {
1034 1035
1035 // Widget observer which grabs capture when the widget is activated. 1036 // Widget observer which grabs capture when the widget is activated.
1036 class CaptureOnActivationObserver : public WidgetObserver { 1037 class CaptureOnActivationObserver : public WidgetObserver {
1037 public: 1038 public:
1038 CaptureOnActivationObserver() { 1039 CaptureOnActivationObserver() : activation_observed_(false) {}
1039 }
1040 ~CaptureOnActivationObserver() override {} 1040 ~CaptureOnActivationObserver() override {}
1041 1041
1042 // WidgetObserver: 1042 // WidgetObserver:
1043 void OnWidgetActivationChanged(Widget* widget, bool active) override { 1043 void OnWidgetActivationChanged(Widget* widget, bool active) override {
1044 if (active) 1044 if (active) {
1045 widget->SetCapture(NULL); 1045 widget->SetCapture(nullptr);
1046 activation_observed_ = true;
1047 }
1046 } 1048 }
1047 1049
1050 bool activation_observed() const { return activation_observed_; }
1051
1048 private: 1052 private:
1053 bool activation_observed_;
1054
1049 DISALLOW_COPY_AND_ASSIGN(CaptureOnActivationObserver); 1055 DISALLOW_COPY_AND_ASSIGN(CaptureOnActivationObserver);
1050 }; 1056 };
1051 1057
1052 } // namespace 1058 } // namespace
1053 1059
1054 // Test that setting capture on widget activation of a non-toplevel widget 1060 // Test that setting capture on widget activation of a non-toplevel widget
1055 // (e.g. a bubble on Linux) succeeds. 1061 // (e.g. a bubble on Linux) succeeds.
1056 TEST_F(WidgetCaptureTest, SetCaptureToNonToplevel) { 1062 TEST_F(WidgetCaptureTest, SetCaptureToNonToplevel) {
1057 Widget toplevel; 1063 Widget toplevel;
1058 Widget::InitParams toplevel_params = 1064 Widget::InitParams toplevel_params =
1059 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); 1065 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
1060 toplevel_params.native_widget = CreateNativeWidget(true, &toplevel); 1066 toplevel_params.native_widget = CreateNativeWidget(true, &toplevel);
1061 toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 1067 toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
1062 toplevel.Init(toplevel_params); 1068 toplevel.Init(toplevel_params);
1063 toplevel.Show(); 1069 toplevel.Show();
1064 1070
1065 Widget* child = new Widget; 1071 Widget* child = new Widget;
1066 Widget::InitParams child_params = 1072 Widget::InitParams child_params =
1067 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); 1073 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
1068 child_params.parent = toplevel.GetNativeView(); 1074 child_params.parent = toplevel.GetNativeView();
1069 child_params.context = toplevel.GetNativeWindow(); 1075 child_params.context = toplevel.GetNativeWindow();
1070 child->Init(child_params); 1076 child->Init(child_params);
1071 1077
1072 CaptureOnActivationObserver observer; 1078 CaptureOnActivationObserver observer;
1073 child->AddObserver(&observer); 1079 child->AddObserver(&observer);
1074 child->Show(); 1080 child->Show();
1075 1081
1082 #if defined(OS_MACOSX) && !defined(USE_AURA)
1083 // On Mac, activation is asynchronous. A single trip to the runloop should be
1084 // sufficient. On Aura platforms, note that since the child widget isn't top-
1085 // level, the aura window manager gets asked whether the widget is active, not
1086 // the OS.
1087 base::RunLoop().RunUntilIdle();
1088 #endif
1089
1090 EXPECT_TRUE(observer.activation_observed());
1076 EXPECT_TRUE(child->HasCapture()); 1091 EXPECT_TRUE(child->HasCapture());
1077 } 1092 }
1078 1093
1079 1094
1080 #if defined(OS_WIN) 1095 #if defined(OS_WIN)
1081 namespace { 1096 namespace {
1082 1097
1083 // Used to verify OnMouseEvent() has been invoked. 1098 // Used to verify OnMouseEvent() has been invoked.
1084 class MouseEventTrackingWidget : public Widget { 1099 class MouseEventTrackingWidget : public Widget {
1085 public: 1100 public:
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> 1155 ui::EventDispatchDetails details = widget1.GetNativeWindow()->
1141 GetHost()->event_processor()->OnEventFromSource(&mouse_event); 1156 GetHost()->event_processor()->OnEventFromSource(&mouse_event);
1142 ASSERT_FALSE(details.dispatcher_destroyed); 1157 ASSERT_FALSE(details.dispatcher_destroyed);
1143 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); 1158 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent());
1144 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); 1159 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent());
1145 } 1160 }
1146 #endif // defined(OS_WIN) 1161 #endif // defined(OS_WIN)
1147 1162
1148 } // namespace test 1163 } // namespace test
1149 } // namespace views 1164 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698