Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: third_party/WebKit/Source/web/tests/WebPluginContainerTest.cpp

Issue 2844823002: Support Coalesced Touch in ppapi (Closed)
Patch Set: Support Coalesced Touch in ppapi Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 EXPECT_EQ(WebString("x"), Platform::Current()->Clipboard()->ReadPlainText( 444 EXPECT_EQ(WebString("x"), Platform::Current()->Clipboard()->ReadPlainText(
445 WebClipboard::Buffer())); 445 WebClipboard::Buffer()));
446 } 446 }
447 447
448 // A class to facilitate testing that events are correctly received by plugins. 448 // A class to facilitate testing that events are correctly received by plugins.
449 class EventTestPlugin : public FakeWebPlugin { 449 class EventTestPlugin : public FakeWebPlugin {
450 public: 450 public:
451 explicit EventTestPlugin(const WebPluginParams& params) 451 explicit EventTestPlugin(const WebPluginParams& params)
452 : FakeWebPlugin(params), last_event_type_(WebInputEvent::kUndefined) {} 452 : FakeWebPlugin(params), last_event_type_(WebInputEvent::kUndefined) {}
453 453
454 WebInputEventResult HandleInputEvent(const WebInputEvent& event, 454 WebInputEventResult HandleInputEvent(
455 WebCursorInfo&) override { 455 const WebCoalescedInputEvent& coalesced_event,
456 WebCursorInfo&) override {
457 const WebInputEvent& event = coalesced_event.Event();
458 coalesced_event_count_ = coalesced_event.CoalescedEventSize();
456 last_event_type_ = event.GetType(); 459 last_event_type_ = event.GetType();
457 if (WebInputEvent::IsMouseEventType(event.GetType()) || 460 if (WebInputEvent::IsMouseEventType(event.GetType()) ||
458 event.GetType() == WebInputEvent::kMouseWheel) { 461 event.GetType() == WebInputEvent::kMouseWheel) {
459 const WebMouseEvent& mouse_event = 462 const WebMouseEvent& mouse_event =
460 static_cast<const WebMouseEvent&>(event); 463 static_cast<const WebMouseEvent&>(event);
461 last_event_location_ = IntPoint(mouse_event.PositionInWidget().x, 464 last_event_location_ = IntPoint(mouse_event.PositionInWidget().x,
462 mouse_event.PositionInWidget().y); 465 mouse_event.PositionInWidget().y);
463 } else if (WebInputEvent::IsTouchEventType(event.GetType())) { 466 } else if (WebInputEvent::IsTouchEventType(event.GetType())) {
464 const WebTouchEvent& touch_event = 467 const WebTouchEvent& touch_event =
465 static_cast<const WebTouchEvent&>(event); 468 static_cast<const WebTouchEvent&>(event);
466 if (touch_event.touches_length == 1) { 469 if (touch_event.touches_length == 1) {
467 last_event_location_ = IntPoint(touch_event.touches[0].position.x, 470 last_event_location_ = IntPoint(touch_event.touches[0].position.x,
468 touch_event.touches[0].position.y); 471 touch_event.touches[0].position.y);
469 } else { 472 } else {
470 last_event_location_ = IntPoint(); 473 last_event_location_ = IntPoint();
471 } 474 }
472 } 475 }
473 476
474 return WebInputEventResult::kHandledSystem; 477 return WebInputEventResult::kHandledSystem;
475 } 478 }
476 WebInputEvent::Type GetLastInputEventType() { return last_event_type_; } 479 WebInputEvent::Type GetLastInputEventType() { return last_event_type_; }
477 480
478 IntPoint GetLastEventLocation() { return last_event_location_; } 481 IntPoint GetLastEventLocation() { return last_event_location_; }
479 482
480 void ClearLastEventType() { last_event_type_ = WebInputEvent::kUndefined; } 483 void ClearLastEventType() { last_event_type_ = WebInputEvent::kUndefined; }
481 484
485 size_t GetCoalescedEventCount() { return coalesced_event_count_; }
486
482 private: 487 private:
488 size_t coalesced_event_count_;
483 WebInputEvent::Type last_event_type_; 489 WebInputEvent::Type last_event_type_;
484 IntPoint last_event_location_; 490 IntPoint last_event_location_;
485 }; 491 };
486 492
487 TEST_F(WebPluginContainerTest, GestureLongPressReachesPlugin) { 493 TEST_F(WebPluginContainerTest, GestureLongPressReachesPlugin) {
488 RegisterMockedURL("plugin_container.html"); 494 RegisterMockedURL("plugin_container.html");
489 CustomPluginWebFrameClient<EventTestPlugin> 495 CustomPluginWebFrameClient<EventTestPlugin>
490 plugin_web_frame_client; // Must outlive webViewHelper. 496 plugin_web_frame_client; // Must outlive webViewHelper.
491 FrameTestHelpers::WebViewHelper web_view_helper; 497 FrameTestHelpers::WebViewHelper web_view_helper;
492 WebView* web_view = web_view_helper.InitializeAndLoad( 498 WebView* web_view = web_view_helper.InitializeAndLoad(
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 WebFloatPoint(rect.x + rect.width / 2, rect.y + rect.height / 2); 610 WebFloatPoint(rect.x + rect.width / 2, rect.y + rect.height / 2);
605 611
606 web_view->HandleInputEvent(WebCoalescedInputEvent(event)); 612 web_view->HandleInputEvent(WebCoalescedInputEvent(event));
607 RunPendingTasks(); 613 RunPendingTasks();
608 614
609 EXPECT_EQ(WebInputEvent::kTouchStart, test_plugin->GetLastInputEventType()); 615 EXPECT_EQ(WebInputEvent::kTouchStart, test_plugin->GetLastInputEventType());
610 EXPECT_EQ(rect.width / 2, test_plugin->GetLastEventLocation().X()); 616 EXPECT_EQ(rect.width / 2, test_plugin->GetLastEventLocation().X());
611 EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y()); 617 EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y());
612 } 618 }
613 619
620 TEST_F(WebPluginContainerTest, TouchEventScrolledWithCoalescedTouches) {
621 RegisterMockedURL("plugin_scroll.html");
622 CustomPluginWebFrameClient<EventTestPlugin>
623 plugin_web_frame_client; // Must outlive webViewHelper.
624 FrameTestHelpers::WebViewHelper web_view_helper;
625 WebView* web_view = web_view_helper.InitializeAndLoad(
626 base_url_ + "plugin_scroll.html", true, &plugin_web_frame_client);
627 DCHECK(web_view);
628 web_view->GetSettings()->SetPluginsEnabled(true);
629 web_view->Resize(WebSize(300, 300));
630 web_view->UpdateAllLifecyclePhases();
631 RunPendingTasks();
632 web_view->SmoothScroll(0, 200, 0);
633 web_view->UpdateAllLifecyclePhases();
634 RunPendingTasks();
635
636 WebElement plugin_container_one_element =
637 web_view->MainFrame()->GetDocument().GetElementById(
638 WebString::FromUTF8("scrolled-plugin"));
639 plugin_container_one_element.PluginContainer()->RequestTouchEventType(
640 WebPluginContainer::kTouchEventRequestTypeRaw);
641 WebPlugin* plugin = static_cast<WebPluginContainerImpl*>(
642 plugin_container_one_element.PluginContainer())
643 ->Plugin();
644 EventTestPlugin* test_plugin = static_cast<EventTestPlugin*>(plugin);
645
646 WebTouchEvent event(WebInputEvent::kTouchStart, WebInputEvent::kNoModifiers,
647 WebInputEvent::kTimeStampForTesting);
648 WebRect rect = plugin_container_one_element.BoundsInViewport();
649 event.touches_length = 1;
650 event.touches[0].state = WebTouchPoint::kStatePressed;
651 event.touches[0].position =
652 WebFloatPoint(rect.x + rect.width / 2, rect.y + rect.height / 2);
653
654 WebCoalescedInputEvent coalesced_event(event);
655
656 WebTouchEvent c_event(WebInputEvent::kTouchMove, WebInputEvent::kNoModifiers,
657 WebInputEvent::kTimeStampForTesting);
658 c_event.touches_length = 1;
659 c_event.touches[0].state = WebTouchPoint::kStatePressed;
660 c_event.touches[0].position =
661 WebFloatPoint(rect.x + rect.width / 2 + 1, rect.y + rect.height / 2 + 1);
662
663 coalesced_event.AddCoalescedEvent(c_event);
664 c_event.touches[0].position =
665 WebFloatPoint(rect.x + rect.width / 2 + 2, rect.y + rect.height / 2 + 2);
666 coalesced_event.AddCoalescedEvent(c_event);
667
668 web_view->HandleInputEvent(coalesced_event);
669 RunPendingTasks();
670
671 EXPECT_EQ(static_cast<const size_t>(3),
672 test_plugin->GetCoalescedEventCount());
673 EXPECT_EQ(WebInputEvent::kTouchStart, test_plugin->GetLastInputEventType());
674 EXPECT_EQ(rect.width / 2, test_plugin->GetLastEventLocation().X());
675 EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y());
676 }
677
614 TEST_F(WebPluginContainerTest, MouseWheelEventScrolled) { 678 TEST_F(WebPluginContainerTest, MouseWheelEventScrolled) {
615 RegisterMockedURL("plugin_scroll.html"); 679 RegisterMockedURL("plugin_scroll.html");
616 CustomPluginWebFrameClient<EventTestPlugin> 680 CustomPluginWebFrameClient<EventTestPlugin>
617 plugin_web_frame_client; // Must outlive webViewHelper. 681 plugin_web_frame_client; // Must outlive webViewHelper.
618 FrameTestHelpers::WebViewHelper web_view_helper; 682 FrameTestHelpers::WebViewHelper web_view_helper;
619 WebView* web_view = web_view_helper.InitializeAndLoad( 683 WebView* web_view = web_view_helper.InitializeAndLoad(
620 base_url_ + "plugin_scroll.html", true, &plugin_web_frame_client); 684 base_url_ + "plugin_scroll.html", true, &plugin_web_frame_client);
621 DCHECK(web_view); 685 DCHECK(web_view);
622 web_view->GetSettings()->SetPluginsEnabled(true); 686 web_view->GetSettings()->SetPluginsEnabled(true);
623 web_view->Resize(WebSize(300, 300)); 687 web_view->Resize(WebSize(300, 300));
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 web_view->MainFrame()->GetDocument().GetElementById( 1127 web_view->MainFrame()->GetDocument().GetElementById(
1064 WebString::FromUTF8("translated-plugin")); 1128 WebString::FromUTF8("translated-plugin"));
1065 plugin_container_one_element.PluginContainer()->SetWantsWheelEvents(true); 1129 plugin_container_one_element.PluginContainer()->SetWantsWheelEvents(true);
1066 1130
1067 RunPendingTasks(); 1131 RunPendingTasks();
1068 EXPECT_TRUE(web_view->GetPage()->GetEventHandlerRegistry().HasEventHandlers( 1132 EXPECT_TRUE(web_view->GetPage()->GetEventHandlerRegistry().HasEventHandlers(
1069 EventHandlerRegistry::kWheelEventBlocking)); 1133 EventHandlerRegistry::kWheelEventBlocking));
1070 } 1134 }
1071 1135
1072 } // namespace blink 1136 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/tests/FakeWebPlugin.h ('k') | third_party/WebKit/public/platform/WebCoalescedInputEvent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698