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

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

Issue 191153004: Provide access to the WindowEventDispatcher as a ui::EventProcessor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 9 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/test/event_generator.cc ('k') | ui/aura/window_tree_host.h » ('j') | 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/window_event_dispatcher.h" 5 #include "ui/aura/window_event_dispatcher.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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT); 133 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT);
134 } 134 }
135 135
136 TEST_F(WindowEventDispatcherTest, RepostEvent) { 136 TEST_F(WindowEventDispatcherTest, RepostEvent) {
137 // Test RepostEvent in RootWindow. It only works for Mouse Press. 137 // Test RepostEvent in RootWindow. It only works for Mouse Press.
138 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); 138 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown());
139 gfx::Point point(10, 10); 139 gfx::Point point(10, 10);
140 ui::MouseEvent event( 140 ui::MouseEvent event(
141 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON, 141 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON,
142 ui::EF_LEFT_MOUSE_BUTTON); 142 ui::EF_LEFT_MOUSE_BUTTON);
143 dispatcher()->RepostEvent(event); 143 host()->dispatcher()->RepostEvent(event);
144 RunAllPendingInMessageLoop(); 144 RunAllPendingInMessageLoop();
145 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); 145 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown());
146 } 146 }
147 147
148 // Check that we correctly track the state of the mouse buttons in response to 148 // Check that we correctly track the state of the mouse buttons in response to
149 // button press and release events. 149 // button press and release events.
150 TEST_F(WindowEventDispatcherTest, MouseButtonState) { 150 TEST_F(WindowEventDispatcherTest, MouseButtonState) {
151 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); 151 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown());
152 152
153 gfx::Point location; 153 gfx::Point location;
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 // capture). 585 // capture).
586 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); 586 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown());
587 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); 587 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL));
588 window->SetBounds(gfx::Rect(20, 20, 40, 30)); 588 window->SetBounds(gfx::Rect(20, 20, 40, 30));
589 EventFilterRecorder* recorder = new EventFilterRecorder; 589 EventFilterRecorder* recorder = new EventFilterRecorder;
590 window->SetEventFilter(recorder); // Takes ownership. 590 window->SetEventFilter(recorder); // Takes ownership.
591 window->SetCapture(); 591 window->SetCapture();
592 const ui::MouseEvent press_event( 592 const ui::MouseEvent press_event(
593 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 593 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
594 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 594 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
595 dispatcher()->RepostEvent(press_event); 595 host()->dispatcher()->RepostEvent(press_event);
596 RunAllPendingInMessageLoop(); // Necessitated by RepostEvent(). 596 RunAllPendingInMessageLoop(); // Necessitated by RepostEvent().
597 // Mouse moves/enters may be generated. We only care about a pressed. 597 // Mouse moves/enters may be generated. We only care about a pressed.
598 EXPECT_TRUE(EventTypesToString(recorder->events()).find("MOUSE_PRESSED") != 598 EXPECT_TRUE(EventTypesToString(recorder->events()).find("MOUSE_PRESSED") !=
599 std::string::npos) << EventTypesToString(recorder->events()); 599 std::string::npos) << EventTypesToString(recorder->events());
600 } 600 }
601 601
602 TEST_F(WindowEventDispatcherTest, MouseMovesHeld) { 602 TEST_F(WindowEventDispatcherTest, MouseMovesHeld) {
603 EventFilterRecorder* filter = new EventFilterRecorder; 603 EventFilterRecorder* filter = new EventFilterRecorder;
604 root_window()->SetEventFilter(filter); // passes ownership 604 root_window()->SetEventFilter(filter); // passes ownership
605 605
606 test::TestWindowDelegate delegate; 606 test::TestWindowDelegate delegate;
607 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 607 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
608 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); 608 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window()));
609 609
610 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), 610 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0),
611 gfx::Point(0, 0), 0, 0); 611 gfx::Point(0, 0), 0, 0);
612 DispatchEventUsingWindowDispatcher(&mouse_move_event); 612 DispatchEventUsingWindowDispatcher(&mouse_move_event);
613 // Discard MOUSE_ENTER. 613 // Discard MOUSE_ENTER.
614 filter->Reset(); 614 filter->Reset();
615 615
616 dispatcher()->HoldPointerMoves(); 616 host()->dispatcher()->HoldPointerMoves();
617 617
618 // Check that we don't immediately dispatch the MOUSE_DRAGGED event. 618 // Check that we don't immediately dispatch the MOUSE_DRAGGED event.
619 ui::MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), 619 ui::MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0),
620 gfx::Point(0, 0), 0, 0); 620 gfx::Point(0, 0), 0, 0);
621 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); 621 DispatchEventUsingWindowDispatcher(&mouse_dragged_event);
622 EXPECT_TRUE(filter->events().empty()); 622 EXPECT_TRUE(filter->events().empty());
623 623
624 // Check that we do dispatch the held MOUSE_DRAGGED event before another type 624 // Check that we do dispatch the held MOUSE_DRAGGED event before another type
625 // of event. 625 // of event.
626 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), 626 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0),
(...skipping 10 matching lines...) Expand all
637 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); 637 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2);
638 EXPECT_TRUE(filter->events().empty()); 638 EXPECT_TRUE(filter->events().empty());
639 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); 639 DispatchEventUsingWindowDispatcher(&mouse_pressed_event);
640 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", 640 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED",
641 EventTypesToString(filter->events())); 641 EventTypesToString(filter->events()));
642 filter->Reset(); 642 filter->Reset();
643 643
644 // Check that on ReleasePointerMoves, held events are not dispatched 644 // Check that on ReleasePointerMoves, held events are not dispatched
645 // immediately, but posted instead. 645 // immediately, but posted instead.
646 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); 646 DispatchEventUsingWindowDispatcher(&mouse_dragged_event);
647 dispatcher()->ReleasePointerMoves(); 647 host()->dispatcher()->ReleasePointerMoves();
648 EXPECT_TRUE(filter->events().empty()); 648 EXPECT_TRUE(filter->events().empty());
649 RunAllPendingInMessageLoop(); 649 RunAllPendingInMessageLoop();
650 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events())); 650 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events()));
651 filter->Reset(); 651 filter->Reset();
652 652
653 // However if another message comes in before the dispatch of the posted 653 // However if another message comes in before the dispatch of the posted
654 // event, check that the posted event is dispatched before this new event. 654 // event, check that the posted event is dispatched before this new event.
655 dispatcher()->HoldPointerMoves(); 655 host()->dispatcher()->HoldPointerMoves();
656 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); 656 DispatchEventUsingWindowDispatcher(&mouse_dragged_event);
657 dispatcher()->ReleasePointerMoves(); 657 host()->dispatcher()->ReleasePointerMoves();
658 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); 658 DispatchEventUsingWindowDispatcher(&mouse_pressed_event);
659 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", 659 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED",
660 EventTypesToString(filter->events())); 660 EventTypesToString(filter->events()));
661 filter->Reset(); 661 filter->Reset();
662 RunAllPendingInMessageLoop(); 662 RunAllPendingInMessageLoop();
663 EXPECT_TRUE(filter->events().empty()); 663 EXPECT_TRUE(filter->events().empty());
664 664
665 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce 665 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce
666 // them. 666 // them.
667 dispatcher()->HoldPointerMoves(); 667 host()->dispatcher()->HoldPointerMoves();
668 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); 668 DispatchEventUsingWindowDispatcher(&mouse_dragged_event);
669 dispatcher()->ReleasePointerMoves(); 669 host()->dispatcher()->ReleasePointerMoves();
670 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); 670 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2);
671 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events())); 671 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events()));
672 filter->Reset(); 672 filter->Reset();
673 RunAllPendingInMessageLoop(); 673 RunAllPendingInMessageLoop();
674 EXPECT_TRUE(filter->events().empty()); 674 EXPECT_TRUE(filter->events().empty());
675 675
676 // Check that synthetic mouse move event has a right location when issued 676 // Check that synthetic mouse move event has a right location when issued
677 // while holding pointer moves. 677 // while holding pointer moves.
678 ui::MouseEvent mouse_dragged_event3(ui::ET_MOUSE_DRAGGED, gfx::Point(28, 28), 678 ui::MouseEvent mouse_dragged_event3(ui::ET_MOUSE_DRAGGED, gfx::Point(28, 28),
679 gfx::Point(28, 28), 0, 0); 679 gfx::Point(28, 28), 0, 0);
680 dispatcher()->HoldPointerMoves(); 680 host()->dispatcher()->HoldPointerMoves();
681 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); 681 DispatchEventUsingWindowDispatcher(&mouse_dragged_event);
682 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); 682 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2);
683 window->SetBounds(gfx::Rect(15, 15, 80, 80)); 683 window->SetBounds(gfx::Rect(15, 15, 80, 80));
684 DispatchEventUsingWindowDispatcher(&mouse_dragged_event3); 684 DispatchEventUsingWindowDispatcher(&mouse_dragged_event3);
685 RunAllPendingInMessageLoop(); 685 RunAllPendingInMessageLoop();
686 EXPECT_TRUE(filter->events().empty()); 686 EXPECT_TRUE(filter->events().empty());
687 dispatcher()->ReleasePointerMoves(); 687 host()->dispatcher()->ReleasePointerMoves();
688 RunAllPendingInMessageLoop(); 688 RunAllPendingInMessageLoop();
689 EXPECT_EQ("MOUSE_MOVED", EventTypesToString(filter->events())); 689 EXPECT_EQ("MOUSE_MOVED", EventTypesToString(filter->events()));
690 EXPECT_EQ(gfx::Point(13, 13), filter->mouse_location(0)); 690 EXPECT_EQ(gfx::Point(13, 13), filter->mouse_location(0));
691 filter->Reset(); 691 filter->Reset();
692 } 692 }
693 693
694 TEST_F(WindowEventDispatcherTest, TouchMovesHeld) { 694 TEST_F(WindowEventDispatcherTest, TouchMovesHeld) {
695 EventFilterRecorder* filter = new EventFilterRecorder; 695 EventFilterRecorder* filter = new EventFilterRecorder;
696 root_window()->SetEventFilter(filter); // passes ownership 696 root_window()->SetEventFilter(filter); // passes ownership
697 697
698 test::TestWindowDelegate delegate; 698 test::TestWindowDelegate delegate;
699 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 699 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
700 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); 700 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window()));
701 701
702 const gfx::Point touch_location(60, 60); 702 const gfx::Point touch_location(60, 60);
703 // Starting the touch and throwing out the first few events, since the system 703 // Starting the touch and throwing out the first few events, since the system
704 // is going to generate synthetic mouse events that are not relevant to the 704 // is going to generate synthetic mouse events that are not relevant to the
705 // test. 705 // test.
706 ui::TouchEvent touch_pressed_event(ui::ET_TOUCH_PRESSED, touch_location, 706 ui::TouchEvent touch_pressed_event(ui::ET_TOUCH_PRESSED, touch_location,
707 0, base::TimeDelta()); 707 0, base::TimeDelta());
708 DispatchEventUsingWindowDispatcher(&touch_pressed_event); 708 DispatchEventUsingWindowDispatcher(&touch_pressed_event);
709 filter->WaitUntilReceivedEvent(ui::ET_GESTURE_SHOW_PRESS); 709 filter->WaitUntilReceivedEvent(ui::ET_GESTURE_SHOW_PRESS);
710 filter->Reset(); 710 filter->Reset();
711 711
712 dispatcher()->HoldPointerMoves(); 712 host()->dispatcher()->HoldPointerMoves();
713 713
714 // Check that we don't immediately dispatch the TOUCH_MOVED event. 714 // Check that we don't immediately dispatch the TOUCH_MOVED event.
715 ui::TouchEvent touch_moved_event(ui::ET_TOUCH_MOVED, touch_location, 715 ui::TouchEvent touch_moved_event(ui::ET_TOUCH_MOVED, touch_location,
716 0, base::TimeDelta()); 716 0, base::TimeDelta());
717 DispatchEventUsingWindowDispatcher(&touch_moved_event); 717 DispatchEventUsingWindowDispatcher(&touch_moved_event);
718 EXPECT_TRUE(filter->events().empty()); 718 EXPECT_TRUE(filter->events().empty());
719 719
720 // Check that on ReleasePointerMoves, held events are not dispatched 720 // Check that on ReleasePointerMoves, held events are not dispatched
721 // immediately, but posted instead. 721 // immediately, but posted instead.
722 DispatchEventUsingWindowDispatcher(&touch_moved_event); 722 DispatchEventUsingWindowDispatcher(&touch_moved_event);
723 dispatcher()->ReleasePointerMoves(); 723 host()->dispatcher()->ReleasePointerMoves();
724 EXPECT_TRUE(filter->events().empty()); 724 EXPECT_TRUE(filter->events().empty());
725 725
726 RunAllPendingInMessageLoop(); 726 RunAllPendingInMessageLoop();
727 EXPECT_EQ("TOUCH_MOVED", EventTypesToString(filter->events())); 727 EXPECT_EQ("TOUCH_MOVED", EventTypesToString(filter->events()));
728 filter->Reset(); 728 filter->Reset();
729 729
730 // If another touch event occurs then the held touch should be dispatched 730 // If another touch event occurs then the held touch should be dispatched
731 // immediately before it. 731 // immediately before it.
732 ui::TouchEvent touch_released_event(ui::ET_TOUCH_RELEASED, touch_location, 732 ui::TouchEvent touch_released_event(ui::ET_TOUCH_RELEASED, touch_location,
733 0, base::TimeDelta()); 733 0, base::TimeDelta());
734 filter->Reset(); 734 filter->Reset();
735 dispatcher()->HoldPointerMoves(); 735 host()->dispatcher()->HoldPointerMoves();
736 DispatchEventUsingWindowDispatcher(&touch_moved_event); 736 DispatchEventUsingWindowDispatcher(&touch_moved_event);
737 DispatchEventUsingWindowDispatcher(&touch_released_event); 737 DispatchEventUsingWindowDispatcher(&touch_released_event);
738 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP_CANCEL GESTURE_END", 738 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP_CANCEL GESTURE_END",
739 EventTypesToString(filter->events())); 739 EventTypesToString(filter->events()));
740 filter->Reset(); 740 filter->Reset();
741 dispatcher()->ReleasePointerMoves(); 741 host()->dispatcher()->ReleasePointerMoves();
742 RunAllPendingInMessageLoop(); 742 RunAllPendingInMessageLoop();
743 EXPECT_TRUE(filter->events().empty()); 743 EXPECT_TRUE(filter->events().empty());
744 } 744 }
745 745
746 class HoldPointerOnScrollHandler : public test::TestEventHandler { 746 class HoldPointerOnScrollHandler : public test::TestEventHandler {
747 public: 747 public:
748 HoldPointerOnScrollHandler(WindowEventDispatcher* dispatcher, 748 HoldPointerOnScrollHandler(WindowEventDispatcher* dispatcher,
749 EventFilterRecorder* filter) 749 EventFilterRecorder* filter)
750 : dispatcher_(dispatcher), 750 : dispatcher_(dispatcher),
751 filter_(filter), 751 filter_(filter),
(...skipping 20 matching lines...) Expand all
772 772
773 DISALLOW_COPY_AND_ASSIGN(HoldPointerOnScrollHandler); 773 DISALLOW_COPY_AND_ASSIGN(HoldPointerOnScrollHandler);
774 }; 774 };
775 775
776 // Tests that touch-move events don't contribute to an in-progress scroll 776 // Tests that touch-move events don't contribute to an in-progress scroll
777 // gesture if touch-move events are being held by the dispatcher. 777 // gesture if touch-move events are being held by the dispatcher.
778 TEST_F(WindowEventDispatcherTest, TouchMovesHeldOnScroll) { 778 TEST_F(WindowEventDispatcherTest, TouchMovesHeldOnScroll) {
779 EventFilterRecorder* filter = new EventFilterRecorder; 779 EventFilterRecorder* filter = new EventFilterRecorder;
780 root_window()->SetEventFilter(filter); 780 root_window()->SetEventFilter(filter);
781 test::TestWindowDelegate delegate; 781 test::TestWindowDelegate delegate;
782 HoldPointerOnScrollHandler handler(dispatcher(), filter); 782 HoldPointerOnScrollHandler handler(host()->dispatcher(), filter);
783 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 783 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
784 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); 784 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window()));
785 window->AddPreTargetHandler(&handler); 785 window->AddPreTargetHandler(&handler);
786 786
787 test::EventGenerator generator(root_window()); 787 test::EventGenerator generator(root_window());
788 generator.GestureScrollSequence( 788 generator.GestureScrollSequence(
789 gfx::Point(60, 60), gfx::Point(10, 60), 789 gfx::Point(60, 60), gfx::Point(10, 60),
790 base::TimeDelta::FromMilliseconds(100), 25); 790 base::TimeDelta::FromMilliseconds(100), 25);
791 791
792 // |handler| will have reset |filter| and started holding the touch-move 792 // |handler| will have reset |filter| and started holding the touch-move
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 // Dispatch a mouse move event into the window. 854 // Dispatch a mouse move event into the window.
855 gfx::Point mouse_location(gfx::Point(15, 25)); 855 gfx::Point mouse_location(gfx::Point(15, 25));
856 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, 856 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location,
857 mouse_location, 0, 0); 857 mouse_location, 0, 0);
858 EXPECT_TRUE(filter->events().empty()); 858 EXPECT_TRUE(filter->events().empty());
859 DispatchEventUsingWindowDispatcher(&mouse1); 859 DispatchEventUsingWindowDispatcher(&mouse1);
860 EXPECT_FALSE(filter->events().empty()); 860 EXPECT_FALSE(filter->events().empty());
861 filter->Reset(); 861 filter->Reset();
862 862
863 // Hide the cursor and verify a mouse exit was dispatched. 863 // Hide the cursor and verify a mouse exit was dispatched.
864 dispatcher()->host()->OnCursorVisibilityChanged(false); 864 host()->OnCursorVisibilityChanged(false);
865 EXPECT_FALSE(filter->events().empty()); 865 EXPECT_FALSE(filter->events().empty());
866 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(filter->events())); 866 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(filter->events()));
867 867
868 // Verify the mouse exit was dispatched at the correct location 868 // Verify the mouse exit was dispatched at the correct location
869 // (in the correct coordinate space). 869 // (in the correct coordinate space).
870 int translated_x = mouse_location.x() - window_origin.x(); 870 int translated_x = mouse_location.x() - window_origin.x();
871 int translated_y = mouse_location.y() - window_origin.y(); 871 int translated_y = mouse_location.y() - window_origin.y();
872 gfx::Point translated_point(translated_x, translated_y); 872 gfx::Point translated_point(translated_x, translated_y);
873 EXPECT_EQ(filter->mouse_location(0).ToString(), translated_point.ToString()); 873 EXPECT_EQ(filter->mouse_location(0).ToString(), translated_point.ToString());
874 } 874 }
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 ui::GestureEventDetails details(ui::ET_GESTURE_TAP_DOWN, 0.0f, 0.0f); 1089 ui::GestureEventDetails details(ui::ET_GESTURE_TAP_DOWN, 0.0f, 0.0f);
1090 gfx::Point point(10, 10); 1090 gfx::Point point(10, 10);
1091 ui::GestureEvent event( 1091 ui::GestureEvent event(
1092 ui::ET_GESTURE_TAP_DOWN, 1092 ui::ET_GESTURE_TAP_DOWN,
1093 point.x(), 1093 point.x(),
1094 point.y(), 1094 point.y(),
1095 0, 1095 0,
1096 ui::EventTimeForNow(), 1096 ui::EventTimeForNow(),
1097 details, 1097 details,
1098 0); 1098 0);
1099 dispatcher()->RepostEvent(event); 1099 host()->dispatcher()->RepostEvent(event);
1100 RunAllPendingInMessageLoop(); 1100 RunAllPendingInMessageLoop();
1101 // TODO(rbyers): Currently disabled - crbug.com/170987 1101 // TODO(rbyers): Currently disabled - crbug.com/170987
1102 EXPECT_FALSE(EventTypesToString(filter->events()).find("GESTURE_TAP_DOWN") != 1102 EXPECT_FALSE(EventTypesToString(filter->events()).find("GESTURE_TAP_DOWN") !=
1103 std::string::npos); 1103 std::string::npos);
1104 filter->Reset(); 1104 filter->Reset();
1105 } 1105 }
1106 1106
1107 // This class inherits from the EventFilterRecorder class which provides a 1107 // This class inherits from the EventFilterRecorder class which provides a
1108 // facility to record events. This class additionally provides a facility to 1108 // facility to record events. This class additionally provides a facility to
1109 // repost the ET_GESTURE_TAP_DOWN gesture to the target window and records 1109 // repost the ET_GESTURE_TAP_DOWN gesture to the target window and records
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 // a child, but the child is destroyed because of the synthesized mouse-exit 1243 // a child, but the child is destroyed because of the synthesized mouse-exit
1244 // event generated on the previous mouse_moved_handler_. 1244 // event generated on the previous mouse_moved_handler_.
1245 TEST_F(WindowEventDispatcherTest, DeleteWindowDuringMouseMovedDispatch) { 1245 TEST_F(WindowEventDispatcherTest, DeleteWindowDuringMouseMovedDispatch) {
1246 // Create window 1 and set its event filter. Window 1 will take ownership of 1246 // Create window 1 and set its event filter. Window 1 will take ownership of
1247 // the event filter. 1247 // the event filter.
1248 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); 1248 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL));
1249 OnMouseExitDeletingEventFilter* w1_filter = 1249 OnMouseExitDeletingEventFilter* w1_filter =
1250 new OnMouseExitDeletingEventFilter(); 1250 new OnMouseExitDeletingEventFilter();
1251 w1->SetEventFilter(w1_filter); 1251 w1->SetEventFilter(w1_filter);
1252 w1->SetBounds(gfx::Rect(20, 20, 60, 60)); 1252 w1->SetBounds(gfx::Rect(20, 20, 60, 60));
1253 EXPECT_EQ(NULL, dispatcher()->mouse_moved_handler()); 1253 EXPECT_EQ(NULL, host()->dispatcher()->mouse_moved_handler());
1254 1254
1255 test::EventGenerator generator(root_window(), w1.get()); 1255 test::EventGenerator generator(root_window(), w1.get());
1256 1256
1257 // Move mouse over window 1 to set it as the |mouse_moved_handler_| for the 1257 // Move mouse over window 1 to set it as the |mouse_moved_handler_| for the
1258 // root window. 1258 // root window.
1259 generator.MoveMouseTo(51, 51); 1259 generator.MoveMouseTo(51, 51);
1260 EXPECT_EQ(w1.get(), dispatcher()->mouse_moved_handler()); 1260 EXPECT_EQ(w1.get(), host()->dispatcher()->mouse_moved_handler());
1261 1261
1262 // Create window 2 under the mouse cursor and stack it above window 1. 1262 // Create window 2 under the mouse cursor and stack it above window 1.
1263 Window* w2 = CreateNormalWindow(2, root_window(), NULL); 1263 Window* w2 = CreateNormalWindow(2, root_window(), NULL);
1264 w2->SetBounds(gfx::Rect(30, 30, 40, 40)); 1264 w2->SetBounds(gfx::Rect(30, 30, 40, 40));
1265 root_window()->StackChildAbove(w2, w1.get()); 1265 root_window()->StackChildAbove(w2, w1.get());
1266 1266
1267 // Set window 2 as the window that is to be deleted when a mouse-exited event 1267 // Set window 2 as the window that is to be deleted when a mouse-exited event
1268 // happens on window 1. 1268 // happens on window 1.
1269 w1_filter->set_window_to_delete(w2); 1269 w1_filter->set_window_to_delete(w2);
1270 1270
1271 // Move mosue over window 2. This should generate a mouse-exited event for 1271 // Move mosue over window 2. This should generate a mouse-exited event for
1272 // window 1 resulting in deletion of window 2. The original mouse-moved event 1272 // window 1 resulting in deletion of window 2. The original mouse-moved event
1273 // that was targeted to window 2 should be dropped since window 2 is 1273 // that was targeted to window 2 should be dropped since window 2 is
1274 // destroyed. This test passes if no crash happens. 1274 // destroyed. This test passes if no crash happens.
1275 generator.MoveMouseTo(52, 52); 1275 generator.MoveMouseTo(52, 52);
1276 EXPECT_EQ(NULL, dispatcher()->mouse_moved_handler()); 1276 EXPECT_EQ(NULL, host()->dispatcher()->mouse_moved_handler());
1277 1277
1278 // Check events received by window 1. 1278 // Check events received by window 1.
1279 EXPECT_EQ("MOUSE_ENTERED MOUSE_MOVED MOUSE_EXITED", 1279 EXPECT_EQ("MOUSE_ENTERED MOUSE_MOVED MOUSE_EXITED",
1280 EventTypesToString(w1_filter->events())); 1280 EventTypesToString(w1_filter->events()));
1281 } 1281 }
1282 1282
1283 namespace { 1283 namespace {
1284 1284
1285 // Used to track if OnWindowDestroying() is invoked and if there is a valid 1285 // Used to track if OnWindowDestroying() is invoked and if there is a valid
1286 // RootWindow at such time. 1286 // RootWindow at such time.
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 // (e.g. mouse-move events if the mouse cursor is over the window). 1619 // (e.g. mouse-move events if the mouse cursor is over the window).
1620 handler_.Reset(); 1620 handler_.Reset();
1621 1621
1622 // Start a nested message-loop, post an event to be dispatched, and then 1622 // Start a nested message-loop, post an event to be dispatched, and then
1623 // terminate the message-loop. When the message-loop unwinds and gets back, 1623 // terminate the message-loop. When the message-loop unwinds and gets back,
1624 // the reposted event should not have fired. 1624 // the reposted event should not have fired.
1625 ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), 1625 ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10),
1626 gfx::Point(10, 10), ui::EF_NONE, ui::EF_NONE); 1626 gfx::Point(10, 10), ui::EF_NONE, ui::EF_NONE);
1627 message_loop()->PostTask(FROM_HERE, 1627 message_loop()->PostTask(FROM_HERE,
1628 base::Bind(&WindowEventDispatcher::RepostEvent, 1628 base::Bind(&WindowEventDispatcher::RepostEvent,
1629 base::Unretained(dispatcher()), 1629 base::Unretained(host()->dispatcher()),
1630 mouse)); 1630 mouse));
1631 message_loop()->PostTask(FROM_HERE, 1631 message_loop()->PostTask(FROM_HERE,
1632 message_loop()->QuitClosure()); 1632 message_loop()->QuitClosure());
1633 1633
1634 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop()); 1634 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop());
1635 base::RunLoop loop; 1635 base::RunLoop loop;
1636 loop.Run(); 1636 loop.Run();
1637 EXPECT_EQ(0, handler_.num_mouse_events()); 1637 EXPECT_EQ(0, handler_.num_mouse_events());
1638 1638
1639 // Let the current message-loop run. The event-handler will terminate the 1639 // Let the current message-loop run. The event-handler will terminate the
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1719 } 1719 }
1720 1720
1721 child->RemovePreTargetHandler(&handler_child); 1721 child->RemovePreTargetHandler(&handler_child);
1722 root_window()->RemovePreTargetHandler(&handler_root); 1722 root_window()->RemovePreTargetHandler(&handler_root);
1723 } 1723 }
1724 1724
1725 TEST_F(WindowEventDispatcherTestInHighDPI, TouchMovesHeldOnScroll) { 1725 TEST_F(WindowEventDispatcherTestInHighDPI, TouchMovesHeldOnScroll) {
1726 EventFilterRecorder* filter = new EventFilterRecorder; 1726 EventFilterRecorder* filter = new EventFilterRecorder;
1727 root_window()->SetEventFilter(filter); 1727 root_window()->SetEventFilter(filter);
1728 test::TestWindowDelegate delegate; 1728 test::TestWindowDelegate delegate;
1729 HoldPointerOnScrollHandler handler(dispatcher(), filter); 1729 HoldPointerOnScrollHandler handler(host()->dispatcher(), filter);
1730 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1730 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1731 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); 1731 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window()));
1732 window->AddPreTargetHandler(&handler); 1732 window->AddPreTargetHandler(&handler);
1733 1733
1734 test::EventGenerator generator(root_window()); 1734 test::EventGenerator generator(root_window());
1735 generator.GestureScrollSequence( 1735 generator.GestureScrollSequence(
1736 gfx::Point(120, 120), gfx::Point(20, 120), 1736 gfx::Point(120, 120), gfx::Point(20, 120),
1737 base::TimeDelta::FromMilliseconds(100), 25); 1737 base::TimeDelta::FromMilliseconds(100), 25);
1738 1738
1739 // |handler| will have reset |filter| and started holding the touch-move 1739 // |handler| will have reset |filter| and started holding the touch-move
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1824 // when the focused window does not live in the dispatcher's tree. 1824 // when the focused window does not live in the dispatcher's tree.
1825 TEST_F(WindowEventDispatcherTest, HostCancelModeWithFocusedWindowOutside) { 1825 TEST_F(WindowEventDispatcherTest, HostCancelModeWithFocusedWindowOutside) {
1826 test::TestWindowDelegate delegate; 1826 test::TestWindowDelegate delegate;
1827 scoped_ptr<Window> focused(CreateTestWindowWithDelegate(&delegate, 123, 1827 scoped_ptr<Window> focused(CreateTestWindowWithDelegate(&delegate, 123,
1828 gfx::Rect(20, 30, 100, 50), NULL)); 1828 gfx::Rect(20, 30, 100, 50), NULL));
1829 StaticFocusClient focus_client(focused.get()); 1829 StaticFocusClient focus_client(focused.get());
1830 client::SetFocusClient(root_window(), &focus_client); 1830 client::SetFocusClient(root_window(), &focus_client);
1831 EXPECT_FALSE(root_window()->Contains(focused.get())); 1831 EXPECT_FALSE(root_window()->Contains(focused.get()));
1832 EXPECT_EQ(focused.get(), 1832 EXPECT_EQ(focused.get(),
1833 client::GetFocusClient(root_window())->GetFocusedWindow()); 1833 client::GetFocusClient(root_window())->GetFocusedWindow());
1834 dispatcher()->DispatchCancelModeEvent(); 1834 host()->dispatcher()->DispatchCancelModeEvent();
1835 EXPECT_EQ(focused.get(), 1835 EXPECT_EQ(focused.get(),
1836 client::GetFocusClient(root_window())->GetFocusedWindow()); 1836 client::GetFocusClient(root_window())->GetFocusedWindow());
1837 } 1837 }
1838 1838
1839 // Dispatches a mouse-move event to |target| when it receives a mouse-move 1839 // Dispatches a mouse-move event to |target| when it receives a mouse-move
1840 // event. 1840 // event.
1841 class DispatchEventHandler : public ui::EventHandler { 1841 class DispatchEventHandler : public ui::EventHandler {
1842 public: 1842 public:
1843 explicit DispatchEventHandler(Window* target) 1843 explicit DispatchEventHandler(Window* target)
1844 : target_(target), 1844 : target_(target),
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 second->AddPreTargetHandler(&move_window); 1924 second->AddPreTargetHandler(&move_window);
1925 1925
1926 // Some sanity checks: |first| is inside |root_window()|'s tree. 1926 // Some sanity checks: |first| is inside |root_window()|'s tree.
1927 EXPECT_EQ(root_window(), first->GetRootWindow()); 1927 EXPECT_EQ(root_window(), first->GetRootWindow());
1928 // The two root windows are different. 1928 // The two root windows are different.
1929 EXPECT_NE(root_window(), second_root); 1929 EXPECT_NE(root_window(), second_root);
1930 1930
1931 // Dispatch an event to |first|. 1931 // Dispatch an event to |first|.
1932 ui::MouseEvent move(ui::ET_MOUSE_MOVED, first->bounds().CenterPoint(), 1932 ui::MouseEvent move(ui::ET_MOUSE_MOVED, first->bounds().CenterPoint(),
1933 first->bounds().CenterPoint(), ui::EF_NONE, ui::EF_NONE); 1933 first->bounds().CenterPoint(), ui::EF_NONE, ui::EF_NONE);
1934 ui::EventDispatchDetails details = dispatcher()->OnEventFromSource(&move); 1934 ui::EventDispatchDetails details =
1935 host()->dispatcher()->OnEventFromSource(&move);
1935 ASSERT_FALSE(details.dispatcher_destroyed); 1936 ASSERT_FALSE(details.dispatcher_destroyed);
1936 EXPECT_TRUE(details.target_destroyed); 1937 EXPECT_TRUE(details.target_destroyed);
1937 EXPECT_EQ(first.get(), move.target()); 1938 EXPECT_EQ(first.get(), move.target());
1938 EXPECT_TRUE(dispatch_event.dispatched()); 1939 EXPECT_TRUE(dispatch_event.dispatched());
1939 EXPECT_EQ(second_root, first->GetRootWindow()); 1940 EXPECT_EQ(second_root, first->GetRootWindow());
1940 1941
1941 first->RemovePreTargetHandler(&dispatch_event); 1942 first->RemovePreTargetHandler(&dispatch_event);
1942 second->RemovePreTargetHandler(&move_window); 1943 second->RemovePreTargetHandler(&move_window);
1943 } 1944 }
1944 1945
1945 } // namespace aura 1946 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/test/event_generator.cc ('k') | ui/aura/window_tree_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698