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

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

Issue 23202016: Addressing sadruls comments from the previous CL https://codereview.chromium.org/22865036/ which was (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 3 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
« no previous file with comments | « ui/aura/root_window.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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
sadrul 2013/08/28 15:16:59 You should add a virtual destructor here too.
ananta 2013/08/28 18:39:10 Done.
923 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
924 EXPECT_EQ(reposted_ ? repost_target_ : repost_source_, event->target());
925 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
926 if (!reposted_) {
927 EXPECT_NE(repost_target_, event->target());
928 reposted_ = true;
929 events().clear();
930 repost_target_->GetRootWindow()->RepostEvent(*event);
931 // Ensure that the reposted gesture event above goes to the
932 // repost_target_;
933 repost_source_->GetRootWindow()->RemoveChild(repost_source_);
934 return;
935 }
936 }
937 EventFilterRecorder::OnGestureEvent(event);
938 }
939
940 // Ignore mouse events as they don't fire at all times. This causes
941 // the GestureRepostEventOrder test to fail randomly.
942 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
943 return;
sadrul 2013/08/28 15:16:59 Don't need this.
ananta 2013/08/28 18:39:10 Done.
944 }
945
946
947 private:
948 aura::Window* repost_source_;
949 aura::Window* repost_target_;
950 // set to true if we reposted the ET_GESTURE_TAP_DOWN event.
951 bool reposted_;
952 DISALLOW_COPY_AND_ASSIGN(RepostGestureEventRecorder);
953 };
954
955 // Tests whether events which are generated after the reposted gesture event
956 // are received after that. In this case the scroll sequence events should
957 // be received after the reposted gesture event.
958 TEST_F(RootWindowTest, GestureRepostEventOrder) {
959 // Expected events at the end for the repost_target window defined below.
960 const ui::EventType kExpectedTargetEvents[] = {
961 ui::ET_GESTURE_BEGIN,
962 ui::ET_GESTURE_TAP_DOWN,
963 ui::ET_TOUCH_RELEASED,
sadrul 2013/08/28 15:16:59 Do you know why we don't get a GESTURE_END here?
ananta 2013/08/28 18:39:10 If you look at the RootWindow::ProcessGestures fun
sadrul 2013/08/28 18:44:43 The first window is destroyed/removed from the Roo
964 ui::ET_TOUCH_PRESSED,
965 ui::ET_GESTURE_BEGIN,
966 ui::ET_GESTURE_TAP_DOWN,
967 ui::ET_TOUCH_MOVED,
968 ui::ET_GESTURE_TAP_CANCEL,
969 ui::ET_GESTURE_SCROLL_BEGIN,
970 ui::ET_GESTURE_SCROLL_UPDATE,
971 ui::ET_TOUCH_MOVED,
972 ui::ET_GESTURE_SCROLL_UPDATE,
973 ui::ET_TOUCH_MOVED,
974 ui::ET_GESTURE_SCROLL_UPDATE,
975 ui::ET_TOUCH_RELEASED,
976 ui::ET_GESTURE_SCROLL_END,
977 ui::ET_GESTURE_END,
978 };
979 // We create two windows.
980 // The first window (repost_source) is the one to which the initial tap
981 // gesture is sent. It reposts this event to the second window
982 // (repost_target).
983 // We then generate the scroll sequence for repost_target and look for two
984 // ET_GESTURE_TAP_DOWN events in the event list at the end.
985 test::TestWindowDelegate delegate;
986 scoped_ptr<aura::Window> repost_target(CreateTestWindowWithDelegate(
987 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window()));
988
989 scoped_ptr<aura::Window> repost_source(CreateTestWindowWithDelegate(
990 &delegate, 1, gfx::Rect(0, 0, 50, 50), root_window()));
991
992 RepostGestureEventRecorder* repost_event_recorder =
993 new RepostGestureEventRecorder(repost_source.get(), repost_target.get());
994 root_window()->SetEventFilter(repost_event_recorder); // passes ownership
995
996 // Generate a tap down gesture for the repost_source. This will be reposted
997 // to repost_target.
998 test::EventGenerator repost_generator(root_window(), repost_source.get());
999 repost_generator.GestureTapAt(gfx::Point(40, 40));
1000 RunAllPendingInMessageLoop();
1001
1002 test::EventGenerator scroll_generator(root_window(), repost_target.get());
1003 scroll_generator.GestureScrollSequence(
1004 gfx::Point(80, 80),
1005 gfx::Point(100, 100),
1006 base::TimeDelta::FromMilliseconds(100),
1007 3);
1008 RunAllPendingInMessageLoop();
1009
1010 int tap_down_count = 0;
1011 for (size_t i = 0; i < repost_event_recorder->events().size(); ++i) {
1012 if (repost_event_recorder->events()[i] == ui::ET_GESTURE_TAP_DOWN)
1013 ++tap_down_count;
1014 }
1015
1016 // We expect two tap down events. One from the repost and the other one from
1017 // the scroll sequence posted above.
1018 EXPECT_EQ(tap_down_count, 2);
1019
1020 EXPECT_EQ(repost_event_recorder->events().size(),
1021 arraysize(kExpectedTargetEvents));
1022
1023 EXPECT_EQ(memcmp(repost_event_recorder->events().data(),
1024 kExpectedTargetEvents,
1025 repost_event_recorder->events().size()), 0);
sadrul 2013/08/28 15:16:59 Please go back to using EventTypeToString (it'd be
ananta 2013/08/28 18:39:10 Done.
1026 }
1027
911 } // namespace aura 1028 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/root_window.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698