OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/input/touch_selection_controller.h" | 5 #include "content/browser/renderer_host/input/touch_selection_controller.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/events/test/mock_motion_event.h" | 8 #include "ui/events/test/mock_motion_event.h" |
9 | 9 |
10 using ui::test::MockMotionEvent; | 10 using ui::test::MockMotionEvent; |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 controller().OnSelectionEditable(true); | 367 controller().OnSelectionEditable(true); |
368 SetDraggingEnabled(true); | 368 SetDraggingEnabled(true); |
369 | 369 |
370 gfx::RectF start_rect(10, 0, 0, 10); | 370 gfx::RectF start_rect(10, 0, 0, 10); |
371 bool visible = true; | 371 bool visible = true; |
372 ChangeInsertion(start_rect, visible); | 372 ChangeInsertion(start_rect, visible); |
373 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 373 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
374 | 374 |
375 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 375 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
376 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 376 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
377 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 377 //TODO(AKV): this test case has to be modified once crbug.com/394093 is fixed. |
| 378 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); |
378 | 379 |
379 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); | 380 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); |
380 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 381 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
381 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType()); | 382 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType()); |
382 | 383 |
383 // Reset the insertion. | 384 // Reset the insertion. |
384 ClearInsertion(); | 385 ClearInsertion(); |
385 controller().OnTapEvent(); | 386 controller().OnTapEvent(); |
386 ChangeInsertion(start_rect, visible); | 387 ChangeInsertion(start_rect, visible); |
387 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); | 388 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); |
388 | 389 |
389 // No tap should be signalled if the time between DOWN and UP was too long. | 390 // No tap should be signalled if the time between DOWN and UP was too long. |
390 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 391 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
391 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 392 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
392 event = MockMotionEvent(MockMotionEvent::ACTION_UP, | 393 event = MockMotionEvent(MockMotionEvent::ACTION_UP, |
393 event_time + base::TimeDelta::FromSeconds(1), | 394 event_time + base::TimeDelta::FromSeconds(1), |
394 0, | 395 0, |
395 0); | 396 0); |
396 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 397 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
397 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 398 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); |
398 | 399 |
399 // Reset the insertion. | 400 // Reset the insertion. |
400 ClearInsertion(); | 401 ClearInsertion(); |
401 controller().OnTapEvent(); | 402 controller().OnTapEvent(); |
402 ChangeInsertion(start_rect, visible); | 403 ChangeInsertion(start_rect, visible); |
403 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); | 404 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); |
404 | 405 |
405 // No tap should be signalled if the touch sequence is cancelled. | 406 // No tap should be signalled if the touch sequence is cancelled. |
406 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 407 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
407 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 408 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
408 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); | 409 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); |
409 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 410 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
410 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 411 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); |
411 } | 412 } |
412 | 413 |
413 TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) { | 414 TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) { |
414 base::TimeTicks event_time = base::TimeTicks::Now(); | 415 base::TimeTicks event_time = base::TimeTicks::Now(); |
415 controller().OnTapEvent(); | 416 controller().OnTapEvent(); |
416 controller().OnSelectionEditable(true); | 417 controller().OnSelectionEditable(true); |
417 SetDraggingEnabled(true); | 418 SetDraggingEnabled(true); |
418 | 419 |
419 gfx::RectF anchor_rect(10, 0, 0, 10); | 420 gfx::RectF anchor_rect(10, 0, 0, 10); |
420 bool visible = true; | 421 bool visible = true; |
421 ChangeInsertion(anchor_rect, visible); | 422 ChangeInsertion(anchor_rect, visible); |
422 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 423 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
423 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 424 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
424 | 425 |
425 // Tapping again shouldn't reset the active insertion point. | 426 // Tapping again shouldn't reset the active insertion point. |
426 controller().OnTapEvent(); | 427 controller().OnTapEvent(); |
427 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 428 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
428 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 429 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
429 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 430 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); |
430 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 431 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
431 | 432 |
432 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); | 433 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); |
433 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 434 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
434 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType()); | 435 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType()); |
435 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 436 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
436 | 437 |
437 anchor_rect.Offset(5, 15); | 438 anchor_rect.Offset(5, 15); |
438 ChangeInsertion(anchor_rect, visible); | 439 ChangeInsertion(anchor_rect, visible); |
439 EXPECT_EQ(INSERTION_MOVED, GetLastEventType()); | 440 EXPECT_EQ(INSERTION_MOVED, GetLastEventType()); |
440 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 441 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
441 | 442 |
442 // Pressing shouldn't reset the active insertion point. | 443 // Pressing shouldn't reset the active insertion point. |
443 controller().OnLongPressEvent(); | 444 controller().OnLongPressEvent(); |
444 controller().OnSelectionEmpty(true); | 445 controller().OnSelectionEmpty(true); |
445 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 446 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
446 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 447 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
447 EXPECT_EQ(INSERTION_MOVED, GetLastEventType()); | 448 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); |
448 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 449 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
449 | 450 |
450 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); | 451 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); |
451 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 452 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
452 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType()); | 453 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType()); |
453 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 454 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); |
454 } | 455 } |
455 | 456 |
456 TEST_F(TouchSelectionControllerTest, SelectionBasic) { | 457 TEST_F(TouchSelectionControllerTest, SelectionBasic) { |
457 gfx::RectF start_rect(5, 5, 0, 10); | 458 gfx::RectF start_rect(5, 5, 0, 10); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 | 619 |
619 visible = true; | 620 visible = true; |
620 ChangeInsertion(insertion_rect, visible); | 621 ChangeInsertion(insertion_rect, visible); |
621 EXPECT_FALSE(GetAndResetNeedsAnimate()); | 622 EXPECT_FALSE(GetAndResetNeedsAnimate()); |
622 | 623 |
623 controller().SetTemporarilyHidden(false); | 624 controller().SetTemporarilyHidden(false); |
624 EXPECT_TRUE(GetAndResetNeedsAnimate()); | 625 EXPECT_TRUE(GetAndResetNeedsAnimate()); |
625 } | 626 } |
626 | 627 |
627 } // namespace content | 628 } // namespace content |
OLD | NEW |