Chromium Code Reviews| 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/default_capture_client.h" | |
| 10 #include "ui/aura/client/event_client.h" | 11 #include "ui/aura/client/event_client.h" |
| 12 #include "ui/aura/client/screen_position_client.h" | |
| 11 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
| 12 #include "ui/aura/focus_manager.h" | 14 #include "ui/aura/focus_manager.h" |
| 13 #include "ui/aura/test/aura_test_base.h" | 15 #include "ui/aura/test/aura_test_base.h" |
| 14 #include "ui/aura/test/event_generator.h" | 16 #include "ui/aura/test/event_generator.h" |
| 15 #include "ui/aura/test/test_cursor_client.h" | 17 #include "ui/aura/test/test_cursor_client.h" |
| 16 #include "ui/aura/test/test_event_handler.h" | 18 #include "ui/aura/test/test_event_handler.h" |
| 19 #include "ui/aura/test/test_screen.h" | |
| 17 #include "ui/aura/test/test_window_delegate.h" | 20 #include "ui/aura/test/test_window_delegate.h" |
| 18 #include "ui/aura/test/test_windows.h" | 21 #include "ui/aura/test/test_windows.h" |
| 19 #include "ui/aura/window_tracker.h" | 22 #include "ui/aura/window_tracker.h" |
| 20 #include "ui/base/events/event.h" | 23 #include "ui/base/events/event.h" |
| 21 #include "ui/base/events/event_handler.h" | 24 #include "ui/base/events/event_handler.h" |
| 22 #include "ui/base/events/event_utils.h" | 25 #include "ui/base/events/event_utils.h" |
| 23 #include "ui/base/gestures/gesture_configuration.h" | 26 #include "ui/base/gestures/gesture_configuration.h" |
| 24 #include "ui/base/hit_test.h" | 27 #include "ui/base/hit_test.h" |
| 25 #include "ui/base/keycodes/keyboard_codes.h" | 28 #include "ui/base/keycodes/keyboard_codes.h" |
| 26 #include "ui/gfx/point.h" | 29 #include "ui/gfx/point.h" |
| (...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 ui::EventTimeForNow(), | 904 ui::EventTimeForNow(), |
| 902 details, | 905 details, |
| 903 0); | 906 0); |
| 904 root_window()->RepostEvent(event); | 907 root_window()->RepostEvent(event); |
| 905 RunAllPendingInMessageLoop(); | 908 RunAllPendingInMessageLoop(); |
| 906 EXPECT_TRUE(EventTypesToString(filter->events()).find("GESTURE_TAP_DOWN") != | 909 EXPECT_TRUE(EventTypesToString(filter->events()).find("GESTURE_TAP_DOWN") != |
| 907 std::string::npos); | 910 std::string::npos); |
| 908 filter->events().clear(); | 911 filter->events().clear(); |
| 909 } | 912 } |
| 910 | 913 |
| 914 // This class inherits from the EventFilterRecorder class which provides a | |
| 915 // facility to record events. This class additionally provides a facility to | |
| 916 // repost the ET_GESTURE_TAP_DOWN gesture to the target window and records | |
| 917 // events after that. | |
| 918 class RepostGestureEventRecorder : public EventFilterRecorder { | |
| 919 public: | |
| 920 explicit RepostGestureEventRecorder(aura::Window* repost_target) | |
| 921 : repost_target_(repost_target), | |
| 922 reposted_(false) {} | |
| 923 | |
| 924 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | |
| 925 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | |
| 926 if (!reposted_) { | |
| 927 EXPECT_NE(repost_target_, event->target()); | |
| 928 reposted_ = true; | |
| 929 repost_target_->GetRootWindow()->RepostEvent(*event); | |
| 930 return; | |
| 931 } | |
| 932 } | |
| 933 EventFilterRecorder::OnGestureEvent(event); | |
| 934 } | |
| 935 | |
| 936 private: | |
| 937 aura::Window* repost_target_; | |
| 938 // set to true if we reposted the ET_GESTURE_TAP_DOWN event. | |
| 939 bool reposted_; | |
| 940 DISALLOW_COPY_AND_ASSIGN(RepostGestureEventRecorder); | |
| 941 }; | |
| 942 | |
| 943 // Dummy screen position client implementation for the gesture repost test. | |
| 944 // We need two root windows for the repost to succeed. The AURA code assumes | |
| 945 // the existence of a screen position client if the source and target windows | |
| 946 // are in different root window hierarchies. | |
| 947 class RepostGestureDummyScreenPositionClient : | |
| 948 public aura::client::ScreenPositionClient { | |
| 949 public: | |
| 950 virtual void ConvertPointToScreen(const Window* window, | |
| 951 gfx::Point* point) OVERRIDE { | |
| 952 } | |
| 953 | |
| 954 virtual void ConvertPointFromScreen(const Window* window, | |
| 955 gfx::Point* point) OVERRIDE { | |
| 956 } | |
| 957 | |
| 958 virtual void ConvertHostPointToScreen(aura::RootWindow* root_window, | |
| 959 gfx::Point* point) OVERRIDE { | |
| 960 } | |
| 961 | |
| 962 virtual void SetBounds(Window* window, | |
| 963 const gfx::Rect& bounds, | |
| 964 const gfx::Display& display) { | |
| 965 } | |
| 966 }; | |
| 967 | |
| 968 // Tests whether events which are generated after the reposted gesture event | |
| 969 // are received after that. In this case the scroll sequence events should | |
| 970 // be received after the reposted gesture event. | |
| 971 TEST_F(RootWindowTest, GestureRepostEventOrder) { | |
| 972 // We create two windows in different root window hierarchies. The | |
|
sadrul
2013/08/26 17:07:18
Can you explain why it is necessary to create two
ananta
2013/08/26 19:19:03
As per our discussion, changed the test to only us
| |
| 973 // window (repost_window) is the one to which the initial tap gesture is | |
| 974 // sent. It reposts this event to the second window (window2) below. We then | |
| 975 // generate the scroll sequence for window 2 and validate the event list at | |
| 976 // the end. | |
| 977 test::TestWindowDelegate delegate; | |
| 978 scoped_ptr<aura::Window> repost_window(CreateTestWindowWithDelegate( | |
| 979 &delegate, 1, gfx::Rect(0, 0, 50, 50), root_window())); | |
| 980 | |
| 981 scoped_ptr<TestScreen> test_screen; | |
| 982 test_screen.reset(TestScreen::Create()); | |
| 983 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get()); | |
| 984 scoped_ptr<aura::RootWindow> root_window2; | |
| 985 root_window2.reset(test_screen->CreateRootWindowForPrimaryDisplay()); | |
| 986 | |
| 987 aura::Window* window2 = CreateTestWindowWithDelegate( | |
| 988 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window2.get()); | |
| 989 | |
| 990 RepostGestureEventRecorder* event_recorder = | |
| 991 new RepostGestureEventRecorder(window2); | |
| 992 root_window()->SetEventFilter(event_recorder); // passes ownership | |
| 993 | |
| 994 EventFilterRecorder* root_window2_filter = new EventFilterRecorder; | |
| 995 root_window2->SetEventFilter(root_window2_filter); // passes ownership | |
| 996 | |
| 997 // Dummy screen position client. Needed to avoid a crash | |
| 998 scoped_ptr<RepostGestureDummyScreenPositionClient> screen_pos_client1; | |
| 999 screen_pos_client1.reset(new RepostGestureDummyScreenPositionClient); | |
| 1000 scoped_ptr<RepostGestureDummyScreenPositionClient> screen_pos_client2; | |
| 1001 screen_pos_client2.reset(new RepostGestureDummyScreenPositionClient); | |
| 1002 | |
| 1003 aura::client::SetScreenPositionClient(root_window(), | |
| 1004 screen_pos_client1.get()); | |
| 1005 aura::client::SetScreenPositionClient(root_window2.get(), | |
| 1006 screen_pos_client2.get()); | |
| 1007 | |
| 1008 // Dummy capture client. Needed to avoid a crash | |
| 1009 scoped_ptr<aura::client::DefaultCaptureClient> capture_client2; | |
| 1010 capture_client2.reset(new aura::client::DefaultCaptureClient( | |
| 1011 root_window2.get())); | |
| 1012 | |
| 1013 // Generate a tap down gesture for the source window. This will be reposted | |
| 1014 // to window 2. | |
| 1015 test::EventGenerator repost_generator(root_window(), repost_window.get()); | |
| 1016 repost_generator.GestureTapAt(gfx::Point(40, 40)); | |
| 1017 RunAllPendingInMessageLoop(); | |
| 1018 | |
| 1019 test::EventGenerator scroll_generator(root_window2.get(), window2); | |
| 1020 scroll_generator.GestureScrollSequence( | |
| 1021 gfx::Point(80, 80), | |
| 1022 gfx::Point(100, 100), | |
| 1023 base::TimeDelta::FromMilliseconds(100), | |
| 1024 3); | |
| 1025 RunAllPendingInMessageLoop(); | |
| 1026 | |
| 1027 std::string event_string = EventTypesToString(root_window2_filter->events()); | |
| 1028 DLOG(INFO) << "Event types: " << event_string; | |
| 1029 | |
| 1030 int tap_down_count = 0; | |
| 1031 for (size_t i = 0; i < root_window2_filter->events().size(); ++i) { | |
| 1032 if (root_window2_filter->events()[i] == ui::ET_GESTURE_TAP_DOWN) | |
| 1033 ++tap_down_count; | |
| 1034 } | |
| 1035 | |
| 1036 aura::client::SetScreenPositionClient(root_window(), NULL); | |
| 1037 aura::client::SetScreenPositionClient(root_window2.get(), NULL); | |
| 1038 | |
| 1039 capture_client2.reset(NULL); | |
| 1040 root_window2.reset(NULL); | |
| 1041 screen_pos_client1.reset(); | |
| 1042 screen_pos_client2.reset(NULL); | |
| 1043 | |
| 1044 // We expect two tap down events. One from the repost and the other one from | |
| 1045 // the scroll sequence posted above. | |
| 1046 EXPECT_EQ(tap_down_count, 2); | |
| 1047 } | |
| 1048 | |
| 911 } // namespace aura | 1049 } // namespace aura |
| OLD | NEW |