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 25 matching lines...) Expand all Loading... |
36 namespace views { | 36 namespace views { |
37 namespace test { | 37 namespace test { |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 // A View that closes the Widget and exits the current message-loop when it | 41 // A View that closes the Widget and exits the current message-loop when it |
42 // receives a mouse-release event. | 42 // receives a mouse-release event. |
43 class ExitLoopOnRelease : public View { | 43 class ExitLoopOnRelease : public View { |
44 public: | 44 public: |
45 ExitLoopOnRelease() {} | 45 ExitLoopOnRelease() {} |
46 virtual ~ExitLoopOnRelease() {} | 46 ~ExitLoopOnRelease() override {} |
47 | 47 |
48 private: | 48 private: |
49 // Overridden from View: | 49 // Overridden from View: |
50 virtual void OnMouseReleased(const ui::MouseEvent& event) override { | 50 void OnMouseReleased(const ui::MouseEvent& event) override { |
51 GetWidget()->Close(); | 51 GetWidget()->Close(); |
52 base::MessageLoop::current()->QuitNow(); | 52 base::MessageLoop::current()->QuitNow(); |
53 } | 53 } |
54 | 54 |
55 DISALLOW_COPY_AND_ASSIGN(ExitLoopOnRelease); | 55 DISALLOW_COPY_AND_ASSIGN(ExitLoopOnRelease); |
56 }; | 56 }; |
57 | 57 |
58 // A view that does a capture on ui::ET_GESTURE_TAP_DOWN events. | 58 // A view that does a capture on ui::ET_GESTURE_TAP_DOWN events. |
59 class GestureCaptureView : public View { | 59 class GestureCaptureView : public View { |
60 public: | 60 public: |
61 GestureCaptureView() {} | 61 GestureCaptureView() {} |
62 virtual ~GestureCaptureView() {} | 62 ~GestureCaptureView() override {} |
63 | 63 |
64 private: | 64 private: |
65 // Overridden from View: | 65 // Overridden from View: |
66 virtual void OnGestureEvent(ui::GestureEvent* event) override { | 66 void OnGestureEvent(ui::GestureEvent* event) override { |
67 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | 67 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
68 GetWidget()->SetCapture(this); | 68 GetWidget()->SetCapture(this); |
69 event->StopPropagation(); | 69 event->StopPropagation(); |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 DISALLOW_COPY_AND_ASSIGN(GestureCaptureView); | 73 DISALLOW_COPY_AND_ASSIGN(GestureCaptureView); |
74 }; | 74 }; |
75 | 75 |
76 // A view that always processes all mouse events. | 76 // A view that always processes all mouse events. |
77 class MouseView : public View { | 77 class MouseView : public View { |
78 public: | 78 public: |
79 MouseView() | 79 MouseView() |
80 : View(), | 80 : View(), |
81 entered_(0), | 81 entered_(0), |
82 exited_(0), | 82 exited_(0), |
83 pressed_(0) { | 83 pressed_(0) { |
84 } | 84 } |
85 virtual ~MouseView() {} | 85 ~MouseView() override {} |
86 | 86 |
87 virtual bool OnMousePressed(const ui::MouseEvent& event) override { | 87 bool OnMousePressed(const ui::MouseEvent& event) override { |
88 pressed_++; | 88 pressed_++; |
89 return true; | 89 return true; |
90 } | 90 } |
91 | 91 |
92 virtual void OnMouseEntered(const ui::MouseEvent& event) override { | 92 void OnMouseEntered(const ui::MouseEvent& event) override { entered_++; } |
93 entered_++; | |
94 } | |
95 | 93 |
96 virtual void OnMouseExited(const ui::MouseEvent& event) override { | 94 void OnMouseExited(const ui::MouseEvent& event) override { exited_++; } |
97 exited_++; | |
98 } | |
99 | 95 |
100 // Return the number of OnMouseEntered calls and reset the counter. | 96 // Return the number of OnMouseEntered calls and reset the counter. |
101 int EnteredCalls() { | 97 int EnteredCalls() { |
102 int i = entered_; | 98 int i = entered_; |
103 entered_ = 0; | 99 entered_ = 0; |
104 return i; | 100 return i; |
105 } | 101 } |
106 | 102 |
107 // Return the number of OnMouseExited calls and reset the counter. | 103 // Return the number of OnMouseExited calls and reset the counter. |
108 int ExitedCalls() { | 104 int ExitedCalls() { |
(...skipping 11 matching lines...) Expand all Loading... |
120 int pressed_; | 116 int pressed_; |
121 | 117 |
122 DISALLOW_COPY_AND_ASSIGN(MouseView); | 118 DISALLOW_COPY_AND_ASSIGN(MouseView); |
123 }; | 119 }; |
124 | 120 |
125 // A View that shows a different widget, sets capture on that widget, and | 121 // A View that shows a different widget, sets capture on that widget, and |
126 // initiates a nested message-loop when it receives a mouse-press event. | 122 // initiates a nested message-loop when it receives a mouse-press event. |
127 class NestedLoopCaptureView : public View { | 123 class NestedLoopCaptureView : public View { |
128 public: | 124 public: |
129 explicit NestedLoopCaptureView(Widget* widget) : widget_(widget) {} | 125 explicit NestedLoopCaptureView(Widget* widget) : widget_(widget) {} |
130 virtual ~NestedLoopCaptureView() {} | 126 ~NestedLoopCaptureView() override {} |
131 | 127 |
132 private: | 128 private: |
133 // Overridden from View: | 129 // Overridden from View: |
134 virtual bool OnMousePressed(const ui::MouseEvent& event) override { | 130 bool OnMousePressed(const ui::MouseEvent& event) override { |
135 // Start a nested loop. | 131 // Start a nested loop. |
136 widget_->Show(); | 132 widget_->Show(); |
137 widget_->SetCapture(widget_->GetContentsView()); | 133 widget_->SetCapture(widget_->GetContentsView()); |
138 EXPECT_TRUE(widget_->HasCapture()); | 134 EXPECT_TRUE(widget_->HasCapture()); |
139 | 135 |
140 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); | 136 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
141 base::MessageLoop::ScopedNestableTaskAllower allow(loop); | 137 base::MessageLoop::ScopedNestableTaskAllower allow(loop); |
142 | 138 |
143 base::RunLoop run_loop; | 139 base::RunLoop run_loop; |
144 run_loop.Run(); | 140 run_loop.Run(); |
145 return true; | 141 return true; |
146 } | 142 } |
147 | 143 |
148 Widget* widget_; | 144 Widget* widget_; |
149 | 145 |
150 DISALLOW_COPY_AND_ASSIGN(NestedLoopCaptureView); | 146 DISALLOW_COPY_AND_ASSIGN(NestedLoopCaptureView); |
151 }; | 147 }; |
152 | 148 |
153 } // namespace | 149 } // namespace |
154 | 150 |
155 class WidgetTestInteractive : public WidgetTest { | 151 class WidgetTestInteractive : public WidgetTest { |
156 public: | 152 public: |
157 WidgetTestInteractive() {} | 153 WidgetTestInteractive() {} |
158 virtual ~WidgetTestInteractive() {} | 154 ~WidgetTestInteractive() override {} |
159 | 155 |
160 virtual void SetUp() override { | 156 void SetUp() override { |
161 gfx::GLSurface::InitializeOneOffForTests(); | 157 gfx::GLSurface::InitializeOneOffForTests(); |
162 ui::RegisterPathProvider(); | 158 ui::RegisterPathProvider(); |
163 base::FilePath ui_test_pak_path; | 159 base::FilePath ui_test_pak_path; |
164 ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); | 160 ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); |
165 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); | 161 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); |
166 WidgetTest::SetUp(); | 162 WidgetTest::SetUp(); |
167 } | 163 } |
168 | 164 |
169 protected: | 165 protected: |
170 static void ShowQuickMenuImmediately( | 166 static void ShowQuickMenuImmediately( |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 EXPECT_EQ(true, widget1.active()); | 626 EXPECT_EQ(true, widget1.active()); |
631 EXPECT_EQ(false, widget2.active()); | 627 EXPECT_EQ(false, widget2.active()); |
632 } | 628 } |
633 #endif // defined(OS_WIN) | 629 #endif // defined(OS_WIN) |
634 | 630 |
635 #if !defined(OS_CHROMEOS) | 631 #if !defined(OS_CHROMEOS) |
636 // Provides functionality to create a window modal dialog. | 632 // Provides functionality to create a window modal dialog. |
637 class ModalDialogDelegate : public DialogDelegateView { | 633 class ModalDialogDelegate : public DialogDelegateView { |
638 public: | 634 public: |
639 explicit ModalDialogDelegate(ui::ModalType type) : type_(type) {} | 635 explicit ModalDialogDelegate(ui::ModalType type) : type_(type) {} |
640 virtual ~ModalDialogDelegate() {} | 636 ~ModalDialogDelegate() override {} |
641 | 637 |
642 // WidgetDelegate overrides. | 638 // WidgetDelegate overrides. |
643 virtual ui::ModalType GetModalType() const override { | 639 ui::ModalType GetModalType() const override { return type_; } |
644 return type_; | |
645 } | |
646 | 640 |
647 private: | 641 private: |
648 ui::ModalType type_; | 642 ui::ModalType type_; |
649 | 643 |
650 DISALLOW_COPY_AND_ASSIGN(ModalDialogDelegate); | 644 DISALLOW_COPY_AND_ASSIGN(ModalDialogDelegate); |
651 }; | 645 }; |
652 | 646 |
653 // Tests whether the focused window is set correctly when a modal window is | 647 // Tests whether the focused window is set correctly when a modal window is |
654 // created and destroyed. When it is destroyed it should focus the owner window. | 648 // created and destroyed. When it is destroyed it should focus the owner window. |
655 TEST_F(WidgetTestInteractive, WindowModalWindowDestroyedActivationTest) { | 649 TEST_F(WidgetTestInteractive, WindowModalWindowDestroyedActivationTest) { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 EXPECT_FALSE(widget1.IsActive()); | 845 EXPECT_FALSE(widget1.IsActive()); |
852 EXPECT_TRUE(widget2.IsActive()); | 846 EXPECT_TRUE(widget2.IsActive()); |
853 } | 847 } |
854 | 848 |
855 namespace { | 849 namespace { |
856 | 850 |
857 // Used to veirfy OnMouseCaptureLost() has been invoked. | 851 // Used to veirfy OnMouseCaptureLost() has been invoked. |
858 class CaptureLostTrackingWidget : public Widget { | 852 class CaptureLostTrackingWidget : public Widget { |
859 public: | 853 public: |
860 CaptureLostTrackingWidget() : got_capture_lost_(false) {} | 854 CaptureLostTrackingWidget() : got_capture_lost_(false) {} |
861 virtual ~CaptureLostTrackingWidget() {} | 855 ~CaptureLostTrackingWidget() override {} |
862 | 856 |
863 bool GetAndClearGotCaptureLost() { | 857 bool GetAndClearGotCaptureLost() { |
864 bool value = got_capture_lost_; | 858 bool value = got_capture_lost_; |
865 got_capture_lost_ = false; | 859 got_capture_lost_ = false; |
866 return value; | 860 return value; |
867 } | 861 } |
868 | 862 |
869 // Widget: | 863 // Widget: |
870 virtual void OnMouseCaptureLost() override { | 864 void OnMouseCaptureLost() override { |
871 got_capture_lost_ = true; | 865 got_capture_lost_ = true; |
872 Widget::OnMouseCaptureLost(); | 866 Widget::OnMouseCaptureLost(); |
873 } | 867 } |
874 | 868 |
875 private: | 869 private: |
876 bool got_capture_lost_; | 870 bool got_capture_lost_; |
877 | 871 |
878 DISALLOW_COPY_AND_ASSIGN(CaptureLostTrackingWidget); | 872 DISALLOW_COPY_AND_ASSIGN(CaptureLostTrackingWidget); |
879 }; | 873 }; |
880 | 874 |
881 } // namespace | 875 } // namespace |
882 | 876 |
883 class WidgetCaptureTest : public ViewsTestBase { | 877 class WidgetCaptureTest : public ViewsTestBase { |
884 public: | 878 public: |
885 WidgetCaptureTest() { | 879 WidgetCaptureTest() { |
886 } | 880 } |
887 | 881 |
888 virtual ~WidgetCaptureTest() { | 882 ~WidgetCaptureTest() override {} |
889 } | |
890 | 883 |
891 virtual void SetUp() override { | 884 void SetUp() override { |
892 gfx::GLSurface::InitializeOneOffForTests(); | 885 gfx::GLSurface::InitializeOneOffForTests(); |
893 ui::RegisterPathProvider(); | 886 ui::RegisterPathProvider(); |
894 base::FilePath ui_test_pak_path; | 887 base::FilePath ui_test_pak_path; |
895 ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); | 888 ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); |
896 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); | 889 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); |
897 ViewsTestBase::SetUp(); | 890 ViewsTestBase::SetUp(); |
898 } | 891 } |
899 | 892 |
900 // Verifies Widget::SetCapture() results in updating native capture along with | 893 // Verifies Widget::SetCapture() results in updating native capture along with |
901 // invoking the right Widget function. | 894 // invoking the right Widget function. |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 } | 1030 } |
1038 #endif // !defined(OS_CHROMEOS) | 1031 #endif // !defined(OS_CHROMEOS) |
1039 | 1032 |
1040 namespace { | 1033 namespace { |
1041 | 1034 |
1042 // Widget observer which grabs capture when the widget is activated. | 1035 // Widget observer which grabs capture when the widget is activated. |
1043 class CaptureOnActivationObserver : public WidgetObserver { | 1036 class CaptureOnActivationObserver : public WidgetObserver { |
1044 public: | 1037 public: |
1045 CaptureOnActivationObserver() { | 1038 CaptureOnActivationObserver() { |
1046 } | 1039 } |
1047 virtual ~CaptureOnActivationObserver() { | 1040 ~CaptureOnActivationObserver() override {} |
1048 } | |
1049 | 1041 |
1050 // WidgetObserver: | 1042 // WidgetObserver: |
1051 virtual void OnWidgetActivationChanged(Widget* widget, bool active) override { | 1043 void OnWidgetActivationChanged(Widget* widget, bool active) override { |
1052 if (active) | 1044 if (active) |
1053 widget->SetCapture(NULL); | 1045 widget->SetCapture(NULL); |
1054 } | 1046 } |
1055 | 1047 |
1056 private: | 1048 private: |
1057 DISALLOW_COPY_AND_ASSIGN(CaptureOnActivationObserver); | 1049 DISALLOW_COPY_AND_ASSIGN(CaptureOnActivationObserver); |
1058 }; | 1050 }; |
1059 | 1051 |
1060 } // namespace | 1052 } // namespace |
1061 | 1053 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> | 1140 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> |
1149 GetHost()->event_processor()->OnEventFromSource(&mouse_event); | 1141 GetHost()->event_processor()->OnEventFromSource(&mouse_event); |
1150 ASSERT_FALSE(details.dispatcher_destroyed); | 1142 ASSERT_FALSE(details.dispatcher_destroyed); |
1151 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); | 1143 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); |
1152 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); | 1144 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); |
1153 } | 1145 } |
1154 #endif // defined(OS_WIN) | 1146 #endif // defined(OS_WIN) |
1155 | 1147 |
1156 } // namespace test | 1148 } // namespace test |
1157 } // namespace views | 1149 } // namespace views |
OLD | NEW |