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

Side by Side Diff: ui/views/mus/native_widget_mus_unittest.cc

Issue 2013503002: Keep non-key event handling in-house for NativeWidgetMus Base URL: https://chromium.googlesource.com/chromium/src.git@native_widget_mus9
Patch Set: Add test for mouse input info agreement between widget and view Created 4 years, 6 months 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
« no previous file with comments | « ui/views/mus/native_widget_mus.cc ('k') | ui/views/mus/window_tree_host_mus.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ui/views/mus/native_widget_mus.h" 5 #include "ui/views/mus/native_widget_mus.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "components/mus/public/cpp/property_type_converters.h" 9 #include "components/mus/public/cpp/property_type_converters.h"
10 #include "components/mus/public/cpp/tests/window_tree_client_impl_private.h" 10 #include "components/mus/public/cpp/tests/window_tree_client_impl_private.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 void GetWidgetHitTestMask(gfx::Path* mask) const override { 134 void GetWidgetHitTestMask(gfx::Path* mask) const override {
135 mask->addRect(gfx::RectToSkRect(mask_rect_)); 135 mask->addRect(gfx::RectToSkRect(mask_rect_));
136 } 136 }
137 137
138 private: 138 private:
139 gfx::Rect mask_rect_; 139 gfx::Rect mask_rect_;
140 140
141 DISALLOW_COPY_AND_ASSIGN(WidgetDelegateWithHitTestMask); 141 DISALLOW_COPY_AND_ASSIGN(WidgetDelegateWithHitTestMask);
142 }; 142 };
143 143
144 class UIMouseEventHandler : public ui::test::TestEventHandler {
145 public:
146 explicit UIMouseEventHandler(ui::PointerDetails* pointer_details)
147 : pointer_details_(pointer_details), event_received_(false) {}
148 ~UIMouseEventHandler() override {}
149
150 void OnMouseEvent(ui::MouseEvent* event) override {
151 *pointer_details_ = event->pointer_details();
152 set_event_received();
153 }
154
155 bool event_received() { return event_received_; }
156
157 private:
158 void set_event_received() { event_received_ = true; }
159
160 ui::PointerDetails* pointer_details_;
161 bool event_received_;
162
163 DISALLOW_COPY_AND_ASSIGN(UIMouseEventHandler);
164 };
165
166 class MusMouseEventHandler : public mus::InputEventHandler {
167 public:
168 explicit MusMouseEventHandler(ui::PointerDetails* pointer_details,
169 mus::Window* window)
170 : pointer_details_(pointer_details), window_(window),
171 event_received_(false) {
172 delegate_ = window->input_event_handler();
173 window->set_input_event_handler(this);
174 }
175 ~MusMouseEventHandler() override {
176 window_->set_input_event_handler(delegate_);
177 }
178
179 bool event_received() { return event_received_; }
180
181 private:
182 void set_event_received() { event_received_ = true; }
183
184 // InputEventHandler:
185 void OnWindowInputEvent(
186 mus::Window* target,
187 const ui::Event& event,
188 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback)
189 override {
190 DCHECK(event.IsMouseEvent());
191 *pointer_details_ = event.AsMouseEvent()->pointer_details();
192 set_event_received();
193 if (delegate_)
194 delegate_->OnWindowInputEvent(target, event, ack_callback);
195 }
196
197 ui::PointerDetails* pointer_details_;
198 mus::Window* window_;
199 bool event_received_;
200 mus::InputEventHandler* delegate_;
201
202 DISALLOW_COPY_AND_ASSIGN(MusMouseEventHandler);
203 };
204
144 } // namespace 205 } // namespace
145 206
146 class NativeWidgetMusTest : public ViewsTestBase { 207 class NativeWidgetMusTest : public ViewsTestBase {
147 public: 208 public:
148 NativeWidgetMusTest() {} 209 NativeWidgetMusTest() {}
149 ~NativeWidgetMusTest() override {} 210 ~NativeWidgetMusTest() override {}
150 211
151 // Creates a test widget. Takes ownership of |delegate|. 212 // Creates a test widget. Takes ownership of |delegate|.
152 std::unique_ptr<Widget> CreateWidget(WidgetDelegate* delegate) { 213 std::unique_ptr<Widget> CreateWidget(WidgetDelegate* delegate) {
153 std::unique_ptr<Widget> widget(new Widget()); 214 std::unique_ptr<Widget> widget(new Widget());
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 content->AddPreTargetHandler(&handler); 477 content->AddPreTargetHandler(&handler);
417 478
418 std::unique_ptr<ui::MouseEvent> mouse = CreateMouseEvent(); 479 std::unique_ptr<ui::MouseEvent> mouse = CreateMouseEvent();
419 NativeWidgetMus* native_widget = 480 NativeWidgetMus* native_widget =
420 static_cast<NativeWidgetMus*>(widget->native_widget_private()); 481 static_cast<NativeWidgetMus*>(widget->native_widget_private());
421 mus::WindowTreeClientImplPrivate test_api(native_widget->window()); 482 mus::WindowTreeClientImplPrivate test_api(native_widget->window());
422 test_api.CallOnWindowInputEvent(native_widget->window(), *mouse); 483 test_api.CallOnWindowInputEvent(native_widget->window(), *mouse);
423 EXPECT_EQ(1, handler.num_mouse_events()); 484 EXPECT_EQ(1, handler.num_mouse_events());
424 } 485 }
425 486
487 TEST_F(NativeWidgetMusTest, WidgetViewMouseEventAgreement) {
488 std::unique_ptr<Widget> widget(CreateWidget(nullptr));
489 widget->Show();
490
491 View* content = new HandleMousePressView;
492 content->SetBounds(10, 20, 90, 180);
493 widget->GetContentsView()->AddChildView(content);
494
495 ui::PointerDetails ui_pointer_details;
496 UIMouseEventHandler ui_handler(&ui_pointer_details);
497 content->AddPreTargetHandler(&ui_handler);
498
499 ui::PointerDetails mus_pointer_details;
500 NativeWidgetMus* native_widget =
501 static_cast<NativeWidgetMus*>(widget->native_widget_private());
502 MusMouseEventHandler mus_handler(&mus_pointer_details,
503 native_widget->window()); // Self-installed.
504
505 std::unique_ptr<ui::MouseEvent> mouse = CreateMouseEvent();
506 mus::WindowTreeClientImplPrivate test_api(native_widget->window());
507 test_api.CallOnWindowInputEvent(native_widget->window(), *mouse);
508
509 // Expectation: Event delivered to view and widget in same coordinate space.
510 EXPECT_TRUE(ui_handler.event_received());
511 EXPECT_TRUE(mus_handler.event_received());
512 EXPECT_EQ(ui_pointer_details, mus_pointer_details);
sadrul 2016/05/26 22:00:50 PointerDetails do not contain event-location, whic
Mark Dittmer 2016/05/27 12:37:32 Wait. So does that mean that the view and widget _
Mark Dittmer 2016/05/27 13:46:19 Done.
513 }
514
426 // Tests that an incoming UI event is acked with the handled status. 515 // Tests that an incoming UI event is acked with the handled status.
427 TEST_F(NativeWidgetMusTest, EventAcked) { 516 TEST_F(NativeWidgetMusTest, EventAcked) {
428 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); 517 std::unique_ptr<Widget> widget(CreateWidget(nullptr));
429 widget->Show(); 518 widget->Show();
430 519
431 View* content = new HandleMousePressView; 520 View* content = new HandleMousePressView;
432 content->SetBounds(10, 20, 90, 180); 521 content->SetBounds(10, 20, 90, 180);
433 widget->GetContentsView()->AddChildView(content); 522 widget->GetContentsView()->AddChildView(content);
434 523
435 // Dispatch an input event to the window and view. 524 // Dispatch an input event to the window and view.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 mus_window->SetBounds(end_bounds); 606 mus_window->SetBounds(end_bounds);
518 607
519 EXPECT_EQ(end_bounds, mus_window->bounds()); 608 EXPECT_EQ(end_bounds, mus_window->bounds());
520 609
521 // Main check for this test: Setting |mus_window| bounds while bypassing 610 // Main check for this test: Setting |mus_window| bounds while bypassing
522 // |native_widget| must update window_tree_host bounds. 611 // |native_widget| must update window_tree_host bounds.
523 EXPECT_EQ(end_bounds, native_widget->window_tree_host()->GetBounds()); 612 EXPECT_EQ(end_bounds, native_widget->window_tree_host()->GetBounds());
524 } 613 }
525 614
526 } // namespace views 615 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/native_widget_mus.cc ('k') | ui/views/mus/window_tree_host_mus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698