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

Side by Side Diff: ui/aura/mus/window_tree_client_unittest.cc

Issue 2681613002: Avoid two targeting phases in aura client-lib and EventProcessor. (Closed)
Patch Set: nits and tests Created 3 years, 10 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
OLDNEW
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"
(...skipping 13 matching lines...) Expand all
24 #include "ui/aura/mus/capture_synchronizer.h" 24 #include "ui/aura/mus/capture_synchronizer.h"
25 #include "ui/aura/mus/property_converter.h" 25 #include "ui/aura/mus/property_converter.h"
26 #include "ui/aura/mus/window_mus.h" 26 #include "ui/aura/mus/window_mus.h"
27 #include "ui/aura/mus/window_tree_client_delegate.h" 27 #include "ui/aura/mus/window_tree_client_delegate.h"
28 #include "ui/aura/mus/window_tree_client_observer.h" 28 #include "ui/aura/mus/window_tree_client_observer.h"
29 #include "ui/aura/mus/window_tree_host_mus.h" 29 #include "ui/aura/mus/window_tree_host_mus.h"
30 #include "ui/aura/test/aura_mus_test_base.h" 30 #include "ui/aura/test/aura_mus_test_base.h"
31 #include "ui/aura/test/mus/test_window_tree.h" 31 #include "ui/aura/test/mus/test_window_tree.h"
32 #include "ui/aura/test/mus/window_tree_client_private.h" 32 #include "ui/aura/test/mus/window_tree_client_private.h"
33 #include "ui/aura/test/test_window_delegate.h" 33 #include "ui/aura/test/test_window_delegate.h"
34 #include "ui/aura/test/test_window_targeter.h"
34 #include "ui/aura/window.h" 35 #include "ui/aura/window.h"
36 #include "ui/aura/window_targeter.h"
35 #include "ui/aura/window_tracker.h" 37 #include "ui/aura/window_tracker.h"
36 #include "ui/aura/window_tree_host_observer.h" 38 #include "ui/aura/window_tree_host_observer.h"
37 #include "ui/base/class_property.h" 39 #include "ui/base/class_property.h"
38 #include "ui/compositor/compositor.h" 40 #include "ui/compositor/compositor.h"
39 #include "ui/display/display.h" 41 #include "ui/display/display.h"
40 #include "ui/display/display_switches.h" 42 #include "ui/display/display_switches.h"
41 #include "ui/display/screen.h" 43 #include "ui/display/screen.h"
42 #include "ui/events/event.h" 44 #include "ui/events/event.h"
43 #include "ui/events/event_utils.h" 45 #include "ui/events/event_utils.h"
44 #include "ui/gfx/geometry/dip_util.h" 46 #include "ui/gfx/geometry/dip_util.h"
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 // Simulate server changing back to original visible. Should take immediately. 488 // Simulate server changing back to original visible. Should take immediately.
487 window_tree_client()->OnWindowVisibilityChanged(server_id(root_window()), 489 window_tree_client()->OnWindowVisibilityChanged(server_id(root_window()),
488 original_visible); 490 original_visible);
489 EXPECT_EQ(original_visible, root_window()->TargetVisibility()); 491 EXPECT_EQ(original_visible, root_window()->TargetVisibility());
490 } 492 }
491 493
492 namespace { 494 namespace {
493 495
494 class InputEventBasicTestWindowDelegate : public test::TestWindowDelegate { 496 class InputEventBasicTestWindowDelegate : public test::TestWindowDelegate {
495 public: 497 public:
496 static uint32_t constexpr kEventId = 1;
497
498 explicit InputEventBasicTestWindowDelegate(TestWindowTree* test_window_tree) 498 explicit InputEventBasicTestWindowDelegate(TestWindowTree* test_window_tree)
499 : test_window_tree_(test_window_tree) {} 499 : test_window_tree_(test_window_tree) {}
500 ~InputEventBasicTestWindowDelegate() override {} 500 ~InputEventBasicTestWindowDelegate() override {}
501 501
502 bool got_move() const { return got_move_; } 502 bool got_move() const { return got_move_; }
503 bool was_acked() const { return was_acked_; } 503 bool was_acked() const { return was_acked_; }
504 const gfx::Point& last_event_location() const { return last_event_location_; } 504 const gfx::Point& last_event_location() const { return last_event_location_; }
505 void set_event_id(uint32_t event_id) { event_id_ = event_id; }
505 506
506 // TestWindowDelegate:: 507 // TestWindowDelegate::
507 void OnMouseEvent(ui::MouseEvent* event) override { 508 void OnMouseEvent(ui::MouseEvent* event) override {
508 was_acked_ = test_window_tree_->WasEventAcked(kEventId); 509 was_acked_ = test_window_tree_->WasEventAcked(event_id_);
509 if (event->type() == ui::ET_MOUSE_MOVED) 510 if (event->type() == ui::ET_MOUSE_MOVED)
510 got_move_ = true; 511 got_move_ = true;
511 last_event_location_ = event->location(); 512 last_event_location_ = event->location();
512 event->SetHandled(); 513 event->SetHandled();
513 } 514 }
514 515
516 void reset() {
517 was_acked_ = false;
518 got_move_ = false;
519 last_event_location_ = gfx::Point();
520 event_id_ = 0;
521 }
522
515 private: 523 private:
516 TestWindowTree* test_window_tree_; 524 TestWindowTree* test_window_tree_;
517 bool was_acked_ = false; 525 bool was_acked_ = false;
518 bool got_move_ = false; 526 bool got_move_ = false;
519 gfx::Point last_event_location_; 527 gfx::Point last_event_location_;
528 uint32_t event_id_ = 0;
520 529
521 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate); 530 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate);
522 }; 531 };
523 532
524 } // namespace 533 } // namespace
525 534
526 TEST_F(WindowTreeClientClientTest, InputEventBasic) { 535 TEST_F(WindowTreeClientClientTest, InputEventBasic) {
527 InputEventBasicTestWindowDelegate window_delegate(window_tree()); 536 InputEventBasicTestWindowDelegate window_delegate(window_tree());
528 WindowTreeHostMus window_tree_host(window_tree_client_impl()); 537 WindowTreeHostMus window_tree_host(window_tree_client_impl());
529 Window* top_level = window_tree_host.window(); 538 Window* top_level = window_tree_host.window();
530 const gfx::Rect bounds(0, 0, 100, 100); 539 const gfx::Rect bounds(0, 0, 100, 100);
531 window_tree_host.SetBoundsInPixels(bounds); 540 window_tree_host.SetBoundsInPixels(bounds);
532 window_tree_host.InitHost(); 541 window_tree_host.InitHost();
533 window_tree_host.Show(); 542 window_tree_host.Show();
534 EXPECT_EQ(bounds, top_level->bounds()); 543 EXPECT_EQ(bounds, top_level->bounds());
535 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels()); 544 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels());
536 Window child(&window_delegate); 545 Window child(&window_delegate);
537 child.Init(ui::LAYER_NOT_DRAWN); 546 child.Init(ui::LAYER_NOT_DRAWN);
538 top_level->AddChild(&child); 547 top_level->AddChild(&child);
539 child.SetBounds(gfx::Rect(10, 10, 100, 100)); 548 child.SetBounds(gfx::Rect(10, 10, 100, 100));
540 child.Show(); 549 child.Show();
541 EXPECT_FALSE(window_delegate.got_move()); 550 EXPECT_FALSE(window_delegate.got_move());
542 EXPECT_FALSE(window_delegate.was_acked()); 551 EXPECT_FALSE(window_delegate.was_acked());
543 const gfx::Point event_location_in_child(2, 3); 552 const gfx::Point event_location_in_child(2, 3);
553 const uint32_t event_id = 1;
554 window_delegate.set_event_id(event_id);
544 std::unique_ptr<ui::Event> ui_event( 555 std::unique_ptr<ui::Event> ui_event(
545 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location_in_child, 556 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location_in_child,
546 gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, 0)); 557 gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, 0));
547 window_tree_client()->OnWindowInputEvent( 558 window_tree_client()->OnWindowInputEvent(
548 InputEventBasicTestWindowDelegate::kEventId, server_id(&child), 559 event_id, server_id(&child), window_tree_host.display_id(),
549 window_tree_host.display_id(), ui::Event::Clone(*ui_event.get()), 0); 560 ui::Event::Clone(*ui_event.get()), 0);
550 EXPECT_TRUE(window_tree()->WasEventAcked( 561 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
551 InputEventBasicTestWindowDelegate::kEventId));
552 EXPECT_EQ(ui::mojom::EventResult::HANDLED, 562 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
553 window_tree()->GetEventResult( 563 window_tree()->GetEventResult(event_id));
554 InputEventBasicTestWindowDelegate::kEventId));
555 EXPECT_TRUE(window_delegate.got_move()); 564 EXPECT_TRUE(window_delegate.got_move());
556 EXPECT_FALSE(window_delegate.was_acked()); 565 EXPECT_FALSE(window_delegate.was_acked());
557 EXPECT_EQ(event_location_in_child, window_delegate.last_event_location()); 566 EXPECT_EQ(event_location_in_child, window_delegate.last_event_location());
558 } 567 }
559 568
569 TEST_F(WindowTreeClientClientTest, InputEventFindTargetAndConversion) {
570 WindowTreeHostMus window_tree_host(window_tree_client_impl());
571 Window* top_level = window_tree_host.window();
572 const gfx::Rect bounds(0, 0, 100, 100);
573 window_tree_host.SetBoundsInPixels(bounds);
574 window_tree_host.InitHost();
575 window_tree_host.Show();
576 EXPECT_EQ(bounds, top_level->bounds());
577 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels());
578 InputEventBasicTestWindowDelegate window_delegate1(window_tree());
579 Window child1(&window_delegate1);
580 child1.Init(ui::LAYER_NOT_DRAWN);
581 child1.SetEventTargeter(base::MakeUnique<WindowTargeter>());
582 top_level->AddChild(&child1);
583 child1.SetBounds(gfx::Rect(10, 10, 100, 100));
584 child1.Show();
585 InputEventBasicTestWindowDelegate window_delegate2(window_tree());
586 Window child2(&window_delegate2);
587 child2.Init(ui::LAYER_NOT_DRAWN);
588 child1.AddChild(&child2);
589 child2.SetBounds(gfx::Rect(20, 30, 100, 100));
590 child2.Show();
591
592 EXPECT_FALSE(window_delegate1.got_move());
593 EXPECT_FALSE(window_delegate1.was_acked());
594 EXPECT_FALSE(window_delegate2.got_move());
595 EXPECT_FALSE(window_delegate2.was_acked());
596
597 // child1 has a targeter set and event_location is (50, 60), child2
598 // should get the event even though mus-ws wants to send to child1.
599 const gfx::Point event_location(50, 60);
600 uint32_t event_id = 1;
601 window_delegate1.set_event_id(event_id);
602 window_delegate2.set_event_id(event_id);
603 std::unique_ptr<ui::Event> ui_event(
604 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location, gfx::Point(),
605 ui::EventTimeForNow(), ui::EF_NONE, 0));
606 window_tree_client()->OnWindowInputEvent(
607 event_id, server_id(&child1), window_tree_host.display_id(),
608 ui::Event::Clone(*ui_event.get()), 0);
609 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
610 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
611 window_tree()->GetEventResult(event_id));
612 EXPECT_FALSE(window_delegate1.got_move());
613 EXPECT_FALSE(window_delegate1.was_acked());
614 EXPECT_TRUE(window_delegate2.got_move());
615 EXPECT_FALSE(window_delegate2.was_acked());
616 EXPECT_EQ(gfx::Point(30, 30), window_delegate2.last_event_location());
617 window_delegate1.reset();
618 window_delegate2.reset();
619
620 // Keep the event location in child2's space. Remove the targeter for
621 // child1 and specify the event to go to child1. However, since there's
622 // no targeter set for the root target returned by
623 // EventProcessor::GetRootForEvent, we fall back to use default targeter
624 // which will send the event to child2.
sadrul 2017/02/14 21:40:10 Because mus-ws sends the event to client1, and non
riajiang 2017/02/15 18:09:27 Changed the logic in EventProcessor and updated th
625 child1.SetEventTargeter(nullptr);
626 const gfx::Point event_location1(45, 50);
627 event_id = 2;
628 window_delegate1.set_event_id(event_id);
629 window_delegate2.set_event_id(event_id);
630 std::unique_ptr<ui::Event> ui_event1(
631 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location1, gfx::Point(),
632 ui::EventTimeForNow(), ui::EF_NONE, 0));
633 window_tree_client()->OnWindowInputEvent(
634 event_id, server_id(&child1), window_tree_host.display_id(),
635 ui::Event::Clone(*ui_event1.get()), 0);
636 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
637 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
638 window_tree()->GetEventResult(event_id));
639 EXPECT_FALSE(window_delegate1.got_move());
640 EXPECT_FALSE(window_delegate1.was_acked());
641 EXPECT_TRUE(window_delegate2.got_move());
642 EXPECT_FALSE(window_delegate2.was_acked());
643 EXPECT_EQ(gfx::Point(25, 20), window_delegate2.last_event_location());
644 window_delegate1.reset();
645 window_delegate2.reset();
646
647 // Change the location to be in child1's space and child1 should get the
648 // event this time.
649 const gfx::Point event_location2(10, 15);
650 event_id = 3;
651 window_delegate1.set_event_id(event_id);
652 window_delegate2.set_event_id(event_id);
653 std::unique_ptr<ui::Event> ui_event2(
654 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location2, gfx::Point(),
655 ui::EventTimeForNow(), ui::EF_NONE, 0));
656 window_tree_client()->OnWindowInputEvent(
657 event_id, server_id(&child1), window_tree_host.display_id(),
658 ui::Event::Clone(*ui_event2.get()), 0);
659 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
660 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
661 window_tree()->GetEventResult(event_id));
662 EXPECT_TRUE(window_delegate1.got_move());
663 EXPECT_FALSE(window_delegate1.was_acked());
664 EXPECT_FALSE(window_delegate2.got_move());
665 EXPECT_FALSE(window_delegate2.was_acked());
666 EXPECT_EQ(gfx::Point(10, 15), window_delegate1.last_event_location());
667 }
668
669 TEST_F(WindowTreeClientClientTest, InputEventCustomWindowTargeter) {
670 WindowTreeHostMus window_tree_host(window_tree_client_impl());
671 Window* top_level = window_tree_host.window();
672 const gfx::Rect bounds(0, 0, 100, 100);
673 window_tree_host.SetBoundsInPixels(bounds);
674 window_tree_host.InitHost();
675 window_tree_host.Show();
676 EXPECT_EQ(bounds, top_level->bounds());
677 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels());
678 InputEventBasicTestWindowDelegate window_delegate1(window_tree());
679 Window child1(&window_delegate1);
680 child1.Init(ui::LAYER_NOT_DRAWN);
681 child1.SetEventTargeter(base::MakeUnique<test::TestWindowTargeter>());
682 top_level->AddChild(&child1);
683 child1.SetBounds(gfx::Rect(10, 10, 100, 100));
684 child1.Show();
685 InputEventBasicTestWindowDelegate window_delegate2(window_tree());
686 Window child2(&window_delegate2);
687 child2.Init(ui::LAYER_NOT_DRAWN);
688 child1.AddChild(&child2);
689 child2.SetBounds(gfx::Rect(20, 30, 100, 100));
690 child2.Show();
691
692 EXPECT_FALSE(window_delegate1.got_move());
693 EXPECT_FALSE(window_delegate1.was_acked());
694 EXPECT_FALSE(window_delegate2.got_move());
695 EXPECT_FALSE(window_delegate2.was_acked());
696
697 // child1 has a custom targeter set which would always return itself as the
698 // target window therefore event should go to child1 unlike
699 // WindowTreeClientClientTest.InputEventFindTargetAndConversion.
700 const gfx::Point event_location(50, 60);
701 uint32_t event_id = 1;
702 window_delegate1.set_event_id(event_id);
703 window_delegate2.set_event_id(event_id);
704 std::unique_ptr<ui::Event> ui_event(
705 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location, gfx::Point(),
706 ui::EventTimeForNow(), ui::EF_NONE, 0));
707 window_tree_client()->OnWindowInputEvent(
708 event_id, server_id(&child1), window_tree_host.display_id(),
709 ui::Event::Clone(*ui_event.get()), 0);
710 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
711 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
712 window_tree()->GetEventResult(event_id));
713 EXPECT_TRUE(window_delegate1.got_move());
714 EXPECT_FALSE(window_delegate1.was_acked());
715 EXPECT_FALSE(window_delegate2.got_move());
716 EXPECT_FALSE(window_delegate2.was_acked());
717 EXPECT_EQ(gfx::Point(50, 60), window_delegate1.last_event_location());
718 window_delegate1.reset();
719 window_delegate2.reset();
720
721 // child1 should get the event even though mus-ws specifies child2 and it's
722 // actually in child2's space. Event location will be transformed.
723 const gfx::Point event_location1(50, 60);
724 event_id = 2;
725 window_delegate1.set_event_id(event_id);
726 window_delegate2.set_event_id(event_id);
727 std::unique_ptr<ui::Event> ui_event1(
728 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location1, gfx::Point(),
729 ui::EventTimeForNow(), ui::EF_NONE, 0));
730 window_tree_client()->OnWindowInputEvent(
731 event_id, server_id(&child2), window_tree_host.display_id(),
732 ui::Event::Clone(*ui_event1.get()), 0);
733 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
734 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
735 window_tree()->GetEventResult(event_id));
736 EXPECT_TRUE(window_delegate1.got_move());
737 EXPECT_FALSE(window_delegate1.was_acked());
738 EXPECT_FALSE(window_delegate2.got_move());
739 EXPECT_FALSE(window_delegate2.was_acked());
740 EXPECT_EQ(gfx::Point(70, 90), window_delegate1.last_event_location());
741 }
742
560 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest { 743 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest {
561 public: 744 public:
562 WindowTreeClientPointerObserverTest() {} 745 WindowTreeClientPointerObserverTest() {}
563 ~WindowTreeClientPointerObserverTest() override {} 746 ~WindowTreeClientPointerObserverTest() override {}
564 747
565 void DeleteLastEventObserved() { last_event_observed_.reset(); } 748 void DeleteLastEventObserved() { last_event_observed_.reset(); }
566 const ui::PointerEvent* last_event_observed() const { 749 const ui::PointerEvent* last_event_observed() const {
567 return last_event_observed_.get(); 750 return last_event_observed_.get();
568 } 751 }
569 752
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 // Delegate received the event in Dips. 1799 // Delegate received the event in Dips.
1617 const ui::PointerEvent* last_event = last_event_observed(); 1800 const ui::PointerEvent* last_event = last_event_observed();
1618 ASSERT_TRUE(last_event); 1801 ASSERT_TRUE(last_event);
1619 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, location_pixels), 1802 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, location_pixels),
1620 last_event->location()); 1803 last_event->location());
1621 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, root_location_pixels), 1804 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, root_location_pixels),
1622 last_event->root_location()); 1805 last_event->root_location());
1623 } 1806 }
1624 1807
1625 } // namespace aura 1808 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698