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/window.h" | 11 #include "components/mus/public/cpp/window.h" |
11 #include "components/mus/public/cpp/window_property.h" | 12 #include "components/mus/public/cpp/window_property.h" |
12 #include "components/mus/public/cpp/window_tree_connection.h" | 13 #include "components/mus/public/cpp/window_tree_connection.h" |
13 #include "components/mus/public/interfaces/window_manager.mojom.h" | 14 #include "components/mus/public/interfaces/window_manager.mojom.h" |
14 #include "components/mus/public/interfaces/window_tree.mojom.h" | 15 #include "components/mus/public/interfaces/window_tree.mojom.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
17 #include "third_party/skia/include/core/SkColor.h" | 18 #include "third_party/skia/include/core/SkColor.h" |
18 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
19 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
| 21 #include "ui/events/test/test_event_handler.h" |
20 #include "ui/gfx/geometry/rect.h" | 22 #include "ui/gfx/geometry/rect.h" |
21 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" |
22 #include "ui/gfx/skia_util.h" | 24 #include "ui/gfx/skia_util.h" |
23 #include "ui/views/controls/native/native_view_host.h" | 25 #include "ui/views/controls/native/native_view_host.h" |
24 #include "ui/views/test/focus_manager_test.h" | 26 #include "ui/views/test/focus_manager_test.h" |
25 #include "ui/views/test/views_test_base.h" | 27 #include "ui/views/test/views_test_base.h" |
26 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
27 #include "ui/views/widget/widget_delegate.h" | 29 #include "ui/views/widget/widget_delegate.h" |
28 #include "ui/views/widget/widget_observer.h" | 30 #include "ui/views/widget/widget_observer.h" |
29 #include "ui/wm/public/activation_client.h" | 31 #include "ui/wm/public/activation_client.h" |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 // the Widget's window instead. | 358 // the Widget's window instead. |
357 focusable->RequestFocus(); | 359 focusable->RequestFocus(); |
358 EXPECT_FALSE(window->HasFocus()); | 360 EXPECT_FALSE(window->HasFocus()); |
359 EXPECT_TRUE(widget.GetNativeView()->HasFocus()); | 361 EXPECT_TRUE(widget.GetNativeView()->HasFocus()); |
360 active_window = | 362 active_window = |
361 aura::client::GetActivationClient(window.get()->GetRootWindow()) | 363 aura::client::GetActivationClient(window.get()->GetRootWindow()) |
362 ->GetActiveWindow(); | 364 ->GetActiveWindow(); |
363 EXPECT_EQ(widget.GetNativeView(), active_window); | 365 EXPECT_EQ(widget.GetNativeView(), active_window); |
364 } | 366 } |
365 | 367 |
| 368 TEST_F(NativeWidgetMusTest, WidgetReceivesEvent) { |
| 369 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); |
| 370 widget->Show(); |
| 371 |
| 372 View* content = new HandleMousePressView; |
| 373 content->SetBounds(10, 20, 90, 180); |
| 374 widget->GetContentsView()->AddChildView(content); |
| 375 |
| 376 ui::test::TestEventHandler handler; |
| 377 content->AddPreTargetHandler(&handler); |
| 378 |
| 379 std::unique_ptr<ui::MouseEvent> mouse = CreateMouseEvent(); |
| 380 NativeWidgetMus* native_widget = |
| 381 static_cast<NativeWidgetMus*>(widget->native_widget_private()); |
| 382 mus::WindowTreeClientImplPrivate test_api(native_widget->window()); |
| 383 test_api.CallOnWindowInputEvent(native_widget->window(), *mouse); |
| 384 EXPECT_EQ(1, handler.num_mouse_events()); |
| 385 } |
| 386 |
366 // Tests that an incoming UI event is acked with the handled status. | 387 // Tests that an incoming UI event is acked with the handled status. |
367 TEST_F(NativeWidgetMusTest, EventAcked) { | 388 TEST_F(NativeWidgetMusTest, EventAcked) { |
368 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); | 389 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); |
369 widget->Show(); | 390 widget->Show(); |
370 | 391 |
371 View* content = new HandleMousePressView; | 392 View* content = new HandleMousePressView; |
372 content->SetBounds(10, 20, 90, 180); | 393 content->SetBounds(10, 20, 90, 180); |
373 widget->GetContentsView()->AddChildView(content); | 394 widget->GetContentsView()->AddChildView(content); |
374 | 395 |
375 // Dispatch an input event to the window and view. | 396 // Dispatch an input event to the window and view. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 | 430 |
410 // The widget was deleted. | 431 // The widget was deleted. |
411 EXPECT_FALSE(widget.get()); | 432 EXPECT_FALSE(widget.get()); |
412 | 433 |
413 // The test took ownership of the callback and called it. | 434 // The test took ownership of the callback and called it. |
414 EXPECT_FALSE(ack_callback); | 435 EXPECT_FALSE(ack_callback); |
415 EXPECT_EQ(1, ack_callback_count()); | 436 EXPECT_EQ(1, ack_callback_count()); |
416 } | 437 } |
417 | 438 |
418 } // namespace views | 439 } // namespace views |
OLD | NEW |