OLD | NEW |
---|---|
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 "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/aura/client/event_client.h" | 10 #include "ui/aura/client/event_client.h" |
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
901 ui::EventTimeForNow(), | 901 ui::EventTimeForNow(), |
902 details, | 902 details, |
903 0); | 903 0); |
904 root_window()->RepostEvent(event); | 904 root_window()->RepostEvent(event); |
905 RunAllPendingInMessageLoop(); | 905 RunAllPendingInMessageLoop(); |
906 EXPECT_TRUE(EventTypesToString(filter->events()).find("GESTURE_TAP_DOWN") != | 906 EXPECT_TRUE(EventTypesToString(filter->events()).find("GESTURE_TAP_DOWN") != |
907 std::string::npos); | 907 std::string::npos); |
908 filter->events().clear(); | 908 filter->events().clear(); |
909 } | 909 } |
910 | 910 |
911 // This class inherits from the EventFilterRecorder class which provides a | |
912 // facility to record events. This class additionally provides a facility to | |
913 // repost the ET_GESTURE_TAP_DOWN gesture to the target window and records | |
914 // events after that. | |
915 class RepostGestureEventRecorder : public EventFilterRecorder { | |
916 public: | |
917 explicit RepostGestureEventRecorder(aura::Window* repost_target) | |
918 : repost_target_(repost_target), | |
919 reposted_(false) {} | |
920 | |
921 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | |
922 if (event->type() == ui::ET_GESTURE_TAP_DOWN && !reposted_) { | |
923 // We are about to repost here. We clear out the events recorded until | |
924 // now. This helps in detecting whether the events are recieved in the | |
925 // correct order at the end, i.e Reposted event first followed by the | |
926 // rest. | |
927 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.
| |
928 reposted_ = true; | |
929 repost_target_->GetRootWindow()->RepostEvent(*event); | |
930 return; | |
931 } | |
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
| |
932 EventFilterRecorder::OnGestureEvent(event); | |
933 } | |
934 | |
935 private: | |
936 aura::Window* repost_target_; | |
937 bool reposted_; | |
938 | |
939 DISALLOW_COPY_AND_ASSIGN(RepostGestureEventRecorder); | |
940 }; | |
941 | |
942 // Tests whether events which are generated after the reposted gesture event | |
943 // are received after that. In this case the scroll sequence events should | |
944 // be received after the reposted gesture event. | |
945 TEST_F(RootWindowTest, GestureRepostEventOrder) { | |
946 // Expected events at the end for the target window. The first three events | |
947 // are the reposted ones and the rest are for the scroll gesture. | |
948 const char kExpectedEventOrder[] = | |
949 "GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_RELEASED TOUCH_PRESSED" | |
950 " GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_MOVED GESTURE_SCROLL_BEGIN" | |
951 " GESTURE_SCROLL_UPDATE TOUCH_MOVED GESTURE_SCROLL_UPDATE TOUCH_MOVED" | |
952 " GESTURE_SCROLL_UPDATE TOUCH_RELEASED GESTURE_SCROLL_END GESTURE_END"; | |
953 | |
954 // We create two windows. The first window (repost_window) is the one to | |
955 // which the initial tap gesture is sent. It reposts this event to the | |
956 // second window (window2) below. We then generate the scroll sequence for | |
957 // window 2 and validate the event list at the end. | |
958 test::TestWindowDelegate delegate; | |
959 scoped_ptr<aura::Window> repost_window(CreateTestWindowWithDelegate( | |
960 &delegate, 1, gfx::Rect(0, 0, 50, 50), root_window())); | |
961 | |
962 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( | |
963 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); | |
964 | |
965 RepostGestureEventRecorder* event_recorder = | |
966 new RepostGestureEventRecorder(window2.get()); | |
967 root_window()->SetEventFilter(event_recorder); // passes ownership | |
968 | |
969 test::EventGenerator repost_generator(root_window(), repost_window.get()); | |
970 repost_generator.GestureTapAt(gfx::Point(40, 40)); | |
971 | |
972 test::EventGenerator scroll_generator(root_window(), window2.get()); | |
973 scroll_generator.GestureScrollSequence( | |
974 gfx::Point(60, 60), | |
975 gfx::Point(90, 90), | |
976 base::TimeDelta::FromMilliseconds(100), | |
977 3); | |
978 | |
979 EXPECT_TRUE(EventTypesToString(event_recorder->events()) == | |
980 kExpectedEventOrder); | |
981 } | |
982 | |
911 } // namespace aura | 983 } // namespace aura |
OLD | NEW |