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

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 explicit RepostGestureEventRecorder(aura::Window* repost_source,
sadrul 2013/08/26 19:52:50 remove 'explicit'
ananta 2013/08/26 21:23:16 Done.
918 aura::Window* repost_target)
919 : repost_source_(repost_source),
920 repost_target_(repost_target),
921 reposted_(false) {}
922
923 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
924 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
925 if (!reposted_) {
926 EXPECT_NE(repost_target_, event->target());
927 reposted_ = true;
928 EXPECT_EQ(static_cast<aura::Window*>(event->target()), repost_source_);
929 repost_target_->GetRootWindow()->RepostEvent(*event);
930 // Ensure that the reposted gesture event above goes to the
931 // repost_target_;
932 repost_source_->GetRootWindow()->RemoveChild(repost_source_);
933 return;
934 } else {
935 EXPECT_EQ(static_cast<aura::Window*>(event->target()), repost_target_);
sadrul 2013/08/26 19:52:50 This should be outside of the == TAP_DOWN check in
ananta 2013/08/26 21:23:16 Done.
936 }
937 }
938 EventFilterRecorder::OnGestureEvent(event);
939 }
940
941 private:
942 aura::Window* repost_source_;
943 aura::Window* repost_target_;
944 // set to true if we reposted the ET_GESTURE_TAP_DOWN event.
945 bool reposted_;
946 DISALLOW_COPY_AND_ASSIGN(RepostGestureEventRecorder);
947 };
948
949 // Tests whether events which are generated after the reposted gesture event
950 // are received after that. In this case the scroll sequence events should
951 // be received after the reposted gesture event.
952 TEST_F(RootWindowTest, GestureRepostEventOrder) {
953 // We create two windows.
954 // The first window (repost_source) is the one to which the initial tap
955 // gesture is sent. It reposts this event to the second window
956 // (repost_target).
957 // We then generate the scroll sequence for repost_target and look for two
958 // ET_GESTURE_TAP_DOWN events in the event list at the end.
959 test::TestWindowDelegate delegate;
960 scoped_ptr<aura::Window> repost_target(CreateTestWindowWithDelegate(
961 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window()));
962
963 scoped_ptr<aura::Window> repost_source(CreateTestWindowWithDelegate(
964 &delegate, 1, gfx::Rect(0, 0, 50, 50), root_window()));
965
966 RepostGestureEventRecorder* repost_event_recorder =
967 new RepostGestureEventRecorder(repost_source.get(), repost_target.get());
968 root_window()->SetEventFilter(repost_event_recorder); // passes ownership
969
970 // Generate a tap down gesture for the repost_source. This will be reposted
971 // to repost_target.
972 test::EventGenerator repost_generator(root_window(), repost_source.get());
973 repost_generator.GestureTapAt(gfx::Point(40, 40));
974 RunAllPendingInMessageLoop();
975
976 test::EventGenerator scroll_generator(root_window(), repost_target.get());
977 scroll_generator.GestureScrollSequence(
978 gfx::Point(80, 80),
979 gfx::Point(100, 100),
980 base::TimeDelta::FromMilliseconds(100),
981 3);
982 RunAllPendingInMessageLoop();
983
984 std::string event_string = EventTypesToString(
985 repost_event_recorder->events());
986 DLOG(INFO) << "Event types: " << event_string;
sadrul 2013/08/26 19:52:50 We shouldn't add this in the log.
ananta 2013/08/26 21:23:16 Done.
987
988 int tap_down_count = 0;
989 for (size_t i = 0; i < repost_event_recorder->events().size(); ++i) {
990 if (repost_event_recorder->events()[i] == ui::ET_GESTURE_TAP_DOWN)
991 ++tap_down_count;
992 }
993
994 // We expect two tap down events. One from the repost and the other one from
995 // the scroll sequence posted above.
996 EXPECT_EQ(tap_down_count, 2);
sadrul 2013/08/26 19:52:50 Why did we switch from checking the sequence of ev
ananta 2013/08/26 21:23:16 I removed that with a comment in the gcl upload in
997 }
998
911 } // namespace aura 999 } // 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