| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/time/time.h" | 6 #include "base/time/time.h" |
| 7 #include "content/browser/renderer_host/input/synthetic_gesture.h" | 7 #include "content/browser/renderer_host/input/synthetic_gesture.h" |
| 8 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" | 8 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" |
| 9 #include "content/browser/renderer_host/input/synthetic_pointer_action.h" | 9 #include "content/browser/renderer_host/input/synthetic_pointer_action.h" |
| 10 #include "content/browser/renderer_host/input/synthetic_touch_pointer.h" | 10 #include "content/browser/renderer_host/input/synthetic_touch_pointer.h" |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 action_param_list_->push_back(params); | 379 action_param_list_->push_back(params); |
| 380 ForwardSyntheticPointerAction(); | 380 ForwardSyntheticPointerAction(); |
| 381 | 381 |
| 382 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = | 382 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = |
| 383 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get()); | 383 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get()); |
| 384 EXPECT_EQ(1, num_success_); | 384 EXPECT_EQ(1, num_success_); |
| 385 EXPECT_EQ(0, num_failure_); | 385 EXPECT_EQ(0, num_failure_); |
| 386 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); | 386 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); |
| 387 EXPECT_EQ(pointer_mouse_target->position(), params.position()); | 387 EXPECT_EQ(pointer_mouse_target->position(), params.position()); |
| 388 EXPECT_EQ(pointer_mouse_target->clickCount(), 0); | 388 EXPECT_EQ(pointer_mouse_target->clickCount(), 0); |
| 389 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonNone); | 389 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::NoButton); |
| 390 | 390 |
| 391 // Send a mouse down. | 391 // Send a mouse down. |
| 392 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); | 392 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); |
| 393 params.set_position(gfx::PointF(189, 62)); | 393 params.set_position(gfx::PointF(189, 62)); |
| 394 params.set_pointer_action_type( | 394 params.set_pointer_action_type( |
| 395 SyntheticPointerActionParams::PointerActionType::PRESS); | 395 SyntheticPointerActionParams::PointerActionType::PRESS); |
| 396 action_param_list_->push_back(params); | 396 action_param_list_->push_back(params); |
| 397 ForwardSyntheticPointerAction(); | 397 ForwardSyntheticPointerAction(); |
| 398 | 398 |
| 399 EXPECT_EQ(2, num_success_); | 399 EXPECT_EQ(2, num_success_); |
| 400 EXPECT_EQ(0, num_failure_); | 400 EXPECT_EQ(0, num_failure_); |
| 401 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); | 401 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); |
| 402 EXPECT_EQ(pointer_mouse_target->position(), params.position()); | 402 EXPECT_EQ(pointer_mouse_target->position(), params.position()); |
| 403 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); | 403 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
| 404 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft); | 404 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); |
| 405 | 405 |
| 406 // Send a mouse drag. | 406 // Send a mouse drag. |
| 407 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); | 407 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); |
| 408 params.set_position(gfx::PointF(326, 298)); | 408 params.set_position(gfx::PointF(326, 298)); |
| 409 params.set_pointer_action_type( | 409 params.set_pointer_action_type( |
| 410 SyntheticPointerActionParams::PointerActionType::MOVE); | 410 SyntheticPointerActionParams::PointerActionType::MOVE); |
| 411 action_param_list_->push_back(params); | 411 action_param_list_->push_back(params); |
| 412 ForwardSyntheticPointerAction(); | 412 ForwardSyntheticPointerAction(); |
| 413 | 413 |
| 414 EXPECT_EQ(3, num_success_); | 414 EXPECT_EQ(3, num_success_); |
| 415 EXPECT_EQ(0, num_failure_); | 415 EXPECT_EQ(0, num_failure_); |
| 416 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); | 416 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); |
| 417 EXPECT_EQ(pointer_mouse_target->position(), params.position()); | 417 EXPECT_EQ(pointer_mouse_target->position(), params.position()); |
| 418 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); | 418 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
| 419 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft); | 419 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); |
| 420 | 420 |
| 421 // Send a mouse up. | 421 // Send a mouse up. |
| 422 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); | 422 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); |
| 423 params.set_pointer_action_type( | 423 params.set_pointer_action_type( |
| 424 SyntheticPointerActionParams::PointerActionType::RELEASE); | 424 SyntheticPointerActionParams::PointerActionType::RELEASE); |
| 425 action_param_list_->push_back(params); | 425 action_param_list_->push_back(params); |
| 426 ForwardSyntheticPointerAction(); | 426 ForwardSyntheticPointerAction(); |
| 427 | 427 |
| 428 EXPECT_EQ(4, num_success_); | 428 EXPECT_EQ(4, num_success_); |
| 429 EXPECT_EQ(0, num_failure_); | 429 EXPECT_EQ(0, num_failure_); |
| 430 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseUp); | 430 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseUp); |
| 431 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); | 431 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
| 432 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft); | 432 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); |
| 433 } | 433 } |
| 434 | 434 |
| 435 TEST_F(SyntheticPointerActionTest, PointerMouseActionSourceTypeInvalid) { | 435 TEST_F(SyntheticPointerActionTest, PointerMouseActionSourceTypeInvalid) { |
| 436 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>(); | 436 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>(); |
| 437 | 437 |
| 438 // Users' gesture source type does not match with the mouse action. | 438 // Users' gesture source type does not match with the mouse action. |
| 439 SyntheticPointerActionParams params = SyntheticPointerActionParams( | 439 SyntheticPointerActionParams params = SyntheticPointerActionParams( |
| 440 SyntheticPointerActionParams::PointerActionType::PRESS); | 440 SyntheticPointerActionParams::PointerActionType::PRESS); |
| 441 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 441 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| 442 params.set_index(0); | 442 params.set_index(0); |
| 443 params.set_position(gfx::PointF(54, 89)); | 443 params.set_position(gfx::PointF(54, 89)); |
| 444 action_param_list_->push_back(params); | 444 action_param_list_->push_back(params); |
| 445 ForwardSyntheticPointerAction(); | 445 ForwardSyntheticPointerAction(); |
| 446 | 446 |
| 447 EXPECT_EQ(0, num_success_); | 447 EXPECT_EQ(0, num_success_); |
| 448 EXPECT_EQ(1, num_failure_); | 448 EXPECT_EQ(1, num_failure_); |
| 449 | 449 |
| 450 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); | 450 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); |
| 451 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | 451 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; |
| 452 action_param_list_->push_back(params); | 452 action_param_list_->push_back(params); |
| 453 ForwardSyntheticPointerAction(); | 453 ForwardSyntheticPointerAction(); |
| 454 | 454 |
| 455 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = | 455 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = |
| 456 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get()); | 456 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get()); |
| 457 EXPECT_EQ(1, num_success_); | 457 EXPECT_EQ(1, num_success_); |
| 458 EXPECT_EQ(1, num_failure_); | 458 EXPECT_EQ(1, num_failure_); |
| 459 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); | 459 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); |
| 460 EXPECT_EQ(pointer_mouse_target->position(), params.position()); | 460 EXPECT_EQ(pointer_mouse_target->position(), params.position()); |
| 461 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); | 461 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
| 462 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft); | 462 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); |
| 463 } | 463 } |
| 464 | 464 |
| 465 TEST_F(SyntheticPointerActionTest, PointerMouseActionTypeInvalid) { | 465 TEST_F(SyntheticPointerActionTest, PointerMouseActionTypeInvalid) { |
| 466 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>(); | 466 CreateSyntheticPointerActionTarget<MockSyntheticPointerMouseActionTarget>(); |
| 467 | 467 |
| 468 // Send a mouse move. | 468 // Send a mouse move. |
| 469 SyntheticPointerActionParams params = SyntheticPointerActionParams( | 469 SyntheticPointerActionParams params = SyntheticPointerActionParams( |
| 470 SyntheticPointerActionParams::PointerActionType::MOVE); | 470 SyntheticPointerActionParams::PointerActionType::MOVE); |
| 471 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | 471 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; |
| 472 params.set_index(0); | 472 params.set_index(0); |
| 473 params.set_position(gfx::PointF(189, 62)); | 473 params.set_position(gfx::PointF(189, 62)); |
| 474 action_param_list_->push_back(params); | 474 action_param_list_->push_back(params); |
| 475 ForwardSyntheticPointerAction(); | 475 ForwardSyntheticPointerAction(); |
| 476 | 476 |
| 477 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = | 477 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = |
| 478 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get()); | 478 static_cast<MockSyntheticPointerMouseActionTarget*>(target_.get()); |
| 479 EXPECT_EQ(1, num_success_); | 479 EXPECT_EQ(1, num_success_); |
| 480 EXPECT_EQ(0, num_failure_); | 480 EXPECT_EQ(0, num_failure_); |
| 481 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); | 481 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); |
| 482 EXPECT_EQ(pointer_mouse_target->position(), params.position()); | 482 EXPECT_EQ(pointer_mouse_target->position(), params.position()); |
| 483 EXPECT_EQ(pointer_mouse_target->clickCount(), 0); | 483 EXPECT_EQ(pointer_mouse_target->clickCount(), 0); |
| 484 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonNone); | 484 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::NoButton); |
| 485 | 485 |
| 486 // Cannot send a mouse up without sending a mouse down first. | 486 // Cannot send a mouse up without sending a mouse down first. |
| 487 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); | 487 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); |
| 488 params.set_pointer_action_type( | 488 params.set_pointer_action_type( |
| 489 SyntheticPointerActionParams::PointerActionType::RELEASE); | 489 SyntheticPointerActionParams::PointerActionType::RELEASE); |
| 490 action_param_list_->push_back(params); | 490 action_param_list_->push_back(params); |
| 491 ForwardSyntheticPointerAction(); | 491 ForwardSyntheticPointerAction(); |
| 492 | 492 |
| 493 EXPECT_EQ(1, num_success_); | 493 EXPECT_EQ(1, num_success_); |
| 494 EXPECT_EQ(1, num_failure_); | 494 EXPECT_EQ(1, num_failure_); |
| 495 | 495 |
| 496 // Send a mouse down for one finger. | 496 // Send a mouse down for one finger. |
| 497 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); | 497 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); |
| 498 params.set_pointer_action_type( | 498 params.set_pointer_action_type( |
| 499 SyntheticPointerActionParams::PointerActionType::PRESS); | 499 SyntheticPointerActionParams::PointerActionType::PRESS); |
| 500 action_param_list_->push_back(params); | 500 action_param_list_->push_back(params); |
| 501 ForwardSyntheticPointerAction(); | 501 ForwardSyntheticPointerAction(); |
| 502 | 502 |
| 503 EXPECT_EQ(2, num_success_); | 503 EXPECT_EQ(2, num_success_); |
| 504 EXPECT_EQ(1, num_failure_); | 504 EXPECT_EQ(1, num_failure_); |
| 505 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); | 505 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); |
| 506 EXPECT_EQ(pointer_mouse_target->position(), params.position()); | 506 EXPECT_EQ(pointer_mouse_target->position(), params.position()); |
| 507 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); | 507 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
| 508 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft); | 508 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); |
| 509 | 509 |
| 510 // Cannot send a mouse down again without releasing the mouse button. | 510 // Cannot send a mouse down again without releasing the mouse button. |
| 511 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); | 511 action_param_list_.reset(new std::vector<SyntheticPointerActionParams>()); |
| 512 params.set_pointer_action_type( | 512 params.set_pointer_action_type( |
| 513 SyntheticPointerActionParams::PointerActionType::PRESS); | 513 SyntheticPointerActionParams::PointerActionType::PRESS); |
| 514 action_param_list_->push_back(params); | 514 action_param_list_->push_back(params); |
| 515 ForwardSyntheticPointerAction(); | 515 ForwardSyntheticPointerAction(); |
| 516 | 516 |
| 517 EXPECT_EQ(2, num_success_); | 517 EXPECT_EQ(2, num_success_); |
| 518 EXPECT_EQ(2, num_failure_); | 518 EXPECT_EQ(2, num_failure_); |
| 519 } | 519 } |
| 520 | 520 |
| 521 } // namespace | 521 } // namespace |
| 522 | 522 |
| 523 } // namespace content | 523 } // namespace content |
| OLD | NEW |