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(); | |
457 last_event_type_ = event.GetType(); | 459 last_event_type_ = event.GetType(); |
458 if (WebInputEvent::IsMouseEventType(event.GetType()) || | 460 if (WebInputEvent::IsMouseEventType(event.GetType()) || |
459 event.GetType() == WebInputEvent::kMouseWheel) { | 461 event.GetType() == WebInputEvent::kMouseWheel) { |
460 const WebMouseEvent& mouse_event = | 462 const WebMouseEvent& mouse_event = |
461 static_cast<const WebMouseEvent&>(event); | 463 static_cast<const WebMouseEvent&>(event); |
462 last_event_location_ = IntPoint(mouse_event.PositionInWidget().x, | 464 last_event_location_ = IntPoint(mouse_event.PositionInWidget().x, |
463 mouse_event.PositionInWidget().y); | 465 mouse_event.PositionInWidget().y); |
464 } else if (WebInputEvent::IsTouchEventType(event.GetType())) { | 466 } else if (WebInputEvent::IsTouchEventType(event.GetType())) { |
465 const WebTouchEvent& touch_event = | 467 const WebTouchEvent& touch_event = |
466 static_cast<const WebTouchEvent&>(event); | 468 static_cast<const WebTouchEvent&>(event); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
605 WebFloatPoint(rect.x + rect.width / 2, rect.y + rect.height / 2); | 607 WebFloatPoint(rect.x + rect.width / 2, rect.y + rect.height / 2); |
606 | 608 |
607 web_view->HandleInputEvent(WebCoalescedInputEvent(event)); | 609 web_view->HandleInputEvent(WebCoalescedInputEvent(event)); |
608 RunPendingTasks(); | 610 RunPendingTasks(); |
609 | 611 |
610 EXPECT_EQ(WebInputEvent::kTouchStart, test_plugin->GetLastInputEventType()); | 612 EXPECT_EQ(WebInputEvent::kTouchStart, test_plugin->GetLastInputEventType()); |
611 EXPECT_EQ(rect.width / 2, test_plugin->GetLastEventLocation().X()); | 613 EXPECT_EQ(rect.width / 2, test_plugin->GetLastEventLocation().X()); |
612 EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y()); | 614 EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y()); |
613 } | 615 } |
614 | 616 |
617 TEST_F(WebPluginContainerTest, TouchEventScrolledWithCoalescedTouches) { | |
618 RegisterMockedURL("plugin_scroll.html"); | |
619 CustomPluginWebFrameClient<EventTestPlugin> | |
620 plugin_web_frame_client; // Must outlive webViewHelper. | |
621 FrameTestHelpers::WebViewHelper web_view_helper; | |
622 WebView* web_view = web_view_helper.InitializeAndLoad( | |
623 base_url_ + "plugin_scroll.html", true, &plugin_web_frame_client); | |
624 DCHECK(web_view); | |
625 web_view->GetSettings()->SetPluginsEnabled(true); | |
626 web_view->Resize(WebSize(300, 300)); | |
627 web_view->UpdateAllLifecyclePhases(); | |
628 RunPendingTasks(); | |
629 web_view->SmoothScroll(0, 200, 0); | |
630 web_view->UpdateAllLifecyclePhases(); | |
631 RunPendingTasks(); | |
632 | |
633 WebElement plugin_container_one_element = | |
634 web_view->MainFrame()->GetDocument().GetElementById( | |
635 WebString::FromUTF8("scrolled-plugin")); | |
636 plugin_container_one_element.PluginContainer()->RequestTouchEventType( | |
637 WebPluginContainer::kTouchEventRequestTypeRaw); | |
638 WebPlugin* plugin = static_cast<WebPluginContainerImpl*>( | |
639 plugin_container_one_element.PluginContainer()) | |
640 ->Plugin(); | |
641 EventTestPlugin* test_plugin = static_cast<EventTestPlugin*>(plugin); | |
642 | |
643 WebTouchEvent event(WebInputEvent::kTouchStart, WebInputEvent::kNoModifiers, | |
644 WebInputEvent::kTimeStampForTesting); | |
645 WebRect rect = plugin_container_one_element.BoundsInViewport(); | |
646 event.touches_length = 1; | |
647 event.touches[0].state = WebTouchPoint::kStatePressed; | |
648 event.touches[0].position = | |
649 WebFloatPoint(rect.x + rect.width / 2, rect.y + rect.height / 2); | |
650 | |
651 WebCoalescedInputEvent coalesced_event(event); | |
652 | |
653 WebTouchEvent c_event(WebInputEvent::kTouchMove, WebInputEvent::kNoModifiers, | |
654 WebInputEvent::kTimeStampForTesting); | |
655 c_event.touches_length = 1; | |
656 c_event.touches[0].state = WebTouchPoint::kStatePressed; | |
657 c_event.touches[0].position = | |
658 WebFloatPoint(rect.x + rect.width / 2 + 1, rect.y + rect.height / 2 + 1); | |
659 | |
660 coalesced_event.AddCoalescedEvent(c_event); | |
661 c_event.touches[0].position = | |
662 WebFloatPoint(rect.x + rect.width / 2 + 2, rect.y + rect.height / 2 + 2); | |
663 coalesced_event.AddCoalescedEvent(c_event); | |
664 | |
665 web_view->HandleInputEvent(coalesced_event); | |
dtapuska
2017/05/08 13:11:15
You should likely store how many coalesced events
jkwang
2017/05/08 17:26:53
Done.
| |
666 RunPendingTasks(); | |
667 | |
668 EXPECT_EQ(WebInputEvent::kTouchStart, test_plugin->GetLastInputEventType()); | |
669 EXPECT_EQ(rect.width / 2, test_plugin->GetLastEventLocation().X()); | |
670 EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y()); | |
671 } | |
672 | |
615 TEST_F(WebPluginContainerTest, MouseWheelEventScrolled) { | 673 TEST_F(WebPluginContainerTest, MouseWheelEventScrolled) { |
616 RegisterMockedURL("plugin_scroll.html"); | 674 RegisterMockedURL("plugin_scroll.html"); |
617 CustomPluginWebFrameClient<EventTestPlugin> | 675 CustomPluginWebFrameClient<EventTestPlugin> |
618 plugin_web_frame_client; // Must outlive webViewHelper. | 676 plugin_web_frame_client; // Must outlive webViewHelper. |
619 FrameTestHelpers::WebViewHelper web_view_helper; | 677 FrameTestHelpers::WebViewHelper web_view_helper; |
620 WebView* web_view = web_view_helper.InitializeAndLoad( | 678 WebView* web_view = web_view_helper.InitializeAndLoad( |
621 base_url_ + "plugin_scroll.html", true, &plugin_web_frame_client); | 679 base_url_ + "plugin_scroll.html", true, &plugin_web_frame_client); |
622 DCHECK(web_view); | 680 DCHECK(web_view); |
623 web_view->GetSettings()->SetPluginsEnabled(true); | 681 web_view->GetSettings()->SetPluginsEnabled(true); |
624 web_view->Resize(WebSize(300, 300)); | 682 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( | 1122 web_view->MainFrame()->GetDocument().GetElementById( |
1065 WebString::FromUTF8("translated-plugin")); | 1123 WebString::FromUTF8("translated-plugin")); |
1066 plugin_container_one_element.PluginContainer()->SetWantsWheelEvents(true); | 1124 plugin_container_one_element.PluginContainer()->SetWantsWheelEvents(true); |
1067 | 1125 |
1068 RunPendingTasks(); | 1126 RunPendingTasks(); |
1069 EXPECT_TRUE(web_view->GetPage()->GetEventHandlerRegistry().HasEventHandlers( | 1127 EXPECT_TRUE(web_view->GetPage()->GetEventHandlerRegistry().HasEventHandlers( |
1070 EventHandlerRegistry::kWheelEventBlocking)); | 1128 EventHandlerRegistry::kWheelEventBlocking)); |
1071 } | 1129 } |
1072 | 1130 |
1073 } // namespace blink | 1131 } // namespace blink |
OLD | NEW |