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

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: comments 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) {
sky 2017/02/15 20:47:17 Please add coverage of a case with a scale factor
riajiang 2017/02/16 00:34:08 Done.
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 // Remove the targeter for child1 and specify the event to go to child1. This
621 // time child1 should receive the event not child2.
622 child1.SetEventTargeter(nullptr);
623 event_id = 2;
624 window_delegate1.set_event_id(event_id);
625 window_delegate2.set_event_id(event_id);
626 std::unique_ptr<ui::Event> ui_event1(
627 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location, gfx::Point(),
628 ui::EventTimeForNow(), ui::EF_NONE, 0));
629 window_tree_client()->OnWindowInputEvent(
630 event_id, server_id(&child1), window_tree_host.display_id(),
631 ui::Event::Clone(*ui_event1.get()), 0);
632 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
633 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
634 window_tree()->GetEventResult(event_id));
635 EXPECT_TRUE(window_delegate1.got_move());
636 EXPECT_FALSE(window_delegate1.was_acked());
637 EXPECT_FALSE(window_delegate2.got_move());
638 EXPECT_FALSE(window_delegate2.was_acked());
639 EXPECT_EQ(gfx::Point(50, 60), window_delegate1.last_event_location());
640 }
641
642 TEST_F(WindowTreeClientClientTest, InputEventCustomWindowTargeter) {
643 WindowTreeHostMus window_tree_host(window_tree_client_impl());
644 Window* top_level = window_tree_host.window();
645 const gfx::Rect bounds(0, 0, 100, 100);
646 window_tree_host.SetBoundsInPixels(bounds);
647 window_tree_host.InitHost();
648 window_tree_host.Show();
649 EXPECT_EQ(bounds, top_level->bounds());
650 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels());
651 InputEventBasicTestWindowDelegate window_delegate1(window_tree());
652 Window child1(&window_delegate1);
653 child1.Init(ui::LAYER_NOT_DRAWN);
654 child1.SetEventTargeter(base::MakeUnique<test::TestWindowTargeter>());
655 top_level->AddChild(&child1);
656 child1.SetBounds(gfx::Rect(10, 10, 100, 100));
657 child1.Show();
658 InputEventBasicTestWindowDelegate window_delegate2(window_tree());
659 Window child2(&window_delegate2);
660 child2.Init(ui::LAYER_NOT_DRAWN);
661 child1.AddChild(&child2);
662 child2.SetBounds(gfx::Rect(20, 30, 100, 100));
663 child2.Show();
664
665 EXPECT_FALSE(window_delegate1.got_move());
666 EXPECT_FALSE(window_delegate1.was_acked());
667 EXPECT_FALSE(window_delegate2.got_move());
668 EXPECT_FALSE(window_delegate2.was_acked());
669
670 // child1 has a custom targeter set which would always return itself as the
671 // target window therefore event should go to child1 unlike
672 // WindowTreeClientClientTest.InputEventFindTargetAndConversion.
673 const gfx::Point event_location(50, 60);
674 uint32_t event_id = 1;
675 window_delegate1.set_event_id(event_id);
676 window_delegate2.set_event_id(event_id);
677 std::unique_ptr<ui::Event> ui_event(
678 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location, gfx::Point(),
679 ui::EventTimeForNow(), ui::EF_NONE, 0));
680 window_tree_client()->OnWindowInputEvent(
681 event_id, server_id(&child1), window_tree_host.display_id(),
682 ui::Event::Clone(*ui_event.get()), 0);
683 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
684 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
685 window_tree()->GetEventResult(event_id));
686 EXPECT_TRUE(window_delegate1.got_move());
687 EXPECT_FALSE(window_delegate1.was_acked());
688 EXPECT_FALSE(window_delegate2.got_move());
689 EXPECT_FALSE(window_delegate2.was_acked());
690 EXPECT_EQ(gfx::Point(50, 60), window_delegate1.last_event_location());
691 window_delegate1.reset();
692 window_delegate2.reset();
693
694 // child1 should get the event even though mus-ws specifies child2 and it's
695 // actually in child2's space. Event location will be transformed.
696 const gfx::Point event_location1(50, 60);
697 event_id = 2;
698 window_delegate1.set_event_id(event_id);
699 window_delegate2.set_event_id(event_id);
700 std::unique_ptr<ui::Event> ui_event1(
701 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location1, gfx::Point(),
702 ui::EventTimeForNow(), ui::EF_NONE, 0));
703 window_tree_client()->OnWindowInputEvent(
704 event_id, server_id(&child2), window_tree_host.display_id(),
705 ui::Event::Clone(*ui_event1.get()), 0);
706 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
707 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
708 window_tree()->GetEventResult(event_id));
709 EXPECT_TRUE(window_delegate1.got_move());
710 EXPECT_FALSE(window_delegate1.was_acked());
711 EXPECT_FALSE(window_delegate2.got_move());
712 EXPECT_FALSE(window_delegate2.was_acked());
713 EXPECT_EQ(gfx::Point(70, 90), window_delegate1.last_event_location());
714 }
715
560 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest { 716 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest {
561 public: 717 public:
562 WindowTreeClientPointerObserverTest() {} 718 WindowTreeClientPointerObserverTest() {}
563 ~WindowTreeClientPointerObserverTest() override {} 719 ~WindowTreeClientPointerObserverTest() override {}
564 720
565 void DeleteLastEventObserved() { last_event_observed_.reset(); } 721 void DeleteLastEventObserved() { last_event_observed_.reset(); }
566 const ui::PointerEvent* last_event_observed() const { 722 const ui::PointerEvent* last_event_observed() const {
567 return last_event_observed_.get(); 723 return last_event_observed_.get();
568 } 724 }
569 725
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 // Delegate received the event in Dips. 1772 // Delegate received the event in Dips.
1617 const ui::PointerEvent* last_event = last_event_observed(); 1773 const ui::PointerEvent* last_event = last_event_observed();
1618 ASSERT_TRUE(last_event); 1774 ASSERT_TRUE(last_event);
1619 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, location_pixels), 1775 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, location_pixels),
1620 last_event->location()); 1776 last_event->location());
1621 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, root_location_pixels), 1777 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, root_location_pixels),
1622 last_event->root_location()); 1778 last_event->root_location());
1623 } 1779 }
1624 1780
1625 } // namespace aura 1781 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698