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

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: Added unit test for checking Pointer states when other than position changed. 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 radiusX, float radiusY) {
jdduke (slow) 2015/01/29 16:53:19 radius_x, radius_y.
USE s.singapati at gmail.com 2015/01/30 12:19:28 Done. My bad. made some silly mistakes.
173 touch_event_.ChangePointRadius(index, radiusX, radiusY);
jdduke (slow) 2015/01/29 16:53:19 Let's instead just modify the touch_event_ pointer
USE s.singapati at gmail.com 2015/01/30 12:19:27 Done.
174 SendTouchEvent();
175 }
176
177 void ChangeTouchPointRotationAngleAndForce(int index,
178 float rotationAngle,
jdduke (slow) 2015/01/29 16:53:19 rotation_angle
USE s.singapati at gmail.com 2015/01/30 12:19:28 Done.
179 float force) {
180 touch_event_.ChangePointRotationAngleAndForce(index, rotationAngle, force);
181 SendTouchEvent();
182 }
183
172 void ReleaseTouchPoint(int index) { 184 void ReleaseTouchPoint(int index) {
173 touch_event_.ReleasePoint(index); 185 touch_event_.ReleasePoint(index);
174 SendTouchEvent(); 186 SendTouchEvent();
175 } 187 }
176 188
177 void CancelTouchPoint(int index) { 189 void CancelTouchPoint(int index) {
178 touch_event_.CancelPoint(index); 190 touch_event_.CancelPoint(index);
179 SendTouchEvent(); 191 SendTouchEvent();
180 } 192 }
181 193
(...skipping 1715 matching lines...) Expand 10 before | Expand all | Expand 10 after
1897 // An unconsumed scroll should resume synchronous touch handling. 1909 // An unconsumed scroll should resume synchronous touch handling.
1898 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, 1910 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1899 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1911 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1900 1912
1901 // The pending touchmove should be coalesced with the next (now synchronous) 1913 // The pending touchmove should be coalesced with the next (now synchronous)
1902 // touchmove. 1914 // touchmove.
1903 MoveTouchPoint(0, 0, 25); 1915 MoveTouchPoint(0, 0, 25);
1904 EXPECT_TRUE(sent_event().cancelable); 1916 EXPECT_TRUE(sent_event().cancelable);
1905 EXPECT_FALSE(HasPendingAsyncTouchMove()); 1917 EXPECT_FALSE(HasPendingAsyncTouchMove());
1906 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); 1918 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
1907 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[0].state); 1919 EXPECT_EQ(WebTouchPoint::StateStationary, sent_event().touches[0].state);
1908 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[1].state); 1920 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[1].state);
1909 EXPECT_EQ(1U, queued_event_count()); 1921 EXPECT_EQ(1U, queued_event_count());
1910 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1922 EXPECT_EQ(1U, GetAndResetSentEventCount());
1911 EXPECT_EQ(0U, GetAndResetAckedEventCount()); 1923 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1912 1924
1913 // Subsequent touches will queue until the preceding, synchronous touches are 1925 // Subsequent touches will queue until the preceding, synchronous touches are
1914 // ack'ed. 1926 // ack'ed.
1915 ReleaseTouchPoint(1); 1927 ReleaseTouchPoint(1);
1916 EXPECT_EQ(2U, queued_event_count()); 1928 EXPECT_EQ(2U, queued_event_count());
1917 ReleaseTouchPoint(0); 1929 ReleaseTouchPoint(0);
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
2248 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 2260 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2249 2261
2250 // Give the touchmove a valid id; it should be sent. 2262 // Give the touchmove a valid id; it should be sent.
2251 event.touches[0].id = press_id; 2263 event.touches[0].id = press_id;
2252 SendTouchEvent(event); 2264 SendTouchEvent(event);
2253 EXPECT_EQ(1U, GetAndResetSentEventCount()); 2265 EXPECT_EQ(1U, GetAndResetSentEventCount());
2254 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 2266 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2255 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 2267 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2256 } 2268 }
2257 2269
2270 // Tests that touch points states are correct in TouchMove events.
2271 TEST_F(TouchEventQueueTest, PointerStatesInTouchMove) {
2272 PressTouchPoint(1, 1);
2273 PressTouchPoint(2, 2);
2274 PressTouchPoint(3, 3);
2275 PressTouchPoint(4, 4);
2276 EXPECT_EQ(4U, queued_event_count());
2277 EXPECT_EQ(1U, GetAndResetSentEventCount());
2278
2279 // Receive ACK for the first three touch-events.
2280 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2281 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2282 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2283 EXPECT_EQ(1U, queued_event_count());
2284
2285 // Test current touches state before sending TouchMoves.
2286 const WebTouchEvent& event1 = sent_event();
2287 EXPECT_EQ(WebInputEvent::TouchStart, event1.type);
2288 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[0].state);
2289 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[1].state);
2290 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[2].state);
2291 EXPECT_EQ(WebTouchPoint::StatePressed, event1.touches[3].state);
2292
2293 // Move x-position for 1st touch, y-position for 2nd touch
2294 // and do not move other touches.
2295 MoveTouchPoints(0, 1.1f, 1.f, 1, 2.f, 20.001f);
2296 MoveTouchPoints(2, 3.f, 3.f, 3, 4.f, 4.f);
2297 EXPECT_EQ(2U, queued_event_count());
2298
2299 // Receive an ACK for the last TouchPress event.
2300 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2301
2302 // 1st TouchMove is sent. Test for touches state.
2303 const WebTouchEvent& event2 = sent_event();
2304 EXPECT_EQ(WebInputEvent::TouchMove, event2.type);
2305 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[0].state);
2306 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state);
2307 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[2].state);
2308 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[3].state);
2309
2310 // Move only 4th touch but not others.
2311 MoveTouchPoints(0, 1.1f, 1.f, 1, 2.f, 20.001f);
2312 MoveTouchPoints(2, 3.f, 3.f, 3, 4.1f, 4.1f);
2313
2314 // Receive an ACK for previous (1st) TouchMove.
2315 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2316
2317 // 2nd TouchMove is sent. Test for touches state.
2318 const WebTouchEvent& event3 = sent_event();
2319 EXPECT_EQ(WebInputEvent::TouchMove, event3.type);
2320 EXPECT_EQ(WebTouchPoint::StateStationary, event3.touches[0].state);
2321 EXPECT_EQ(WebTouchPoint::StateStationary, event3.touches[1].state);
2322 EXPECT_EQ(WebTouchPoint::StateStationary, event3.touches[2].state);
2323 EXPECT_EQ(WebTouchPoint::StateMoved, event3.touches[3].state);
2324 }
2325
2326 // Tests that touch point state is correct in TouchMove events
2327 // when point properties other than position changed.
2328 TEST_F(TouchEventQueueTest, PointerStatesWhenOtherThanPositionChanged) {
2329 PressTouchPoint(1, 1);
2330 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2331
2332 // Default initial radiusX/Y is (1.f, 1.f).
2333 // Default initial rotationAngle is 1.f.
2334 // Default initial force is 1.f.
2335
2336 // Change touch point radius only.
2337 ChangeTouchPointRadius(0, 1.5f, 1.f);
2338 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2339
2340 // TouchMove is sent. Test for pointer state.
2341 const WebTouchEvent& event1 = sent_event();
2342 EXPECT_EQ(WebInputEvent::TouchMove, event1.type);
2343 EXPECT_EQ(WebTouchPoint::StateMoved, event1.touches[0].state);
2344
2345 // Change touch point force only, but not changing rotationAngle.
2346 ChangeTouchPointRotationAngleAndForce(0, 1.f, 0.9f);
2347 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2348
2349 // TouchMove is sent. Test for pointer state.
2350 const WebTouchEvent& event2 = sent_event();
2351 EXPECT_EQ(WebInputEvent::TouchMove, event2.type);
2352 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[0].state);
2353
2354 // Change touch point rotationAngle only, but not changing force.
2355 ChangeTouchPointRotationAngleAndForce(0, 1.1f, 0.9f);
2356
2357 // TouchMove is sent. Test for pointer state.
2358 const WebTouchEvent& event3 = sent_event();
2359 EXPECT_EQ(WebInputEvent::TouchMove, event3.type);
2360 EXPECT_EQ(WebTouchPoint::StateMoved, event3.touches[0].state);
2361
2362 // TODO(jdduke): Now trying to forward a TouchMove event without really
2363 // changing touch point properties. Update below test with testing for
2364 // rejected TouchMove with ack state INPUT_EVENT_ACK_STATE_NOT_CONSUMED,
2365 // crbug.com/452032. Or should it be in a separte test?.
2366
2367 // Do not change any properties, but use previous values.
2368 MoveTouchPoint(0, 1.f, 1.f);
2369 ChangeTouchPointRadius(0, 1.5f, 1.f);
2370
2371 // Receive an ACK for previous TouchMove.
2372 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2373
2374 // TouchMove is sent, but pointer state should be StateStationary.
2375 const WebTouchEvent& event4 = sent_event();
2376 EXPECT_EQ(WebInputEvent::TouchMove, event4.type);
2377 EXPECT_EQ(WebTouchPoint::StateStationary, event4.touches[0].state);
2378 }
2379
2258 } // namespace content 2380 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698