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

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

Issue 2814473003: Fix frame coordinate translation issue with scroll views. (Closed)
Patch Set: Add unittest Created 3 years, 8 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "platform/graphics/paint/PaintRecorder.h" 44 #include "platform/graphics/paint/PaintRecorder.h"
45 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" 45 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h"
46 #include "platform/testing/URLTestHelpers.h" 46 #include "platform/testing/URLTestHelpers.h"
47 #include "platform/testing/UnitTestHelpers.h" 47 #include "platform/testing/UnitTestHelpers.h"
48 #include "public/platform/Platform.h" 48 #include "public/platform/Platform.h"
49 #include "public/platform/WebClipboard.h" 49 #include "public/platform/WebClipboard.h"
50 #include "public/platform/WebCompositorSupport.h" 50 #include "public/platform/WebCompositorSupport.h"
51 #include "public/platform/WebLayer.h" 51 #include "public/platform/WebLayer.h"
52 #include "public/platform/WebMouseWheelEvent.h" 52 #include "public/platform/WebMouseWheelEvent.h"
53 #include "public/platform/WebThread.h" 53 #include "public/platform/WebThread.h"
54 #include "public/platform/WebTouchEvent.h"
54 #include "public/platform/WebURLLoaderMockFactory.h" 55 #include "public/platform/WebURLLoaderMockFactory.h"
55 #include "public/web/WebDocument.h" 56 #include "public/web/WebDocument.h"
56 #include "public/web/WebElement.h" 57 #include "public/web/WebElement.h"
57 #include "public/web/WebFrame.h" 58 #include "public/web/WebFrame.h"
58 #include "public/web/WebFrameClient.h" 59 #include "public/web/WebFrameClient.h"
59 #include "public/web/WebPluginParams.h" 60 #include "public/web/WebPluginParams.h"
60 #include "public/web/WebPrintParams.h" 61 #include "public/web/WebPrintParams.h"
61 #include "public/web/WebSettings.h" 62 #include "public/web/WebSettings.h"
62 #include "public/web/WebView.h" 63 #include "public/web/WebView.h"
63 #include "testing/gtest/include/gtest/gtest.h" 64 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 : FakeWebPlugin(frame, params), 458 : FakeWebPlugin(frame, params),
458 last_event_type_(WebInputEvent::kUndefined) {} 459 last_event_type_(WebInputEvent::kUndefined) {}
459 460
460 WebInputEventResult HandleInputEvent(const WebInputEvent& event, 461 WebInputEventResult HandleInputEvent(const WebInputEvent& event,
461 WebCursorInfo&) override { 462 WebCursorInfo&) override {
462 last_event_type_ = event.GetType(); 463 last_event_type_ = event.GetType();
463 if (WebInputEvent::IsMouseEventType(event.GetType()) || 464 if (WebInputEvent::IsMouseEventType(event.GetType()) ||
464 event.GetType() == WebInputEvent::kMouseWheel) { 465 event.GetType() == WebInputEvent::kMouseWheel) {
465 const WebMouseEvent& mouse_event = 466 const WebMouseEvent& mouse_event =
466 static_cast<const WebMouseEvent&>(event); 467 static_cast<const WebMouseEvent&>(event);
467 last_mouse_event_location_ = IntPoint(mouse_event.PositionInWidget().x, 468 last_event_location_ = IntPoint(mouse_event.PositionInWidget().x,
468 mouse_event.PositionInWidget().y); 469 mouse_event.PositionInWidget().y);
470 } else if (WebInputEvent::IsTouchEventType(event.GetType())) {
471 const WebTouchEvent& touch_event =
472 static_cast<const WebTouchEvent&>(event);
473 if (touch_event.touches_length == 1) {
474 last_event_location_ = IntPoint(touch_event.touches[0].position.x,
475 touch_event.touches[0].position.y);
476 } else {
477 last_event_location_ = IntPoint();
478 }
469 } 479 }
470 480
471 return WebInputEventResult::kHandledSystem; 481 return WebInputEventResult::kHandledSystem;
472 } 482 }
473 WebInputEvent::Type GetLastInputEventType() { return last_event_type_; } 483 WebInputEvent::Type GetLastInputEventType() { return last_event_type_; }
474 484
475 IntPoint GetLastMouseEventLocation() { return last_mouse_event_location_; } 485 IntPoint GetLastEventLocation() { return last_event_location_; }
476 486
477 private: 487 private:
478 WebInputEvent::Type last_event_type_; 488 WebInputEvent::Type last_event_type_;
479 IntPoint last_mouse_event_location_; 489 IntPoint last_event_location_;
480 }; 490 };
481 491
482 TEST_F(WebPluginContainerTest, GestureLongPressReachesPlugin) { 492 TEST_F(WebPluginContainerTest, GestureLongPressReachesPlugin) {
483 RegisterMockedURL("plugin_container.html"); 493 RegisterMockedURL("plugin_container.html");
484 CustomPluginWebFrameClient<EventTestPlugin> 494 CustomPluginWebFrameClient<EventTestPlugin>
485 plugin_web_frame_client; // Must outlive webViewHelper. 495 plugin_web_frame_client; // Must outlive webViewHelper.
486 FrameTestHelpers::WebViewHelper web_view_helper; 496 FrameTestHelpers::WebViewHelper web_view_helper;
487 WebView* web_view = web_view_helper.InitializeAndLoad( 497 WebView* web_view = web_view_helper.InitializeAndLoad(
488 base_url_ + "plugin_container.html", true, &plugin_web_frame_client); 498 base_url_ + "plugin_container.html", true, &plugin_web_frame_client);
489 DCHECK(web_view); 499 DCHECK(web_view);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 WebInputEvent::kNoModifiers, 563 WebInputEvent::kNoModifiers,
554 WebInputEvent::kTimeStampForTesting); 564 WebInputEvent::kTimeStampForTesting);
555 565
556 WebRect rect = plugin_container_one_element.BoundsInViewport(); 566 WebRect rect = plugin_container_one_element.BoundsInViewport();
557 event.SetPositionInWidget(rect.x + rect.width / 2, rect.y + rect.height / 2); 567 event.SetPositionInWidget(rect.x + rect.width / 2, rect.y + rect.height / 2);
558 568
559 web_view->HandleInputEvent(WebCoalescedInputEvent(event)); 569 web_view->HandleInputEvent(WebCoalescedInputEvent(event));
560 RunPendingTasks(); 570 RunPendingTasks();
561 571
562 EXPECT_EQ(WebInputEvent::kMouseWheel, test_plugin->GetLastInputEventType()); 572 EXPECT_EQ(WebInputEvent::kMouseWheel, test_plugin->GetLastInputEventType());
563 EXPECT_EQ(rect.width / 2, test_plugin->GetLastMouseEventLocation().X()); 573 EXPECT_EQ(rect.width / 2, test_plugin->GetLastEventLocation().X());
564 EXPECT_EQ(rect.height / 2, test_plugin->GetLastMouseEventLocation().Y()); 574 EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y());
575 }
576
577 TEST_F(WebPluginContainerTest, TouchEventScrolled) {
bokan 2017/04/12 17:28:44 Perhaps add a test with some pinch-zoom to ensure
dtapuska 2017/04/12 19:02:56 Done.
578 RegisterMockedURL("plugin_scroll.html");
579 CustomPluginWebFrameClient<EventTestPlugin>
580 plugin_web_frame_client; // Must outlive webViewHelper.
581 FrameTestHelpers::WebViewHelper web_view_helper;
582 WebView* web_view = web_view_helper.InitializeAndLoad(
583 base_url_ + "plugin_scroll.html", true, &plugin_web_frame_client);
584 DCHECK(web_view);
585 web_view->GetSettings()->SetPluginsEnabled(true);
586 web_view->Resize(WebSize(300, 300));
587 web_view->UpdateAllLifecyclePhases();
588 RunPendingTasks();
589 web_view->SmoothScroll(0, 200, 0);
590 web_view->UpdateAllLifecyclePhases();
591 RunPendingTasks();
592
593 WebElement plugin_container_one_element =
594 web_view->MainFrame()->GetDocument().GetElementById(
595 WebString::FromUTF8("scrolled-plugin"));
596 plugin_container_one_element.PluginContainer()->RequestTouchEventType(
597 WebPluginContainer::kTouchEventRequestTypeRaw);
598 WebPlugin* plugin = static_cast<WebPluginContainerImpl*>(
599 plugin_container_one_element.PluginContainer())
600 ->Plugin();
601 EventTestPlugin* test_plugin = static_cast<EventTestPlugin*>(plugin);
602
603 WebTouchEvent event(WebInputEvent::kTouchStart, WebInputEvent::kNoModifiers,
604 WebInputEvent::kTimeStampForTesting);
605 event.touches_length = 1;
606 WebRect rect = plugin_container_one_element.BoundsInViewport();
607 event.touches[0].state = WebTouchPoint::kStatePressed;
608 event.touches[0].position =
609 WebFloatPoint(rect.x + rect.width / 2, rect.y + rect.height / 2);
610
611 web_view->HandleInputEvent(WebCoalescedInputEvent(event));
612 RunPendingTasks();
613
614 EXPECT_EQ(WebInputEvent::kTouchStart, test_plugin->GetLastInputEventType());
615 EXPECT_EQ(rect.width / 2, test_plugin->GetLastEventLocation().X());
616 EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y());
617 }
618
619 TEST_F(WebPluginContainerTest, MouseWheelEventScrolled) {
620 RegisterMockedURL("plugin_scroll.html");
621 CustomPluginWebFrameClient<EventTestPlugin>
622 plugin_web_frame_client; // Must outlive webViewHelper.
623 FrameTestHelpers::WebViewHelper web_view_helper;
624 WebView* web_view = web_view_helper.InitializeAndLoad(
625 base_url_ + "plugin_scroll.html", true, &plugin_web_frame_client);
626 DCHECK(web_view);
627 web_view->GetSettings()->SetPluginsEnabled(true);
628 web_view->Resize(WebSize(300, 300));
629 web_view->UpdateAllLifecyclePhases();
630 RunPendingTasks();
631 web_view->SmoothScroll(0, 200, 0);
632 web_view->UpdateAllLifecyclePhases();
633 RunPendingTasks();
634
635 WebElement plugin_container_one_element =
636 web_view->MainFrame()->GetDocument().GetElementById(
637 WebString::FromUTF8("scrolled-plugin"));
638 plugin_container_one_element.PluginContainer()->RequestTouchEventType(
639 WebPluginContainer::kTouchEventRequestTypeRaw);
640 WebPlugin* plugin = static_cast<WebPluginContainerImpl*>(
641 plugin_container_one_element.PluginContainer())
642 ->Plugin();
643 EventTestPlugin* test_plugin = static_cast<EventTestPlugin*>(plugin);
644
645 WebMouseWheelEvent event(WebInputEvent::kMouseWheel,
646 WebInputEvent::kNoModifiers,
647 WebInputEvent::kTimeStampForTesting);
648
649 WebRect rect = plugin_container_one_element.BoundsInViewport();
650 event.SetPositionInWidget(rect.x + rect.width / 2, rect.y + rect.height / 2);
651
652 web_view->HandleInputEvent(WebCoalescedInputEvent(event));
653 RunPendingTasks();
654
655 EXPECT_EQ(WebInputEvent::kMouseWheel, test_plugin->GetLastInputEventType());
656 EXPECT_EQ(rect.width / 2, test_plugin->GetLastEventLocation().X());
657 EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y());
658 }
659
660 TEST_F(WebPluginContainerTest, MouseEventScrolled) {
661 RegisterMockedURL("plugin_scroll.html");
662 CustomPluginWebFrameClient<EventTestPlugin>
663 plugin_web_frame_client; // Must outlive webViewHelper.
664 FrameTestHelpers::WebViewHelper web_view_helper;
665 WebView* web_view = web_view_helper.InitializeAndLoad(
666 base_url_ + "plugin_scroll.html", true, &plugin_web_frame_client);
667 DCHECK(web_view);
668 web_view->GetSettings()->SetPluginsEnabled(true);
669 web_view->Resize(WebSize(300, 300));
670 web_view->UpdateAllLifecyclePhases();
671 RunPendingTasks();
672 web_view->SmoothScroll(0, 200, 0);
673 web_view->UpdateAllLifecyclePhases();
674 RunPendingTasks();
675
676 WebElement plugin_container_one_element =
677 web_view->MainFrame()->GetDocument().GetElementById(
678 WebString::FromUTF8("scrolled-plugin"));
679 plugin_container_one_element.PluginContainer()->RequestTouchEventType(
680 WebPluginContainer::kTouchEventRequestTypeRaw);
681 WebPlugin* plugin = static_cast<WebPluginContainerImpl*>(
682 plugin_container_one_element.PluginContainer())
683 ->Plugin();
684 EventTestPlugin* test_plugin = static_cast<EventTestPlugin*>(plugin);
685
686 WebMouseEvent event(WebInputEvent::kMouseMove, WebInputEvent::kNoModifiers,
687 WebInputEvent::kTimeStampForTesting);
688
689 WebRect rect = plugin_container_one_element.BoundsInViewport();
690 event.SetPositionInWidget(rect.x + rect.width / 2, rect.y + rect.height / 2);
691
692 web_view->HandleInputEvent(WebCoalescedInputEvent(event));
693 RunPendingTasks();
694
695 EXPECT_EQ(WebInputEvent::kMouseMove, test_plugin->GetLastInputEventType());
696 EXPECT_EQ(rect.width / 2, test_plugin->GetLastEventLocation().X());
697 EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y());
565 } 698 }
566 699
567 // Verify that isRectTopmost returns false when the document is detached. 700 // Verify that isRectTopmost returns false when the document is detached.
568 TEST_F(WebPluginContainerTest, IsRectTopmostTest) { 701 TEST_F(WebPluginContainerTest, IsRectTopmostTest) {
569 RegisterMockedURL("plugin_container.html"); 702 RegisterMockedURL("plugin_container.html");
570 TestPluginWebFrameClient 703 TestPluginWebFrameClient
571 plugin_web_frame_client; // Must outlive webViewHelper. 704 plugin_web_frame_client; // Must outlive webViewHelper.
572 FrameTestHelpers::WebViewHelper web_view_helper; 705 FrameTestHelpers::WebViewHelper web_view_helper;
573 WebView* web_view = web_view_helper.InitializeAndLoad( 706 WebView* web_view = web_view_helper.InitializeAndLoad(
574 base_url_ + "plugin_container.html", true, &plugin_web_frame_client); 707 base_url_ + "plugin_container.html", true, &plugin_web_frame_client);
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 web_view->MainFrame()->GetDocument().GetElementById( 941 web_view->MainFrame()->GetDocument().GetElementById(
809 WebString::FromUTF8("translated-plugin")); 942 WebString::FromUTF8("translated-plugin"));
810 plugin_container_one_element.PluginContainer()->SetWantsWheelEvents(true); 943 plugin_container_one_element.PluginContainer()->SetWantsWheelEvents(true);
811 944
812 RunPendingTasks(); 945 RunPendingTasks();
813 EXPECT_TRUE(web_view->GetPage()->GetEventHandlerRegistry().HasEventHandlers( 946 EXPECT_TRUE(web_view->GetPage()->GetEventHandlerRegistry().HasEventHandlers(
814 EventHandlerRegistry::kWheelEventBlocking)); 947 EventHandlerRegistry::kWheelEventBlocking));
815 } 948 }
816 949
817 } // namespace blink 950 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698