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 27 matching lines...) Expand all Loading... |
38 #include "core/events/TouchEvent.h" | 38 #include "core/events/TouchEvent.h" |
39 #include "core/events/WheelEvent.h" | 39 #include "core/events/WheelEvent.h" |
40 #include "core/frame/FrameHost.h" | 40 #include "core/frame/FrameHost.h" |
41 #include "core/frame/FrameView.h" | 41 #include "core/frame/FrameView.h" |
42 #include "core/frame/LocalFrame.h" | 42 #include "core/frame/LocalFrame.h" |
43 #include "core/frame/VisualViewport.h" | 43 #include "core/frame/VisualViewport.h" |
44 #include "core/layout/api/LayoutViewItem.h" | 44 #include "core/layout/api/LayoutViewItem.h" |
45 #include "core/page/Page.h" | 45 #include "core/page/Page.h" |
46 #include "platform/geometry/IntSize.h" | 46 #include "platform/geometry/IntSize.h" |
47 #include "platform/testing/URLTestHelpers.h" | 47 #include "platform/testing/URLTestHelpers.h" |
| 48 #include "platform/testing/UnitTestHelpers.h" |
48 #include "public/web/WebFrame.h" | 49 #include "public/web/WebFrame.h" |
49 #include "public/web/WebSettings.h" | 50 #include "public/web/WebSettings.h" |
50 #include "testing/gtest/include/gtest/gtest.h" | 51 #include "testing/gtest/include/gtest/gtest.h" |
51 #include "web/WebLocalFrameImpl.h" | 52 #include "web/WebLocalFrameImpl.h" |
52 #include "web/WebViewImpl.h" | 53 #include "web/WebViewImpl.h" |
53 #include "web/tests/FrameTestHelpers.h" | 54 #include "web/tests/FrameTestHelpers.h" |
54 | 55 |
55 namespace blink { | 56 namespace blink { |
56 | 57 |
| 58 namespace { |
| 59 |
57 KeyboardEvent* createKeyboardEventWithLocation( | 60 KeyboardEvent* createKeyboardEventWithLocation( |
58 KeyboardEvent::KeyLocationCode location) { | 61 KeyboardEvent::KeyLocationCode location) { |
59 KeyboardEventInit keyEventInit; | 62 KeyboardEventInit keyEventInit; |
60 keyEventInit.setBubbles(true); | 63 keyEventInit.setBubbles(true); |
61 keyEventInit.setCancelable(true); | 64 keyEventInit.setCancelable(true); |
62 keyEventInit.setLocation(location); | 65 keyEventInit.setLocation(location); |
63 return new KeyboardEvent("keydown", keyEventInit); | 66 return new KeyboardEvent("keydown", keyEventInit); |
64 } | 67 } |
65 | 68 |
66 int getModifiersForKeyLocationCode(KeyboardEvent::KeyLocationCode location) { | 69 int getModifiersForKeyLocationCode(KeyboardEvent::KeyLocationCode location) { |
67 KeyboardEvent* event = createKeyboardEventWithLocation(location); | 70 KeyboardEvent* event = createKeyboardEventWithLocation(location); |
68 WebKeyboardEventBuilder convertedEvent(*event); | 71 WebKeyboardEventBuilder convertedEvent(*event); |
69 return convertedEvent.modifiers(); | 72 return convertedEvent.modifiers(); |
70 } | 73 } |
71 | 74 |
| 75 void registerMockedURL(const std::string& baseURL, |
| 76 const std::string& fileName) { |
| 77 URLTestHelpers::registerMockedURLLoadFromBase(WebString::fromUTF8(baseURL), |
| 78 testing::webTestDataPath(), |
| 79 WebString::fromUTF8(fileName)); |
| 80 } |
| 81 |
| 82 } // namespace |
| 83 |
72 TEST(WebInputEventConversionTest, WebKeyboardEventBuilder) { | 84 TEST(WebInputEventConversionTest, WebKeyboardEventBuilder) { |
73 // Test key location conversion. | 85 // Test key location conversion. |
74 int modifiers = | 86 int modifiers = |
75 getModifiersForKeyLocationCode(KeyboardEvent::kDomKeyLocationStandard); | 87 getModifiersForKeyLocationCode(KeyboardEvent::kDomKeyLocationStandard); |
76 EXPECT_FALSE(modifiers & WebInputEvent::IsKeyPad || | 88 EXPECT_FALSE(modifiers & WebInputEvent::IsKeyPad || |
77 modifiers & WebInputEvent::IsLeft || | 89 modifiers & WebInputEvent::IsLeft || |
78 modifiers & WebInputEvent::IsRight); | 90 modifiers & WebInputEvent::IsRight); |
79 | 91 |
80 modifiers = | 92 modifiers = |
81 getModifiersForKeyLocationCode(KeyboardEvent::kDomKeyLocationLeft); | 93 getModifiersForKeyLocationCode(KeyboardEvent::kDomKeyLocationLeft); |
(...skipping 17 matching lines...) Expand all Loading... |
99 TEST(WebInputEventConversionTest, WebMouseEventBuilder) { | 111 TEST(WebInputEventConversionTest, WebMouseEventBuilder) { |
100 TouchEvent* event = TouchEvent::create(); | 112 TouchEvent* event = TouchEvent::create(); |
101 WebMouseEventBuilder mouse(0, 0, *event); | 113 WebMouseEventBuilder mouse(0, 0, *event); |
102 EXPECT_EQ(WebInputEvent::Undefined, mouse.type()); | 114 EXPECT_EQ(WebInputEvent::Undefined, mouse.type()); |
103 } | 115 } |
104 | 116 |
105 TEST(WebInputEventConversionTest, InputEventsScaling) { | 117 TEST(WebInputEventConversionTest, InputEventsScaling) { |
106 const std::string baseURL("http://www.test1.com/"); | 118 const std::string baseURL("http://www.test1.com/"); |
107 const std::string fileName("fixed_layout.html"); | 119 const std::string fileName("fixed_layout.html"); |
108 | 120 |
109 URLTestHelpers::registerMockedURLFromBaseURL( | 121 registerMockedURL(baseURL, fileName); |
110 WebString::fromUTF8(baseURL.c_str()), | |
111 WebString::fromUTF8("fixed_layout.html")); | |
112 FrameTestHelpers::WebViewHelper webViewHelper; | 122 FrameTestHelpers::WebViewHelper webViewHelper; |
113 WebViewImpl* webViewImpl = | 123 WebViewImpl* webViewImpl = |
114 webViewHelper.initializeAndLoad(baseURL + fileName, true); | 124 webViewHelper.initializeAndLoad(baseURL + fileName, true); |
115 webViewImpl->settings()->setViewportEnabled(true); | 125 webViewImpl->settings()->setViewportEnabled(true); |
116 int pageWidth = 640; | 126 int pageWidth = 640; |
117 int pageHeight = 480; | 127 int pageHeight = 480; |
118 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 128 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
119 webViewImpl->updateAllLifecyclePhases(); | 129 webViewImpl->updateAllLifecyclePhases(); |
120 | 130 |
121 webViewImpl->setPageScaleFactor(2); | 131 webViewImpl->setPageScaleFactor(2); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 EXPECT_FLOAT_EQ(5.2f, transformedPoint.position.y); | 335 EXPECT_FLOAT_EQ(5.2f, transformedPoint.position.y); |
326 EXPECT_FLOAT_EQ(5.3f, transformedPoint.radiusX); | 336 EXPECT_FLOAT_EQ(5.3f, transformedPoint.radiusX); |
327 EXPECT_FLOAT_EQ(5.2f, transformedPoint.radiusY); | 337 EXPECT_FLOAT_EQ(5.2f, transformedPoint.radiusY); |
328 } | 338 } |
329 } | 339 } |
330 | 340 |
331 TEST(WebInputEventConversionTest, InputEventsTransform) { | 341 TEST(WebInputEventConversionTest, InputEventsTransform) { |
332 const std::string baseURL("http://www.test2.com/"); | 342 const std::string baseURL("http://www.test2.com/"); |
333 const std::string fileName("fixed_layout.html"); | 343 const std::string fileName("fixed_layout.html"); |
334 | 344 |
335 URLTestHelpers::registerMockedURLFromBaseURL( | 345 registerMockedURL(baseURL, fileName); |
336 WebString::fromUTF8(baseURL.c_str()), | |
337 WebString::fromUTF8("fixed_layout.html")); | |
338 FrameTestHelpers::WebViewHelper webViewHelper; | 346 FrameTestHelpers::WebViewHelper webViewHelper; |
339 WebViewImpl* webViewImpl = | 347 WebViewImpl* webViewImpl = |
340 webViewHelper.initializeAndLoad(baseURL + fileName, true); | 348 webViewHelper.initializeAndLoad(baseURL + fileName, true); |
341 webViewImpl->settings()->setViewportEnabled(true); | 349 webViewImpl->settings()->setViewportEnabled(true); |
342 int pageWidth = 640; | 350 int pageWidth = 640; |
343 int pageHeight = 480; | 351 int pageHeight = 480; |
344 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 352 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
345 webViewImpl->updateAllLifecyclePhases(); | 353 webViewImpl->updateAllLifecyclePhases(); |
346 | 354 |
347 webViewImpl->setPageScaleFactor(2); | 355 webViewImpl->setPageScaleFactor(2); |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 EXPECT_FLOAT_EQ(30, transformedPoint.position.y); | 615 EXPECT_FLOAT_EQ(30, transformedPoint.position.y); |
608 EXPECT_FLOAT_EQ(20, transformedPoint.radiusX); | 616 EXPECT_FLOAT_EQ(20, transformedPoint.radiusX); |
609 EXPECT_FLOAT_EQ(10, transformedPoint.radiusY); | 617 EXPECT_FLOAT_EQ(10, transformedPoint.radiusY); |
610 } | 618 } |
611 } | 619 } |
612 | 620 |
613 TEST(WebInputEventConversionTest, InputEventsConversions) { | 621 TEST(WebInputEventConversionTest, InputEventsConversions) { |
614 const std::string baseURL("http://www.test3.com/"); | 622 const std::string baseURL("http://www.test3.com/"); |
615 const std::string fileName("fixed_layout.html"); | 623 const std::string fileName("fixed_layout.html"); |
616 | 624 |
617 URLTestHelpers::registerMockedURLFromBaseURL( | 625 registerMockedURL(baseURL, fileName); |
618 WebString::fromUTF8(baseURL.c_str()), | |
619 WebString::fromUTF8("fixed_layout.html")); | |
620 FrameTestHelpers::WebViewHelper webViewHelper; | 626 FrameTestHelpers::WebViewHelper webViewHelper; |
621 WebViewImpl* webViewImpl = | 627 WebViewImpl* webViewImpl = |
622 webViewHelper.initializeAndLoad(baseURL + fileName, true); | 628 webViewHelper.initializeAndLoad(baseURL + fileName, true); |
623 int pageWidth = 640; | 629 int pageWidth = 640; |
624 int pageHeight = 480; | 630 int pageHeight = 480; |
625 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 631 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
626 webViewImpl->updateAllLifecyclePhases(); | 632 webViewImpl->updateAllLifecyclePhases(); |
627 | 633 |
628 FrameView* view = toLocalFrame(webViewImpl->page()->mainFrame())->view(); | 634 FrameView* view = toLocalFrame(webViewImpl->page()->mainFrame())->view(); |
629 { | 635 { |
(...skipping 18 matching lines...) Expand all Loading... |
648 EXPECT_EQ(10.f, scaledGestureEvent.globalX); | 654 EXPECT_EQ(10.f, scaledGestureEvent.globalX); |
649 EXPECT_EQ(10.f, scaledGestureEvent.globalY); | 655 EXPECT_EQ(10.f, scaledGestureEvent.globalY); |
650 EXPECT_EQ(1, scaledGestureEvent.tapCount()); | 656 EXPECT_EQ(1, scaledGestureEvent.tapCount()); |
651 } | 657 } |
652 } | 658 } |
653 | 659 |
654 TEST(WebInputEventConversionTest, VisualViewportOffset) { | 660 TEST(WebInputEventConversionTest, VisualViewportOffset) { |
655 const std::string baseURL("http://www.test4.com/"); | 661 const std::string baseURL("http://www.test4.com/"); |
656 const std::string fileName("fixed_layout.html"); | 662 const std::string fileName("fixed_layout.html"); |
657 | 663 |
658 URLTestHelpers::registerMockedURLFromBaseURL( | 664 registerMockedURL(baseURL, fileName); |
659 WebString::fromUTF8(baseURL.c_str()), | |
660 WebString::fromUTF8("fixed_layout.html")); | |
661 FrameTestHelpers::WebViewHelper webViewHelper; | 665 FrameTestHelpers::WebViewHelper webViewHelper; |
662 WebViewImpl* webViewImpl = | 666 WebViewImpl* webViewImpl = |
663 webViewHelper.initializeAndLoad(baseURL + fileName, true); | 667 webViewHelper.initializeAndLoad(baseURL + fileName, true); |
664 int pageWidth = 640; | 668 int pageWidth = 640; |
665 int pageHeight = 480; | 669 int pageHeight = 480; |
666 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 670 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
667 webViewImpl->updateAllLifecyclePhases(); | 671 webViewImpl->updateAllLifecyclePhases(); |
668 | 672 |
669 webViewImpl->setPageScaleFactor(2); | 673 webViewImpl->setPageScaleFactor(2); |
670 | 674 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 EXPECT_FLOAT_EQ(10.4f, transformedPoint.screenPosition.y); | 763 EXPECT_FLOAT_EQ(10.4f, transformedPoint.screenPosition.y); |
760 EXPECT_FLOAT_EQ(5.3f + visualOffset.x(), transformedPoint.position.x); | 764 EXPECT_FLOAT_EQ(5.3f + visualOffset.x(), transformedPoint.position.x); |
761 EXPECT_FLOAT_EQ(5.2f + visualOffset.y(), transformedPoint.position.y); | 765 EXPECT_FLOAT_EQ(5.2f + visualOffset.y(), transformedPoint.position.y); |
762 } | 766 } |
763 } | 767 } |
764 | 768 |
765 TEST(WebInputEventConversionTest, ElasticOverscroll) { | 769 TEST(WebInputEventConversionTest, ElasticOverscroll) { |
766 const std::string baseURL("http://www.test5.com/"); | 770 const std::string baseURL("http://www.test5.com/"); |
767 const std::string fileName("fixed_layout.html"); | 771 const std::string fileName("fixed_layout.html"); |
768 | 772 |
769 URLTestHelpers::registerMockedURLFromBaseURL( | 773 registerMockedURL(baseURL, fileName); |
770 WebString::fromUTF8(baseURL.c_str()), | |
771 WebString::fromUTF8("fixed_layout.html")); | |
772 FrameTestHelpers::WebViewHelper webViewHelper; | 774 FrameTestHelpers::WebViewHelper webViewHelper; |
773 WebViewImpl* webViewImpl = | 775 WebViewImpl* webViewImpl = |
774 webViewHelper.initializeAndLoad(baseURL + fileName, true); | 776 webViewHelper.initializeAndLoad(baseURL + fileName, true); |
775 int pageWidth = 640; | 777 int pageWidth = 640; |
776 int pageHeight = 480; | 778 int pageHeight = 480; |
777 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 779 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
778 webViewImpl->updateAllLifecyclePhases(); | 780 webViewImpl->updateAllLifecyclePhases(); |
779 | 781 |
780 FrameView* view = toLocalFrame(webViewImpl->page()->mainFrame())->view(); | 782 FrameView* view = toLocalFrame(webViewImpl->page()->mainFrame())->view(); |
781 | 783 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 EXPECT_EQ(webMouseEvent.globalX, transformedMouseEvent.globalX); | 840 EXPECT_EQ(webMouseEvent.globalX, transformedMouseEvent.globalX); |
839 EXPECT_EQ(webMouseEvent.globalY, transformedMouseEvent.globalY); | 841 EXPECT_EQ(webMouseEvent.globalY, transformedMouseEvent.globalY); |
840 } | 842 } |
841 } | 843 } |
842 | 844 |
843 // Page reload/navigation should not reset elastic overscroll. | 845 // Page reload/navigation should not reset elastic overscroll. |
844 TEST(WebInputEventConversionTest, ElasticOverscrollWithPageReload) { | 846 TEST(WebInputEventConversionTest, ElasticOverscrollWithPageReload) { |
845 const std::string baseURL("http://www.test6.com/"); | 847 const std::string baseURL("http://www.test6.com/"); |
846 const std::string fileName("fixed_layout.html"); | 848 const std::string fileName("fixed_layout.html"); |
847 | 849 |
848 URLTestHelpers::registerMockedURLFromBaseURL( | 850 registerMockedURL(baseURL, fileName); |
849 WebString::fromUTF8(baseURL.c_str()), | |
850 WebString::fromUTF8("fixed_layout.html")); | |
851 FrameTestHelpers::WebViewHelper webViewHelper; | 851 FrameTestHelpers::WebViewHelper webViewHelper; |
852 WebViewImpl* webViewImpl = | 852 WebViewImpl* webViewImpl = |
853 webViewHelper.initializeAndLoad(baseURL + fileName, true); | 853 webViewHelper.initializeAndLoad(baseURL + fileName, true); |
854 int pageWidth = 640; | 854 int pageWidth = 640; |
855 int pageHeight = 480; | 855 int pageHeight = 480; |
856 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 856 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
857 webViewImpl->updateAllLifecyclePhases(); | 857 webViewImpl->updateAllLifecyclePhases(); |
858 | 858 |
859 FloatSize elasticOverscroll(10, -20); | 859 FloatSize elasticOverscroll(10, -20); |
860 webViewImpl->applyViewportDeltas(WebFloatSize(), WebFloatSize(), | 860 webViewImpl->applyViewportDeltas(WebFloatSize(), WebFloatSize(), |
(...skipping 19 matching lines...) Expand all Loading... |
880 flooredIntPoint(transformedMouseEvent.positionInRootFrame()); | 880 flooredIntPoint(transformedMouseEvent.positionInRootFrame()); |
881 | 881 |
882 EXPECT_EQ(webMouseEvent.x + elasticOverscroll.width(), position.x()); | 882 EXPECT_EQ(webMouseEvent.x + elasticOverscroll.width(), position.x()); |
883 EXPECT_EQ(webMouseEvent.y + elasticOverscroll.height(), position.y()); | 883 EXPECT_EQ(webMouseEvent.y + elasticOverscroll.height(), position.y()); |
884 EXPECT_EQ(webMouseEvent.globalX, transformedMouseEvent.globalX); | 884 EXPECT_EQ(webMouseEvent.globalX, transformedMouseEvent.globalX); |
885 EXPECT_EQ(webMouseEvent.globalY, transformedMouseEvent.globalY); | 885 EXPECT_EQ(webMouseEvent.globalY, transformedMouseEvent.globalY); |
886 } | 886 } |
887 } | 887 } |
888 | 888 |
889 } // namespace blink | 889 } // namespace blink |
OLD | NEW |