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

Side by Side Diff: ui/aura/root_window_unittest.cc

Issue 135483002: aura: Fix a couple of issues related to held touch events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « ui/aura/root_window.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/root_window.h" 5 #include "ui/aura/root_window.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 dispatcher()->AsWindowTreeHostDelegate()->OnHostScrollEvent(&scroll2); 420 dispatcher()->AsWindowTreeHostDelegate()->OnHostScrollEvent(&scroll2);
421 EXPECT_EQ(2, filter->num_scroll_events()); 421 EXPECT_EQ(2, filter->num_scroll_events());
422 } 422 }
423 423
424 namespace { 424 namespace {
425 425
426 // FilterFilter that tracks the types of events it's seen. 426 // FilterFilter that tracks the types of events it's seen.
427 class EventFilterRecorder : public ui::EventHandler { 427 class EventFilterRecorder : public ui::EventHandler {
428 public: 428 public:
429 typedef std::vector<ui::EventType> Events; 429 typedef std::vector<ui::EventType> Events;
430 typedef std::vector<gfx::Point> MouseEventLocations; 430 typedef std::vector<gfx::Point> EventLocations;
431 431
432 EventFilterRecorder() {} 432 EventFilterRecorder() {}
433 433
434 Events& events() { return events_; } 434 const Events& events() const { return events_; }
435 435
436 MouseEventLocations& mouse_locations() { return mouse_locations_; } 436 const EventLocations& mouse_locations() const { return mouse_locations_; }
437 gfx::Point mouse_location(int i) const { return mouse_locations_[i]; } 437 gfx::Point mouse_location(int i) const { return mouse_locations_[i]; }
438 const EventLocations& touch_locations() const { return touch_locations_; }
438 439
439 Events GetAndResetEvents() { 440 Events GetAndResetEvents() {
440 Events events = events_; 441 Events events = events_;
441 events_.clear(); 442 Reset();
442 return events; 443 return events;
443 } 444 }
444 445
446 void Reset() {
447 events_.clear();
448 mouse_locations_.clear();
449 touch_locations_.clear();
450 }
451
445 // ui::EventHandler overrides: 452 // ui::EventHandler overrides:
446 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE { 453 virtual void OnEvent(ui::Event* event) OVERRIDE {
454 ui::EventHandler::OnEvent(event);
447 events_.push_back(event->type()); 455 events_.push_back(event->type());
448 } 456 }
449 457
450 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { 458 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
451 events_.push_back(event->type());
452 mouse_locations_.push_back(event->location()); 459 mouse_locations_.push_back(event->location());
453 } 460 }
454 461
455 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE {
456 events_.push_back(event->type());
457 }
458
459 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { 462 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
460 events_.push_back(event->type()); 463 touch_locations_.push_back(event->location());
461 }
462
463 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
464 events_.push_back(event->type());
465 } 464 }
466 465
467 private: 466 private:
468 Events events_; 467 Events events_;
469 MouseEventLocations mouse_locations_; 468 EventLocations mouse_locations_;
469 EventLocations touch_locations_;
470 470
471 DISALLOW_COPY_AND_ASSIGN(EventFilterRecorder); 471 DISALLOW_COPY_AND_ASSIGN(EventFilterRecorder);
472 }; 472 };
473 473
474 // Converts an EventType to a string. 474 // Converts an EventType to a string.
475 std::string EventTypeToString(ui::EventType type) { 475 std::string EventTypeToString(ui::EventType type) {
476 switch (type) { 476 switch (type) {
477 case ui::ET_TOUCH_RELEASED: 477 case ui::ET_TOUCH_RELEASED:
478 return "TOUCH_RELEASED"; 478 return "TOUCH_RELEASED";
479 479
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 588
589 test::TestWindowDelegate delegate; 589 test::TestWindowDelegate delegate;
590 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 590 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
591 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); 591 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window()));
592 592
593 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), 593 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0),
594 gfx::Point(0, 0), 0, 0); 594 gfx::Point(0, 0), 0, 0);
595 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 595 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(
596 &mouse_move_event); 596 &mouse_move_event);
597 // Discard MOUSE_ENTER. 597 // Discard MOUSE_ENTER.
598 filter->events().clear(); 598 filter->Reset();
599 599
600 dispatcher()->HoldPointerMoves(); 600 dispatcher()->HoldPointerMoves();
601 601
602 // Check that we don't immediately dispatch the MOUSE_DRAGGED event. 602 // Check that we don't immediately dispatch the MOUSE_DRAGGED event.
603 ui::MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), 603 ui::MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0),
604 gfx::Point(0, 0), 0, 0); 604 gfx::Point(0, 0), 0, 0);
605 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 605 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(
606 &mouse_dragged_event); 606 &mouse_dragged_event);
607 EXPECT_TRUE(filter->events().empty()); 607 EXPECT_TRUE(filter->events().empty());
608 608
609 // Check that we do dispatch the held MOUSE_DRAGGED event before another type 609 // Check that we do dispatch the held MOUSE_DRAGGED event before another type
610 // of event. 610 // of event.
611 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), 611 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0),
612 gfx::Point(0, 0), 0, 0); 612 gfx::Point(0, 0), 0, 0);
613 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 613 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(
614 &mouse_pressed_event); 614 &mouse_pressed_event);
615 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", 615 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED",
616 EventTypesToString(filter->events())); 616 EventTypesToString(filter->events()));
617 filter->events().clear(); 617 filter->Reset();
618 618
619 // Check that we coalesce held MOUSE_DRAGGED events. 619 // Check that we coalesce held MOUSE_DRAGGED events.
620 ui::MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(1, 1), 620 ui::MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(1, 1),
621 gfx::Point(1, 1), 0, 0); 621 gfx::Point(1, 1), 0, 0);
622 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 622 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(
623 &mouse_dragged_event); 623 &mouse_dragged_event);
624 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 624 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(
625 &mouse_dragged_event2); 625 &mouse_dragged_event2);
626 EXPECT_TRUE(filter->events().empty()); 626 EXPECT_TRUE(filter->events().empty());
627 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 627 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(
628 &mouse_pressed_event); 628 &mouse_pressed_event);
629 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", 629 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED",
630 EventTypesToString(filter->events())); 630 EventTypesToString(filter->events()));
631 filter->events().clear(); 631 filter->Reset();
632 632
633 // Check that on ReleasePointerMoves, held events are not dispatched 633 // Check that on ReleasePointerMoves, held events are not dispatched
634 // immediately, but posted instead. 634 // immediately, but posted instead.
635 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 635 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(
636 &mouse_dragged_event); 636 &mouse_dragged_event);
637 dispatcher()->ReleasePointerMoves(); 637 dispatcher()->ReleasePointerMoves();
638 EXPECT_TRUE(filter->events().empty()); 638 EXPECT_TRUE(filter->events().empty());
639 RunAllPendingInMessageLoop(); 639 RunAllPendingInMessageLoop();
640 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events())); 640 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events()));
641 filter->events().clear(); 641 filter->Reset();
642 642
643 // However if another message comes in before the dispatch of the posted 643 // However if another message comes in before the dispatch of the posted
644 // event, check that the posted event is dispatched before this new event. 644 // event, check that the posted event is dispatched before this new event.
645 dispatcher()->HoldPointerMoves(); 645 dispatcher()->HoldPointerMoves();
646 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 646 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(
647 &mouse_dragged_event); 647 &mouse_dragged_event);
648 dispatcher()->ReleasePointerMoves(); 648 dispatcher()->ReleasePointerMoves();
649 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 649 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(
650 &mouse_pressed_event); 650 &mouse_pressed_event);
651 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", 651 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED",
652 EventTypesToString(filter->events())); 652 EventTypesToString(filter->events()));
653 filter->events().clear(); 653 filter->Reset();
654 RunAllPendingInMessageLoop(); 654 RunAllPendingInMessageLoop();
655 EXPECT_TRUE(filter->events().empty()); 655 EXPECT_TRUE(filter->events().empty());
656 656
657 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce 657 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce
658 // them. 658 // them.
659 dispatcher()->HoldPointerMoves(); 659 dispatcher()->HoldPointerMoves();
660 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 660 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(
661 &mouse_dragged_event); 661 &mouse_dragged_event);
662 dispatcher()->ReleasePointerMoves(); 662 dispatcher()->ReleasePointerMoves();
663 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 663 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(
664 &mouse_dragged_event2); 664 &mouse_dragged_event2);
665 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events())); 665 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events()));
666 filter->events().clear(); 666 filter->Reset();
667 RunAllPendingInMessageLoop(); 667 RunAllPendingInMessageLoop();
668 EXPECT_TRUE(filter->events().empty()); 668 EXPECT_TRUE(filter->events().empty());
669 } 669 }
670 670
671 TEST_F(RootWindowTest, TouchMovesHeld) { 671 TEST_F(RootWindowTest, TouchMovesHeld) {
672 EventFilterRecorder* filter = new EventFilterRecorder; 672 EventFilterRecorder* filter = new EventFilterRecorder;
673 root_window()->SetEventFilter(filter); // passes ownership 673 root_window()->SetEventFilter(filter); // passes ownership
674 674
675 test::TestWindowDelegate delegate; 675 test::TestWindowDelegate delegate;
676 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 676 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
677 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); 677 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window()));
678 678
679 const gfx::Point touch_location(60, 60);
679 // Starting the touch and throwing out the first few events, since the system 680 // Starting the touch and throwing out the first few events, since the system
680 // is going to generate synthetic mouse events that are not relevant to the 681 // is going to generate synthetic mouse events that are not relevant to the
681 // test. 682 // test.
682 ui::TouchEvent touch_pressed_event(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 683 ui::TouchEvent touch_pressed_event(ui::ET_TOUCH_PRESSED, touch_location,
683 0, base::TimeDelta()); 684 0, base::TimeDelta());
684 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( 685 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(
685 &touch_pressed_event); 686 &touch_pressed_event);
686 RunAllPendingInMessageLoop(); 687 RunAllPendingInMessageLoop();
687 filter->events().clear(); 688 filter->Reset();
688 689
689 dispatcher()->HoldPointerMoves(); 690 dispatcher()->HoldPointerMoves();
690 691
691 // Check that we don't immediately dispatch the TOUCH_MOVED event. 692 // Check that we don't immediately dispatch the TOUCH_MOVED event.
692 ui::TouchEvent touch_moved_event(ui::ET_TOUCH_MOVED, gfx::Point(0, 0), 693 ui::TouchEvent touch_moved_event(ui::ET_TOUCH_MOVED, touch_location,
693 0, base::TimeDelta()); 694 0, base::TimeDelta());
694 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( 695 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(
695 &touch_moved_event); 696 &touch_moved_event);
696 EXPECT_TRUE(filter->events().empty()); 697 EXPECT_TRUE(filter->events().empty());
697 698
698 // Check that on ReleasePointerMoves, held events are not dispatched 699 // Check that on ReleasePointerMoves, held events are not dispatched
699 // immediately, but posted instead. 700 // immediately, but posted instead.
700 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( 701 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(
701 &touch_moved_event); 702 &touch_moved_event);
702 dispatcher()->ReleasePointerMoves(); 703 dispatcher()->ReleasePointerMoves();
703 EXPECT_TRUE(filter->events().empty()); 704 EXPECT_TRUE(filter->events().empty());
705
704 RunAllPendingInMessageLoop(); 706 RunAllPendingInMessageLoop();
705 EXPECT_EQ("TOUCH_MOVED", EventTypesToString(filter->events())); 707 EXPECT_EQ("TOUCH_MOVED", EventTypesToString(filter->events()));
706 filter->events().clear(); 708 filter->Reset();
707 709
708 // If another touch event occurs then the held touch should be dispatched 710 // If another touch event occurs then the held touch should be dispatched
709 // immediately before it. 711 // immediately before it.
710 ui::TouchEvent touch_released_event(ui::ET_TOUCH_RELEASED, gfx::Point(0, 0), 712 ui::TouchEvent touch_released_event(ui::ET_TOUCH_RELEASED, touch_location,
711 0, base::TimeDelta()); 713 0, base::TimeDelta());
712 filter->events().clear(); 714 filter->Reset();
713 dispatcher()->HoldPointerMoves(); 715 dispatcher()->HoldPointerMoves();
714 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( 716 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(
715 &touch_moved_event); 717 &touch_moved_event);
716 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( 718 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(
717 &touch_released_event); 719 &touch_released_event);
718 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP_CANCEL GESTURE_END", 720 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP_CANCEL GESTURE_END",
719 EventTypesToString(filter->events())); 721 EventTypesToString(filter->events()));
720 filter->events().clear(); 722 filter->Reset();
721 dispatcher()->ReleasePointerMoves(); 723 dispatcher()->ReleasePointerMoves();
722 RunAllPendingInMessageLoop(); 724 RunAllPendingInMessageLoop();
723 EXPECT_TRUE(filter->events().empty()); 725 EXPECT_TRUE(filter->events().empty());
724 } 726 }
725 727
728 class HoldPointerOnScrollHandler : public test::TestEventHandler {
729 public:
730 HoldPointerOnScrollHandler(WindowEventDispatcher* dispatcher,
731 EventFilterRecorder* filter)
732 : dispatcher_(dispatcher),
733 filter_(filter),
734 holding_moves_(false) {
735 }
736 virtual ~HoldPointerOnScrollHandler() {}
737
738 private:
739 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE {
740 if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
741 CHECK(!holding_moves_);
742 holding_moves_ = true;
743 dispatcher_->HoldPointerMoves();
744 filter_->Reset();
745 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_END) {
746 dispatcher_->ReleasePointerMoves();
747 holding_moves_ = false;
748 }
749 }
750
751 WindowEventDispatcher* dispatcher_;
752 EventFilterRecorder* filter_;
753 bool holding_moves_;
754
755 DISALLOW_COPY_AND_ASSIGN(HoldPointerOnScrollHandler);
756 };
757
758 // Tests that touch-move events don't contribute to an in-progress scroll
759 // gesture if touch-move events are being held by the dispatcher.
760 TEST_F(RootWindowTest, TouchMovesHeldOnScroll) {
761 EventFilterRecorder* filter = new EventFilterRecorder;
762 root_window()->SetEventFilter(filter);
763 test::TestWindowDelegate delegate;
764 HoldPointerOnScrollHandler handler(dispatcher(), filter);
765 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
766 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window()));
767 window->AddPreTargetHandler(&handler);
768
769 test::EventGenerator generator(root_window());
770 generator.GestureScrollSequence(
771 gfx::Point(60, 60), gfx::Point(10, 60),
772 base::TimeDelta::FromMilliseconds(100), 25);
773
774 // |handler| will have reset |filter| and started holding the touch-move
775 // events when scrolling started. At the end of the scroll (i.e. upon
776 // touch-release), the held touch-move event will have been dispatched first,
777 // along with the subsequent events (i.e. touch-release, scroll-end, and
778 // gesture-end).
779 const EventFilterRecorder::Events& events = filter->events();
780 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_SCROLL_END GESTURE_END",
781 EventTypesToString(events));
782 ASSERT_EQ(2u, filter->touch_locations().size());
783 EXPECT_EQ(gfx::Point(-40, 10).ToString(),
784 filter->touch_locations()[0].ToString());
785 EXPECT_EQ(gfx::Point(-40, 10).ToString(),
786 filter->touch_locations()[1].ToString());
787 }
788
726 // Tests that synthetic mouse events are ignored when mouse 789 // Tests that synthetic mouse events are ignored when mouse
727 // events are disabled. 790 // events are disabled.
728 TEST_F(RootWindowTest, DispatchSyntheticMouseEvents) { 791 TEST_F(RootWindowTest, DispatchSyntheticMouseEvents) {
729 EventFilterRecorder* filter = new EventFilterRecorder; 792 EventFilterRecorder* filter = new EventFilterRecorder;
730 root_window()->SetEventFilter(filter); // passes ownership 793 root_window()->SetEventFilter(filter); // passes ownership
731 794
732 test::TestWindowDelegate delegate; 795 test::TestWindowDelegate delegate;
733 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 796 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
734 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); 797 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window()));
735 window->Show(); 798 window->Show();
736 window->SetCapture(); 799 window->SetCapture();
737 800
738 test::TestCursorClient cursor_client(root_window()); 801 test::TestCursorClient cursor_client(root_window());
739 802
740 // Dispatch a non-synthetic mouse event when mouse events are enabled. 803 // Dispatch a non-synthetic mouse event when mouse events are enabled.
741 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), 804 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10),
742 gfx::Point(10, 10), 0, 0); 805 gfx::Point(10, 10), 0, 0);
743 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse1); 806 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse1);
744 EXPECT_FALSE(filter->events().empty()); 807 EXPECT_FALSE(filter->events().empty());
745 filter->events().clear(); 808 filter->Reset();
746 809
747 // Dispatch a synthetic mouse event when mouse events are enabled. 810 // Dispatch a synthetic mouse event when mouse events are enabled.
748 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), 811 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10),
749 gfx::Point(10, 10), ui::EF_IS_SYNTHESIZED, 0); 812 gfx::Point(10, 10), ui::EF_IS_SYNTHESIZED, 0);
750 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse2); 813 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse2);
751 EXPECT_FALSE(filter->events().empty()); 814 EXPECT_FALSE(filter->events().empty());
752 filter->events().clear(); 815 filter->Reset();
753 816
754 // Dispatch a synthetic mouse event when mouse events are disabled. 817 // Dispatch a synthetic mouse event when mouse events are disabled.
755 cursor_client.DisableMouseEvents(); 818 cursor_client.DisableMouseEvents();
756 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse2); 819 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse2);
757 EXPECT_TRUE(filter->events().empty()); 820 EXPECT_TRUE(filter->events().empty());
758 } 821 }
759 822
760 // Tests that a mouse exit is dispatched to the last known cursor location 823 // Tests that a mouse exit is dispatched to the last known cursor location
761 // when the cursor becomes invisible. 824 // when the cursor becomes invisible.
762 TEST_F(RootWindowTest, DispatchMouseExitWhenCursorHidden) { 825 TEST_F(RootWindowTest, DispatchMouseExitWhenCursorHidden) {
763 EventFilterRecorder* filter = new EventFilterRecorder; 826 EventFilterRecorder* filter = new EventFilterRecorder;
764 root_window()->SetEventFilter(filter); // passes ownership 827 root_window()->SetEventFilter(filter); // passes ownership
765 828
766 test::TestWindowDelegate delegate; 829 test::TestWindowDelegate delegate;
767 gfx::Point window_origin(7, 18); 830 gfx::Point window_origin(7, 18);
768 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 831 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
769 &delegate, 1234, gfx::Rect(window_origin, 832 &delegate, 1234, gfx::Rect(window_origin,
770 gfx::Size(100, 100)), root_window())); 833 gfx::Size(100, 100)), root_window()));
771 window->Show(); 834 window->Show();
772 835
773 // Dispatch a mouse move event into the window. 836 // Dispatch a mouse move event into the window.
774 gfx::Point mouse_location(gfx::Point(15, 25)); 837 gfx::Point mouse_location(gfx::Point(15, 25));
775 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, 838 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location,
776 mouse_location, 0, 0); 839 mouse_location, 0, 0);
777 EXPECT_TRUE(filter->events().empty()); 840 EXPECT_TRUE(filter->events().empty());
778 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse1); 841 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse1);
779 EXPECT_FALSE(filter->events().empty()); 842 EXPECT_FALSE(filter->events().empty());
780 filter->events().clear(); 843 filter->Reset();
781 844
782 // Hide the cursor and verify a mouse exit was dispatched. 845 // Hide the cursor and verify a mouse exit was dispatched.
783 dispatcher()->OnCursorVisibilityChanged(false); 846 dispatcher()->OnCursorVisibilityChanged(false);
784 EXPECT_FALSE(filter->events().empty()); 847 EXPECT_FALSE(filter->events().empty());
785 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(filter->events())); 848 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(filter->events()));
786 849
787 // Verify the mouse exit was dispatched at the correct location 850 // Verify the mouse exit was dispatched at the correct location
788 // (in the correct coordinate space). 851 // (in the correct coordinate space).
789 int translated_x = mouse_location.x() - window_origin.x(); 852 int translated_x = mouse_location.x() - window_origin.x();
790 int translated_y = mouse_location.y() - window_origin.y(); 853 int translated_y = mouse_location.y() - window_origin.y();
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 point.y(), 1075 point.y(),
1013 0, 1076 0,
1014 ui::EventTimeForNow(), 1077 ui::EventTimeForNow(),
1015 details, 1078 details,
1016 0); 1079 0);
1017 dispatcher()->RepostEvent(event); 1080 dispatcher()->RepostEvent(event);
1018 RunAllPendingInMessageLoop(); 1081 RunAllPendingInMessageLoop();
1019 // TODO(rbyers): Currently disabled - crbug.com/170987 1082 // TODO(rbyers): Currently disabled - crbug.com/170987
1020 EXPECT_FALSE(EventTypesToString(filter->events()).find("GESTURE_TAP_DOWN") != 1083 EXPECT_FALSE(EventTypesToString(filter->events()).find("GESTURE_TAP_DOWN") !=
1021 std::string::npos); 1084 std::string::npos);
1022 filter->events().clear(); 1085 filter->Reset();
1023 } 1086 }
1024 1087
1025 // This class inherits from the EventFilterRecorder class which provides a 1088 // This class inherits from the EventFilterRecorder class which provides a
1026 // facility to record events. This class additionally provides a facility to 1089 // facility to record events. This class additionally provides a facility to
1027 // repost the ET_GESTURE_TAP_DOWN gesture to the target window and records 1090 // repost the ET_GESTURE_TAP_DOWN gesture to the target window and records
1028 // events after that. 1091 // events after that.
1029 class RepostGestureEventRecorder : public EventFilterRecorder { 1092 class RepostGestureEventRecorder : public EventFilterRecorder {
1030 public: 1093 public:
1031 RepostGestureEventRecorder(aura::Window* repost_source, 1094 RepostGestureEventRecorder(aura::Window* repost_source,
1032 aura::Window* repost_target) 1095 aura::Window* repost_target)
1033 : repost_source_(repost_source), 1096 : repost_source_(repost_source),
1034 repost_target_(repost_target), 1097 repost_target_(repost_target),
1035 reposted_(false), 1098 reposted_(false),
1036 done_cleanup_(false) {} 1099 done_cleanup_(false) {}
1037 1100
1038 virtual ~RepostGestureEventRecorder() {} 1101 virtual ~RepostGestureEventRecorder() {}
1039 1102
1040 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { 1103 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
1041 if (reposted_ && event->type() == ui::ET_TOUCH_PRESSED) { 1104 if (reposted_ && event->type() == ui::ET_TOUCH_PRESSED) {
1042 done_cleanup_ = true; 1105 done_cleanup_ = true;
1043 events().clear(); 1106 Reset();
1044 } 1107 }
1045 EventFilterRecorder::OnTouchEvent(event); 1108 EventFilterRecorder::OnTouchEvent(event);
1046 } 1109 }
1047 1110
1048 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { 1111 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
1049 EXPECT_EQ(done_cleanup_ ? repost_target_ : repost_source_, event->target()); 1112 EXPECT_EQ(done_cleanup_ ? repost_target_ : repost_source_, event->target());
1050 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { 1113 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
1051 if (!reposted_) { 1114 if (!reposted_) {
1052 EXPECT_NE(repost_target_, event->target()); 1115 EXPECT_NE(repost_target_, event->target());
1053 reposted_ = true; 1116 reposted_ = true;
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 CHECK(!message_loop()->is_running()); 1595 CHECK(!message_loop()->is_running());
1533 // Perform the test in a callback, so that it runs after the message-loop 1596 // Perform the test in a callback, so that it runs after the message-loop
1534 // starts. 1597 // starts.
1535 message_loop()->PostTask(FROM_HERE, 1598 message_loop()->PostTask(FROM_HERE,
1536 base::Bind(&RootWindowTestWithMessageLoop::RunTest, 1599 base::Bind(&RootWindowTestWithMessageLoop::RunTest,
1537 base::Unretained(this))); 1600 base::Unretained(this)));
1538 message_loop()->Run(); 1601 message_loop()->Run();
1539 } 1602 }
1540 1603
1541 } // namespace aura 1604 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/root_window.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698