| 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 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 EXPECT_EQ(0, mouse_view1->ExitedCalls()); | 923 EXPECT_EQ(0, mouse_view1->ExitedCalls()); |
| 924 | 924 |
| 925 widget2.SetCapture(NULL); | 925 widget2.SetCapture(NULL); |
| 926 EXPECT_EQ(0, mouse_view1->EnteredCalls()); | 926 EXPECT_EQ(0, mouse_view1->EnteredCalls()); |
| 927 // Grabbing native capture on Windows generates a ui::ET_MOUSE_EXITED event | 927 // Grabbing native capture on Windows generates a ui::ET_MOUSE_EXITED event |
| 928 // in addition to the one generated by Chrome. | 928 // in addition to the one generated by Chrome. |
| 929 EXPECT_LT(0, mouse_view1->ExitedCalls()); | 929 EXPECT_LT(0, mouse_view1->ExitedCalls()); |
| 930 } | 930 } |
| 931 #endif | 931 #endif |
| 932 | 932 |
| 933 namespace { |
| 934 |
| 935 // Widget observer which grabs capture when the widget is activated. |
| 936 class CaptureOnActivationObserver : public WidgetObserver { |
| 937 public: |
| 938 CaptureOnActivationObserver() { |
| 939 } |
| 940 virtual ~CaptureOnActivationObserver() { |
| 941 } |
| 942 |
| 943 // WidgetObserver: |
| 944 virtual void OnWidgetActivationChanged(Widget* widget, bool active) OVERRIDE { |
| 945 if (active) |
| 946 widget->SetCapture(NULL); |
| 947 } |
| 948 |
| 949 private: |
| 950 DISALLOW_COPY_AND_ASSIGN(CaptureOnActivationObserver); |
| 951 }; |
| 952 |
| 953 } // namespace |
| 954 |
| 955 // Test that setting capture on widget activation of a non-toplevel widget |
| 956 // (e.g. a bubble on Linux) succeeds. |
| 957 TEST_F(WidgetCaptureTest, SetCaptureToNonToplevel) { |
| 958 Widget toplevel; |
| 959 Widget::InitParams toplevel_params = |
| 960 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 961 toplevel_params.native_widget = CreateNativeWidget(true, &toplevel); |
| 962 toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 963 toplevel.Init(toplevel_params); |
| 964 toplevel.Show(); |
| 965 |
| 966 Widget* child = new Widget; |
| 967 Widget::InitParams child_params = |
| 968 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 969 child_params.parent = toplevel.GetNativeView(); |
| 970 child_params.context = toplevel.GetNativeView(); |
| 971 child->Init(child_params); |
| 972 |
| 973 CaptureOnActivationObserver observer; |
| 974 child->AddObserver(&observer); |
| 975 child->Show(); |
| 976 |
| 977 EXPECT_TRUE(child->HasCapture()); |
| 978 } |
| 979 |
| 980 |
| 933 #if defined(OS_WIN) | 981 #if defined(OS_WIN) |
| 934 namespace { | 982 namespace { |
| 935 | 983 |
| 936 // Used to verify OnMouseEvent() has been invoked. | 984 // Used to verify OnMouseEvent() has been invoked. |
| 937 class MouseEventTrackingWidget : public Widget { | 985 class MouseEventTrackingWidget : public Widget { |
| 938 public: | 986 public: |
| 939 MouseEventTrackingWidget() : got_mouse_event_(false) {} | 987 MouseEventTrackingWidget() : got_mouse_event_(false) {} |
| 940 virtual ~MouseEventTrackingWidget() {} | 988 virtual ~MouseEventTrackingWidget() {} |
| 941 | 989 |
| 942 bool GetAndClearGotMouseEvent() { | 990 bool GetAndClearGotMouseEvent() { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> | 1041 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> |
| 994 GetHost()->event_processor()->OnEventFromSource(&mouse_event); | 1042 GetHost()->event_processor()->OnEventFromSource(&mouse_event); |
| 995 ASSERT_FALSE(details.dispatcher_destroyed); | 1043 ASSERT_FALSE(details.dispatcher_destroyed); |
| 996 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); | 1044 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); |
| 997 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); | 1045 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); |
| 998 } | 1046 } |
| 999 #endif | 1047 #endif |
| 1000 | 1048 |
| 1001 } // namespace test | 1049 } // namespace test |
| 1002 } // namespace views | 1050 } // namespace views |
| OLD | NEW |