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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 WebMouseEventBuilder mouse(0, 0, *event); | 112 WebMouseEventBuilder mouse(0, 0, *event); |
113 EXPECT_EQ(WebInputEvent::kUndefined, mouse.GetType()); | 113 EXPECT_EQ(WebInputEvent::kUndefined, mouse.GetType()); |
114 } | 114 } |
115 | 115 |
116 TEST(WebInputEventConversionTest, InputEventsScaling) { | 116 TEST(WebInputEventConversionTest, InputEventsScaling) { |
117 const std::string base_url("http://www.test1.com/"); | 117 const std::string base_url("http://www.test1.com/"); |
118 const std::string file_name("fixed_layout.html"); | 118 const std::string file_name("fixed_layout.html"); |
119 | 119 |
120 RegisterMockedURL(base_url, file_name); | 120 RegisterMockedURL(base_url, file_name); |
121 FrameTestHelpers::WebViewHelper web_view_helper; | 121 FrameTestHelpers::WebViewHelper web_view_helper; |
122 WebViewImpl* web_view_impl = | 122 WebViewBase* web_view = |
123 web_view_helper.InitializeAndLoad(base_url + file_name, true); | 123 web_view_helper.InitializeAndLoad(base_url + file_name, true); |
124 web_view_impl->GetSettings()->SetViewportEnabled(true); | 124 web_view->GetSettings()->SetViewportEnabled(true); |
125 int page_width = 640; | 125 int page_width = 640; |
126 int page_height = 480; | 126 int page_height = 480; |
127 web_view_impl->Resize(WebSize(page_width, page_height)); | 127 web_view->Resize(WebSize(page_width, page_height)); |
128 web_view_impl->UpdateAllLifecyclePhases(); | 128 web_view->UpdateAllLifecyclePhases(); |
129 | 129 |
130 web_view_impl->SetPageScaleFactor(2); | 130 web_view->SetPageScaleFactor(2); |
131 | 131 |
132 FrameView* view = ToLocalFrame(web_view_impl->GetPage()->MainFrame())->View(); | 132 FrameView* view = ToLocalFrame(web_view->GetPage()->MainFrame())->View(); |
133 | 133 |
134 { | 134 { |
135 WebMouseEvent web_mouse_event(WebInputEvent::kMouseMove, | 135 WebMouseEvent web_mouse_event(WebInputEvent::kMouseMove, |
136 WebInputEvent::kNoModifiers, | 136 WebInputEvent::kNoModifiers, |
137 WebInputEvent::kTimeStampForTesting); | 137 WebInputEvent::kTimeStampForTesting); |
138 web_mouse_event.SetPositionInWidget(10, 10); | 138 web_mouse_event.SetPositionInWidget(10, 10); |
139 web_mouse_event.SetPositionInScreen(10, 10); | 139 web_mouse_event.SetPositionInScreen(10, 10); |
140 web_mouse_event.movement_x = 10; | 140 web_mouse_event.movement_x = 10; |
141 web_mouse_event.movement_y = 10; | 141 web_mouse_event.movement_y = 10; |
142 | 142 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 EXPECT_EQ(10, transformed_point.movement_y); | 341 EXPECT_EQ(10, transformed_point.movement_y); |
342 } | 342 } |
343 } | 343 } |
344 | 344 |
345 TEST(WebInputEventConversionTest, InputEventsTransform) { | 345 TEST(WebInputEventConversionTest, InputEventsTransform) { |
346 const std::string base_url("http://www.test2.com/"); | 346 const std::string base_url("http://www.test2.com/"); |
347 const std::string file_name("fixed_layout.html"); | 347 const std::string file_name("fixed_layout.html"); |
348 | 348 |
349 RegisterMockedURL(base_url, file_name); | 349 RegisterMockedURL(base_url, file_name); |
350 FrameTestHelpers::WebViewHelper web_view_helper; | 350 FrameTestHelpers::WebViewHelper web_view_helper; |
351 WebViewImpl* web_view_impl = | 351 WebViewBase* web_view = |
352 web_view_helper.InitializeAndLoad(base_url + file_name, true); | 352 web_view_helper.InitializeAndLoad(base_url + file_name, true); |
353 web_view_impl->GetSettings()->SetViewportEnabled(true); | 353 web_view->GetSettings()->SetViewportEnabled(true); |
354 int page_width = 640; | 354 int page_width = 640; |
355 int page_height = 480; | 355 int page_height = 480; |
356 web_view_impl->Resize(WebSize(page_width, page_height)); | 356 web_view->Resize(WebSize(page_width, page_height)); |
357 web_view_impl->UpdateAllLifecyclePhases(); | 357 web_view->UpdateAllLifecyclePhases(); |
358 | 358 |
359 web_view_impl->SetPageScaleFactor(2); | 359 web_view->SetPageScaleFactor(2); |
360 web_view_impl->MainFrameImpl()->SetInputEventsTransformForEmulation( | 360 web_view->MainFrameImpl()->SetInputEventsTransformForEmulation( |
361 IntSize(10, 20), 1.5); | 361 IntSize(10, 20), 1.5); |
362 | 362 |
363 FrameView* view = ToLocalFrame(web_view_impl->GetPage()->MainFrame())->View(); | 363 FrameView* view = ToLocalFrame(web_view->GetPage()->MainFrame())->View(); |
364 | 364 |
365 { | 365 { |
366 WebMouseEvent web_mouse_event(WebInputEvent::kMouseMove, | 366 WebMouseEvent web_mouse_event(WebInputEvent::kMouseMove, |
367 WebInputEvent::kNoModifiers, | 367 WebInputEvent::kNoModifiers, |
368 WebInputEvent::kTimeStampForTesting); | 368 WebInputEvent::kTimeStampForTesting); |
369 web_mouse_event.SetPositionInWidget(100, 110); | 369 web_mouse_event.SetPositionInWidget(100, 110); |
370 web_mouse_event.SetPositionInScreen(100, 110); | 370 web_mouse_event.SetPositionInScreen(100, 110); |
371 web_mouse_event.movement_x = 60; | 371 web_mouse_event.movement_x = 60; |
372 web_mouse_event.movement_y = 60; | 372 web_mouse_event.movement_y = 60; |
373 | 373 |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 EXPECT_FLOAT_EQ(10, transformed_point.radius_y); | 616 EXPECT_FLOAT_EQ(10, transformed_point.radius_y); |
617 } | 617 } |
618 } | 618 } |
619 | 619 |
620 TEST(WebInputEventConversionTest, InputEventsConversions) { | 620 TEST(WebInputEventConversionTest, InputEventsConversions) { |
621 const std::string base_url("http://www.test3.com/"); | 621 const std::string base_url("http://www.test3.com/"); |
622 const std::string file_name("fixed_layout.html"); | 622 const std::string file_name("fixed_layout.html"); |
623 | 623 |
624 RegisterMockedURL(base_url, file_name); | 624 RegisterMockedURL(base_url, file_name); |
625 FrameTestHelpers::WebViewHelper web_view_helper; | 625 FrameTestHelpers::WebViewHelper web_view_helper; |
626 WebViewImpl* web_view_impl = | 626 WebViewBase* web_view = |
627 web_view_helper.InitializeAndLoad(base_url + file_name, true); | 627 web_view_helper.InitializeAndLoad(base_url + file_name, true); |
628 int page_width = 640; | 628 int page_width = 640; |
629 int page_height = 480; | 629 int page_height = 480; |
630 web_view_impl->Resize(WebSize(page_width, page_height)); | 630 web_view->Resize(WebSize(page_width, page_height)); |
631 web_view_impl->UpdateAllLifecyclePhases(); | 631 web_view->UpdateAllLifecyclePhases(); |
632 | 632 |
633 FrameView* view = ToLocalFrame(web_view_impl->GetPage()->MainFrame())->View(); | 633 FrameView* view = ToLocalFrame(web_view->GetPage()->MainFrame())->View(); |
634 { | 634 { |
635 WebGestureEvent web_gesture_event(WebInputEvent::kGestureTap, | 635 WebGestureEvent web_gesture_event(WebInputEvent::kGestureTap, |
636 WebInputEvent::kNoModifiers, | 636 WebInputEvent::kNoModifiers, |
637 WebInputEvent::kTimeStampForTesting); | 637 WebInputEvent::kTimeStampForTesting); |
638 web_gesture_event.source_device = kWebGestureDeviceTouchscreen; | 638 web_gesture_event.source_device = kWebGestureDeviceTouchscreen; |
639 web_gesture_event.x = 10; | 639 web_gesture_event.x = 10; |
640 web_gesture_event.y = 10; | 640 web_gesture_event.y = 10; |
641 web_gesture_event.global_x = 10; | 641 web_gesture_event.global_x = 10; |
642 web_gesture_event.global_y = 10; | 642 web_gesture_event.global_y = 10; |
643 web_gesture_event.data.tap.tap_count = 1; | 643 web_gesture_event.data.tap.tap_count = 1; |
(...skipping 11 matching lines...) Expand all Loading... |
655 EXPECT_EQ(1, scaled_gesture_event.TapCount()); | 655 EXPECT_EQ(1, scaled_gesture_event.TapCount()); |
656 } | 656 } |
657 } | 657 } |
658 | 658 |
659 TEST(WebInputEventConversionTest, VisualViewportOffset) { | 659 TEST(WebInputEventConversionTest, VisualViewportOffset) { |
660 const std::string base_url("http://www.test4.com/"); | 660 const std::string base_url("http://www.test4.com/"); |
661 const std::string file_name("fixed_layout.html"); | 661 const std::string file_name("fixed_layout.html"); |
662 | 662 |
663 RegisterMockedURL(base_url, file_name); | 663 RegisterMockedURL(base_url, file_name); |
664 FrameTestHelpers::WebViewHelper web_view_helper; | 664 FrameTestHelpers::WebViewHelper web_view_helper; |
665 WebViewImpl* web_view_impl = | 665 WebViewBase* web_view = |
666 web_view_helper.InitializeAndLoad(base_url + file_name, true); | 666 web_view_helper.InitializeAndLoad(base_url + file_name, true); |
667 int page_width = 640; | 667 int page_width = 640; |
668 int page_height = 480; | 668 int page_height = 480; |
669 web_view_impl->Resize(WebSize(page_width, page_height)); | 669 web_view->Resize(WebSize(page_width, page_height)); |
670 web_view_impl->UpdateAllLifecyclePhases(); | 670 web_view->UpdateAllLifecyclePhases(); |
671 | 671 |
672 web_view_impl->SetPageScaleFactor(2); | 672 web_view->SetPageScaleFactor(2); |
673 | 673 |
674 IntPoint visual_offset(35, 60); | 674 IntPoint visual_offset(35, 60); |
675 web_view_impl->GetPage()->GetVisualViewport().SetLocation(visual_offset); | 675 web_view->GetPage()->GetVisualViewport().SetLocation(visual_offset); |
676 | 676 |
677 FrameView* view = ToLocalFrame(web_view_impl->GetPage()->MainFrame())->View(); | 677 FrameView* view = ToLocalFrame(web_view->GetPage()->MainFrame())->View(); |
678 | 678 |
679 { | 679 { |
680 WebMouseEvent web_mouse_event(WebInputEvent::kMouseMove, | 680 WebMouseEvent web_mouse_event(WebInputEvent::kMouseMove, |
681 WebInputEvent::kNoModifiers, | 681 WebInputEvent::kNoModifiers, |
682 WebInputEvent::kTimeStampForTesting); | 682 WebInputEvent::kTimeStampForTesting); |
683 web_mouse_event.SetPositionInWidget(10, 10); | 683 web_mouse_event.SetPositionInWidget(10, 10); |
684 web_mouse_event.SetPositionInScreen(10, 10); | 684 web_mouse_event.SetPositionInScreen(10, 10); |
685 | 685 |
686 WebMouseEvent transformed_mouse_event = | 686 WebMouseEvent transformed_mouse_event = |
687 TransformWebMouseEvent(view, web_mouse_event); | 687 TransformWebMouseEvent(view, web_mouse_event); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 EXPECT_FLOAT_EQ(5.2f + visual_offset.Y(), transformed_point.position.y); | 756 EXPECT_FLOAT_EQ(5.2f + visual_offset.Y(), transformed_point.position.y); |
757 } | 757 } |
758 } | 758 } |
759 | 759 |
760 TEST(WebInputEventConversionTest, ElasticOverscroll) { | 760 TEST(WebInputEventConversionTest, ElasticOverscroll) { |
761 const std::string base_url("http://www.test5.com/"); | 761 const std::string base_url("http://www.test5.com/"); |
762 const std::string file_name("fixed_layout.html"); | 762 const std::string file_name("fixed_layout.html"); |
763 | 763 |
764 RegisterMockedURL(base_url, file_name); | 764 RegisterMockedURL(base_url, file_name); |
765 FrameTestHelpers::WebViewHelper web_view_helper; | 765 FrameTestHelpers::WebViewHelper web_view_helper; |
766 WebViewImpl* web_view_impl = | 766 WebViewBase* web_view = |
767 web_view_helper.InitializeAndLoad(base_url + file_name, true); | 767 web_view_helper.InitializeAndLoad(base_url + file_name, true); |
768 int page_width = 640; | 768 int page_width = 640; |
769 int page_height = 480; | 769 int page_height = 480; |
770 web_view_impl->Resize(WebSize(page_width, page_height)); | 770 web_view->Resize(WebSize(page_width, page_height)); |
771 web_view_impl->UpdateAllLifecyclePhases(); | 771 web_view->UpdateAllLifecyclePhases(); |
772 | 772 |
773 FrameView* view = ToLocalFrame(web_view_impl->GetPage()->MainFrame())->View(); | 773 FrameView* view = ToLocalFrame(web_view->GetPage()->MainFrame())->View(); |
774 | 774 |
775 FloatSize elastic_overscroll(10, -20); | 775 FloatSize elastic_overscroll(10, -20); |
776 web_view_impl->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), | 776 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), |
777 elastic_overscroll, 1.0f, 0.0f); | 777 elastic_overscroll, 1.0f, 0.0f); |
778 | 778 |
779 // Just elastic overscroll. | 779 // Just elastic overscroll. |
780 { | 780 { |
781 WebMouseEvent web_mouse_event(WebInputEvent::kMouseMove, | 781 WebMouseEvent web_mouse_event(WebInputEvent::kMouseMove, |
782 WebInputEvent::kNoModifiers, | 782 WebInputEvent::kNoModifiers, |
783 WebInputEvent::kTimeStampForTesting); | 783 WebInputEvent::kTimeStampForTesting); |
784 web_mouse_event.SetPositionInWidget(10, 50); | 784 web_mouse_event.SetPositionInWidget(10, 50); |
785 web_mouse_event.SetPositionInScreen(10, 50); | 785 web_mouse_event.SetPositionInScreen(10, 50); |
786 | 786 |
787 WebMouseEvent transformed_mouse_event = | 787 WebMouseEvent transformed_mouse_event = |
788 TransformWebMouseEvent(view, web_mouse_event); | 788 TransformWebMouseEvent(view, web_mouse_event); |
789 IntPoint position = | 789 IntPoint position = |
790 FlooredIntPoint(transformed_mouse_event.PositionInRootFrame()); | 790 FlooredIntPoint(transformed_mouse_event.PositionInRootFrame()); |
791 | 791 |
792 EXPECT_EQ(web_mouse_event.PositionInWidget().x + elastic_overscroll.Width(), | 792 EXPECT_EQ(web_mouse_event.PositionInWidget().x + elastic_overscroll.Width(), |
793 position.X()); | 793 position.X()); |
794 EXPECT_EQ( | 794 EXPECT_EQ( |
795 web_mouse_event.PositionInWidget().y + elastic_overscroll.Height(), | 795 web_mouse_event.PositionInWidget().y + elastic_overscroll.Height(), |
796 position.Y()); | 796 position.Y()); |
797 EXPECT_EQ(web_mouse_event.PositionInScreen().x, | 797 EXPECT_EQ(web_mouse_event.PositionInScreen().x, |
798 transformed_mouse_event.PositionInScreen().x); | 798 transformed_mouse_event.PositionInScreen().x); |
799 EXPECT_EQ(web_mouse_event.PositionInScreen().y, | 799 EXPECT_EQ(web_mouse_event.PositionInScreen().y, |
800 transformed_mouse_event.PositionInScreen().y); | 800 transformed_mouse_event.PositionInScreen().y); |
801 } | 801 } |
802 | 802 |
803 // Elastic overscroll and pinch-zoom (this doesn't actually ever happen, | 803 // Elastic overscroll and pinch-zoom (this doesn't actually ever happen, |
804 // but ensure that if it were to, the overscroll would be applied after the | 804 // but ensure that if it were to, the overscroll would be applied after the |
805 // pinch-zoom). | 805 // pinch-zoom). |
806 float page_scale = 2; | 806 float page_scale = 2; |
807 web_view_impl->SetPageScaleFactor(page_scale); | 807 web_view->SetPageScaleFactor(page_scale); |
808 IntPoint visual_offset(35, 60); | 808 IntPoint visual_offset(35, 60); |
809 web_view_impl->GetPage()->GetVisualViewport().SetLocation(visual_offset); | 809 web_view->GetPage()->GetVisualViewport().SetLocation(visual_offset); |
810 { | 810 { |
811 WebMouseEvent web_mouse_event(WebInputEvent::kMouseMove, | 811 WebMouseEvent web_mouse_event(WebInputEvent::kMouseMove, |
812 WebInputEvent::kNoModifiers, | 812 WebInputEvent::kNoModifiers, |
813 WebInputEvent::kTimeStampForTesting); | 813 WebInputEvent::kTimeStampForTesting); |
814 web_mouse_event.SetPositionInWidget(10, 10); | 814 web_mouse_event.SetPositionInWidget(10, 10); |
815 web_mouse_event.SetPositionInScreen(10, 10); | 815 web_mouse_event.SetPositionInScreen(10, 10); |
816 | 816 |
817 WebMouseEvent transformed_mouse_event = | 817 WebMouseEvent transformed_mouse_event = |
818 TransformWebMouseEvent(view, web_mouse_event); | 818 TransformWebMouseEvent(view, web_mouse_event); |
819 IntPoint position = | 819 IntPoint position = |
(...skipping 12 matching lines...) Expand all Loading... |
832 } | 832 } |
833 } | 833 } |
834 | 834 |
835 // Page reload/navigation should not reset elastic overscroll. | 835 // Page reload/navigation should not reset elastic overscroll. |
836 TEST(WebInputEventConversionTest, ElasticOverscrollWithPageReload) { | 836 TEST(WebInputEventConversionTest, ElasticOverscrollWithPageReload) { |
837 const std::string base_url("http://www.test6.com/"); | 837 const std::string base_url("http://www.test6.com/"); |
838 const std::string file_name("fixed_layout.html"); | 838 const std::string file_name("fixed_layout.html"); |
839 | 839 |
840 RegisterMockedURL(base_url, file_name); | 840 RegisterMockedURL(base_url, file_name); |
841 FrameTestHelpers::WebViewHelper web_view_helper; | 841 FrameTestHelpers::WebViewHelper web_view_helper; |
842 WebViewImpl* web_view_impl = | 842 WebViewBase* web_view = |
843 web_view_helper.InitializeAndLoad(base_url + file_name, true); | 843 web_view_helper.InitializeAndLoad(base_url + file_name, true); |
844 int page_width = 640; | 844 int page_width = 640; |
845 int page_height = 480; | 845 int page_height = 480; |
846 web_view_impl->Resize(WebSize(page_width, page_height)); | 846 web_view->Resize(WebSize(page_width, page_height)); |
847 web_view_impl->UpdateAllLifecyclePhases(); | 847 web_view->UpdateAllLifecyclePhases(); |
848 | 848 |
849 FloatSize elastic_overscroll(10, -20); | 849 FloatSize elastic_overscroll(10, -20); |
850 web_view_impl->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), | 850 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), |
851 elastic_overscroll, 1.0f, 0.0f); | 851 elastic_overscroll, 1.0f, 0.0f); |
852 FrameTestHelpers::ReloadFrame(web_view_helper.WebView()->MainFrame()); | 852 FrameTestHelpers::ReloadFrame(web_view_helper.WebView()->MainFrame()); |
853 FrameView* view = ToLocalFrame(web_view_impl->GetPage()->MainFrame())->View(); | 853 FrameView* view = ToLocalFrame(web_view->GetPage()->MainFrame())->View(); |
854 | 854 |
855 // Just elastic overscroll. | 855 // Just elastic overscroll. |
856 { | 856 { |
857 WebMouseEvent web_mouse_event(WebInputEvent::kMouseMove, | 857 WebMouseEvent web_mouse_event(WebInputEvent::kMouseMove, |
858 WebInputEvent::kNoModifiers, | 858 WebInputEvent::kNoModifiers, |
859 WebInputEvent::kTimeStampForTesting); | 859 WebInputEvent::kTimeStampForTesting); |
860 web_mouse_event.SetPositionInWidget(10, 50); | 860 web_mouse_event.SetPositionInWidget(10, 50); |
861 web_mouse_event.SetPositionInScreen(10, 50); | 861 web_mouse_event.SetPositionInScreen(10, 50); |
862 | 862 |
863 WebMouseEvent transformed_mouse_event = | 863 WebMouseEvent transformed_mouse_event = |
864 TransformWebMouseEvent(view, web_mouse_event); | 864 TransformWebMouseEvent(view, web_mouse_event); |
865 IntPoint position = | 865 IntPoint position = |
866 FlooredIntPoint(transformed_mouse_event.PositionInRootFrame()); | 866 FlooredIntPoint(transformed_mouse_event.PositionInRootFrame()); |
867 | 867 |
868 EXPECT_EQ(web_mouse_event.PositionInWidget().x + elastic_overscroll.Width(), | 868 EXPECT_EQ(web_mouse_event.PositionInWidget().x + elastic_overscroll.Width(), |
869 position.X()); | 869 position.X()); |
870 EXPECT_EQ( | 870 EXPECT_EQ( |
871 web_mouse_event.PositionInWidget().y + elastic_overscroll.Height(), | 871 web_mouse_event.PositionInWidget().y + elastic_overscroll.Height(), |
872 position.Y()); | 872 position.Y()); |
873 EXPECT_EQ(web_mouse_event.PositionInScreen().x, | 873 EXPECT_EQ(web_mouse_event.PositionInScreen().x, |
874 transformed_mouse_event.PositionInScreen().x); | 874 transformed_mouse_event.PositionInScreen().x); |
875 EXPECT_EQ(web_mouse_event.PositionInScreen().y, | 875 EXPECT_EQ(web_mouse_event.PositionInScreen().y, |
876 transformed_mouse_event.PositionInScreen().y); | 876 transformed_mouse_event.PositionInScreen().y); |
877 } | 877 } |
878 } | 878 } |
879 | 879 |
880 } // namespace blink | 880 } // namespace blink |
OLD | NEW |