OLD | NEW |
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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 content->AddPreTargetHandler(&handler); | 411 content->AddPreTargetHandler(&handler); |
412 | 412 |
413 std::unique_ptr<ui::MouseEvent> mouse = CreateMouseEvent(); | 413 std::unique_ptr<ui::MouseEvent> mouse = CreateMouseEvent(); |
414 NativeWidgetMus* native_widget = | 414 NativeWidgetMus* native_widget = |
415 static_cast<NativeWidgetMus*>(widget->native_widget_private()); | 415 static_cast<NativeWidgetMus*>(widget->native_widget_private()); |
416 mus::WindowTreeClientImplPrivate test_api(native_widget->window()); | 416 mus::WindowTreeClientImplPrivate test_api(native_widget->window()); |
417 test_api.CallOnWindowInputEvent(native_widget->window(), *mouse); | 417 test_api.CallOnWindowInputEvent(native_widget->window(), *mouse); |
418 EXPECT_EQ(1, handler.num_mouse_events()); | 418 EXPECT_EQ(1, handler.num_mouse_events()); |
419 } | 419 } |
420 | 420 |
| 421 // Tests that an incoming UI event is acked with the handled status. |
| 422 TEST_F(NativeWidgetMusTest, EventAcked) { |
| 423 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); |
| 424 widget->Show(); |
| 425 |
| 426 View* content = new HandleMousePressView; |
| 427 content->SetBounds(10, 20, 90, 180); |
| 428 widget->GetContentsView()->AddChildView(content); |
| 429 |
| 430 // Dispatch an input event to the window and view. |
| 431 std::unique_ptr<ui::MouseEvent> event = CreateMouseEvent(); |
| 432 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback( |
| 433 new base::Callback<void(EventResult)>(base::Bind( |
| 434 &NativeWidgetMusTest::AckCallback, base::Unretained(this)))); |
| 435 OnWindowInputEvent( |
| 436 static_cast<NativeWidgetMus*>(widget->native_widget_private()), |
| 437 *event, |
| 438 &ack_callback); |
| 439 |
| 440 // The test took ownership of the callback and called it. |
| 441 EXPECT_FALSE(ack_callback); |
| 442 EXPECT_EQ(1, ack_callback_count()); |
| 443 } |
| 444 |
| 445 // Tests that a window that is deleted during event handling properly acks the |
| 446 // event. |
| 447 TEST_F(NativeWidgetMusTest, EventAckedWithWindowDestruction) { |
| 448 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); |
| 449 widget->Show(); |
| 450 |
| 451 View* content = new DeleteWidgetView(&widget); |
| 452 content->SetBounds(10, 20, 90, 180); |
| 453 widget->GetContentsView()->AddChildView(content); |
| 454 |
| 455 // Dispatch an input event to the window and view. |
| 456 std::unique_ptr<ui::MouseEvent> event = CreateMouseEvent(); |
| 457 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback( |
| 458 new base::Callback<void(EventResult)>(base::Bind( |
| 459 &NativeWidgetMusTest::AckCallback, base::Unretained(this)))); |
| 460 OnWindowInputEvent( |
| 461 static_cast<NativeWidgetMus*>(widget->native_widget_private()), |
| 462 *event, |
| 463 &ack_callback); |
| 464 |
| 465 // The widget was deleted. |
| 466 EXPECT_FALSE(widget.get()); |
| 467 |
| 468 // The test took ownership of the callback and called it. |
| 469 EXPECT_FALSE(ack_callback); |
| 470 EXPECT_EQ(1, ack_callback_count()); |
| 471 } |
| 472 |
421 TEST_F(NativeWidgetMusTest, SetAndReleaseCapture) { | 473 TEST_F(NativeWidgetMusTest, SetAndReleaseCapture) { |
422 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); | 474 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); |
423 widget->Show(); | 475 widget->Show(); |
424 View* content = new View; | 476 View* content = new View; |
425 widget->GetContentsView()->AddChildView(content); | 477 widget->GetContentsView()->AddChildView(content); |
426 internal::NativeWidgetPrivate* widget_private = | 478 internal::NativeWidgetPrivate* widget_private = |
427 widget->native_widget_private(); | 479 widget->native_widget_private(); |
428 mus::Window* mus_window = | 480 mus::Window* mus_window = |
429 static_cast<NativeWidgetMus*>(widget_private)->window(); | 481 static_cast<NativeWidgetMus*>(widget_private)->window(); |
430 EXPECT_FALSE(widget_private->HasCapture()); | 482 EXPECT_FALSE(widget_private->HasCapture()); |
431 EXPECT_FALSE(mus_window->HasCapture()); | 483 EXPECT_FALSE(mus_window->HasCapture()); |
432 | 484 |
433 widget->SetCapture(content); | 485 widget->SetCapture(content); |
434 EXPECT_TRUE(widget_private->HasCapture()); | 486 EXPECT_TRUE(widget_private->HasCapture()); |
435 EXPECT_TRUE(mus_window->HasCapture()); | 487 EXPECT_TRUE(mus_window->HasCapture()); |
436 | 488 |
437 widget->ReleaseCapture(); | 489 widget->ReleaseCapture(); |
438 EXPECT_FALSE(widget_private->HasCapture()); | 490 EXPECT_FALSE(widget_private->HasCapture()); |
439 EXPECT_FALSE(mus_window->HasCapture()); | 491 EXPECT_FALSE(mus_window->HasCapture()); |
440 } | 492 } |
441 | 493 |
442 } // namespace views | 494 } // namespace views |
OLD | NEW |