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

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

Issue 148453012: Chrome requires WebTouchPoint to store WebFloatPoint, instead of WebPoint. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address jdduke's comments. Created 6 years, 9 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 | « no previous file | content/browser/renderer_host/input/touch_event_queue.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 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/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "content/browser/renderer_host/input/synthetic_gesture.h" 8 #include "content/browser/renderer_host/input/synthetic_gesture.h"
9 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" 9 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h"
10 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" 10 #include "content/browser/renderer_host/input/synthetic_gesture_target.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 204
205 virtual void DispatchInputEventToPlatform( 205 virtual void DispatchInputEventToPlatform(
206 const WebInputEvent& event) OVERRIDE { 206 const WebInputEvent& event) OVERRIDE {
207 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); 207 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type));
208 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); 208 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event);
209 ASSERT_EQ(touch_event.touchesLength, 2U); 209 ASSERT_EQ(touch_event.touchesLength, 2U);
210 210
211 if (!started_) { 211 if (!started_) {
212 ASSERT_EQ(touch_event.type, WebInputEvent::TouchStart); 212 ASSERT_EQ(touch_event.type, WebInputEvent::TouchStart);
213 213
214 start_0_ = gfx::PointF(touch_event.touches[0].position.x, 214 start_0_ = gfx::PointF(touch_event.touches[0].position);
215 touch_event.touches[0].position.y); 215 start_1_ = gfx::PointF(touch_event.touches[1].position);
216 start_1_ = gfx::PointF(touch_event.touches[1].position.x,
217 touch_event.touches[1].position.y);
218 last_pointer_distance_ = (start_0_ - start_1_).Length(); 216 last_pointer_distance_ = (start_0_ - start_1_).Length();
219 217
220 started_ = true; 218 started_ = true;
221 } else { 219 } else {
222 ASSERT_NE(touch_event.type, WebInputEvent::TouchStart); 220 ASSERT_NE(touch_event.type, WebInputEvent::TouchStart);
223 ASSERT_NE(touch_event.type, WebInputEvent::TouchCancel); 221 ASSERT_NE(touch_event.type, WebInputEvent::TouchCancel);
224 222
225 gfx::PointF current_0 = gfx::PointF(touch_event.touches[0].position.x, 223 gfx::PointF current_0 = gfx::PointF(touch_event.touches[0].position);
226 touch_event.touches[0].position.y); 224 gfx::PointF current_1 = gfx::PointF(touch_event.touches[1].position);
227 gfx::PointF current_1 = gfx::PointF(touch_event.touches[1].position.x,
228 touch_event.touches[1].position.y);
229 225
230 total_num_pixels_covered_ = 226 total_num_pixels_covered_ =
231 (current_0 - start_0_).Length() + (current_1 - start_1_).Length(); 227 (current_0 - start_0_).Length() + (current_1 - start_1_).Length();
232 float pointer_distance = (current_0 - current_1).Length(); 228 float pointer_distance = (current_0 - current_1).Length();
233 229
234 if (last_pointer_distance_ != pointer_distance) { 230 if (last_pointer_distance_ != pointer_distance) {
235 if (zoom_direction_ == ZOOM_DIRECTION_UNKNOWN) 231 if (zoom_direction_ == ZOOM_DIRECTION_UNKNOWN)
236 zoom_direction_ = 232 zoom_direction_ =
237 ComputeZoomDirection(last_pointer_distance_, pointer_distance); 233 ComputeZoomDirection(last_pointer_distance_, pointer_distance);
238 else 234 else
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 gfx::PointF position() const { return position_; } 269 gfx::PointF position() const { return position_; }
274 base::TimeDelta GetDuration() const { return stop_time_ - start_time_; } 270 base::TimeDelta GetDuration() const { return stop_time_ - start_time_; }
275 271
276 protected: 272 protected:
277 enum GestureState { 273 enum GestureState {
278 NOT_STARTED, 274 NOT_STARTED,
279 STARTED, 275 STARTED,
280 FINISHED 276 FINISHED
281 }; 277 };
282 278
283 // TODO(tdresser): clean up accesses to position_ once WebTouchPoint stores
284 // its location as a WebFloatPoint. See crbug.com/336807.
285 gfx::PointF position_; 279 gfx::PointF position_;
286 base::TimeDelta start_time_; 280 base::TimeDelta start_time_;
287 base::TimeDelta stop_time_; 281 base::TimeDelta stop_time_;
288 GestureState state_; 282 GestureState state_;
289 }; 283 };
290 284
291 class MockSyntheticTapTouchTarget : public MockSyntheticTapGestureTarget { 285 class MockSyntheticTapTouchTarget : public MockSyntheticTapGestureTarget {
292 public: 286 public:
293 MockSyntheticTapTouchTarget() {} 287 MockSyntheticTapTouchTarget() {}
294 virtual ~MockSyntheticTapTouchTarget() {} 288 virtual ~MockSyntheticTapTouchTarget() {}
295 289
296 virtual void DispatchInputEventToPlatform( 290 virtual void DispatchInputEventToPlatform(
297 const WebInputEvent& event) OVERRIDE { 291 const WebInputEvent& event) OVERRIDE {
298 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); 292 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type));
299 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); 293 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event);
300 ASSERT_EQ(touch_event.touchesLength, 1U); 294 ASSERT_EQ(touch_event.touchesLength, 1U);
301 295
302 switch (state_) { 296 switch (state_) {
303 case NOT_STARTED: 297 case NOT_STARTED:
304 EXPECT_EQ(touch_event.type, WebInputEvent::TouchStart); 298 EXPECT_EQ(touch_event.type, WebInputEvent::TouchStart);
305 position_ = gfx::PointF(touch_event.touches[0].position.x, 299 position_ = gfx::PointF(touch_event.touches[0].position);
306 touch_event.touches[0].position.y);
307 start_time_ = base::TimeDelta::FromMilliseconds( 300 start_time_ = base::TimeDelta::FromMilliseconds(
308 static_cast<int64>(touch_event.timeStampSeconds * 1000)); 301 static_cast<int64>(touch_event.timeStampSeconds * 1000));
309 state_ = STARTED; 302 state_ = STARTED;
310 break; 303 break;
311 case STARTED: 304 case STARTED:
312 EXPECT_EQ(touch_event.type, WebInputEvent::TouchEnd); 305 EXPECT_EQ(touch_event.type, WebInputEvent::TouchEnd);
313 EXPECT_EQ(position_, gfx::PointF(touch_event.touches[0].position.x, 306 EXPECT_EQ(position_, gfx::PointF(touch_event.touches[0].position));
314 touch_event.touches[0].position.y));
315 stop_time_ = base::TimeDelta::FromMilliseconds( 307 stop_time_ = base::TimeDelta::FromMilliseconds(
316 static_cast<int64>(touch_event.timeStampSeconds * 1000)); 308 static_cast<int64>(touch_event.timeStampSeconds * 1000));
317 state_ = FINISHED; 309 state_ = FINISHED;
318 break; 310 break;
319 case FINISHED: 311 case FINISHED:
320 EXPECT_FALSE(true); 312 EXPECT_FALSE(true);
321 break; 313 break;
322 } 314 }
323 } 315 }
324 }; 316 };
325 317
326 class MockSyntheticTapMouseTarget : public MockSyntheticTapGestureTarget { 318 class MockSyntheticTapMouseTarget : public MockSyntheticTapGestureTarget {
327 public: 319 public:
328 MockSyntheticTapMouseTarget() {} 320 MockSyntheticTapMouseTarget() {}
329 virtual ~MockSyntheticTapMouseTarget() {} 321 virtual ~MockSyntheticTapMouseTarget() {}
330 322
331 virtual void DispatchInputEventToPlatform( 323 virtual void DispatchInputEventToPlatform(
332 const WebInputEvent& event) OVERRIDE { 324 const WebInputEvent& event) OVERRIDE {
333 ASSERT_TRUE(WebInputEvent::isMouseEventType(event.type)); 325 ASSERT_TRUE(WebInputEvent::isMouseEventType(event.type));
334 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); 326 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event);
335 327
336 switch (state_) { 328 switch (state_) {
337 case NOT_STARTED: 329 case NOT_STARTED:
338 EXPECT_EQ(mouse_event.type, WebInputEvent::MouseDown); 330 EXPECT_EQ(mouse_event.type, WebInputEvent::MouseDown);
339 EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft); 331 EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft);
340 EXPECT_EQ(mouse_event.clickCount, 1); 332 EXPECT_EQ(mouse_event.clickCount, 1);
341 position_ = gfx::Point(mouse_event.x, mouse_event.y); 333 position_ = gfx::PointF(mouse_event.x, mouse_event.y);
342 start_time_ = base::TimeDelta::FromMilliseconds( 334 start_time_ = base::TimeDelta::FromMilliseconds(
343 static_cast<int64>(mouse_event.timeStampSeconds * 1000)); 335 static_cast<int64>(mouse_event.timeStampSeconds * 1000));
344 state_ = STARTED; 336 state_ = STARTED;
345 break; 337 break;
346 case STARTED: 338 case STARTED:
347 EXPECT_EQ(mouse_event.type, WebInputEvent::MouseUp); 339 EXPECT_EQ(mouse_event.type, WebInputEvent::MouseUp);
348 EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft); 340 EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft);
349 EXPECT_EQ(mouse_event.clickCount, 1); 341 EXPECT_EQ(mouse_event.clickCount, 1);
350 EXPECT_EQ(position_, gfx::Point(mouse_event.x, mouse_event.y)); 342 EXPECT_EQ(position_, gfx::PointF(mouse_event.x, mouse_event.y));
351 stop_time_ = base::TimeDelta::FromMilliseconds( 343 stop_time_ = base::TimeDelta::FromMilliseconds(
352 static_cast<int64>(mouse_event.timeStampSeconds * 1000)); 344 static_cast<int64>(mouse_event.timeStampSeconds * 1000));
353 state_ = FINISHED; 345 state_ = FINISHED;
354 break; 346 break;
355 case FINISHED: 347 case FINISHED:
356 EXPECT_FALSE(true); 348 EXPECT_FALSE(true);
357 break; 349 break;
358 } 350 }
359 } 351 }
360 }; 352 };
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 EXPECT_TRUE(tap_target->GestureFinished()); 949 EXPECT_TRUE(tap_target->GestureFinished());
958 EXPECT_EQ(tap_target->position(), params.position); 950 EXPECT_EQ(tap_target->position(), params.position);
959 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); 951 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms);
960 EXPECT_GE(GetTotalTime(), 952 EXPECT_GE(GetTotalTime(),
961 base::TimeDelta::FromMilliseconds(params.duration_ms)); 953 base::TimeDelta::FromMilliseconds(params.duration_ms));
962 } 954 }
963 955
964 } // namespace 956 } // namespace
965 957
966 } // namespace content 958 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/input/touch_event_queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698