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 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 TestCapture(false); | 886 TestCapture(false); |
887 } | 887 } |
888 | 888 |
889 #if !defined(OS_CHROMEOS) | 889 #if !defined(OS_CHROMEOS) |
890 // See description in TestCapture(). Creates DesktopNativeWidget. | 890 // See description in TestCapture(). Creates DesktopNativeWidget. |
891 TEST_F(WidgetCaptureTest, CaptureDesktopNativeWidget) { | 891 TEST_F(WidgetCaptureTest, CaptureDesktopNativeWidget) { |
892 TestCapture(true); | 892 TestCapture(true); |
893 } | 893 } |
894 #endif | 894 #endif |
895 | 895 |
| 896 // Test that no state is set if capture fails. |
| 897 TEST_F(WidgetCaptureTest, FailedCaptureRequestIsNoop) { |
| 898 Widget widget; |
| 899 Widget::InitParams params = |
| 900 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 901 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 902 params.bounds = gfx::Rect(400, 400); |
| 903 widget.Init(params); |
| 904 |
| 905 MouseView* mouse_view1 = new MouseView; |
| 906 MouseView* mouse_view2 = new MouseView; |
| 907 View* contents_view = new View; |
| 908 contents_view->AddChildView(mouse_view1); |
| 909 contents_view->AddChildView(mouse_view2); |
| 910 widget.SetContentsView(contents_view); |
| 911 |
| 912 mouse_view1->SetBounds(0, 0, 200, 400); |
| 913 mouse_view2->SetBounds(200, 0, 200, 400); |
| 914 |
| 915 // Setting capture should fail because |widget| is not visible. |
| 916 widget.SetCapture(mouse_view1); |
| 917 EXPECT_FALSE(widget.HasCapture()); |
| 918 |
| 919 widget.Show(); |
| 920 ui::MouseEvent mouse_press_event(ui::ET_MOUSE_PRESSED, gfx::Point(300, 10), |
| 921 gfx::Point(300, 10), ui::EF_NONE, ui::EF_NONE); |
| 922 ui::EventDispatchDetails details = widget.GetNativeWindow()->GetHost()-> |
| 923 event_processor()->OnEventFromSource(&mouse_press_event); |
| 924 ASSERT_FALSE(details.dispatcher_destroyed); |
| 925 EXPECT_FALSE(mouse_view1->pressed()); |
| 926 EXPECT_TRUE(mouse_view2->pressed()); |
| 927 } |
| 928 |
896 #if !defined(OS_CHROMEOS) | 929 #if !defined(OS_CHROMEOS) |
897 // Test that a synthetic mouse exit is sent to the widget which was handling | 930 // Test that a synthetic mouse exit is sent to the widget which was handling |
898 // mouse events when a different widget grabs capture. | 931 // mouse events when a different widget grabs capture. |
899 // TODO(pkotwicz): Make test pass on CrOS. | 932 // TODO(pkotwicz): Make test pass on CrOS. |
900 TEST_F(WidgetCaptureTest, MouseExitOnCaptureGrab) { | 933 TEST_F(WidgetCaptureTest, MouseExitOnCaptureGrab) { |
901 Widget widget1; | 934 Widget widget1; |
902 Widget::InitParams params1 = | 935 Widget::InitParams params1 = |
903 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 936 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
904 params1.native_widget = CreateNativeWidget(true, &widget1); | 937 params1.native_widget = CreateNativeWidget(true, &widget1); |
905 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 938 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> | 1078 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> |
1046 GetHost()->event_processor()->OnEventFromSource(&mouse_event); | 1079 GetHost()->event_processor()->OnEventFromSource(&mouse_event); |
1047 ASSERT_FALSE(details.dispatcher_destroyed); | 1080 ASSERT_FALSE(details.dispatcher_destroyed); |
1048 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); | 1081 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); |
1049 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); | 1082 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); |
1050 } | 1083 } |
1051 #endif | 1084 #endif |
1052 | 1085 |
1053 } // namespace test | 1086 } // namespace test |
1054 } // namespace views | 1087 } // namespace views |
OLD | NEW |