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 | |
sadrul
2016/05/26 01:31:01
We should keep these tests.
Mark Dittmer
2016/05/26 13:37:33
Done.
| |
473 TEST_F(NativeWidgetMusTest, SetAndReleaseCapture) { | 421 TEST_F(NativeWidgetMusTest, SetAndReleaseCapture) { |
474 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); | 422 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); |
475 widget->Show(); | 423 widget->Show(); |
476 View* content = new View; | 424 View* content = new View; |
477 widget->GetContentsView()->AddChildView(content); | 425 widget->GetContentsView()->AddChildView(content); |
478 internal::NativeWidgetPrivate* widget_private = | 426 internal::NativeWidgetPrivate* widget_private = |
479 widget->native_widget_private(); | 427 widget->native_widget_private(); |
480 mus::Window* mus_window = | 428 mus::Window* mus_window = |
481 static_cast<NativeWidgetMus*>(widget_private)->window(); | 429 static_cast<NativeWidgetMus*>(widget_private)->window(); |
482 EXPECT_FALSE(widget_private->HasCapture()); | 430 EXPECT_FALSE(widget_private->HasCapture()); |
483 EXPECT_FALSE(mus_window->HasCapture()); | 431 EXPECT_FALSE(mus_window->HasCapture()); |
484 | 432 |
485 widget->SetCapture(content); | 433 widget->SetCapture(content); |
486 EXPECT_TRUE(widget_private->HasCapture()); | 434 EXPECT_TRUE(widget_private->HasCapture()); |
487 EXPECT_TRUE(mus_window->HasCapture()); | 435 EXPECT_TRUE(mus_window->HasCapture()); |
488 | 436 |
489 widget->ReleaseCapture(); | 437 widget->ReleaseCapture(); |
490 EXPECT_FALSE(widget_private->HasCapture()); | 438 EXPECT_FALSE(widget_private->HasCapture()); |
491 EXPECT_FALSE(mus_window->HasCapture()); | 439 EXPECT_FALSE(mus_window->HasCapture()); |
492 } | 440 } |
493 | 441 |
494 } // namespace views | 442 } // namespace views |
OLD | NEW |