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

Side by Side Diff: ash/drag_drop/drag_drop_controller_unittest.cc

Issue 16463002: Change ordering of Shell event handlers: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | « ash/drag_drop/drag_drop_controller.cc ('k') | ash/shell.cc » ('j') | 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 "ash/drag_drop/drag_drop_controller.h" 5 #include "ash/drag_drop/drag_drop_controller.h"
6 6
7 #include "ash/drag_drop/drag_drop_tracker.h" 7 #include "ash/drag_drop/drag_drop_tracker.h"
8 #include "ash/drag_drop/drag_image_view.h" 8 #include "ash/drag_drop/drag_image_view.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
(...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 CompleteCancelAnimation(); 1101 CompleteCancelAnimation();
1102 1102
1103 EXPECT_EQ("405,405", observer.window_location_on_destroying().ToString()); 1103 EXPECT_EQ("405,405", observer.window_location_on_destroying().ToString());
1104 } 1104 }
1105 for (Shell::RootWindowList::iterator iter = root_windows.begin(); 1105 for (Shell::RootWindowList::iterator iter = root_windows.begin();
1106 iter != root_windows.end(); ++iter) { 1106 iter != root_windows.end(); ++iter) {
1107 aura::client::SetDragDropClient(*iter, NULL); 1107 aura::client::SetDragDropClient(*iter, NULL);
1108 } 1108 }
1109 } 1109 }
1110 1110
1111 class SimpleEventHandler : public ui::EventHandler {
1112 public:
1113 SimpleEventHandler()
1114 : handled_event_received_(false),
1115 unhandled_event_received_(false) {
1116 ash::Shell::GetInstance()->PrependPreTargetHandler(this);
1117 }
1118
1119 virtual ~SimpleEventHandler() {
1120 ash::Shell::GetInstance()->RemovePreTargetHandler(this);
1121 }
1122
1123 bool handled_event_received() { return handled_event_received_; }
1124 bool unhandled_event_received() { return unhandled_event_received_; }
1125
1126 void Reset() {
1127 handled_event_received_ = false;
1128 unhandled_event_received_ = false;
1129 }
1130
1131 private:
1132 // Overridden from ui::EventHandler.
1133 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
1134 if (event->handled())
1135 handled_event_received_ = true;
1136 else
1137 unhandled_event_received_ = true;
1138 }
1139
1140 bool handled_event_received_;
1141 bool unhandled_event_received_;
1142
1143 DISALLOW_COPY_AND_ASSIGN(SimpleEventHandler);
1144 };
1145
1146 TEST_F(DragDropControllerTest,
1147 DragDropControllerReceivesAllEventsDuringDragDrop) {
1148 CommandLine::ForCurrentProcess()->AppendSwitch(
1149 switches::kEnableTouchDragDrop);
1150 scoped_ptr<views::Widget> widget(CreateNewWidget());
1151 DragTestView* drag_view = new DragTestView;
1152 AddViewToWidgetAndResize(widget.get(), drag_view);
1153 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1154 widget->GetNativeView());
1155 ui::OSExchangeData data;
1156 data.SetString(UTF8ToUTF16("I am being dragged"));
1157 SimpleEventHandler handler;
1158
1159 // Since we are not in drag/drop, |handler| should receive unhandled events.
1160 generator.PressTouch();
1161 gfx::Point point = gfx::Rect(drag_view->bounds()).CenterPoint();
1162 handler.Reset();
1163 DispatchGesture(ui::ET_GESTURE_LONG_PRESS, point);
1164 EXPECT_TRUE(handler.unhandled_event_received());
1165 EXPECT_FALSE(handler.handled_event_received());
1166
1167 EXPECT_TRUE(drag_drop_controller_->drag_start_received_);
1168
1169 // Since dragging has started, |handler| should not receive unhandled events.
1170 UpdateDragData(&data);
1171 gfx::Point gesture_location = point;
1172 int num_drags = drag_view->width();
1173 for (int i = 0; i < num_drags; ++i) {
1174 gesture_location.Offset(1, 0);
1175 handler.Reset();
1176 DispatchGesture(ui::ET_GESTURE_SCROLL_UPDATE, gesture_location);
1177 EXPECT_FALSE(handler.handled_event_received());
1178 EXPECT_FALSE(handler.unhandled_event_received());
1179
1180 // Execute any scheduled draws to process deferred mouse events.
1181 RunAllPendingInMessageLoop();
1182 }
1183
1184 // Handler should not receive any other gestures that DragDropController
1185 // does not care about.
1186 std::set<ui::EventType> drag_drop_gestures;
1187 drag_drop_gestures.insert(ui::ET_GESTURE_SCROLL_UPDATE);
1188 drag_drop_gestures.insert(ui::ET_GESTURE_SCROLL_END);
1189 drag_drop_gestures.insert(ui::ET_GESTURE_LONG_TAP);
1190 drag_drop_gestures.insert(ui::ET_SCROLL_FLING_START);
1191 for (ui::EventType type = ui::ET_UNKNOWN; type < ui::ET_LAST;
1192 type = static_cast<ui::EventType>(type + 1)) {
1193 if (!IsGestureEventType(type) ||
1194 drag_drop_gestures.find(type) != drag_drop_gestures.end())
1195 continue;
1196
1197 handler.Reset();
1198 DispatchGesture(ui::ET_GESTURE_SCROLL_UPDATE, gesture_location);
1199 EXPECT_FALSE(handler.handled_event_received());
1200 EXPECT_FALSE(handler.unhandled_event_received());
1201
1202 // Execute any scheduled draws to process deferred mouse events.
1203 RunAllPendingInMessageLoop();
1204 }
1205
1206 // End dragging.
1207 DispatchGesture(ui::ET_GESTURE_SCROLL_END, gesture_location);
1208 EXPECT_TRUE(drag_drop_controller_->drop_received_);
1209 }
1210
1211 } // namespace test 1111 } // namespace test
1212 } // namespace aura 1112 } // namespace aura
OLDNEW
« no previous file with comments | « ash/drag_drop/drag_drop_controller.cc ('k') | ash/shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698