OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/aura/mus/window_tree_client.h" | 5 #include "ui/aura/mus/window_tree_client.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "mojo/public/cpp/bindings/map.h" | 14 #include "mojo/public/cpp/bindings/map.h" |
15 #include "services/ui/public/cpp/property_type_converters.h" | 15 #include "services/ui/public/cpp/property_type_converters.h" |
16 #include "services/ui/public/interfaces/window_manager.mojom.h" | 16 #include "services/ui/public/interfaces/window_manager.mojom.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "ui/aura/client/aura_constants.h" | 18 #include "ui/aura/client/aura_constants.h" |
19 #include "ui/aura/client/capture_client.h" | 19 #include "ui/aura/client/capture_client.h" |
20 #include "ui/aura/client/capture_client_observer.h" | 20 #include "ui/aura/client/capture_client_observer.h" |
21 #include "ui/aura/client/default_capture_client.h" | 21 #include "ui/aura/client/default_capture_client.h" |
22 #include "ui/aura/client/focus_client.h" | 22 #include "ui/aura/client/focus_client.h" |
23 #include "ui/aura/client/transient_window_client.h" | 23 #include "ui/aura/client/transient_window_client.h" |
24 #include "ui/aura/mus/capture_synchronizer.h" | 24 #include "ui/aura/mus/capture_synchronizer.h" |
| 25 #include "ui/aura/mus/mus_types.h" |
25 #include "ui/aura/mus/property_converter.h" | 26 #include "ui/aura/mus/property_converter.h" |
26 #include "ui/aura/mus/window_mus.h" | 27 #include "ui/aura/mus/window_mus.h" |
27 #include "ui/aura/mus/window_tree_client_delegate.h" | 28 #include "ui/aura/mus/window_tree_client_delegate.h" |
28 #include "ui/aura/mus/window_tree_client_observer.h" | 29 #include "ui/aura/mus/window_tree_client_observer.h" |
29 #include "ui/aura/mus/window_tree_host_mus.h" | 30 #include "ui/aura/mus/window_tree_host_mus.h" |
30 #include "ui/aura/test/aura_mus_test_base.h" | 31 #include "ui/aura/test/aura_mus_test_base.h" |
31 #include "ui/aura/test/mus/test_window_tree.h" | 32 #include "ui/aura/test/mus/test_window_tree.h" |
32 #include "ui/aura/test/mus/window_tree_client_private.h" | 33 #include "ui/aura/test/mus/window_tree_client_private.h" |
33 #include "ui/aura/test/test_window_delegate.h" | 34 #include "ui/aura/test/test_window_delegate.h" |
34 #include "ui/aura/window.h" | 35 #include "ui/aura/window.h" |
35 #include "ui/aura/window_tracker.h" | 36 #include "ui/aura/window_tracker.h" |
36 #include "ui/aura/window_tree_host_observer.h" | 37 #include "ui/aura/window_tree_host_observer.h" |
37 #include "ui/base/class_property.h" | 38 #include "ui/base/class_property.h" |
38 #include "ui/compositor/compositor.h" | 39 #include "ui/compositor/compositor.h" |
39 #include "ui/display/display.h" | 40 #include "ui/display/display.h" |
40 #include "ui/display/display_switches.h" | 41 #include "ui/display/display_switches.h" |
41 #include "ui/display/screen.h" | 42 #include "ui/display/screen.h" |
42 #include "ui/events/event.h" | 43 #include "ui/events/event.h" |
43 #include "ui/events/event_utils.h" | 44 #include "ui/events/event_utils.h" |
| 45 #include "ui/events/test/test_event_handler.h" |
44 #include "ui/gfx/geometry/dip_util.h" | 46 #include "ui/gfx/geometry/dip_util.h" |
45 #include "ui/gfx/geometry/rect.h" | 47 #include "ui/gfx/geometry/rect.h" |
46 | 48 |
47 namespace aura { | 49 namespace aura { |
48 | 50 |
49 namespace { | 51 namespace { |
50 | 52 |
51 DEFINE_UI_CLASS_PROPERTY_KEY(uint8_t, kTestPropertyKey1, 0); | 53 DEFINE_UI_CLASS_PROPERTY_KEY(uint8_t, kTestPropertyKey1, 0); |
52 DEFINE_UI_CLASS_PROPERTY_KEY(uint16_t, kTestPropertyKey2, 0); | 54 DEFINE_UI_CLASS_PROPERTY_KEY(uint16_t, kTestPropertyKey2, 0); |
53 DEFINE_UI_CLASS_PROPERTY_KEY(bool, kTestPropertyKey3, false); | 55 DEFINE_UI_CLASS_PROPERTY_KEY(bool, kTestPropertyKey3, false); |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 | 516 |
515 private: | 517 private: |
516 TestWindowTree* test_window_tree_; | 518 TestWindowTree* test_window_tree_; |
517 bool was_acked_ = false; | 519 bool was_acked_ = false; |
518 bool got_move_ = false; | 520 bool got_move_ = false; |
519 gfx::Point last_event_location_; | 521 gfx::Point last_event_location_; |
520 | 522 |
521 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate); | 523 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate); |
522 }; | 524 }; |
523 | 525 |
| 526 class InputEventBasicTestEventHandler : public ui::test::TestEventHandler { |
| 527 public: |
| 528 static uint32_t constexpr kEventId = 1; |
| 529 |
| 530 explicit InputEventBasicTestEventHandler(TestWindowTree* test_window_tree) |
| 531 : test_window_tree_(test_window_tree) {} |
| 532 ~InputEventBasicTestEventHandler() override {} |
| 533 |
| 534 bool got_move() const { return got_move_; } |
| 535 bool was_acked() const { return was_acked_; } |
| 536 const gfx::Point& last_event_location() const { return last_event_location_; } |
| 537 |
| 538 // ui::test::TestEventHandler overrides. |
| 539 void OnMouseEvent(ui::MouseEvent* event) override { |
| 540 was_acked_ = test_window_tree_->WasEventAcked(kEventId); |
| 541 if (event->type() == ui::ET_MOUSE_MOVED) |
| 542 got_move_ = true; |
| 543 last_event_location_ = event->location(); |
| 544 event->SetHandled(); |
| 545 } |
| 546 |
| 547 private: |
| 548 TestWindowTree* test_window_tree_; |
| 549 bool was_acked_ = false; |
| 550 bool got_move_ = false; |
| 551 gfx::Point last_event_location_; |
| 552 |
| 553 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestEventHandler); |
| 554 }; |
| 555 |
524 } // namespace | 556 } // namespace |
525 | 557 |
526 TEST_F(WindowTreeClientClientTest, InputEventBasic) { | 558 TEST_F(WindowTreeClientClientTest, InputEventBasic) { |
527 InputEventBasicTestWindowDelegate window_delegate(window_tree()); | 559 InputEventBasicTestWindowDelegate window_delegate(window_tree()); |
528 WindowTreeHostMus window_tree_host(window_tree_client_impl()); | 560 WindowTreeHostMus window_tree_host(window_tree_client_impl()); |
529 Window* top_level = window_tree_host.window(); | 561 Window* top_level = window_tree_host.window(); |
530 const gfx::Rect bounds(0, 0, 100, 100); | 562 const gfx::Rect bounds(0, 0, 100, 100); |
531 window_tree_host.SetBoundsInPixels(bounds); | 563 window_tree_host.SetBoundsInPixels(bounds); |
532 window_tree_host.InitHost(); | 564 window_tree_host.InitHost(); |
533 window_tree_host.Show(); | 565 window_tree_host.Show(); |
(...skipping 16 matching lines...) Expand all Loading... |
550 EXPECT_TRUE(window_tree()->WasEventAcked( | 582 EXPECT_TRUE(window_tree()->WasEventAcked( |
551 InputEventBasicTestWindowDelegate::kEventId)); | 583 InputEventBasicTestWindowDelegate::kEventId)); |
552 EXPECT_EQ(ui::mojom::EventResult::HANDLED, | 584 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
553 window_tree()->GetEventResult( | 585 window_tree()->GetEventResult( |
554 InputEventBasicTestWindowDelegate::kEventId)); | 586 InputEventBasicTestWindowDelegate::kEventId)); |
555 EXPECT_TRUE(window_delegate.got_move()); | 587 EXPECT_TRUE(window_delegate.got_move()); |
556 EXPECT_FALSE(window_delegate.was_acked()); | 588 EXPECT_FALSE(window_delegate.was_acked()); |
557 EXPECT_EQ(event_location_in_child, window_delegate.last_event_location()); | 589 EXPECT_EQ(event_location_in_child, window_delegate.last_event_location()); |
558 } | 590 } |
559 | 591 |
| 592 TEST_F(WindowTreeClientClientTest, InputEventNoWindow) { |
| 593 WindowTreeHostMus window_tree_host(window_tree_client_impl()); |
| 594 Window* top_level = window_tree_host.window(); |
| 595 InputEventBasicTestEventHandler event_handler(window_tree()); |
| 596 top_level->AddPreTargetHandler(&event_handler); |
| 597 const gfx::Rect bounds(0, 0, 100, 100); |
| 598 window_tree_host.SetBoundsInPixels(bounds); |
| 599 window_tree_host.InitHost(); |
| 600 window_tree_host.Show(); |
| 601 EXPECT_EQ(bounds, top_level->bounds()); |
| 602 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels()); |
| 603 InputEventBasicTestWindowDelegate window_delegate(window_tree()); |
| 604 Window child(&window_delegate); |
| 605 child.Init(ui::LAYER_NOT_DRAWN); |
| 606 top_level->AddChild(&child); |
| 607 child.SetBounds(gfx::Rect(10, 10, 100, 100)); |
| 608 child.Show(); |
| 609 EXPECT_FALSE(event_handler.got_move()); |
| 610 EXPECT_FALSE(event_handler.was_acked()); |
| 611 EXPECT_FALSE(window_delegate.got_move()); |
| 612 EXPECT_FALSE(window_delegate.was_acked()); |
| 613 const gfx::Point event_location_in_child(20, 30); |
| 614 std::unique_ptr<ui::Event> ui_event(new ui::MouseEvent( |
| 615 ui::ET_MOUSE_MOVED, event_location_in_child, gfx::Point(2, 3), |
| 616 ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| 617 window_tree_client()->OnWindowInputEvent( |
| 618 InputEventBasicTestWindowDelegate::kEventId, kInvalidServerId, |
| 619 window_tree_host.display_id(), ui::Event::Clone(*ui_event.get()), 0); |
| 620 // WindowTreeClient::OnWindowInputEvent cannot find a target window with |
| 621 // kInvalidServerId but should use the display_id to find the window_tree_host |
| 622 // for event dispatching and dispatch the event to |top_level|. |
| 623 EXPECT_TRUE(window_tree()->WasEventAcked( |
| 624 InputEventBasicTestWindowDelegate::kEventId)); |
| 625 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| 626 window_tree()->GetEventResult( |
| 627 InputEventBasicTestWindowDelegate::kEventId)); |
| 628 EXPECT_TRUE(event_handler.got_move()); |
| 629 EXPECT_FALSE(event_handler.was_acked()); |
| 630 EXPECT_EQ(gfx::Point(2, 3), event_handler.last_event_location()); |
| 631 EXPECT_FALSE(window_delegate.got_move()); |
| 632 EXPECT_FALSE(window_delegate.was_acked()); |
| 633 EXPECT_EQ(gfx::Point(), window_delegate.last_event_location()); |
| 634 } |
| 635 |
560 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest { | 636 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest { |
561 public: | 637 public: |
562 WindowTreeClientPointerObserverTest() {} | 638 WindowTreeClientPointerObserverTest() {} |
563 ~WindowTreeClientPointerObserverTest() override {} | 639 ~WindowTreeClientPointerObserverTest() override {} |
564 | 640 |
565 void DeleteLastEventObserved() { last_event_observed_.reset(); } | 641 void DeleteLastEventObserved() { last_event_observed_.reset(); } |
566 const ui::PointerEvent* last_event_observed() const { | 642 const ui::PointerEvent* last_event_observed() const { |
567 return last_event_observed_.get(); | 643 return last_event_observed_.get(); |
568 } | 644 } |
569 | 645 |
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1616 // Delegate received the event in Dips. | 1692 // Delegate received the event in Dips. |
1617 const ui::PointerEvent* last_event = last_event_observed(); | 1693 const ui::PointerEvent* last_event = last_event_observed(); |
1618 ASSERT_TRUE(last_event); | 1694 ASSERT_TRUE(last_event); |
1619 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, location_pixels), | 1695 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, location_pixels), |
1620 last_event->location()); | 1696 last_event->location()); |
1621 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, root_location_pixels), | 1697 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, root_location_pixels), |
1622 last_event->root_location()); | 1698 last_event->root_location()); |
1623 } | 1699 } |
1624 | 1700 |
1625 } // namespace aura | 1701 } // namespace aura |
OLD | NEW |