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( | |
78 WebString::fromUTF8(baseURL.c_str()), testing::webTestDataPath(), | |
kinuko
2017/01/26 09:32:41
ditto
Takashi Toyoshima
2017/01/26 10:57:58
Done.
| |
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, WebTouchEventBuilder) { | 117 TEST(WebInputEventConversionTest, WebTouchEventBuilder) { |
106 const std::string baseURL("http://www.test0.com/"); | 118 const std::string baseURL("http://www.test0.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 int pageWidth = 640; | 125 int pageWidth = 640; |
116 int pageHeight = 480; | 126 int pageHeight = 480; |
117 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 127 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
118 webViewImpl->updateAllLifecyclePhases(); | 128 webViewImpl->updateAllLifecyclePhases(); |
119 | 129 |
120 Document* document = | 130 Document* document = |
121 toLocalFrame(webViewImpl->page()->mainFrame())->document(); | 131 toLocalFrame(webViewImpl->page()->mainFrame())->document(); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 WebTouchEventBuilder webTouchBuilder(documentLayoutView, *touchEvent); | 305 WebTouchEventBuilder webTouchBuilder(documentLayoutView, *touchEvent); |
296 ASSERT_EQ(static_cast<unsigned>(WebTouchEvent::kTouchesLengthCap), | 306 ASSERT_EQ(static_cast<unsigned>(WebTouchEvent::kTouchesLengthCap), |
297 webTouchBuilder.touchesLength); | 307 webTouchBuilder.touchesLength); |
298 } | 308 } |
299 } | 309 } |
300 | 310 |
301 TEST(WebInputEventConversionTest, InputEventsScaling) { | 311 TEST(WebInputEventConversionTest, InputEventsScaling) { |
302 const std::string baseURL("http://www.test1.com/"); | 312 const std::string baseURL("http://www.test1.com/"); |
303 const std::string fileName("fixed_layout.html"); | 313 const std::string fileName("fixed_layout.html"); |
304 | 314 |
305 URLTestHelpers::registerMockedURLFromBaseURL( | 315 registerMockedURL(baseURL, fileName); |
306 WebString::fromUTF8(baseURL.c_str()), | |
307 WebString::fromUTF8("fixed_layout.html")); | |
308 FrameTestHelpers::WebViewHelper webViewHelper; | 316 FrameTestHelpers::WebViewHelper webViewHelper; |
309 WebViewImpl* webViewImpl = | 317 WebViewImpl* webViewImpl = |
310 webViewHelper.initializeAndLoad(baseURL + fileName, true); | 318 webViewHelper.initializeAndLoad(baseURL + fileName, true); |
311 webViewImpl->settings()->setViewportEnabled(true); | 319 webViewImpl->settings()->setViewportEnabled(true); |
312 int pageWidth = 640; | 320 int pageWidth = 640; |
313 int pageHeight = 480; | 321 int pageHeight = 480; |
314 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 322 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
315 webViewImpl->updateAllLifecyclePhases(); | 323 webViewImpl->updateAllLifecyclePhases(); |
316 | 324 |
317 webViewImpl->setPageScaleFactor(2); | 325 webViewImpl->setPageScaleFactor(2); |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
577 EXPECT_FLOAT_EQ(4, webTouchBuilder.touches[0].radiusX); | 585 EXPECT_FLOAT_EQ(4, webTouchBuilder.touches[0].radiusX); |
578 EXPECT_FLOAT_EQ(4.5, webTouchBuilder.touches[0].radiusY); | 586 EXPECT_FLOAT_EQ(4.5, webTouchBuilder.touches[0].radiusY); |
579 EXPECT_EQ(WebInputEvent::EventNonBlocking, webTouchBuilder.dispatchType); | 587 EXPECT_EQ(WebInputEvent::EventNonBlocking, webTouchBuilder.dispatchType); |
580 } | 588 } |
581 } | 589 } |
582 | 590 |
583 TEST(WebInputEventConversionTest, InputEventsTransform) { | 591 TEST(WebInputEventConversionTest, InputEventsTransform) { |
584 const std::string baseURL("http://www.test2.com/"); | 592 const std::string baseURL("http://www.test2.com/"); |
585 const std::string fileName("fixed_layout.html"); | 593 const std::string fileName("fixed_layout.html"); |
586 | 594 |
587 URLTestHelpers::registerMockedURLFromBaseURL( | 595 registerMockedURL(baseURL, fileName); |
588 WebString::fromUTF8(baseURL.c_str()), | |
589 WebString::fromUTF8("fixed_layout.html")); | |
590 FrameTestHelpers::WebViewHelper webViewHelper; | 596 FrameTestHelpers::WebViewHelper webViewHelper; |
591 WebViewImpl* webViewImpl = | 597 WebViewImpl* webViewImpl = |
592 webViewHelper.initializeAndLoad(baseURL + fileName, true); | 598 webViewHelper.initializeAndLoad(baseURL + fileName, true); |
593 webViewImpl->settings()->setViewportEnabled(true); | 599 webViewImpl->settings()->setViewportEnabled(true); |
594 int pageWidth = 640; | 600 int pageWidth = 640; |
595 int pageHeight = 480; | 601 int pageHeight = 480; |
596 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 602 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
597 webViewImpl->updateAllLifecyclePhases(); | 603 webViewImpl->updateAllLifecyclePhases(); |
598 | 604 |
599 webViewImpl->setPageScaleFactor(2); | 605 webViewImpl->setPageScaleFactor(2); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
842 EXPECT_FLOAT_EQ(30, coalescedevents[1].touchPoints()[0].pos().y()); | 848 EXPECT_FLOAT_EQ(30, coalescedevents[1].touchPoints()[0].pos().y()); |
843 EXPECT_FLOAT_EQ(20, coalescedevents[1].touchPoints()[0].radius().width()); | 849 EXPECT_FLOAT_EQ(20, coalescedevents[1].touchPoints()[0].radius().width()); |
844 EXPECT_FLOAT_EQ(10, coalescedevents[1].touchPoints()[0].radius().height()); | 850 EXPECT_FLOAT_EQ(10, coalescedevents[1].touchPoints()[0].radius().height()); |
845 } | 851 } |
846 } | 852 } |
847 | 853 |
848 TEST(WebInputEventConversionTest, InputEventsConversions) { | 854 TEST(WebInputEventConversionTest, InputEventsConversions) { |
849 const std::string baseURL("http://www.test3.com/"); | 855 const std::string baseURL("http://www.test3.com/"); |
850 const std::string fileName("fixed_layout.html"); | 856 const std::string fileName("fixed_layout.html"); |
851 | 857 |
852 URLTestHelpers::registerMockedURLFromBaseURL( | 858 registerMockedURL(baseURL, fileName); |
853 WebString::fromUTF8(baseURL.c_str()), | |
854 WebString::fromUTF8("fixed_layout.html")); | |
855 FrameTestHelpers::WebViewHelper webViewHelper; | 859 FrameTestHelpers::WebViewHelper webViewHelper; |
856 WebViewImpl* webViewImpl = | 860 WebViewImpl* webViewImpl = |
857 webViewHelper.initializeAndLoad(baseURL + fileName, true); | 861 webViewHelper.initializeAndLoad(baseURL + fileName, true); |
858 int pageWidth = 640; | 862 int pageWidth = 640; |
859 int pageHeight = 480; | 863 int pageHeight = 480; |
860 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 864 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
861 webViewImpl->updateAllLifecyclePhases(); | 865 webViewImpl->updateAllLifecyclePhases(); |
862 | 866 |
863 FrameView* view = toLocalFrame(webViewImpl->page()->mainFrame())->view(); | 867 FrameView* view = toLocalFrame(webViewImpl->page()->mainFrame())->view(); |
864 { | 868 { |
(...skipping 18 matching lines...) Expand all Loading... | |
883 EXPECT_EQ(10.f, scaledGestureEvent.globalX); | 887 EXPECT_EQ(10.f, scaledGestureEvent.globalX); |
884 EXPECT_EQ(10.f, scaledGestureEvent.globalY); | 888 EXPECT_EQ(10.f, scaledGestureEvent.globalY); |
885 EXPECT_EQ(1, scaledGestureEvent.tapCount()); | 889 EXPECT_EQ(1, scaledGestureEvent.tapCount()); |
886 } | 890 } |
887 } | 891 } |
888 | 892 |
889 TEST(WebInputEventConversionTest, VisualViewportOffset) { | 893 TEST(WebInputEventConversionTest, VisualViewportOffset) { |
890 const std::string baseURL("http://www.test4.com/"); | 894 const std::string baseURL("http://www.test4.com/"); |
891 const std::string fileName("fixed_layout.html"); | 895 const std::string fileName("fixed_layout.html"); |
892 | 896 |
893 URLTestHelpers::registerMockedURLFromBaseURL( | 897 registerMockedURL(baseURL, fileName); |
894 WebString::fromUTF8(baseURL.c_str()), | |
895 WebString::fromUTF8("fixed_layout.html")); | |
896 FrameTestHelpers::WebViewHelper webViewHelper; | 898 FrameTestHelpers::WebViewHelper webViewHelper; |
897 WebViewImpl* webViewImpl = | 899 WebViewImpl* webViewImpl = |
898 webViewHelper.initializeAndLoad(baseURL + fileName, true); | 900 webViewHelper.initializeAndLoad(baseURL + fileName, true); |
899 int pageWidth = 640; | 901 int pageWidth = 640; |
900 int pageHeight = 480; | 902 int pageHeight = 480; |
901 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 903 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
902 webViewImpl->updateAllLifecyclePhases(); | 904 webViewImpl->updateAllLifecyclePhases(); |
903 | 905 |
904 webViewImpl->setPageScaleFactor(2); | 906 webViewImpl->setPageScaleFactor(2); |
905 | 907 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
992 platformTouchBuilder.touchPoints()[0].pos().x()); | 994 platformTouchBuilder.touchPoints()[0].pos().x()); |
993 EXPECT_FLOAT_EQ(5.2f + visualOffset.y(), | 995 EXPECT_FLOAT_EQ(5.2f + visualOffset.y(), |
994 platformTouchBuilder.touchPoints()[0].pos().y()); | 996 platformTouchBuilder.touchPoints()[0].pos().y()); |
995 } | 997 } |
996 } | 998 } |
997 | 999 |
998 TEST(WebInputEventConversionTest, ElasticOverscroll) { | 1000 TEST(WebInputEventConversionTest, ElasticOverscroll) { |
999 const std::string baseURL("http://www.test5.com/"); | 1001 const std::string baseURL("http://www.test5.com/"); |
1000 const std::string fileName("fixed_layout.html"); | 1002 const std::string fileName("fixed_layout.html"); |
1001 | 1003 |
1002 URLTestHelpers::registerMockedURLFromBaseURL( | 1004 registerMockedURL(baseURL, fileName); |
1003 WebString::fromUTF8(baseURL.c_str()), | |
1004 WebString::fromUTF8("fixed_layout.html")); | |
1005 FrameTestHelpers::WebViewHelper webViewHelper; | 1005 FrameTestHelpers::WebViewHelper webViewHelper; |
1006 WebViewImpl* webViewImpl = | 1006 WebViewImpl* webViewImpl = |
1007 webViewHelper.initializeAndLoad(baseURL + fileName, true); | 1007 webViewHelper.initializeAndLoad(baseURL + fileName, true); |
1008 int pageWidth = 640; | 1008 int pageWidth = 640; |
1009 int pageHeight = 480; | 1009 int pageHeight = 480; |
1010 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 1010 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
1011 webViewImpl->updateAllLifecyclePhases(); | 1011 webViewImpl->updateAllLifecyclePhases(); |
1012 | 1012 |
1013 FrameView* view = toLocalFrame(webViewImpl->page()->mainFrame())->view(); | 1013 FrameView* view = toLocalFrame(webViewImpl->page()->mainFrame())->view(); |
1014 | 1014 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1065 EXPECT_EQ(webMouseEvent.globalX, platformMouseBuilder.globalPosition().x()); | 1065 EXPECT_EQ(webMouseEvent.globalX, platformMouseBuilder.globalPosition().x()); |
1066 EXPECT_EQ(webMouseEvent.globalY, platformMouseBuilder.globalPosition().y()); | 1066 EXPECT_EQ(webMouseEvent.globalY, platformMouseBuilder.globalPosition().y()); |
1067 } | 1067 } |
1068 } | 1068 } |
1069 | 1069 |
1070 // Page reload/navigation should not reset elastic overscroll. | 1070 // Page reload/navigation should not reset elastic overscroll. |
1071 TEST(WebInputEventConversionTest, ElasticOverscrollWithPageReload) { | 1071 TEST(WebInputEventConversionTest, ElasticOverscrollWithPageReload) { |
1072 const std::string baseURL("http://www.test6.com/"); | 1072 const std::string baseURL("http://www.test6.com/"); |
1073 const std::string fileName("fixed_layout.html"); | 1073 const std::string fileName("fixed_layout.html"); |
1074 | 1074 |
1075 URLTestHelpers::registerMockedURLFromBaseURL( | 1075 registerMockedURL(baseURL, fileName); |
1076 WebString::fromUTF8(baseURL.c_str()), | |
1077 WebString::fromUTF8("fixed_layout.html")); | |
1078 FrameTestHelpers::WebViewHelper webViewHelper; | 1076 FrameTestHelpers::WebViewHelper webViewHelper; |
1079 WebViewImpl* webViewImpl = | 1077 WebViewImpl* webViewImpl = |
1080 webViewHelper.initializeAndLoad(baseURL + fileName, true); | 1078 webViewHelper.initializeAndLoad(baseURL + fileName, true); |
1081 int pageWidth = 640; | 1079 int pageWidth = 640; |
1082 int pageHeight = 480; | 1080 int pageHeight = 480; |
1083 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 1081 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
1084 webViewImpl->updateAllLifecyclePhases(); | 1082 webViewImpl->updateAllLifecyclePhases(); |
1085 | 1083 |
1086 FloatSize elasticOverscroll(10, -20); | 1084 FloatSize elasticOverscroll(10, -20); |
1087 webViewImpl->applyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1085 webViewImpl->applyViewportDeltas(WebFloatSize(), WebFloatSize(), |
(...skipping 17 matching lines...) Expand all Loading... | |
1105 EXPECT_EQ(webMouseEvent.x + elasticOverscroll.width(), | 1103 EXPECT_EQ(webMouseEvent.x + elasticOverscroll.width(), |
1106 platformMouseBuilder.position().x()); | 1104 platformMouseBuilder.position().x()); |
1107 EXPECT_EQ(webMouseEvent.y + elasticOverscroll.height(), | 1105 EXPECT_EQ(webMouseEvent.y + elasticOverscroll.height(), |
1108 platformMouseBuilder.position().y()); | 1106 platformMouseBuilder.position().y()); |
1109 EXPECT_EQ(webMouseEvent.globalX, platformMouseBuilder.globalPosition().x()); | 1107 EXPECT_EQ(webMouseEvent.globalX, platformMouseBuilder.globalPosition().x()); |
1110 EXPECT_EQ(webMouseEvent.globalY, platformMouseBuilder.globalPosition().y()); | 1108 EXPECT_EQ(webMouseEvent.globalY, platformMouseBuilder.globalPosition().y()); |
1111 } | 1109 } |
1112 } | 1110 } |
1113 | 1111 |
1114 } // namespace blink | 1112 } // namespace blink |
OLD | NEW |