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

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

Issue 2813903006: Fix frame coordinate translation issue with scroll views. (Closed)
Patch Set: 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "platform/graphics/paint/PaintRecorder.h" 45 #include "platform/graphics/paint/PaintRecorder.h"
46 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" 46 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h"
47 #include "platform/testing/URLTestHelpers.h" 47 #include "platform/testing/URLTestHelpers.h"
48 #include "platform/testing/UnitTestHelpers.h" 48 #include "platform/testing/UnitTestHelpers.h"
49 #include "public/platform/Platform.h" 49 #include "public/platform/Platform.h"
50 #include "public/platform/WebClipboard.h" 50 #include "public/platform/WebClipboard.h"
51 #include "public/platform/WebCompositorSupport.h" 51 #include "public/platform/WebCompositorSupport.h"
52 #include "public/platform/WebLayer.h" 52 #include "public/platform/WebLayer.h"
53 #include "public/platform/WebMouseWheelEvent.h" 53 #include "public/platform/WebMouseWheelEvent.h"
54 #include "public/platform/WebThread.h" 54 #include "public/platform/WebThread.h"
55 #include "public/platform/WebTouchEvent.h"
55 #include "public/platform/WebURLLoaderMockFactory.h" 56 #include "public/platform/WebURLLoaderMockFactory.h"
56 #include "public/web/WebDocument.h" 57 #include "public/web/WebDocument.h"
57 #include "public/web/WebElement.h" 58 #include "public/web/WebElement.h"
58 #include "public/web/WebFrame.h" 59 #include "public/web/WebFrame.h"
59 #include "public/web/WebFrameClient.h" 60 #include "public/web/WebFrameClient.h"
60 #include "public/web/WebPluginParams.h" 61 #include "public/web/WebPluginParams.h"
61 #include "public/web/WebPrintParams.h" 62 #include "public/web/WebPrintParams.h"
62 #include "public/web/WebSettings.h" 63 #include "public/web/WebSettings.h"
63 #include "public/web/WebView.h" 64 #include "public/web/WebView.h"
64 #include "testing/gtest/include/gtest/gtest.h" 65 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 : FakeWebPlugin(frame, params), 443 : FakeWebPlugin(frame, params),
443 m_lastEventType(WebInputEvent::Undefined) {} 444 m_lastEventType(WebInputEvent::Undefined) {}
444 445
445 WebInputEventResult handleInputEvent(const WebInputEvent& event, 446 WebInputEventResult handleInputEvent(const WebInputEvent& event,
446 WebCursorInfo&) override { 447 WebCursorInfo&) override {
447 m_lastEventType = event.type(); 448 m_lastEventType = event.type();
448 if (WebInputEvent::isMouseEventType(event.type()) || 449 if (WebInputEvent::isMouseEventType(event.type()) ||
449 event.type() == WebInputEvent::MouseWheel) { 450 event.type() == WebInputEvent::MouseWheel) {
450 const WebMouseEvent& mouseEvent = 451 const WebMouseEvent& mouseEvent =
451 static_cast<const WebMouseEvent&>(event); 452 static_cast<const WebMouseEvent&>(event);
452 m_lastMouseEventLocation = IntPoint(mouseEvent.x, mouseEvent.y); 453 m_lastEventLocation = IntPoint(mouseEvent.x, mouseEvent.y);
454 } else if (WebInputEvent::isTouchEventType(event.type())) {
455 const WebTouchEvent& touchEvent =
456 static_cast<const WebTouchEvent&>(event);
457 if (touchEvent.touchesLength == 1) {
458 m_lastEventLocation = IntPoint(touchEvent.touches[0].position.x,
459 touchEvent.touches[0].position.y);
460 } else {
461 m_lastEventLocation = IntPoint();
462 }
453 } 463 }
454 464
455 return WebInputEventResult::HandledSystem; 465 return WebInputEventResult::HandledSystem;
456 } 466 }
457 WebInputEvent::Type getLastInputEventType() { return m_lastEventType; } 467 WebInputEvent::Type getLastInputEventType() { return m_lastEventType; }
458 468
459 IntPoint getLastMouseEventLocation() { return m_lastMouseEventLocation; } 469 IntPoint getLastEventLocation() { return m_lastEventLocation; }
470
471 void ClearLastEventType() { m_lastEventType = WebInputEvent::Undefined; }
460 472
461 private: 473 private:
462 WebInputEvent::Type m_lastEventType; 474 WebInputEvent::Type m_lastEventType;
463 IntPoint m_lastMouseEventLocation; 475 IntPoint m_lastEventLocation;
464 }; 476 };
465 477
466 TEST_F(WebPluginContainerTest, GestureLongPressReachesPlugin) { 478 TEST_F(WebPluginContainerTest, GestureLongPressReachesPlugin) {
467 registerMockedURL("plugin_container.html"); 479 registerMockedURL("plugin_container.html");
468 CustomPluginWebFrameClient<EventTestPlugin> 480 CustomPluginWebFrameClient<EventTestPlugin>
469 pluginWebFrameClient; // Must outlive webViewHelper. 481 pluginWebFrameClient; // Must outlive webViewHelper.
470 FrameTestHelpers::WebViewHelper webViewHelper; 482 FrameTestHelpers::WebViewHelper webViewHelper;
471 WebView* webView = webViewHelper.initializeAndLoad( 483 WebView* webView = webViewHelper.initializeAndLoad(
472 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); 484 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient);
473 DCHECK(webView); 485 DCHECK(webView);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 WebInputEvent::TimeStampForTesting); 550 WebInputEvent::TimeStampForTesting);
539 551
540 WebRect rect = pluginContainerOneElement.boundsInViewport(); 552 WebRect rect = pluginContainerOneElement.boundsInViewport();
541 event.x = rect.x + rect.width / 2; 553 event.x = rect.x + rect.width / 2;
542 event.y = rect.y + rect.height / 2; 554 event.y = rect.y + rect.height / 2;
543 555
544 webView->handleInputEvent(WebCoalescedInputEvent(event)); 556 webView->handleInputEvent(WebCoalescedInputEvent(event));
545 runPendingTasks(); 557 runPendingTasks();
546 558
547 EXPECT_EQ(WebInputEvent::MouseWheel, testPlugin->getLastInputEventType()); 559 EXPECT_EQ(WebInputEvent::MouseWheel, testPlugin->getLastInputEventType());
548 EXPECT_EQ(rect.width / 2, testPlugin->getLastMouseEventLocation().x()); 560 EXPECT_EQ(rect.width / 2, testPlugin->getLastEventLocation().x());
549 EXPECT_EQ(rect.height / 2, testPlugin->getLastMouseEventLocation().y()); 561 EXPECT_EQ(rect.height / 2, testPlugin->getLastEventLocation().y());
562 }
563
564 TEST_F(WebPluginContainerTest, TouchEventScrolled) {
565 registerMockedURL("plugin_scroll.html");
566 CustomPluginWebFrameClient<EventTestPlugin>
567 plugin_web_frame_client; // Must outlive webViewHelper.
568 FrameTestHelpers::WebViewHelper web_view_helper;
569 WebView* web_view = web_view_helper.initializeAndLoad(
570 m_baseURL + "plugin_scroll.html", true, &plugin_web_frame_client);
571 DCHECK(web_view);
572 web_view->settings()->setPluginsEnabled(true);
573 web_view->resize(WebSize(300, 300));
574 web_view->updateAllLifecyclePhases();
575 runPendingTasks();
576 web_view->smoothScroll(0, 200, 0);
577 web_view->updateAllLifecyclePhases();
578 runPendingTasks();
579
580 WebElement plugin_container_one_element =
581 web_view->mainFrame()->document().getElementById(
582 WebString::fromUTF8("scrolled-plugin"));
583 plugin_container_one_element.pluginContainer()->requestTouchEventType(
584 WebPluginContainer::TouchEventRequestTypeRaw);
585 WebPlugin* plugin = static_cast<WebPluginContainerImpl*>(
586 plugin_container_one_element.pluginContainer())
587 ->plugin();
588 EventTestPlugin* test_plugin = static_cast<EventTestPlugin*>(plugin);
589
590 WebTouchEvent event(WebInputEvent::TouchStart, WebInputEvent::NoModifiers,
591 WebInputEvent::TimeStampForTesting);
592 event.touchesLength = 1;
593 WebRect rect = plugin_container_one_element.boundsInViewport();
594 event.touches[0].state = WebTouchPoint::StatePressed;
595 event.touches[0].position =
596 WebFloatPoint(rect.x + rect.width / 2, rect.y + rect.height / 2);
597
598 web_view->handleInputEvent(WebCoalescedInputEvent(event));
599 runPendingTasks();
600
601 EXPECT_EQ(WebInputEvent::TouchStart, test_plugin->getLastInputEventType());
602 EXPECT_EQ(rect.width / 2, test_plugin->getLastEventLocation().x());
603 EXPECT_EQ(rect.height / 2, test_plugin->getLastEventLocation().y());
604 }
605
606 TEST_F(WebPluginContainerTest, MouseWheelEventScrolled) {
607 registerMockedURL("plugin_scroll.html");
608 CustomPluginWebFrameClient<EventTestPlugin>
609 plugin_web_frame_client; // Must outlive webViewHelper.
610 FrameTestHelpers::WebViewHelper web_view_helper;
611 WebView* web_view = web_view_helper.initializeAndLoad(
612 m_baseURL + "plugin_scroll.html", true, &plugin_web_frame_client);
613 DCHECK(web_view);
614 web_view->settings()->setPluginsEnabled(true);
615 web_view->resize(WebSize(300, 300));
616 web_view->updateAllLifecyclePhases();
617 runPendingTasks();
618 web_view->smoothScroll(0, 200, 0);
619 web_view->updateAllLifecyclePhases();
620 runPendingTasks();
621
622 WebElement plugin_container_one_element =
623 web_view->mainFrame()->document().getElementById(
624 WebString::fromUTF8("scrolled-plugin"));
625 plugin_container_one_element.pluginContainer()->requestTouchEventType(
626 WebPluginContainer::TouchEventRequestTypeRaw);
627 WebPlugin* plugin = static_cast<WebPluginContainerImpl*>(
628 plugin_container_one_element.pluginContainer())
629 ->plugin();
630 EventTestPlugin* test_plugin = static_cast<EventTestPlugin*>(plugin);
631
632 WebMouseWheelEvent event(WebInputEvent::MouseWheel,
633 WebInputEvent::NoModifiers,
634 WebInputEvent::TimeStampForTesting);
635
636 WebRect rect = plugin_container_one_element.boundsInViewport();
637 event.x = rect.x + rect.width / 2;
638 event.y = rect.y + rect.height / 2;
639
640 web_view->handleInputEvent(WebCoalescedInputEvent(event));
641 runPendingTasks();
642
643 EXPECT_EQ(WebInputEvent::MouseWheel, test_plugin->getLastInputEventType());
644 EXPECT_EQ(rect.width / 2, test_plugin->getLastEventLocation().x());
645 EXPECT_EQ(rect.height / 2, test_plugin->getLastEventLocation().y());
646 }
647
648 TEST_F(WebPluginContainerTest, MouseEventScrolled) {
649 registerMockedURL("plugin_scroll.html");
650 CustomPluginWebFrameClient<EventTestPlugin>
651 plugin_web_frame_client; // Must outlive webViewHelper.
652 FrameTestHelpers::WebViewHelper web_view_helper;
653 WebView* web_view = web_view_helper.initializeAndLoad(
654 m_baseURL + "plugin_scroll.html", true, &plugin_web_frame_client);
655 DCHECK(web_view);
656 web_view->settings()->setPluginsEnabled(true);
657 web_view->resize(WebSize(300, 300));
658 web_view->updateAllLifecyclePhases();
659 runPendingTasks();
660 web_view->smoothScroll(0, 200, 0);
661 web_view->updateAllLifecyclePhases();
662 runPendingTasks();
663
664 WebElement plugin_container_one_element =
665 web_view->mainFrame()->document().getElementById(
666 WebString::fromUTF8("scrolled-plugin"));
667 plugin_container_one_element.pluginContainer()->requestTouchEventType(
668 WebPluginContainer::TouchEventRequestTypeRaw);
669 WebPlugin* plugin = static_cast<WebPluginContainerImpl*>(
670 plugin_container_one_element.pluginContainer())
671 ->plugin();
672 EventTestPlugin* test_plugin = static_cast<EventTestPlugin*>(plugin);
673
674 WebMouseEvent event(WebInputEvent::MouseMove, WebInputEvent::NoModifiers,
675 WebInputEvent::TimeStampForTesting);
676
677 WebRect rect = plugin_container_one_element.boundsInViewport();
678 event.x = rect.x + rect.width / 2;
679 event.y = rect.y + rect.height / 2;
680
681 web_view->handleInputEvent(WebCoalescedInputEvent(event));
682 runPendingTasks();
683
684 EXPECT_EQ(WebInputEvent::MouseMove, test_plugin->getLastInputEventType());
685 EXPECT_EQ(rect.width / 2, test_plugin->getLastEventLocation().x());
686 EXPECT_EQ(rect.height / 2, test_plugin->getLastEventLocation().y());
687 }
688
689 TEST_F(WebPluginContainerTest, MouseEventZoomed) {
690 registerMockedURL("plugin_scroll.html");
691 CustomPluginWebFrameClient<EventTestPlugin>
692 plugin_web_frame_client; // Must outlive webViewHelper.
693 FrameTestHelpers::WebViewHelper web_view_helper;
694 WebView* web_view = web_view_helper.initializeAndLoad(
695 m_baseURL + "plugin_scroll.html", true, &plugin_web_frame_client);
696 DCHECK(web_view);
697 web_view->settings()->setPluginsEnabled(true);
698 web_view->resize(WebSize(300, 300));
699 web_view->setPageScaleFactor(2);
700 web_view->smoothScroll(0, 300, 0);
701 web_view->updateAllLifecyclePhases();
702 runPendingTasks();
703
704 WebElement plugin_container_one_element =
705 web_view->mainFrame()->document().getElementById(
706 WebString::fromUTF8("scrolled-plugin"));
707 plugin_container_one_element.pluginContainer()->requestTouchEventType(
708 WebPluginContainer::TouchEventRequestTypeRaw);
709 WebPlugin* plugin = static_cast<WebPluginContainerImpl*>(
710 plugin_container_one_element.pluginContainer())
711 ->plugin();
712 EventTestPlugin* test_plugin = static_cast<EventTestPlugin*>(plugin);
713
714 WebMouseEvent event(WebInputEvent::MouseMove, WebInputEvent::NoModifiers,
715 WebInputEvent::TimeStampForTesting);
716
717 WebRect rect = plugin_container_one_element.boundsInViewport();
718 event.x = rect.x + rect.width / 2;
719 event.y = rect.y + rect.height / 2;
720
721 web_view->handleInputEvent(WebCoalescedInputEvent(event));
722 runPendingTasks();
723
724 // rect.width/height divided by 4 because the rect is in viewport bounds and
725 // there is a scale of 2 set.
726 EXPECT_EQ(WebInputEvent::MouseMove, test_plugin->getLastInputEventType());
727 EXPECT_EQ(rect.width / 4, test_plugin->getLastEventLocation().x());
728 EXPECT_EQ(rect.height / 4, test_plugin->getLastEventLocation().y());
729 }
730
731 TEST_F(WebPluginContainerTest, MouseWheelEventZoomed) {
732 registerMockedURL("plugin_scroll.html");
733 CustomPluginWebFrameClient<EventTestPlugin>
734 plugin_web_frame_client; // Must outlive webViewHelper.
735 FrameTestHelpers::WebViewHelper web_view_helper;
736 WebView* web_view = web_view_helper.initializeAndLoad(
737 m_baseURL + "plugin_scroll.html", true, &plugin_web_frame_client);
738 DCHECK(web_view);
739 web_view->settings()->setPluginsEnabled(true);
740 web_view->resize(WebSize(300, 300));
741 web_view->setPageScaleFactor(2);
742 web_view->smoothScroll(0, 300, 0);
743 web_view->updateAllLifecyclePhases();
744 runPendingTasks();
745
746 WebElement plugin_container_one_element =
747 web_view->mainFrame()->document().getElementById(
748 WebString::fromUTF8("scrolled-plugin"));
749 plugin_container_one_element.pluginContainer()->requestTouchEventType(
750 WebPluginContainer::TouchEventRequestTypeRaw);
751 WebPlugin* plugin = static_cast<WebPluginContainerImpl*>(
752 plugin_container_one_element.pluginContainer())
753 ->plugin();
754 EventTestPlugin* test_plugin = static_cast<EventTestPlugin*>(plugin);
755
756 WebMouseWheelEvent event(WebInputEvent::MouseWheel,
757 WebInputEvent::NoModifiers,
758 WebInputEvent::TimeStampForTesting);
759
760 WebRect rect = plugin_container_one_element.boundsInViewport();
761 event.x = rect.x + rect.width / 2;
762 event.y = rect.y + rect.height / 2;
763
764 web_view->handleInputEvent(WebCoalescedInputEvent(event));
765 runPendingTasks();
766
767 // rect.width/height divided by 4 because the rect is in viewport bounds and
768 // there is a scale of 2 set.
769 EXPECT_EQ(WebInputEvent::MouseWheel, test_plugin->getLastInputEventType());
770 EXPECT_EQ(rect.width / 4, test_plugin->getLastEventLocation().x());
771 EXPECT_EQ(rect.height / 4, test_plugin->getLastEventLocation().y());
772 }
773
774 TEST_F(WebPluginContainerTest, TouchEventZoomed) {
775 registerMockedURL("plugin_scroll.html");
776 CustomPluginWebFrameClient<EventTestPlugin>
777 plugin_web_frame_client; // Must outlive webViewHelper.
778 FrameTestHelpers::WebViewHelper web_view_helper;
779 WebView* web_view = web_view_helper.initializeAndLoad(
780 m_baseURL + "plugin_scroll.html", true, &plugin_web_frame_client);
781 DCHECK(web_view);
782 web_view->settings()->setPluginsEnabled(true);
783 web_view->resize(WebSize(300, 300));
784 web_view->setPageScaleFactor(2);
785 web_view->smoothScroll(0, 300, 0);
786 web_view->updateAllLifecyclePhases();
787 runPendingTasks();
788
789 WebElement plugin_container_one_element =
790 web_view->mainFrame()->document().getElementById(
791 WebString::fromUTF8("scrolled-plugin"));
792 plugin_container_one_element.pluginContainer()->requestTouchEventType(
793 WebPluginContainer::TouchEventRequestTypeRaw);
794 WebPlugin* plugin = static_cast<WebPluginContainerImpl*>(
795 plugin_container_one_element.pluginContainer())
796 ->plugin();
797 EventTestPlugin* test_plugin = static_cast<EventTestPlugin*>(plugin);
798
799 WebTouchEvent event(WebInputEvent::TouchStart, WebInputEvent::NoModifiers,
800 WebInputEvent::TimeStampForTesting);
801 event.touchesLength = 1;
802 WebRect rect = plugin_container_one_element.boundsInViewport();
803
804 event.touches[0].state = WebTouchPoint::StatePressed;
805 event.touches[0].position =
806 WebFloatPoint(rect.x + rect.width / 2, rect.y + rect.height / 2);
807
808 web_view->handleInputEvent(WebCoalescedInputEvent(event));
809 runPendingTasks();
810
811 // rect.width/height divided by 4 because the rect is in viewport bounds and
812 // there is a scale of 2 set.
813 EXPECT_EQ(WebInputEvent::TouchStart, test_plugin->getLastInputEventType());
814 EXPECT_EQ(rect.width / 4, test_plugin->getLastEventLocation().x());
815 EXPECT_EQ(rect.height / 4, test_plugin->getLastEventLocation().y());
550 } 816 }
551 817
552 // Verify that isRectTopmost returns false when the document is detached. 818 // Verify that isRectTopmost returns false when the document is detached.
553 TEST_F(WebPluginContainerTest, IsRectTopmostTest) { 819 TEST_F(WebPluginContainerTest, IsRectTopmostTest) {
554 registerMockedURL("plugin_container.html"); 820 registerMockedURL("plugin_container.html");
555 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. 821 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper.
556 FrameTestHelpers::WebViewHelper webViewHelper; 822 FrameTestHelpers::WebViewHelper webViewHelper;
557 WebView* webView = webViewHelper.initializeAndLoad( 823 WebView* webView = webViewHelper.initializeAndLoad(
558 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); 824 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient);
559 DCHECK(webView); 825 DCHECK(webView);
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 WebString::fromUTF8("translated-plugin")); 1051 WebString::fromUTF8("translated-plugin"));
786 pluginContainerOneElement.pluginContainer()->setWantsWheelEvents(true); 1052 pluginContainerOneElement.pluginContainer()->setWantsWheelEvents(true);
787 1053
788 runPendingTasks(); 1054 runPendingTasks();
789 EXPECT_TRUE( 1055 EXPECT_TRUE(
790 webView->page()->frameHost().eventHandlerRegistry().hasEventHandlers( 1056 webView->page()->frameHost().eventHandlerRegistry().hasEventHandlers(
791 EventHandlerRegistry::WheelEventBlocking)); 1057 EventHandlerRegistry::WheelEventBlocking));
792 } 1058 }
793 1059
794 } // namespace blink 1060 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebPluginContainerImpl.cpp ('k') | third_party/WebKit/Source/web/tests/data/plugin_scroll.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698