OLD | NEW |
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 <math.h> | 5 #include <math.h> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 input_router_->SendInput(scoped_ptr<IPC::Message>( | 347 input_router_->SendInput(scoped_ptr<IPC::Message>( |
348 new InputMsg_SelectRange(0, gfx::Point(5, 6), gfx::Point(7, 8)))); | 348 new InputMsg_SelectRange(0, gfx::Point(5, 6), gfx::Point(7, 8)))); |
349 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); | 349 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
350 | 350 |
351 input_router_->SendInput(scoped_ptr<IPC::Message>( | 351 input_router_->SendInput(scoped_ptr<IPC::Message>( |
352 new InputMsg_SelectRange(0, gfx::Point(9, 10), gfx::Point(11, 12)))); | 352 new InputMsg_SelectRange(0, gfx::Point(9, 10), gfx::Point(11, 12)))); |
353 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); | 353 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
354 | 354 |
355 // Now ack the first message. | 355 // Now ack the first message. |
356 { | 356 { |
357 scoped_ptr<IPC::Message> response(new ViewHostMsg_SelectRange_ACK(0)); | 357 scoped_ptr<IPC::Message> response(new InputHostMsg_SelectRange_ACK(0)); |
358 input_router_->OnMessageReceived(*response); | 358 input_router_->OnMessageReceived(*response); |
359 } | 359 } |
360 | 360 |
361 // Verify that the two messages are coalesced into one message. | 361 // Verify that the two messages are coalesced into one message. |
362 ExpectIPCMessageWithArg2<InputMsg_SelectRange>( | 362 ExpectIPCMessageWithArg2<InputMsg_SelectRange>( |
363 process_->sink().GetMessageAt(0), | 363 process_->sink().GetMessageAt(0), |
364 gfx::Point(9, 10), | 364 gfx::Point(9, 10), |
365 gfx::Point(11, 12)); | 365 gfx::Point(11, 12)); |
366 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); | 366 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); |
367 | 367 |
368 // Acking the coalesced msg should not send any more msg. | 368 // Acking the coalesced msg should not send any more msg. |
369 { | 369 { |
370 scoped_ptr<IPC::Message> response(new ViewHostMsg_SelectRange_ACK(0)); | 370 scoped_ptr<IPC::Message> response(new InputHostMsg_SelectRange_ACK(0)); |
371 input_router_->OnMessageReceived(*response); | 371 input_router_->OnMessageReceived(*response); |
372 } | 372 } |
373 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); | 373 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
| 374 } |
| 375 |
| 376 TEST_F(InputRouterImplTest, CoalescesMoveRangeSelectionExtent) { |
| 377 input_router_->SendInput(scoped_ptr<IPC::Message>( |
| 378 new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(1, 2)))); |
| 379 ExpectIPCMessageWithArg1<InputMsg_MoveRangeSelectionExtent>( |
| 380 process_->sink().GetMessageAt(0), |
| 381 gfx::Point(1, 2)); |
| 382 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); |
| 383 |
| 384 // Send two more messages without acking. |
| 385 input_router_->SendInput(scoped_ptr<IPC::Message>( |
| 386 new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(3, 4)))); |
| 387 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
| 388 |
| 389 input_router_->SendInput(scoped_ptr<IPC::Message>( |
| 390 new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(5, 6)))); |
| 391 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
| 392 |
| 393 // Now ack the first message. |
| 394 { |
| 395 scoped_ptr<IPC::Message> response( |
| 396 new InputHostMsg_MoveRangeSelectionExtent_ACK(0)); |
| 397 input_router_->OnMessageReceived(*response); |
| 398 } |
| 399 |
| 400 // Verify that the two messages are coalesced into one message. |
| 401 ExpectIPCMessageWithArg1<InputMsg_MoveRangeSelectionExtent>( |
| 402 process_->sink().GetMessageAt(0), |
| 403 gfx::Point(5, 6)); |
| 404 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); |
| 405 |
| 406 // Acking the coalesced msg should not send any more msg. |
| 407 { |
| 408 scoped_ptr<IPC::Message> response( |
| 409 new InputHostMsg_MoveRangeSelectionExtent_ACK(0)); |
| 410 input_router_->OnMessageReceived(*response); |
| 411 } |
| 412 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
| 413 } |
| 414 |
| 415 TEST_F(InputRouterImplTest, InterleaveSelectRangeAndMoveRangeSelectionExtent) { |
| 416 // Send first message: SelectRange. |
| 417 input_router_->SendInput(scoped_ptr<IPC::Message>( |
| 418 new InputMsg_SelectRange(0, gfx::Point(1, 2), gfx::Point(3, 4)))); |
| 419 ExpectIPCMessageWithArg2<InputMsg_SelectRange>( |
| 420 process_->sink().GetMessageAt(0), |
| 421 gfx::Point(1, 2), |
| 422 gfx::Point(3, 4)); |
| 423 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); |
| 424 |
| 425 // Send second message: MoveRangeSelectionExtent. |
| 426 input_router_->SendInput(scoped_ptr<IPC::Message>( |
| 427 new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(5, 6)))); |
| 428 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
| 429 |
| 430 // Send third message: SelectRange. |
| 431 input_router_->SendInput(scoped_ptr<IPC::Message>( |
| 432 new InputMsg_SelectRange(0, gfx::Point(7, 8), gfx::Point(9, 10)))); |
| 433 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
| 434 |
| 435 // Ack the messages and verify that they're not coalesced and that they're in |
| 436 // correct order. |
| 437 |
| 438 // Ack the first message. |
| 439 { |
| 440 scoped_ptr<IPC::Message> response( |
| 441 new InputHostMsg_SelectRange_ACK(0)); |
| 442 input_router_->OnMessageReceived(*response); |
| 443 } |
| 444 |
| 445 ExpectIPCMessageWithArg1<InputMsg_MoveRangeSelectionExtent>( |
| 446 process_->sink().GetMessageAt(0), |
| 447 gfx::Point(5, 6)); |
| 448 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); |
| 449 |
| 450 // Ack the second message. |
| 451 { |
| 452 scoped_ptr<IPC::Message> response( |
| 453 new InputHostMsg_MoveRangeSelectionExtent_ACK(0)); |
| 454 input_router_->OnMessageReceived(*response); |
| 455 } |
| 456 |
| 457 ExpectIPCMessageWithArg2<InputMsg_SelectRange>( |
| 458 process_->sink().GetMessageAt(0), |
| 459 gfx::Point(7, 8), |
| 460 gfx::Point(9, 10)); |
| 461 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); |
| 462 |
| 463 // Ack the third message. |
| 464 { |
| 465 scoped_ptr<IPC::Message> response( |
| 466 new InputHostMsg_SelectRange_ACK(0)); |
| 467 input_router_->OnMessageReceived(*response); |
| 468 } |
| 469 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
| 470 } |
| 471 |
| 472 TEST_F(InputRouterImplTest, |
| 473 CoalescesInterleavedSelectRangeAndMoveRangeSelectionExtent) { |
| 474 // Send interleaved SelectRange and MoveRangeSelectionExtent messages. They |
| 475 // should be coalesced as shown by the arrows. |
| 476 // > SelectRange |
| 477 // MoveRangeSelectionExtent |
| 478 // MoveRangeSelectionExtent |
| 479 // > MoveRangeSelectionExtent |
| 480 // SelectRange |
| 481 // > SelectRange |
| 482 // > MoveRangeSelectionExtent |
| 483 |
| 484 input_router_->SendInput(scoped_ptr<IPC::Message>( |
| 485 new InputMsg_SelectRange(0, gfx::Point(1, 2), gfx::Point(3, 4)))); |
| 486 ExpectIPCMessageWithArg2<InputMsg_SelectRange>( |
| 487 process_->sink().GetMessageAt(0), |
| 488 gfx::Point(1, 2), |
| 489 gfx::Point(3, 4)); |
| 490 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); |
| 491 |
| 492 input_router_->SendInput(scoped_ptr<IPC::Message>( |
| 493 new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(5, 6)))); |
| 494 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
| 495 |
| 496 input_router_->SendInput(scoped_ptr<IPC::Message>( |
| 497 new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(7, 8)))); |
| 498 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
| 499 |
| 500 input_router_->SendInput(scoped_ptr<IPC::Message>( |
| 501 new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(9, 10)))); |
| 502 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
| 503 |
| 504 input_router_->SendInput(scoped_ptr<IPC::Message>( |
| 505 new InputMsg_SelectRange(0, gfx::Point(11, 12), gfx::Point(13, 14)))); |
| 506 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
| 507 |
| 508 input_router_->SendInput(scoped_ptr<IPC::Message>( |
| 509 new InputMsg_SelectRange(0, gfx::Point(15, 16), gfx::Point(17, 18)))); |
| 510 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
| 511 |
| 512 input_router_->SendInput(scoped_ptr<IPC::Message>( |
| 513 new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(19, 20)))); |
| 514 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
| 515 |
| 516 // Ack the first message. |
| 517 { |
| 518 scoped_ptr<IPC::Message> response( |
| 519 new InputHostMsg_SelectRange_ACK(0)); |
| 520 input_router_->OnMessageReceived(*response); |
| 521 } |
| 522 |
| 523 // Verify that the three MoveRangeSelectionExtent messages are coalesced into |
| 524 // one message. |
| 525 ExpectIPCMessageWithArg1<InputMsg_MoveRangeSelectionExtent>( |
| 526 process_->sink().GetMessageAt(0), |
| 527 gfx::Point(9, 10)); |
| 528 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); |
| 529 |
| 530 // Ack the second message. |
| 531 { |
| 532 scoped_ptr<IPC::Message> response( |
| 533 new InputHostMsg_MoveRangeSelectionExtent_ACK(0)); |
| 534 input_router_->OnMessageReceived(*response); |
| 535 } |
| 536 |
| 537 // Verify that the two SelectRange messages are coalesced into one message. |
| 538 ExpectIPCMessageWithArg2<InputMsg_SelectRange>( |
| 539 process_->sink().GetMessageAt(0), |
| 540 gfx::Point(15, 16), |
| 541 gfx::Point(17, 18)); |
| 542 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); |
| 543 |
| 544 // Ack the third message. |
| 545 { |
| 546 scoped_ptr<IPC::Message> response( |
| 547 new InputHostMsg_SelectRange_ACK(0)); |
| 548 input_router_->OnMessageReceived(*response); |
| 549 } |
| 550 |
| 551 // Verify the fourth message. |
| 552 ExpectIPCMessageWithArg1<InputMsg_MoveRangeSelectionExtent>( |
| 553 process_->sink().GetMessageAt(0), |
| 554 gfx::Point(19, 20)); |
| 555 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); |
| 556 |
| 557 // Ack the fourth message. |
| 558 { |
| 559 scoped_ptr<IPC::Message> response( |
| 560 new InputHostMsg_MoveRangeSelectionExtent_ACK(0)); |
| 561 input_router_->OnMessageReceived(*response); |
| 562 } |
| 563 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
374 } | 564 } |
375 | 565 |
376 TEST_F(InputRouterImplTest, CoalescesCaretMove) { | 566 TEST_F(InputRouterImplTest, CoalescesCaretMove) { |
377 input_router_->SendInput( | 567 input_router_->SendInput( |
378 scoped_ptr<IPC::Message>(new InputMsg_MoveCaret(0, gfx::Point(1, 2)))); | 568 scoped_ptr<IPC::Message>(new InputMsg_MoveCaret(0, gfx::Point(1, 2)))); |
379 ExpectIPCMessageWithArg1<InputMsg_MoveCaret>( | 569 ExpectIPCMessageWithArg1<InputMsg_MoveCaret>( |
380 process_->sink().GetMessageAt(0), gfx::Point(1, 2)); | 570 process_->sink().GetMessageAt(0), gfx::Point(1, 2)); |
381 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); | 571 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); |
382 | 572 |
383 // Send two more messages without acking. | 573 // Send two more messages without acking. |
384 input_router_->SendInput( | 574 input_router_->SendInput( |
385 scoped_ptr<IPC::Message>(new InputMsg_MoveCaret(0, gfx::Point(5, 6)))); | 575 scoped_ptr<IPC::Message>(new InputMsg_MoveCaret(0, gfx::Point(5, 6)))); |
386 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); | 576 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
387 | 577 |
388 input_router_->SendInput( | 578 input_router_->SendInput( |
389 scoped_ptr<IPC::Message>(new InputMsg_MoveCaret(0, gfx::Point(9, 10)))); | 579 scoped_ptr<IPC::Message>(new InputMsg_MoveCaret(0, gfx::Point(9, 10)))); |
390 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); | 580 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
391 | 581 |
392 // Now ack the first message. | 582 // Now ack the first message. |
393 { | 583 { |
394 scoped_ptr<IPC::Message> response(new ViewHostMsg_MoveCaret_ACK(0)); | 584 scoped_ptr<IPC::Message> response(new InputHostMsg_MoveCaret_ACK(0)); |
395 input_router_->OnMessageReceived(*response); | 585 input_router_->OnMessageReceived(*response); |
396 } | 586 } |
397 | 587 |
398 // Verify that the two messages are coalesced into one message. | 588 // Verify that the two messages are coalesced into one message. |
399 ExpectIPCMessageWithArg1<InputMsg_MoveCaret>( | 589 ExpectIPCMessageWithArg1<InputMsg_MoveCaret>( |
400 process_->sink().GetMessageAt(0), gfx::Point(9, 10)); | 590 process_->sink().GetMessageAt(0), gfx::Point(9, 10)); |
401 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); | 591 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); |
402 | 592 |
403 // Acking the coalesced msg should not send any more msg. | 593 // Acking the coalesced msg should not send any more msg. |
404 { | 594 { |
405 scoped_ptr<IPC::Message> response(new ViewHostMsg_MoveCaret_ACK(0)); | 595 scoped_ptr<IPC::Message> response(new InputHostMsg_MoveCaret_ACK(0)); |
406 input_router_->OnMessageReceived(*response); | 596 input_router_->OnMessageReceived(*response); |
407 } | 597 } |
408 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); | 598 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); |
409 } | 599 } |
410 | 600 |
411 TEST_F(InputRouterImplTest, HandledInputEvent) { | 601 TEST_F(InputRouterImplTest, HandledInputEvent) { |
412 client_->set_filter_state(INPUT_EVENT_ACK_STATE_CONSUMED); | 602 client_->set_filter_state(INPUT_EVENT_ACK_STATE_CONSUMED); |
413 | 603 |
414 // Simulate a keyboard event. | 604 // Simulate a keyboard event. |
415 SimulateKeyboardEvent(WebInputEvent::RawKeyDown, false); | 605 SimulateKeyboardEvent(WebInputEvent::RawKeyDown, false); |
(...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1711 client_overscroll = client_->GetAndResetOverscroll(); | 1901 client_overscroll = client_->GetAndResetOverscroll(); |
1712 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, | 1902 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, |
1713 client_overscroll.accumulated_overscroll); | 1903 client_overscroll.accumulated_overscroll); |
1714 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, | 1904 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, |
1715 client_overscroll.latest_overscroll_delta); | 1905 client_overscroll.latest_overscroll_delta); |
1716 EXPECT_EQ(wheel_overscroll.current_fling_velocity, | 1906 EXPECT_EQ(wheel_overscroll.current_fling_velocity, |
1717 client_overscroll.current_fling_velocity); | 1907 client_overscroll.current_fling_velocity); |
1718 } | 1908 } |
1719 | 1909 |
1720 } // namespace content | 1910 } // namespace content |
OLD | NEW |