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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_aura_unittest.cc

Issue 1120293003: Make sure send one WebTouchEvent ack per ui::TouchEvent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.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 "content/browser/renderer_host/render_widget_host_view_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 FakeWindowEventDispatcher(aura::WindowTreeHost* host) 216 FakeWindowEventDispatcher(aura::WindowTreeHost* host)
217 : WindowEventDispatcher(host), 217 : WindowEventDispatcher(host),
218 processed_touch_event_count_(0) {} 218 processed_touch_event_count_(0) {}
219 219
220 void ProcessedTouchEvent(aura::Window* window, 220 void ProcessedTouchEvent(aura::Window* window,
221 ui::EventResult result) override { 221 ui::EventResult result) override {
222 WindowEventDispatcher::ProcessedTouchEvent(window, result); 222 WindowEventDispatcher::ProcessedTouchEvent(window, result);
223 processed_touch_event_count_++; 223 processed_touch_event_count_++;
224 } 224 }
225 225
226 size_t processed_touch_event_count() { 226 size_t GetAndResetProcessedTouchEventCount() {
227 return processed_touch_event_count_; 227 size_t count = processed_touch_event_count_;
228 processed_touch_event_count_ = 0;
229 return count;
228 } 230 }
229 231
230 private: 232 private:
231 size_t processed_touch_event_count_; 233 size_t processed_touch_event_count_;
232 }; 234 };
233 235
234 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura { 236 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura {
235 public: 237 public:
236 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget, 238 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget,
237 bool is_guest_view_hack) 239 bool is_guest_view_hack)
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 EXPECT_EQ(blink::WebTouchPoint::StateMoved, 1119 EXPECT_EQ(blink::WebTouchPoint::StateMoved,
1118 view_->touch_event_->touches[0].state); 1120 view_->touch_event_->touches[0].state);
1119 1121
1120 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(20, 20), 0, 1122 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(20, 20), 0,
1121 base::Time::NowFromSystemTime() - base::Time()); 1123 base::Time::NowFromSystemTime() - base::Time());
1122 view_->OnTouchEvent(&release2); 1124 view_->OnTouchEvent(&release2);
1123 EXPECT_TRUE(press.synchronous_handling_disabled()); 1125 EXPECT_TRUE(press.synchronous_handling_disabled());
1124 EXPECT_EQ(nullptr, view_->touch_event_); 1126 EXPECT_EQ(nullptr, view_->touch_event_);
1125 } 1127 }
1126 1128
1129 // Checks that touch-event state is maintained correctly for multiple touch
1130 // points.
1131 TEST_F(RenderWidgetHostViewAuraTest, MultiTouchPointsStates) {
1132 view_->InitAsFullscreen(parent_view_);
1133 view_->Show();
1134 view_->UseFakeDispatcher();
1135 GetSentMessageCountAndResetSink();
1136
1137 ui::TouchEvent press0(ui::ET_TOUCH_PRESSED, gfx::Point(30, 30), 0,
1138 ui::EventTimeForNow());
1139
1140 view_->OnTouchEvent(&press0);
1141 SendInputEventACK(blink::WebInputEvent::TouchStart,
1142 INPUT_EVENT_ACK_STATE_CONSUMED);
1143 EXPECT_EQ(blink::WebInputEvent::TouchStart, view_->touch_event_->type);
1144 EXPECT_EQ(1U, view_->touch_event_->touchesLength);
1145 EXPECT_EQ(1U, view_->dispatcher_->GetAndResetProcessedTouchEventCount());
1146
1147 ui::TouchEvent move0(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), 0,
1148 ui::EventTimeForNow());
1149
1150 view_->OnTouchEvent(&move0);
1151 SendInputEventACK(blink::WebInputEvent::TouchMove,
1152 INPUT_EVENT_ACK_STATE_CONSUMED);
1153 EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_->type);
1154 EXPECT_EQ(1U, view_->touch_event_->touchesLength);
1155 EXPECT_EQ(1U, view_->dispatcher_->GetAndResetProcessedTouchEventCount());
1156
1157 // For the second touchstart, only the state of the second touch point is
1158 // StatePressed, the state of the first touch point is StateStationary.
1159 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1,
1160 ui::EventTimeForNow());
1161
1162 view_->OnTouchEvent(&press1);
1163 SendInputEventACK(blink::WebInputEvent::TouchStart,
1164 INPUT_EVENT_ACK_STATE_CONSUMED);
1165 EXPECT_EQ(blink::WebInputEvent::TouchStart, view_->touch_event_->type);
1166 EXPECT_EQ(2U, view_->touch_event_->touchesLength);
1167 EXPECT_EQ(1U, view_->dispatcher_->GetAndResetProcessedTouchEventCount());
1168
1169 // For the touchmove of second point, the state of the second touch point is
1170 // StateMoved, the state of the first touch point is StateStationary.
1171 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(30, 30), 1,
1172 ui::EventTimeForNow());
1173
1174 view_->OnTouchEvent(&move1);
1175 SendInputEventACK(blink::WebInputEvent::TouchMove,
1176 INPUT_EVENT_ACK_STATE_CONSUMED);
1177 EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_->type);
1178 EXPECT_EQ(2U, view_->touch_event_->touchesLength);
1179 EXPECT_EQ(1U, view_->dispatcher_->GetAndResetProcessedTouchEventCount());
1180
1181 // For the touchmove of first point, the state of the first touch point is
1182 // StateMoved, the state of the second touch point is StateStationary.
1183 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(10, 10), 0,
1184 ui::EventTimeForNow());
1185
1186 view_->OnTouchEvent(&move2);
1187 SendInputEventACK(blink::WebInputEvent::TouchMove,
1188 INPUT_EVENT_ACK_STATE_CONSUMED);
1189 EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_->type);
1190 EXPECT_EQ(2U, view_->touch_event_->touchesLength);
1191 EXPECT_EQ(1U, view_->dispatcher_->GetAndResetProcessedTouchEventCount());
1192
1193 ui::TouchEvent cancel0(ui::ET_TOUCH_CANCELLED, gfx::Point(10, 10), 0,
1194 ui::EventTimeForNow());
1195
1196 // For the touchcancel, only the state of the current touch point is
1197 // StateCancelled, the state of the other touch point is StateStationary.
1198 view_->OnTouchEvent(&cancel0);
1199 EXPECT_EQ(blink::WebInputEvent::TouchCancel, view_-> touch_event_->type);
1200 EXPECT_EQ(1U, view_->touch_event_->touchesLength);
1201 EXPECT_EQ(1U, view_->dispatcher_->GetAndResetProcessedTouchEventCount());
1202
1203 ui::TouchEvent cancel1(ui::ET_TOUCH_CANCELLED, gfx::Point(30, 30), 1,
1204 ui::EventTimeForNow());
1205
1206 view_->OnTouchEvent(&cancel1);
1207 EXPECT_EQ(1U, view_->dispatcher_->GetAndResetProcessedTouchEventCount());
1208 EXPECT_EQ(nullptr, view_->touch_event_);
1209 }
1210
1127 // Checks that touch-events are queued properly when there is a touch-event 1211 // Checks that touch-events are queued properly when there is a touch-event
1128 // handler on the page. 1212 // handler on the page.
1129 TEST_F(RenderWidgetHostViewAuraTest, TouchEventSyncAsync) { 1213 TEST_F(RenderWidgetHostViewAuraTest, TouchEventSyncAsync) {
1130 view_->InitAsChild(NULL); 1214 view_->InitAsChild(NULL);
1131 view_->Show(); 1215 view_->Show();
1132 1216
1133 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); 1217 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
1134 1218
1135 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, 1219 ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
1136 gfx::Point(30, 30), 1220 gfx::Point(30, 30),
(...skipping 2177 matching lines...) Expand 10 before | Expand all | Expand 10 after
3314 view_->OnTouchEvent(&press1); 3398 view_->OnTouchEvent(&press1);
3315 SendInputEventACK(blink::WebInputEvent::TouchStart, 3399 SendInputEventACK(blink::WebInputEvent::TouchStart,
3316 INPUT_EVENT_ACK_STATE_CONSUMED); 3400 INPUT_EVENT_ACK_STATE_CONSUMED);
3317 3401
3318 ui::TouchEvent press2( 3402 ui::TouchEvent press2(
3319 ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 1, ui::EventTimeForNow()); 3403 ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 1, ui::EventTimeForNow());
3320 view_->OnTouchEvent(&press2); 3404 view_->OnTouchEvent(&press2);
3321 SendInputEventACK(blink::WebInputEvent::TouchStart, 3405 SendInputEventACK(blink::WebInputEvent::TouchStart,
3322 INPUT_EVENT_ACK_STATE_CONSUMED); 3406 INPUT_EVENT_ACK_STATE_CONSUMED);
3323 3407
3324 EXPECT_EQ(2U, view_->dispatcher_->processed_touch_event_count()); 3408 EXPECT_EQ(2U, view_->dispatcher_->GetAndResetProcessedTouchEventCount());
3325 } 3409 }
3326 3410
3327 // Tests that the scroll deltas stored within the overscroll controller get 3411 // Tests that the scroll deltas stored within the overscroll controller get
3328 // reset at the end of the overscroll gesture even if the overscroll threshold 3412 // reset at the end of the overscroll gesture even if the overscroll threshold
3329 // isn't surpassed and the overscroll mode stays OVERSCROLL_NONE. 3413 // isn't surpassed and the overscroll mode stays OVERSCROLL_NONE.
3330 TEST_F(RenderWidgetHostViewAuraOverscrollTest, ScrollDeltasResetOnEnd) { 3414 TEST_F(RenderWidgetHostViewAuraOverscrollTest, ScrollDeltasResetOnEnd) {
3331 SetUpOverscrollEnvironment(); 3415 SetUpOverscrollEnvironment();
3332 // Wheel event scroll ending with mouse move. 3416 // Wheel event scroll ending with mouse move.
3333 SimulateWheelEvent(-30, -10, 0, true); // sent directly 3417 SimulateWheelEvent(-30, -10, 0, true); // sent directly
3334 SendInputEventACK(WebInputEvent::MouseWheel, 3418 SendInputEventACK(WebInputEvent::MouseWheel,
(...skipping 28 matching lines...) Expand all
3363 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 3447 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
3364 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); 3448 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
3365 EXPECT_EQ(15.f, overscroll_delta_x()); 3449 EXPECT_EQ(15.f, overscroll_delta_x());
3366 EXPECT_EQ(-5.f, overscroll_delta_y()); 3450 EXPECT_EQ(-5.f, overscroll_delta_y());
3367 SimulateGestureFlingStartEvent(0.f, 0.1f, blink::WebGestureDeviceTouchpad); 3451 SimulateGestureFlingStartEvent(0.f, 0.1f, blink::WebGestureDeviceTouchpad);
3368 EXPECT_EQ(0.f, overscroll_delta_x()); 3452 EXPECT_EQ(0.f, overscroll_delta_x());
3369 EXPECT_EQ(0.f, overscroll_delta_y()); 3453 EXPECT_EQ(0.f, overscroll_delta_y());
3370 } 3454 }
3371 3455
3372 } // namespace content 3456 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698