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

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

Issue 306483003: Prepare for Unified Gesture Recognizer landing in Aura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable UGR. Created 6 years, 7 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
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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 492
493 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { 493 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
494 mouse_locations_.push_back(event->location()); 494 mouse_locations_.push_back(event->location());
495 mouse_event_flags_.push_back(event->flags()); 495 mouse_event_flags_.push_back(event->flags());
496 } 496 }
497 497
498 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { 498 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
499 touch_locations_.push_back(event->location()); 499 touch_locations_.push_back(event->location());
500 } 500 }
501 501
502 bool HasReceivedEvent(ui::EventType type) {
503 for (size_t i = 0; i < events_.size(); ++i) {
504 if (events_[i] == type)
505 return true;
506 }
507 return false;
508 }
509
502 private: 510 private:
503 scoped_ptr<base::RunLoop> run_loop_; 511 scoped_ptr<base::RunLoop> run_loop_;
504 ui::EventType wait_until_event_; 512 ui::EventType wait_until_event_;
505 513
506 Events events_; 514 Events events_;
507 EventLocations mouse_locations_; 515 EventLocations mouse_locations_;
508 EventLocations touch_locations_; 516 EventLocations touch_locations_;
509 EventFlags mouse_event_flags_; 517 EventFlags mouse_event_flags_;
510 518
511 DISALLOW_COPY_AND_ASSIGN(EventFilterRecorder); 519 DISALLOW_COPY_AND_ASSIGN(EventFilterRecorder);
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 host()->dispatcher()->ReleasePointerMoves(); 755 host()->dispatcher()->ReleasePointerMoves();
748 EXPECT_TRUE(recorder.events().empty()); 756 EXPECT_TRUE(recorder.events().empty());
749 757
750 RunAllPendingInMessageLoop(); 758 RunAllPendingInMessageLoop();
751 EXPECT_EQ("TOUCH_MOVED", EventTypesToString(recorder.events())); 759 EXPECT_EQ("TOUCH_MOVED", EventTypesToString(recorder.events()));
752 recorder.Reset(); 760 recorder.Reset();
753 761
754 // If another touch event occurs then the held touch should be dispatched 762 // If another touch event occurs then the held touch should be dispatched
755 // immediately before it. 763 // immediately before it.
756 ui::TouchEvent touch_released_event(ui::ET_TOUCH_RELEASED, touch_location, 764 ui::TouchEvent touch_released_event(ui::ET_TOUCH_RELEASED, touch_location,
757 0, base::TimeDelta()); 765 0, base::TimeDelta::FromMilliseconds(50));
758 recorder.Reset(); 766 recorder.Reset();
759 host()->dispatcher()->HoldPointerMoves(); 767 host()->dispatcher()->HoldPointerMoves();
760 DispatchEventUsingWindowDispatcher(&touch_moved_event); 768 DispatchEventUsingWindowDispatcher(&touch_moved_event);
761 DispatchEventUsingWindowDispatcher(&touch_released_event); 769 DispatchEventUsingWindowDispatcher(&touch_released_event);
762 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP_CANCEL GESTURE_END", 770 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP GESTURE_END",
763 EventTypesToString(recorder.events())); 771 EventTypesToString(recorder.events()));
764 recorder.Reset(); 772 recorder.Reset();
765 host()->dispatcher()->ReleasePointerMoves(); 773 host()->dispatcher()->ReleasePointerMoves();
766 RunAllPendingInMessageLoop(); 774 RunAllPendingInMessageLoop();
767 EXPECT_TRUE(recorder.events().empty()); 775 EXPECT_TRUE(recorder.events().empty());
768 } 776 }
769 777
770 class HoldPointerOnScrollHandler : public ui::test::TestEventHandler { 778 class HoldPointerOnScrollHandler : public ui::test::TestEventHandler {
771 public: 779 public:
772 HoldPointerOnScrollHandler(WindowEventDispatcher* dispatcher, 780 HoldPointerOnScrollHandler(WindowEventDispatcher* dispatcher,
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
1575 1583
1576 gfx::Point position1 = root_window()->bounds().origin(); 1584 gfx::Point position1 = root_window()->bounds().origin();
1577 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position1, 0, base::TimeDelta()); 1585 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position1, 0, base::TimeDelta());
1578 DispatchEventUsingWindowDispatcher(&press); 1586 DispatchEventUsingWindowDispatcher(&press);
1579 1587
1580 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN", 1588 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN",
1581 EventTypesToString(recorder.GetAndResetEvents())); 1589 EventTypesToString(recorder.GetAndResetEvents()));
1582 1590
1583 window->Hide(); 1591 window->Hide();
1584 1592
1585 EXPECT_EQ("TOUCH_CANCELLED GESTURE_TAP_CANCEL GESTURE_END", 1593 EXPECT_EQ(ui::ET_TOUCH_CANCELLED, recorder.events()[0]);
1586 EventTypesToString(recorder.events())); 1594 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_TAP_CANCEL));
1595 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_END));
1596 EXPECT_EQ(3U, recorder.events().size());
1587 root_window()->RemovePreTargetHandler(&recorder); 1597 root_window()->RemovePreTargetHandler(&recorder);
1588 } 1598 }
1589 1599
1590 TEST_F(WindowEventDispatcherTest, WindowHideCancelsActiveGestures) { 1600 TEST_F(WindowEventDispatcherTest, WindowHideCancelsActiveGestures) {
1591 EventFilterRecorder recorder; 1601 EventFilterRecorder recorder;
1592 root_window()->AddPreTargetHandler(&recorder); 1602 root_window()->AddPreTargetHandler(&recorder);
1593 1603
1594 test::TestWindowDelegate delegate; 1604 test::TestWindowDelegate delegate;
1595 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1605 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1596 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); 1606 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window()));
1597 1607
1598 gfx::Point position1 = root_window()->bounds().origin(); 1608 gfx::Point position1 = root_window()->bounds().origin();
1599 gfx::Point position2 = root_window()->bounds().CenterPoint(); 1609 gfx::Point position2 = root_window()->bounds().CenterPoint();
1600 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position1, 0, base::TimeDelta()); 1610 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position1, 0, base::TimeDelta());
1601 DispatchEventUsingWindowDispatcher(&press); 1611 DispatchEventUsingWindowDispatcher(&press);
1602 1612
1603 ui::TouchEvent move(ui::ET_TOUCH_MOVED, position2, 0, base::TimeDelta()); 1613 ui::TouchEvent move(ui::ET_TOUCH_MOVED, position2, 0, base::TimeDelta());
1604 DispatchEventUsingWindowDispatcher(&move); 1614 DispatchEventUsingWindowDispatcher(&move);
1605 1615
1606 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, position1, 1, base::TimeDelta()); 1616 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, position1, 1, base::TimeDelta());
1607 DispatchEventUsingWindowDispatcher(&press2); 1617 DispatchEventUsingWindowDispatcher(&press2);
1608 1618
1609 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_MOVED " 1619 // TODO(tdresser): once the unified Gesture Recognizer has stuck, remove the
1610 "GESTURE_TAP_CANCEL GESTURE_SCROLL_BEGIN GESTURE_SCROLL_UPDATE " 1620 // special casing here. See crbug.com/332418 for details.
1611 "TOUCH_PRESSED GESTURE_BEGIN GESTURE_PINCH_BEGIN", 1621 std::string expected =
1612 EventTypesToString(recorder.GetAndResetEvents())); 1622 "TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_MOVED "
1623 "GESTURE_TAP_CANCEL GESTURE_SCROLL_BEGIN GESTURE_SCROLL_UPDATE "
1624 "TOUCH_PRESSED GESTURE_BEGIN GESTURE_PINCH_BEGIN";
1625
1626 std::string expected_ugr =
1627 "TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_MOVED "
1628 "GESTURE_TAP_CANCEL GESTURE_SCROLL_BEGIN GESTURE_SCROLL_UPDATE "
1629 "TOUCH_PRESSED GESTURE_BEGIN";
1630
1631 std::string events_string = EventTypesToString(recorder.GetAndResetEvents());
1632 EXPECT_TRUE((expected == events_string) || (expected_ugr == events_string));
1613 1633
1614 window->Hide(); 1634 window->Hide();
1615 1635
1616 EXPECT_EQ("TOUCH_CANCELLED GESTURE_PINCH_END GESTURE_END TOUCH_CANCELLED " 1636 expected =
1617 "GESTURE_SCROLL_END GESTURE_END", 1637 "TOUCH_CANCELLED GESTURE_PINCH_END GESTURE_END TOUCH_CANCELLED "
1618 EventTypesToString(recorder.events())); 1638 "GESTURE_SCROLL_END GESTURE_END";
1639 expected_ugr =
1640 "TOUCH_CANCELLED GESTURE_SCROLL_END GESTURE_END GESTURE_END "
1641 "TOUCH_CANCELLED";
1642
1643 events_string = EventTypesToString(recorder.GetAndResetEvents());
1644 EXPECT_TRUE((expected == events_string) || (expected_ugr == events_string));
1645
1619 root_window()->RemovePreTargetHandler(&recorder); 1646 root_window()->RemovePreTargetHandler(&recorder);
1620 } 1647 }
1621 1648
1622 // Places two windows side by side. Presses down on one window, and starts a 1649 // Places two windows side by side. Presses down on one window, and starts a
1623 // scroll. Sets capture on the other window and ensures that the "ending" events 1650 // scroll. Sets capture on the other window and ensures that the "ending" events
1624 // aren't sent to the window which gained capture. 1651 // aren't sent to the window which gained capture.
1625 TEST_F(WindowEventDispatcherTest, EndingEventDoesntRetarget) { 1652 TEST_F(WindowEventDispatcherTest, EndingEventDoesntRetarget) {
1626 EventFilterRecorder recorder1; 1653 EventFilterRecorder recorder1;
1627 EventFilterRecorder recorder2; 1654 EventFilterRecorder recorder2;
1628 scoped_ptr<Window> window1(CreateNormalWindow(1, root_window(), NULL)); 1655 scoped_ptr<Window> window1(CreateNormalWindow(1, root_window(), NULL));
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
2110 delegate.GetMouseMotionCountsAndReset(); 2137 delegate.GetMouseMotionCountsAndReset();
2111 2138
2112 // Notify both hosts that the cursor is now hidden. This should send a single 2139 // Notify both hosts that the cursor is now hidden. This should send a single
2113 // mouse-exit event to |window|. 2140 // mouse-exit event to |window|.
2114 host()->OnCursorVisibilityChanged(false); 2141 host()->OnCursorVisibilityChanged(false);
2115 second_host->OnCursorVisibilityChanged(false); 2142 second_host->OnCursorVisibilityChanged(false);
2116 EXPECT_EQ("0 0 1", delegate.GetMouseMotionCountsAndReset()); 2143 EXPECT_EQ("0 0 1", delegate.GetMouseMotionCountsAndReset());
2117 } 2144 }
2118 2145
2119 } // namespace aura 2146 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698