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 RepostGestureEventRecorder(aura::Window* repost_source, |
| 918 aura::Window* repost_target) |
| 919 : repost_source_(repost_source), |
| 920 repost_target_(repost_target), |
| 921 reposted_(false) {} |
| 922 |
| 923 virtual ~RepostGestureEventRecorder() {} |
| 924 |
| 925 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { |
| 926 EXPECT_EQ(reposted_ ? repost_target_ : repost_source_, event->target()); |
| 927 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
| 928 if (!reposted_) { |
| 929 EXPECT_NE(repost_target_, event->target()); |
| 930 reposted_ = true; |
| 931 events().clear(); |
| 932 repost_target_->GetRootWindow()->RepostEvent(*event); |
| 933 // Ensure that the reposted gesture event above goes to the |
| 934 // repost_target_; |
| 935 repost_source_->GetRootWindow()->RemoveChild(repost_source_); |
| 936 return; |
| 937 } |
| 938 } |
| 939 EventFilterRecorder::OnGestureEvent(event); |
| 940 } |
| 941 |
| 942 // Ignore mouse events as they don't fire at all times. This causes |
| 943 // the GestureRepostEventOrder test to fail randomly. |
| 944 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {} |
| 945 |
| 946 private: |
| 947 aura::Window* repost_source_; |
| 948 aura::Window* repost_target_; |
| 949 // set to true if we reposted the ET_GESTURE_TAP_DOWN event. |
| 950 bool reposted_; |
| 951 DISALLOW_COPY_AND_ASSIGN(RepostGestureEventRecorder); |
| 952 }; |
| 953 |
| 954 // Tests whether events which are generated after the reposted gesture event |
| 955 // are received after that. In this case the scroll sequence events should |
| 956 // be received after the reposted gesture event. |
| 957 TEST_F(RootWindowTest, GestureRepostEventOrder) { |
| 958 // Expected events at the end for the repost_target window defined below. |
| 959 const char kExpectedTargetEvents[] = "GESTURE_BEGIN GESTURE_TAP_DOWN " |
| 960 "TOUCH_RELEASED TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_MOVED " |
| 961 " GESTURE_SCROLL_BEGIN GESTURE_SCROLL_UPDATE TOUCH_MOVED " |
| 962 "GESTURE_SCROLL_UPDATE TOUCH_MOVED GESTURE_SCROLL_UPDATE TOUCH_RELEASED " |
| 963 "GESTURE_SCROLL_END GESTURE_END"; |
| 964 // We create two windows. |
| 965 // The first window (repost_source) is the one to which the initial tap |
| 966 // gesture is sent. It reposts this event to the second window |
| 967 // (repost_target). |
| 968 // We then generate the scroll sequence for repost_target and look for two |
| 969 // ET_GESTURE_TAP_DOWN events in the event list at the end. |
| 970 test::TestWindowDelegate delegate; |
| 971 scoped_ptr<aura::Window> repost_target(CreateTestWindowWithDelegate( |
| 972 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 973 |
| 974 scoped_ptr<aura::Window> repost_source(CreateTestWindowWithDelegate( |
| 975 &delegate, 1, gfx::Rect(0, 0, 50, 50), root_window())); |
| 976 |
| 977 RepostGestureEventRecorder* repost_event_recorder = |
| 978 new RepostGestureEventRecorder(repost_source.get(), repost_target.get()); |
| 979 root_window()->SetEventFilter(repost_event_recorder); // passes ownership |
| 980 |
| 981 // Generate a tap down gesture for the repost_source. This will be reposted |
| 982 // to repost_target. |
| 983 test::EventGenerator repost_generator(root_window(), repost_source.get()); |
| 984 repost_generator.GestureTapAt(gfx::Point(40, 40)); |
| 985 RunAllPendingInMessageLoop(); |
| 986 |
| 987 test::EventGenerator scroll_generator(root_window(), repost_target.get()); |
| 988 scroll_generator.GestureScrollSequence( |
| 989 gfx::Point(80, 80), |
| 990 gfx::Point(100, 100), |
| 991 base::TimeDelta::FromMilliseconds(100), |
| 992 3); |
| 993 RunAllPendingInMessageLoop(); |
| 994 |
| 995 int tap_down_count = 0; |
| 996 for (size_t i = 0; i < repost_event_recorder->events().size(); ++i) { |
| 997 if (repost_event_recorder->events()[i] == ui::ET_GESTURE_TAP_DOWN) |
| 998 ++tap_down_count; |
| 999 } |
| 1000 |
| 1001 // We expect two tap down events. One from the repost and the other one from |
| 1002 // the scroll sequence posted above. |
| 1003 EXPECT_EQ(tap_down_count, 2); |
| 1004 |
| 1005 EXPECT_EQ(kExpectedTargetEvents, |
| 1006 EventTypesToString(repost_event_recorder->events())); |
| 1007 } |
| 1008 |
911 } // namespace aura | 1009 } // namespace aura |
OLD | NEW |