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

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 more zoom tests 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_; }
486
487 void ClearLastEventType() { last_event_type_ = WebInputEvent::kUndefined; }
476 488
477 private: 489 private:
478 WebInputEvent::Type last_event_type_; 490 WebInputEvent::Type last_event_type_;
479 IntPoint last_mouse_event_location_; 491 IntPoint last_event_location_;
480 }; 492 };
481 493
482 TEST_F(WebPluginContainerTest, GestureLongPressReachesPlugin) { 494 TEST_F(WebPluginContainerTest, GestureLongPressReachesPlugin) {
483 RegisterMockedURL("plugin_container.html"); 495 RegisterMockedURL("plugin_container.html");
484 CustomPluginWebFrameClient<EventTestPlugin> 496 CustomPluginWebFrameClient<EventTestPlugin>
485 plugin_web_frame_client; // Must outlive webViewHelper. 497 plugin_web_frame_client; // Must outlive webViewHelper.
486 FrameTestHelpers::WebViewHelper web_view_helper; 498 FrameTestHelpers::WebViewHelper web_view_helper;
487 WebView* web_view = web_view_helper.InitializeAndLoad( 499 WebView* web_view = web_view_helper.InitializeAndLoad(
488 base_url_ + "plugin_container.html", true, &plugin_web_frame_client); 500 base_url_ + "plugin_container.html", true, &plugin_web_frame_client);
489 DCHECK(web_view); 501 DCHECK(web_view);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 WebInputEvent::kNoModifiers, 565 WebInputEvent::kNoModifiers,
554 WebInputEvent::kTimeStampForTesting); 566 WebInputEvent::kTimeStampForTesting);
555 567
556 WebRect rect = plugin_container_one_element.BoundsInViewport(); 568 WebRect rect = plugin_container_one_element.BoundsInViewport();
557 event.SetPositionInWidget(rect.x + rect.width / 2, rect.y + rect.height / 2); 569 event.SetPositionInWidget(rect.x + rect.width / 2, rect.y + rect.height / 2);
558 570
559 web_view->HandleInputEvent(WebCoalescedInputEvent(event)); 571 web_view->HandleInputEvent(WebCoalescedInputEvent(event));
560 RunPendingTasks(); 572 RunPendingTasks();
561 573
562 EXPECT_EQ(WebInputEvent::kMouseWheel, test_plugin->GetLastInputEventType()); 574 EXPECT_EQ(WebInputEvent::kMouseWheel, test_plugin->GetLastInputEventType());
563 EXPECT_EQ(rect.width / 2, test_plugin->GetLastMouseEventLocation().X()); 575 EXPECT_EQ(rect.width / 2, test_plugin->GetLastEventLocation().X());
564 EXPECT_EQ(rect.height / 2, test_plugin->GetLastMouseEventLocation().Y()); 576 EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y());
577 }
578
579 TEST_F(WebPluginContainerTest, TouchEventScrolled) {
580 RegisterMockedURL("plugin_scroll.html");
581 CustomPluginWebFrameClient<EventTestPlugin>
582 plugin_web_frame_client; // Must outlive webViewHelper.
583 FrameTestHelpers::WebViewHelper web_view_helper;
584 WebView* web_view = web_view_helper.InitializeAndLoad(
585 base_url_ + "plugin_scroll.html", true, &plugin_web_frame_client);
586 DCHECK(web_view);
587 web_view->GetSettings()->SetPluginsEnabled(true);
588 web_view->Resize(WebSize(300, 300));
589 web_view->UpdateAllLifecyclePhases();
590 RunPendingTasks();
591 web_view->SmoothScroll(0, 200, 0);
592 web_view->UpdateAllLifecyclePhases();
593 RunPendingTasks();
594
595 WebElement plugin_container_one_element =
596 web_view->MainFrame()->GetDocument().GetElementById(
597 WebString::FromUTF8("scrolled-plugin"));
598 plugin_container_one_element.PluginContainer()->RequestTouchEventType(
599 WebPluginContainer::kTouchEventRequestTypeRaw);
600 WebPlugin* plugin = static_cast<WebPluginContainerImpl*>(
601 plugin_container_one_element.PluginContainer())
602 ->Plugin();
603 EventTestPlugin* test_plugin = static_cast<EventTestPlugin*>(plugin);
604
605 WebTouchEvent event(WebInputEvent::kTouchStart, WebInputEvent::kNoModifiers,
606 WebInputEvent::kTimeStampForTesting);
607 event.touches_length = 1;
608 WebRect rect = plugin_container_one_element.BoundsInViewport();
609 event.touches[0].state = WebTouchPoint::kStatePressed;
610 event.touches[0].position =
611 WebFloatPoint(rect.x + rect.width / 2, rect.y + rect.height / 2);
612
613 web_view->HandleInputEvent(WebCoalescedInputEvent(event));
614 RunPendingTasks();
615
616 EXPECT_EQ(WebInputEvent::kTouchStart, test_plugin->GetLastInputEventType());
617 EXPECT_EQ(rect.width / 2, test_plugin->GetLastEventLocation().X());
618 EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y());
619 }
620
621 TEST_F(WebPluginContainerTest, MouseWheelEventScrolled) {
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 WebMouseWheelEvent event(WebInputEvent::kMouseWheel,
648 WebInputEvent::kNoModifiers,
649 WebInputEvent::kTimeStampForTesting);
650
651 WebRect rect = plugin_container_one_element.BoundsInViewport();
652 event.SetPositionInWidget(rect.x + rect.width / 2, rect.y + rect.height / 2);
653
654 web_view->HandleInputEvent(WebCoalescedInputEvent(event));
655 RunPendingTasks();
656
657 EXPECT_EQ(WebInputEvent::kMouseWheel, test_plugin->GetLastInputEventType());
658 EXPECT_EQ(rect.width / 2, test_plugin->GetLastEventLocation().X());
659 EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y());
660 }
661
662 TEST_F(WebPluginContainerTest, MouseEventScrolled) {
663 RegisterMockedURL("plugin_scroll.html");
664 CustomPluginWebFrameClient<EventTestPlugin>
665 plugin_web_frame_client; // Must outlive webViewHelper.
666 FrameTestHelpers::WebViewHelper web_view_helper;
667 WebView* web_view = web_view_helper.InitializeAndLoad(
668 base_url_ + "plugin_scroll.html", true, &plugin_web_frame_client);
669 DCHECK(web_view);
670 web_view->GetSettings()->SetPluginsEnabled(true);
671 web_view->Resize(WebSize(300, 300));
672 web_view->UpdateAllLifecyclePhases();
673 RunPendingTasks();
674 web_view->SmoothScroll(0, 200, 0);
675 web_view->UpdateAllLifecyclePhases();
676 RunPendingTasks();
677
678 WebElement plugin_container_one_element =
679 web_view->MainFrame()->GetDocument().GetElementById(
680 WebString::FromUTF8("scrolled-plugin"));
681 plugin_container_one_element.PluginContainer()->RequestTouchEventType(
682 WebPluginContainer::kTouchEventRequestTypeRaw);
683 WebPlugin* plugin = static_cast<WebPluginContainerImpl*>(
684 plugin_container_one_element.PluginContainer())
685 ->Plugin();
686 EventTestPlugin* test_plugin = static_cast<EventTestPlugin*>(plugin);
687
688 WebMouseEvent event(WebInputEvent::kMouseMove, WebInputEvent::kNoModifiers,
689 WebInputEvent::kTimeStampForTesting);
690
691 WebRect rect = plugin_container_one_element.BoundsInViewport();
692 event.SetPositionInWidget(rect.x + rect.width / 2, rect.y + rect.height / 2);
693
694 web_view->HandleInputEvent(WebCoalescedInputEvent(event));
695 RunPendingTasks();
696
697 EXPECT_EQ(WebInputEvent::kMouseMove, test_plugin->GetLastInputEventType());
698 EXPECT_EQ(rect.width / 2, test_plugin->GetLastEventLocation().X());
699 EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y());
700 }
701
702 TEST_F(WebPluginContainerTest, MouseEventZoomed) {
703 RegisterMockedURL("plugin_scroll.html");
704 CustomPluginWebFrameClient<EventTestPlugin>
705 plugin_web_frame_client; // Must outlive webViewHelper.
706 FrameTestHelpers::WebViewHelper web_view_helper;
707 WebView* web_view = web_view_helper.InitializeAndLoad(
708 base_url_ + "plugin_scroll.html", true, &plugin_web_frame_client);
709 DCHECK(web_view);
710 web_view->GetSettings()->SetPluginsEnabled(true);
711 web_view->Resize(WebSize(300, 300));
712 web_view->SetPageScaleFactor(2);
713 web_view->SmoothScroll(0, 300, 0);
714 web_view->UpdateAllLifecyclePhases();
715 RunPendingTasks();
716
717 WebElement plugin_container_one_element =
718 web_view->MainFrame()->GetDocument().GetElementById(
719 WebString::FromUTF8("scrolled-plugin"));
720 plugin_container_one_element.PluginContainer()->RequestTouchEventType(
721 WebPluginContainer::kTouchEventRequestTypeRaw);
722 WebPlugin* plugin = static_cast<WebPluginContainerImpl*>(
723 plugin_container_one_element.PluginContainer())
724 ->Plugin();
725 EventTestPlugin* test_plugin = static_cast<EventTestPlugin*>(plugin);
726
727 WebMouseEvent event(WebInputEvent::kMouseMove, WebInputEvent::kNoModifiers,
728 WebInputEvent::kTimeStampForTesting);
729
730 WebRect rect = plugin_container_one_element.BoundsInViewport();
731 event.SetPositionInWidget(rect.x + rect.width / 2, rect.y + rect.height / 2);
732
733 web_view->HandleInputEvent(WebCoalescedInputEvent(event));
734 RunPendingTasks();
735
736 // rect.width/height divided by 4 because the rect is in viewport bounds and
737 // there is a scale of 2 set.
738 EXPECT_EQ(WebInputEvent::kMouseMove, test_plugin->GetLastInputEventType());
739 EXPECT_EQ(rect.width / 4, test_plugin->GetLastEventLocation().X());
740 EXPECT_EQ(rect.height / 4, test_plugin->GetLastEventLocation().Y());
741 }
742
743 TEST_F(WebPluginContainerTest, MouseWheelEventZoomed) {
744 RegisterMockedURL("plugin_scroll.html");
745 CustomPluginWebFrameClient<EventTestPlugin>
746 plugin_web_frame_client; // Must outlive webViewHelper.
747 FrameTestHelpers::WebViewHelper web_view_helper;
748 WebView* web_view = web_view_helper.InitializeAndLoad(
749 base_url_ + "plugin_scroll.html", true, &plugin_web_frame_client);
750 DCHECK(web_view);
751 web_view->GetSettings()->SetPluginsEnabled(true);
752 web_view->Resize(WebSize(300, 300));
753 web_view->SetPageScaleFactor(2);
754 web_view->SmoothScroll(0, 300, 0);
755 web_view->UpdateAllLifecyclePhases();
756 RunPendingTasks();
757
758 WebElement plugin_container_one_element =
759 web_view->MainFrame()->GetDocument().GetElementById(
760 WebString::FromUTF8("scrolled-plugin"));
761 plugin_container_one_element.PluginContainer()->RequestTouchEventType(
762 WebPluginContainer::kTouchEventRequestTypeRaw);
763 WebPlugin* plugin = static_cast<WebPluginContainerImpl*>(
764 plugin_container_one_element.PluginContainer())
765 ->Plugin();
766 EventTestPlugin* test_plugin = static_cast<EventTestPlugin*>(plugin);
767
768 WebMouseWheelEvent event(WebInputEvent::kMouseWheel,
769 WebInputEvent::kNoModifiers,
770 WebInputEvent::kTimeStampForTesting);
771
772 WebRect rect = plugin_container_one_element.BoundsInViewport();
773 event.SetPositionInWidget(rect.x + rect.width / 2, rect.y + rect.height / 2);
774
775 web_view->HandleInputEvent(WebCoalescedInputEvent(event));
776 RunPendingTasks();
777
778 // rect.width/height divided by 4 because the rect is in viewport bounds and
779 // there is a scale of 2 set.
780 EXPECT_EQ(WebInputEvent::kMouseWheel, test_plugin->GetLastInputEventType());
781 EXPECT_EQ(rect.width / 4, test_plugin->GetLastEventLocation().X());
782 EXPECT_EQ(rect.height / 4, test_plugin->GetLastEventLocation().Y());
783 }
784
785 TEST_F(WebPluginContainerTest, TouchEventZoomed) {
786 RegisterMockedURL("plugin_scroll.html");
787 CustomPluginWebFrameClient<EventTestPlugin>
788 plugin_web_frame_client; // Must outlive webViewHelper.
789 FrameTestHelpers::WebViewHelper web_view_helper;
790 WebView* web_view = web_view_helper.InitializeAndLoad(
791 base_url_ + "plugin_scroll.html", true, &plugin_web_frame_client);
792 DCHECK(web_view);
793 web_view->GetSettings()->SetPluginsEnabled(true);
794 web_view->Resize(WebSize(300, 300));
795 web_view->SetPageScaleFactor(2);
796 web_view->SmoothScroll(0, 300, 0);
797 web_view->UpdateAllLifecyclePhases();
798 RunPendingTasks();
799
800 WebElement plugin_container_one_element =
801 web_view->MainFrame()->GetDocument().GetElementById(
802 WebString::FromUTF8("scrolled-plugin"));
803 plugin_container_one_element.PluginContainer()->RequestTouchEventType(
804 WebPluginContainer::kTouchEventRequestTypeRaw);
805 WebPlugin* plugin = static_cast<WebPluginContainerImpl*>(
806 plugin_container_one_element.PluginContainer())
807 ->Plugin();
808 EventTestPlugin* test_plugin = static_cast<EventTestPlugin*>(plugin);
809
810 WebTouchEvent event(WebInputEvent::kTouchStart, WebInputEvent::kNoModifiers,
811 WebInputEvent::kTimeStampForTesting);
812 event.touches_length = 1;
813 WebRect rect = plugin_container_one_element.BoundsInViewport();
814
815 event.touches[0].state = WebTouchPoint::kStatePressed;
816 event.touches[0].position =
817 WebFloatPoint(rect.x + rect.width / 2, rect.y + rect.height / 2);
818
819 web_view->HandleInputEvent(WebCoalescedInputEvent(event));
820 RunPendingTasks();
821
822 // rect.width/height divided by 4 because the rect is in viewport bounds and
823 // there is a scale of 2 set.
824 EXPECT_EQ(WebInputEvent::kTouchStart, test_plugin->GetLastInputEventType());
825 EXPECT_EQ(rect.width / 4, test_plugin->GetLastEventLocation().X());
826 EXPECT_EQ(rect.height / 4, test_plugin->GetLastEventLocation().Y());
565 } 827 }
566 828
567 // Verify that isRectTopmost returns false when the document is detached. 829 // Verify that isRectTopmost returns false when the document is detached.
568 TEST_F(WebPluginContainerTest, IsRectTopmostTest) { 830 TEST_F(WebPluginContainerTest, IsRectTopmostTest) {
569 RegisterMockedURL("plugin_container.html"); 831 RegisterMockedURL("plugin_container.html");
570 TestPluginWebFrameClient 832 TestPluginWebFrameClient
571 plugin_web_frame_client; // Must outlive webViewHelper. 833 plugin_web_frame_client; // Must outlive webViewHelper.
572 FrameTestHelpers::WebViewHelper web_view_helper; 834 FrameTestHelpers::WebViewHelper web_view_helper;
573 WebView* web_view = web_view_helper.InitializeAndLoad( 835 WebView* web_view = web_view_helper.InitializeAndLoad(
574 base_url_ + "plugin_container.html", true, &plugin_web_frame_client); 836 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( 1070 web_view->MainFrame()->GetDocument().GetElementById(
809 WebString::FromUTF8("translated-plugin")); 1071 WebString::FromUTF8("translated-plugin"));
810 plugin_container_one_element.PluginContainer()->SetWantsWheelEvents(true); 1072 plugin_container_one_element.PluginContainer()->SetWantsWheelEvents(true);
811 1073
812 RunPendingTasks(); 1074 RunPendingTasks();
813 EXPECT_TRUE(web_view->GetPage()->GetEventHandlerRegistry().HasEventHandlers( 1075 EXPECT_TRUE(web_view->GetPage()->GetEventHandlerRegistry().HasEventHandlers(
814 EventHandlerRegistry::kWheelEventBlocking)); 1076 EventHandlerRegistry::kWheelEventBlocking));
815 } 1077 }
816 1078
817 } // namespace blink 1079 } // 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