Index: ui/aura/root_window_unittest.cc |
=================================================================== |
--- ui/aura/root_window_unittest.cc (revision 219190) |
+++ ui/aura/root_window_unittest.cc (working copy) |
@@ -908,4 +908,76 @@ |
filter->events().clear(); |
} |
+// This class inherits from the EventFilterRecorder class which provides a |
+// facility to record events. This class additionally provides a facility to |
+// repost the ET_GESTURE_TAP_DOWN gesture to the target window and records |
+// events after that. |
+class RepostGestureEventRecorder : public EventFilterRecorder { |
+ public: |
+ explicit RepostGestureEventRecorder(aura::Window* repost_target) |
+ : repost_target_(repost_target), |
+ reposted_(false) {} |
+ |
+ virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { |
+ if (event->type() == ui::ET_GESTURE_TAP_DOWN && !reposted_) { |
+ // We are about to repost here. We clear out the events recorded until |
+ // now. This helps in detecting whether the events are recieved in the |
+ // correct order at the end, i.e Reposted event first followed by the |
+ // rest. |
+ events().clear(); |
sadrul
2013/08/23 15:00:06
We should verify that repost_target_ is not alread
ananta
2013/08/23 20:27:32
Done.
|
+ reposted_ = true; |
+ repost_target_->GetRootWindow()->RepostEvent(*event); |
+ return; |
+ } |
sadrul
2013/08/23 15:00:06
We should also add:
if (reposted_)
EXPECT_EQ
ananta
2013/08/23 20:27:32
I had to redo the test as we need different root w
|
+ EventFilterRecorder::OnGestureEvent(event); |
+ } |
+ |
+ private: |
+ aura::Window* repost_target_; |
+ bool reposted_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(RepostGestureEventRecorder); |
+}; |
+ |
+// Tests whether events which are generated after the reposted gesture event |
+// are received after that. In this case the scroll sequence events should |
+// be received after the reposted gesture event. |
+TEST_F(RootWindowTest, GestureRepostEventOrder) { |
+ // Expected events at the end for the target window. The first three events |
+ // are the reposted ones and the rest are for the scroll gesture. |
+ const char kExpectedEventOrder[] = |
+ "GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_RELEASED TOUCH_PRESSED" |
+ " GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_MOVED GESTURE_SCROLL_BEGIN" |
+ " GESTURE_SCROLL_UPDATE TOUCH_MOVED GESTURE_SCROLL_UPDATE TOUCH_MOVED" |
+ " GESTURE_SCROLL_UPDATE TOUCH_RELEASED GESTURE_SCROLL_END GESTURE_END"; |
+ |
+ // We create two windows. The first window (repost_window) is the one to |
+ // which the initial tap gesture is sent. It reposts this event to the |
+ // second window (window2) below. We then generate the scroll sequence for |
+ // window 2 and validate the event list at the end. |
+ test::TestWindowDelegate delegate; |
+ scoped_ptr<aura::Window> repost_window(CreateTestWindowWithDelegate( |
+ &delegate, 1, gfx::Rect(0, 0, 50, 50), root_window())); |
+ |
+ scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( |
+ &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
+ |
+ RepostGestureEventRecorder* event_recorder = |
+ new RepostGestureEventRecorder(window2.get()); |
+ root_window()->SetEventFilter(event_recorder); // passes ownership |
+ |
+ test::EventGenerator repost_generator(root_window(), repost_window.get()); |
+ repost_generator.GestureTapAt(gfx::Point(40, 40)); |
+ |
+ test::EventGenerator scroll_generator(root_window(), window2.get()); |
+ scroll_generator.GestureScrollSequence( |
+ gfx::Point(60, 60), |
+ gfx::Point(90, 90), |
+ base::TimeDelta::FromMilliseconds(100), |
+ 3); |
+ |
+ EXPECT_TRUE(EventTypesToString(event_recorder->events()) == |
+ kExpectedEventOrder); |
+} |
+ |
} // namespace aura |