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

Side by Side Diff: content/browser/renderer_host/input/touch_event_queue_unittest.cc

Issue 788923002: Touch Events - changedTouches list includes non-changed touch points on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 10 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "content/browser/renderer_host/input/timeout_monitor.h" 9 #include "content/browser/renderer_host/input/timeout_monitor.h"
10 #include "content/browser/renderer_host/input/touch_event_queue.h" 10 #include "content/browser/renderer_host/input/touch_event_queue.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 float x0, 162 float x0,
163 float y0, 163 float y0,
164 int index1, 164 int index1,
165 float x1, 165 float x1,
166 float y1) { 166 float y1) {
167 touch_event_.MovePoint(index0, x0, y0); 167 touch_event_.MovePoint(index0, x0, y0);
168 touch_event_.MovePoint(index1, x1, y1); 168 touch_event_.MovePoint(index1, x1, y1);
169 SendTouchEvent(); 169 SendTouchEvent();
170 } 170 }
171 171
172 void ChangeTouchPointRadius(int index, float radius_x, float radius_y) {
173 CHECK_GE(index, 0);
174 CHECK_LT(index, touch_event_.touchesLengthCap);
175 WebTouchPoint& point = touch_event_.touches[index];
176 point.radiusX = radius_x;
177 point.radiusY = radius_y;
178 touch_event_.touches[index].state = WebTouchPoint::StateMoved;
179 touch_event_.causesScrollingIfUncanceled = true;
180 WebTouchEventTraits::ResetType(WebInputEvent::TouchMove,
181 touch_event_.timeStampSeconds,
182 &touch_event_);
183 SendTouchEvent();
184 }
185
186 void ChangeTouchPointRotationAngle(int index, float rotation_angle) {
187 CHECK_GE(index, 0);
188 CHECK_LT(index, touch_event_.touchesLengthCap);
189 WebTouchPoint& point = touch_event_.touches[index];
190 point.rotationAngle = rotation_angle;
191 touch_event_.touches[index].state = WebTouchPoint::StateMoved;
192 touch_event_.causesScrollingIfUncanceled = true;
193 WebTouchEventTraits::ResetType(WebInputEvent::TouchMove,
194 touch_event_.timeStampSeconds,
195 &touch_event_);
196 SendTouchEvent();
197 }
198
199 void ChangeTouchPointForce(int index, float force) {
200 CHECK_GE(index, 0);
201 CHECK_LT(index, touch_event_.touchesLengthCap);
202 WebTouchPoint& point = touch_event_.touches[index];
203 point.force = force;
204 touch_event_.touches[index].state = WebTouchPoint::StateMoved;
205 touch_event_.causesScrollingIfUncanceled = true;
206 WebTouchEventTraits::ResetType(WebInputEvent::TouchMove,
207 touch_event_.timeStampSeconds,
208 &touch_event_);
209 SendTouchEvent();
210 }
211
172 void ReleaseTouchPoint(int index) { 212 void ReleaseTouchPoint(int index) {
173 touch_event_.ReleasePoint(index); 213 touch_event_.ReleasePoint(index);
174 SendTouchEvent(); 214 SendTouchEvent();
175 } 215 }
176 216
177 void CancelTouchPoint(int index) { 217 void CancelTouchPoint(int index) {
178 touch_event_.CancelPoint(index); 218 touch_event_.CancelPoint(index);
179 SendTouchEvent(); 219 SendTouchEvent();
180 } 220 }
181 221
(...skipping 1705 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 // An unconsumed scroll should resume synchronous touch handling. 1927 // An unconsumed scroll should resume synchronous touch handling.
1888 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, 1928 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1889 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1929 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1890 1930
1891 // The pending touchmove should be coalesced with the next (now synchronous) 1931 // The pending touchmove should be coalesced with the next (now synchronous)
1892 // touchmove. 1932 // touchmove.
1893 MoveTouchPoint(0, 0, 25); 1933 MoveTouchPoint(0, 0, 25);
1894 EXPECT_TRUE(sent_event().cancelable); 1934 EXPECT_TRUE(sent_event().cancelable);
1895 EXPECT_FALSE(HasPendingAsyncTouchMove()); 1935 EXPECT_FALSE(HasPendingAsyncTouchMove());
1896 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); 1936 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
1897 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[0].state); 1937 EXPECT_EQ(WebTouchPoint::StateStationary, sent_event().touches[0].state);
1898 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[1].state); 1938 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[1].state);
1899 EXPECT_EQ(1U, queued_event_count()); 1939 EXPECT_EQ(1U, queued_event_count());
1900 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1940 EXPECT_EQ(1U, GetAndResetSentEventCount());
1901 EXPECT_EQ(0U, GetAndResetAckedEventCount()); 1941 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1902 1942
1903 // Subsequent touches will queue until the preceding, synchronous touches are 1943 // Subsequent touches will queue until the preceding, synchronous touches are
1904 // ack'ed. 1944 // ack'ed.
1905 ReleaseTouchPoint(1); 1945 ReleaseTouchPoint(1);
1906 EXPECT_EQ(2U, queued_event_count()); 1946 EXPECT_EQ(2U, queued_event_count());
1907 ReleaseTouchPoint(0); 1947 ReleaseTouchPoint(0);
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
2293 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 2333 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2294 2334
2295 // Give the touchmove a valid id; it should be sent. 2335 // Give the touchmove a valid id; it should be sent.
2296 event.touches[0].id = press_id; 2336 event.touches[0].id = press_id;
2297 SendTouchEvent(event); 2337 SendTouchEvent(event);
2298 EXPECT_EQ(1U, GetAndResetSentEventCount()); 2338 EXPECT_EQ(1U, GetAndResetSentEventCount());
2299 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 2339 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2300 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 2340 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2301 } 2341 }
2302 2342
2343 // Tests that touch points states are correct in TouchMove events.
2344 TEST_F(TouchEventQueueTest, PointerStatesInTouchMove) {
2345 PressTouchPoint(1, 1);
2346 PressTouchPoint(2, 2);
2347 PressTouchPoint(3, 3);
2348 PressTouchPoint(4, 4);
2349 EXPECT_EQ(4U, queued_event_count());
2350 EXPECT_EQ(1U, GetAndResetSentEventCount());
2351
2352 // Receive ACK for the first three touch-events.
2353 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2354 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2355 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2356 EXPECT_EQ(1U, queued_event_count());
2357
2358 // Test current touches state before sending TouchMoves.
2359 const WebTouchEvent& event1 = sent_event();
2360 EXPECT_EQ(WebInputEvent::TouchStart, event1.type);
2361 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[0].state);
2362 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[1].state);
2363 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[2].state);
2364 EXPECT_EQ(WebTouchPoint::StatePressed, event1.touches[3].state);
2365
2366 // Move x-position for 1st touch, y-position for 2nd touch
2367 // and do not move other touches.
2368 MoveTouchPoints(0, 1.1f, 1.f, 1, 2.f, 20.001f);
2369 MoveTouchPoints(2, 3.f, 3.f, 3, 4.f, 4.f);
2370 EXPECT_EQ(2U, queued_event_count());
2371
2372 // Receive an ACK for the last TouchPress event.
2373 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2374
2375 // 1st TouchMove is sent. Test for touches state.
2376 const WebTouchEvent& event2 = sent_event();
2377 EXPECT_EQ(WebInputEvent::TouchMove, event2.type);
2378 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[0].state);
2379 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state);
2380 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[2].state);
2381 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[3].state);
2382
2383 // Move only 4th touch but not others.
2384 MoveTouchPoints(0, 1.1f, 1.f, 1, 2.f, 20.001f);
2385 MoveTouchPoints(2, 3.f, 3.f, 3, 4.1f, 4.1f);
2386
2387 // Receive an ACK for previous (1st) TouchMove.
2388 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2389
2390 // 2nd TouchMove is sent. Test for touches state.
2391 const WebTouchEvent& event3 = sent_event();
2392 EXPECT_EQ(WebInputEvent::TouchMove, event3.type);
2393 EXPECT_EQ(WebTouchPoint::StateStationary, event3.touches[0].state);
2394 EXPECT_EQ(WebTouchPoint::StateStationary, event3.touches[1].state);
2395 EXPECT_EQ(WebTouchPoint::StateStationary, event3.touches[2].state);
2396 EXPECT_EQ(WebTouchPoint::StateMoved, event3.touches[3].state);
2397 }
2398
2399 // Tests that touch point state is correct in TouchMove events
2400 // when point properties other than position changed.
2401 TEST_F(TouchEventQueueTest, PointerStatesWhenOtherThanPositionChanged) {
2402 PressTouchPoint(1, 1);
2403 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2404
2405 // Default initial radiusX/Y is (1.f, 1.f).
2406 // Default initial rotationAngle is 1.f.
2407 // Default initial force is 1.f.
2408
2409 // Change touch point radius only.
2410 ChangeTouchPointRadius(0, 1.5f, 1.f);
2411 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2412
2413 // TouchMove is sent. Test for pointer state.
2414 const WebTouchEvent& event1 = sent_event();
2415 EXPECT_EQ(WebInputEvent::TouchMove, event1.type);
2416 EXPECT_EQ(WebTouchPoint::StateMoved, event1.touches[0].state);
2417
2418 // Change touch point force.
2419 ChangeTouchPointForce(0, 0.9f);
2420 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2421
2422 // TouchMove is sent. Test for pointer state.
2423 const WebTouchEvent& event2 = sent_event();
2424 EXPECT_EQ(WebInputEvent::TouchMove, event2.type);
2425 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[0].state);
2426
2427 // Change touch point rotationAngle.
2428 ChangeTouchPointRotationAngle(0, 1.1f);
2429
2430 // TouchMove is sent. Test for pointer state.
2431 const WebTouchEvent& event3 = sent_event();
2432 EXPECT_EQ(WebInputEvent::TouchMove, event3.type);
2433 EXPECT_EQ(WebTouchPoint::StateMoved, event3.touches[0].state);
2434
2435 // TODO(jdduke): Now trying to forward a TouchMove event without really
2436 // changing touch point properties. Update below test with testing for
2437 // rejected TouchMove with ack state INPUT_EVENT_ACK_STATE_NOT_CONSUMED,
2438 // crbug.com/452032. Or should it be in a separte test?.
2439
2440 // Do not change any properties, but use previous values.
2441 MoveTouchPoint(0, 1.f, 1.f);
2442 ChangeTouchPointRadius(0, 1.5f, 1.f);
2443
2444 // Receive an ACK for previous TouchMove.
2445 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2446
2447 // TouchMove is sent, but pointer state should be StateStationary.
2448 const WebTouchEvent& event4 = sent_event();
2449 EXPECT_EQ(WebInputEvent::TouchMove, event4.type);
2450 EXPECT_EQ(WebTouchPoint::StateStationary, event4.touches[0].state);
2451 }
2452
2303 } // namespace content 2453 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/touch_event_queue.cc ('k') | content/common/input/synthetic_web_input_event_builders.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698