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

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

Issue 332703003: aura: Allow held touch-events to contribute to gesture events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 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/window_event_dispatcher.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/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 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 return "GESTURE_SHOW_PRESS"; 581 return "GESTURE_SHOW_PRESS";
582 582
583 case ui::ET_GESTURE_BEGIN: 583 case ui::ET_GESTURE_BEGIN:
584 return "GESTURE_BEGIN"; 584 return "GESTURE_BEGIN";
585 585
586 case ui::ET_GESTURE_END: 586 case ui::ET_GESTURE_END:
587 return "GESTURE_END"; 587 return "GESTURE_END";
588 588
589 default: 589 default:
590 // We should explicitly require each event type. 590 // We should explicitly require each event type.
591 NOTREACHED(); 591 NOTREACHED() << "Received unexpected event: " << type;
592 break; 592 break;
593 } 593 }
594 return ""; 594 return "";
595 } 595 }
596 596
597 std::string EventTypesToString(const EventFilterRecorder::Events& events) { 597 std::string EventTypesToString(const EventFilterRecorder::Events& events) {
598 std::string result; 598 std::string result;
599 for (size_t i = 0; i < events.size(); ++i) { 599 for (size_t i = 0; i < events.size(); ++i) {
600 if (i != 0) 600 if (i != 0)
601 result += " "; 601 result += " ";
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 ui::ET_TOUCH_PRESSED, touch_location, 0, ui::EventTimeForNow()); 737 ui::ET_TOUCH_PRESSED, touch_location, 0, ui::EventTimeForNow());
738 DispatchEventUsingWindowDispatcher(&touch_pressed_event); 738 DispatchEventUsingWindowDispatcher(&touch_pressed_event);
739 recorder.WaitUntilReceivedEvent(ui::ET_GESTURE_SHOW_PRESS); 739 recorder.WaitUntilReceivedEvent(ui::ET_GESTURE_SHOW_PRESS);
740 recorder.Reset(); 740 recorder.Reset();
741 741
742 host()->dispatcher()->HoldPointerMoves(); 742 host()->dispatcher()->HoldPointerMoves();
743 743
744 // Check that we don't immediately dispatch the TOUCH_MOVED event. 744 // Check that we don't immediately dispatch the TOUCH_MOVED event.
745 ui::TouchEvent touch_moved_event( 745 ui::TouchEvent touch_moved_event(
746 ui::ET_TOUCH_MOVED, touch_location, 0, ui::EventTimeForNow()); 746 ui::ET_TOUCH_MOVED, touch_location, 0, ui::EventTimeForNow());
747 ui::TouchEvent touch_moved_event2 = touch_moved_event;
748 ui::TouchEvent touch_moved_event3 = touch_moved_event;
749
747 DispatchEventUsingWindowDispatcher(&touch_moved_event); 750 DispatchEventUsingWindowDispatcher(&touch_moved_event);
748 EXPECT_TRUE(recorder.events().empty()); 751 EXPECT_TRUE(recorder.events().empty());
749 752
750 // Check that on ReleasePointerMoves, held events are not dispatched 753 // Check that on ReleasePointerMoves, held events are not dispatched
751 // immediately, but posted instead. 754 // immediately, but posted instead.
752 DispatchEventUsingWindowDispatcher(&touch_moved_event); 755 DispatchEventUsingWindowDispatcher(&touch_moved_event2);
753 host()->dispatcher()->ReleasePointerMoves(); 756 host()->dispatcher()->ReleasePointerMoves();
754 EXPECT_TRUE(recorder.events().empty()); 757 EXPECT_TRUE(recorder.events().empty());
755 758
756 RunAllPendingInMessageLoop(); 759 RunAllPendingInMessageLoop();
757 EXPECT_EQ("TOUCH_MOVED", EventTypesToString(recorder.events())); 760 EXPECT_EQ("TOUCH_MOVED", EventTypesToString(recorder.events()));
758 recorder.Reset(); 761 recorder.Reset();
759 762
760 // If another touch event occurs then the held touch should be dispatched 763 // If another touch event occurs then the held touch should be dispatched
761 // immediately before it. 764 // immediately before it.
762 ui::TouchEvent touch_released_event( 765 ui::TouchEvent touch_released_event(
763 ui::ET_TOUCH_RELEASED, touch_location, 0, ui::EventTimeForNow()); 766 ui::ET_TOUCH_RELEASED, touch_location, 0, ui::EventTimeForNow());
764 recorder.Reset(); 767 recorder.Reset();
765 host()->dispatcher()->HoldPointerMoves(); 768 host()->dispatcher()->HoldPointerMoves();
766 DispatchEventUsingWindowDispatcher(&touch_moved_event); 769 DispatchEventUsingWindowDispatcher(&touch_moved_event3);
767 DispatchEventUsingWindowDispatcher(&touch_released_event); 770 DispatchEventUsingWindowDispatcher(&touch_released_event);
768 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP GESTURE_END", 771 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP GESTURE_END",
769 EventTypesToString(recorder.events())); 772 EventTypesToString(recorder.events()));
770 recorder.Reset(); 773 recorder.Reset();
771 host()->dispatcher()->ReleasePointerMoves(); 774 host()->dispatcher()->ReleasePointerMoves();
772 RunAllPendingInMessageLoop(); 775 RunAllPendingInMessageLoop();
773 EXPECT_TRUE(recorder.events().empty()); 776 EXPECT_TRUE(recorder.events().empty());
774 } 777 }
775 778
779 // This event handler requests the dispatcher to start holding pointer-move
780 // events when it receives the first scroll-update gesture.
776 class HoldPointerOnScrollHandler : public ui::test::TestEventHandler { 781 class HoldPointerOnScrollHandler : public ui::test::TestEventHandler {
777 public: 782 public:
778 HoldPointerOnScrollHandler(WindowEventDispatcher* dispatcher, 783 HoldPointerOnScrollHandler(WindowEventDispatcher* dispatcher,
779 EventFilterRecorder* filter) 784 EventFilterRecorder* filter)
780 : dispatcher_(dispatcher), 785 : dispatcher_(dispatcher),
781 filter_(filter), 786 filter_(filter),
782 holding_moves_(false) { 787 holding_moves_(false) {}
783 }
784 virtual ~HoldPointerOnScrollHandler() {} 788 virtual ~HoldPointerOnScrollHandler() {}
785 789
786 private: 790 private:
791 // ui::test::TestEventHandler:
787 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE { 792 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE {
788 if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) { 793 if (!holding_moves_ && gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
789 CHECK(!holding_moves_);
790 holding_moves_ = true; 794 holding_moves_ = true;
791 dispatcher_->HoldPointerMoves(); 795 dispatcher_->HoldPointerMoves();
792 filter_->Reset(); 796 filter_->Reset();
793 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_END) { 797 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_END) {
794 dispatcher_->ReleasePointerMoves(); 798 dispatcher_->ReleasePointerMoves();
795 holding_moves_ = false; 799 holding_moves_ = false;
796 } 800 }
797 } 801 }
798 802
799 WindowEventDispatcher* dispatcher_; 803 WindowEventDispatcher* dispatcher_;
(...skipping 18 matching lines...) Expand all
818 generator.GestureScrollSequence( 822 generator.GestureScrollSequence(
819 gfx::Point(60, 60), gfx::Point(10, 60), 823 gfx::Point(60, 60), gfx::Point(10, 60),
820 base::TimeDelta::FromMilliseconds(100), 25); 824 base::TimeDelta::FromMilliseconds(100), 25);
821 825
822 // |handler| will have reset |filter| and started holding the touch-move 826 // |handler| will have reset |filter| and started holding the touch-move
823 // events when scrolling started. At the end of the scroll (i.e. upon 827 // events when scrolling started. At the end of the scroll (i.e. upon
824 // touch-release), the held touch-move event will have been dispatched first, 828 // touch-release), the held touch-move event will have been dispatched first,
825 // along with the subsequent events (i.e. touch-release, scroll-end, and 829 // along with the subsequent events (i.e. touch-release, scroll-end, and
826 // gesture-end). 830 // gesture-end).
827 const EventFilterRecorder::Events& events = recorder.events(); 831 const EventFilterRecorder::Events& events = recorder.events();
828 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_SCROLL_END GESTURE_END", 832 EXPECT_EQ(
829 EventTypesToString(events)); 833 "TOUCH_MOVED GESTURE_SCROLL_UPDATE TOUCH_RELEASED "
834 "GESTURE_SCROLL_END GESTURE_END",
835 EventTypesToString(events));
830 ASSERT_EQ(2u, recorder.touch_locations().size()); 836 ASSERT_EQ(2u, recorder.touch_locations().size());
831 EXPECT_EQ(gfx::Point(-40, 10).ToString(), 837 EXPECT_EQ(gfx::Point(-40, 10).ToString(),
832 recorder.touch_locations()[0].ToString()); 838 recorder.touch_locations()[0].ToString());
833 EXPECT_EQ(gfx::Point(-40, 10).ToString(), 839 EXPECT_EQ(gfx::Point(-40, 10).ToString(),
834 recorder.touch_locations()[1].ToString()); 840 recorder.touch_locations()[1].ToString());
835 } 841 }
836 842
843 // Tests that a 'held' touch-event does contribute to gesture event when it is
844 // dispatched.
845 TEST_F(WindowEventDispatcherTest, HeldTouchMoveContributesToGesture) {
846 EventFilterRecorder recorder;
847 root_window()->AddPreTargetHandler(&recorder);
848
849 const gfx::Point location(20, 20);
850 ui::TouchEvent press(
851 ui::ET_TOUCH_PRESSED, location, 0, ui::EventTimeForNow());
852 DispatchEventUsingWindowDispatcher(&press);
853 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_PRESSED));
854 recorder.Reset();
855
856 host()->dispatcher()->HoldPointerMoves();
857
858 ui::TouchEvent move(ui::ET_TOUCH_MOVED,
859 location + gfx::Vector2d(100, 100),
860 0,
861 ui::EventTimeForNow());
862 DispatchEventUsingWindowDispatcher(&move);
863 EXPECT_FALSE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED));
864 EXPECT_FALSE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_BEGIN));
865 recorder.Reset();
866
867 host()->dispatcher()->ReleasePointerMoves();
868 EXPECT_FALSE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED));
869 RunAllPendingInMessageLoop();
870 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED));
871 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_BEGIN));
872 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_UPDATE));
873
874 root_window()->RemovePreTargetHandler(&recorder);
875 }
876
837 // Tests that synthetic mouse events are ignored when mouse 877 // Tests that synthetic mouse events are ignored when mouse
838 // events are disabled. 878 // events are disabled.
839 TEST_F(WindowEventDispatcherTest, DispatchSyntheticMouseEvents) { 879 TEST_F(WindowEventDispatcherTest, DispatchSyntheticMouseEvents) {
840 EventFilterRecorder recorder; 880 EventFilterRecorder recorder;
841 root_window()->AddPreTargetHandler(&recorder); 881 root_window()->AddPreTargetHandler(&recorder);
842 882
843 test::TestWindowDelegate delegate; 883 test::TestWindowDelegate delegate;
844 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 884 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
845 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); 885 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window()));
846 window->Show(); 886 window->Show();
(...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after
1888 generator.GestureScrollSequence( 1928 generator.GestureScrollSequence(
1889 gfx::Point(120, 120), gfx::Point(20, 120), 1929 gfx::Point(120, 120), gfx::Point(20, 120),
1890 base::TimeDelta::FromMilliseconds(100), 25); 1930 base::TimeDelta::FromMilliseconds(100), 25);
1891 1931
1892 // |handler| will have reset |filter| and started holding the touch-move 1932 // |handler| will have reset |filter| and started holding the touch-move
1893 // events when scrolling started. At the end of the scroll (i.e. upon 1933 // events when scrolling started. At the end of the scroll (i.e. upon
1894 // touch-release), the held touch-move event will have been dispatched first, 1934 // touch-release), the held touch-move event will have been dispatched first,
1895 // along with the subsequent events (i.e. touch-release, scroll-end, and 1935 // along with the subsequent events (i.e. touch-release, scroll-end, and
1896 // gesture-end). 1936 // gesture-end).
1897 const EventFilterRecorder::Events& events = recorder.events(); 1937 const EventFilterRecorder::Events& events = recorder.events();
1898 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_SCROLL_END GESTURE_END", 1938 EXPECT_EQ(
1899 EventTypesToString(events)); 1939 "TOUCH_MOVED GESTURE_SCROLL_UPDATE TOUCH_RELEASED "
1940 "GESTURE_SCROLL_END GESTURE_END",
1941 EventTypesToString(events));
1900 ASSERT_EQ(2u, recorder.touch_locations().size()); 1942 ASSERT_EQ(2u, recorder.touch_locations().size());
1901 EXPECT_EQ(gfx::Point(-40, 10).ToString(), 1943 EXPECT_EQ(gfx::Point(-40, 10).ToString(),
1902 recorder.touch_locations()[0].ToString()); 1944 recorder.touch_locations()[0].ToString());
1903 EXPECT_EQ(gfx::Point(-40, 10).ToString(), 1945 EXPECT_EQ(gfx::Point(-40, 10).ToString(),
1904 recorder.touch_locations()[1].ToString()); 1946 recorder.touch_locations()[1].ToString());
1905 } 1947 }
1906 1948
1907 class SelfDestructDelegate : public test::TestWindowDelegate { 1949 class SelfDestructDelegate : public test::TestWindowDelegate {
1908 public: 1950 public:
1909 SelfDestructDelegate() {} 1951 SelfDestructDelegate() {}
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
2140 delegate.GetMouseMotionCountsAndReset(); 2182 delegate.GetMouseMotionCountsAndReset();
2141 2183
2142 // Notify both hosts that the cursor is now hidden. This should send a single 2184 // Notify both hosts that the cursor is now hidden. This should send a single
2143 // mouse-exit event to |window|. 2185 // mouse-exit event to |window|.
2144 host()->OnCursorVisibilityChanged(false); 2186 host()->OnCursorVisibilityChanged(false);
2145 second_host->OnCursorVisibilityChanged(false); 2187 second_host->OnCursorVisibilityChanged(false);
2146 EXPECT_EQ("0 0 1", delegate.GetMouseMotionCountsAndReset()); 2188 EXPECT_EQ("0 0 1", delegate.GetMouseMotionCountsAndReset());
2147 } 2189 }
2148 2190
2149 } // namespace aura 2191 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window_event_dispatcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698