OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 EXPECT_EQ(WebString("x"), Platform::Current()->Clipboard()->ReadPlainText( | 445 EXPECT_EQ(WebString("x"), Platform::Current()->Clipboard()->ReadPlainText( |
446 WebClipboard::Buffer())); | 446 WebClipboard::Buffer())); |
447 } | 447 } |
448 | 448 |
449 // A class to facilitate testing that events are correctly received by plugins. | 449 // A class to facilitate testing that events are correctly received by plugins. |
450 class EventTestPlugin : public FakeWebPlugin { | 450 class EventTestPlugin : public FakeWebPlugin { |
451 public: | 451 public: |
452 explicit EventTestPlugin(const WebPluginParams& params) | 452 explicit EventTestPlugin(const WebPluginParams& params) |
453 : FakeWebPlugin(params), last_event_type_(WebInputEvent::kUndefined) {} | 453 : FakeWebPlugin(params), last_event_type_(WebInputEvent::kUndefined) {} |
454 | 454 |
455 WebInputEventResult HandleInputEvent(const WebInputEvent& event, | 455 WebInputEventResult HandleInputEvent( |
456 WebCursorInfo&) override { | 456 const WebCoalescedInputEvent& coalesced_event, |
| 457 WebCursorInfo&) override { |
| 458 const WebInputEvent& event = coalesced_event.Event(); |
| 459 coalesced_event_count_ = coalesced_event.CoalescedEventSize(); |
457 last_event_type_ = event.GetType(); | 460 last_event_type_ = event.GetType(); |
458 if (WebInputEvent::IsMouseEventType(event.GetType()) || | 461 if (WebInputEvent::IsMouseEventType(event.GetType()) || |
459 event.GetType() == WebInputEvent::kMouseWheel) { | 462 event.GetType() == WebInputEvent::kMouseWheel) { |
460 const WebMouseEvent& mouse_event = | 463 const WebMouseEvent& mouse_event = |
461 static_cast<const WebMouseEvent&>(event); | 464 static_cast<const WebMouseEvent&>(event); |
462 last_event_location_ = IntPoint(mouse_event.PositionInWidget().x, | 465 last_event_location_ = IntPoint(mouse_event.PositionInWidget().x, |
463 mouse_event.PositionInWidget().y); | 466 mouse_event.PositionInWidget().y); |
464 } else if (WebInputEvent::IsTouchEventType(event.GetType())) { | 467 } else if (WebInputEvent::IsTouchEventType(event.GetType())) { |
465 const WebTouchEvent& touch_event = | 468 const WebTouchEvent& touch_event = |
466 static_cast<const WebTouchEvent&>(event); | 469 static_cast<const WebTouchEvent&>(event); |
467 if (touch_event.touches_length == 1) { | 470 if (touch_event.touches_length == 1) { |
468 last_event_location_ = IntPoint(touch_event.touches[0].position.x, | 471 last_event_location_ = IntPoint(touch_event.touches[0].position.x, |
469 touch_event.touches[0].position.y); | 472 touch_event.touches[0].position.y); |
470 } else { | 473 } else { |
471 last_event_location_ = IntPoint(); | 474 last_event_location_ = IntPoint(); |
472 } | 475 } |
473 } | 476 } |
474 | 477 |
475 return WebInputEventResult::kHandledSystem; | 478 return WebInputEventResult::kHandledSystem; |
476 } | 479 } |
477 WebInputEvent::Type GetLastInputEventType() { return last_event_type_; } | 480 WebInputEvent::Type GetLastInputEventType() { return last_event_type_; } |
478 | 481 |
479 IntPoint GetLastEventLocation() { return last_event_location_; } | 482 IntPoint GetLastEventLocation() { return last_event_location_; } |
480 | 483 |
481 void ClearLastEventType() { last_event_type_ = WebInputEvent::kUndefined; } | 484 void ClearLastEventType() { last_event_type_ = WebInputEvent::kUndefined; } |
482 | 485 |
| 486 size_t GetCoalescedEventCount() { return coalesced_event_count_; } |
| 487 |
483 private: | 488 private: |
| 489 size_t coalesced_event_count_; |
484 WebInputEvent::Type last_event_type_; | 490 WebInputEvent::Type last_event_type_; |
485 IntPoint last_event_location_; | 491 IntPoint last_event_location_; |
486 }; | 492 }; |
487 | 493 |
488 TEST_F(WebPluginContainerTest, GestureLongPressReachesPlugin) { | 494 TEST_F(WebPluginContainerTest, GestureLongPressReachesPlugin) { |
489 RegisterMockedURL("plugin_container.html"); | 495 RegisterMockedURL("plugin_container.html"); |
490 CustomPluginWebFrameClient<EventTestPlugin> | 496 CustomPluginWebFrameClient<EventTestPlugin> |
491 plugin_web_frame_client; // Must outlive webViewHelper. | 497 plugin_web_frame_client; // Must outlive webViewHelper. |
492 FrameTestHelpers::WebViewHelper web_view_helper; | 498 FrameTestHelpers::WebViewHelper web_view_helper; |
493 WebView* web_view = web_view_helper.InitializeAndLoad( | 499 WebView* web_view = web_view_helper.InitializeAndLoad( |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 WebFloatPoint(rect.x + rect.width / 2, rect.y + rect.height / 2); | 611 WebFloatPoint(rect.x + rect.width / 2, rect.y + rect.height / 2); |
606 | 612 |
607 web_view->HandleInputEvent(WebCoalescedInputEvent(event)); | 613 web_view->HandleInputEvent(WebCoalescedInputEvent(event)); |
608 RunPendingTasks(); | 614 RunPendingTasks(); |
609 | 615 |
610 EXPECT_EQ(WebInputEvent::kTouchStart, test_plugin->GetLastInputEventType()); | 616 EXPECT_EQ(WebInputEvent::kTouchStart, test_plugin->GetLastInputEventType()); |
611 EXPECT_EQ(rect.width / 2, test_plugin->GetLastEventLocation().X()); | 617 EXPECT_EQ(rect.width / 2, test_plugin->GetLastEventLocation().X()); |
612 EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y()); | 618 EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y()); |
613 } | 619 } |
614 | 620 |
| 621 TEST_F(WebPluginContainerTest, TouchEventScrolledWithCoalescedTouches) { |
| 622 RegisterMockedURL("plugin_scroll.html"); |
| 623 CustomPluginWebFrameClient<EventTestPlugin> |
| 624 plugin_web_frame_client; // Must outlive webViewHelper. |
| 625 FrameTestHelpers::WebViewHelper web_view_helper; |
| 626 WebView* web_view = web_view_helper.InitializeAndLoad( |
| 627 base_url_ + "plugin_scroll.html", true, &plugin_web_frame_client); |
| 628 DCHECK(web_view); |
| 629 web_view->GetSettings()->SetPluginsEnabled(true); |
| 630 web_view->Resize(WebSize(300, 300)); |
| 631 web_view->UpdateAllLifecyclePhases(); |
| 632 RunPendingTasks(); |
| 633 web_view->SmoothScroll(0, 200, 0); |
| 634 web_view->UpdateAllLifecyclePhases(); |
| 635 RunPendingTasks(); |
| 636 |
| 637 WebElement plugin_container_one_element = |
| 638 web_view->MainFrame()->GetDocument().GetElementById( |
| 639 WebString::FromUTF8("scrolled-plugin")); |
| 640 plugin_container_one_element.PluginContainer()->RequestTouchEventType( |
| 641 WebPluginContainer::kTouchEventRequestTypeRaw); |
| 642 WebPlugin* plugin = static_cast<WebPluginContainerImpl*>( |
| 643 plugin_container_one_element.PluginContainer()) |
| 644 ->Plugin(); |
| 645 EventTestPlugin* test_plugin = static_cast<EventTestPlugin*>(plugin); |
| 646 |
| 647 WebTouchEvent event(WebInputEvent::kTouchStart, WebInputEvent::kNoModifiers, |
| 648 WebInputEvent::kTimeStampForTesting); |
| 649 WebRect rect = plugin_container_one_element.BoundsInViewport(); |
| 650 event.touches_length = 1; |
| 651 event.touches[0].state = WebTouchPoint::kStatePressed; |
| 652 event.touches[0].position = |
| 653 WebFloatPoint(rect.x + rect.width / 2, rect.y + rect.height / 2); |
| 654 |
| 655 WebCoalescedInputEvent coalesced_event(event); |
| 656 |
| 657 WebTouchEvent c_event(WebInputEvent::kTouchMove, WebInputEvent::kNoModifiers, |
| 658 WebInputEvent::kTimeStampForTesting); |
| 659 c_event.touches_length = 1; |
| 660 c_event.touches[0].state = WebTouchPoint::kStatePressed; |
| 661 c_event.touches[0].position = |
| 662 WebFloatPoint(rect.x + rect.width / 2 + 1, rect.y + rect.height / 2 + 1); |
| 663 |
| 664 coalesced_event.AddCoalescedEvent(c_event); |
| 665 c_event.touches[0].position = |
| 666 WebFloatPoint(rect.x + rect.width / 2 + 2, rect.y + rect.height / 2 + 2); |
| 667 coalesced_event.AddCoalescedEvent(c_event); |
| 668 |
| 669 web_view->HandleInputEvent(coalesced_event); |
| 670 RunPendingTasks(); |
| 671 |
| 672 EXPECT_EQ(static_cast<const size_t>(3), |
| 673 test_plugin->GetCoalescedEventCount()); |
| 674 EXPECT_EQ(WebInputEvent::kTouchStart, test_plugin->GetLastInputEventType()); |
| 675 EXPECT_EQ(rect.width / 2, test_plugin->GetLastEventLocation().X()); |
| 676 EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y()); |
| 677 } |
| 678 |
615 TEST_F(WebPluginContainerTest, MouseWheelEventScrolled) { | 679 TEST_F(WebPluginContainerTest, MouseWheelEventScrolled) { |
616 RegisterMockedURL("plugin_scroll.html"); | 680 RegisterMockedURL("plugin_scroll.html"); |
617 CustomPluginWebFrameClient<EventTestPlugin> | 681 CustomPluginWebFrameClient<EventTestPlugin> |
618 plugin_web_frame_client; // Must outlive webViewHelper. | 682 plugin_web_frame_client; // Must outlive webViewHelper. |
619 FrameTestHelpers::WebViewHelper web_view_helper; | 683 FrameTestHelpers::WebViewHelper web_view_helper; |
620 WebView* web_view = web_view_helper.InitializeAndLoad( | 684 WebView* web_view = web_view_helper.InitializeAndLoad( |
621 base_url_ + "plugin_scroll.html", true, &plugin_web_frame_client); | 685 base_url_ + "plugin_scroll.html", true, &plugin_web_frame_client); |
622 DCHECK(web_view); | 686 DCHECK(web_view); |
623 web_view->GetSettings()->SetPluginsEnabled(true); | 687 web_view->GetSettings()->SetPluginsEnabled(true); |
624 web_view->Resize(WebSize(300, 300)); | 688 web_view->Resize(WebSize(300, 300)); |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 web_view->MainFrame()->GetDocument().GetElementById( | 1128 web_view->MainFrame()->GetDocument().GetElementById( |
1065 WebString::FromUTF8("translated-plugin")); | 1129 WebString::FromUTF8("translated-plugin")); |
1066 plugin_container_one_element.PluginContainer()->SetWantsWheelEvents(true); | 1130 plugin_container_one_element.PluginContainer()->SetWantsWheelEvents(true); |
1067 | 1131 |
1068 RunPendingTasks(); | 1132 RunPendingTasks(); |
1069 EXPECT_TRUE(web_view->GetPage()->GetEventHandlerRegistry().HasEventHandlers( | 1133 EXPECT_TRUE(web_view->GetPage()->GetEventHandlerRegistry().HasEventHandlers( |
1070 EventHandlerRegistry::kWheelEventBlocking)); | 1134 EventHandlerRegistry::kWheelEventBlocking)); |
1071 } | 1135 } |
1072 | 1136 |
1073 } // namespace blink | 1137 } // namespace blink |
OLD | NEW |