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

Side by Side Diff: Source/web/tests/WebInputEventConversionTest.cpp

Issue 558773002: Remove WebTouchEvent.targetTouches (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Cleanup and simplify Created 6 years, 3 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
« no previous file with comments | « Source/web/WebInputEventConversion.cpp ('k') | public/web/WebInputEvent.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 modifiers = getModifiersForKeyLocationCode(KeyboardEvent::DOM_KEY_LOCATION_R IGHT); 79 modifiers = getModifiersForKeyLocationCode(KeyboardEvent::DOM_KEY_LOCATION_R IGHT);
80 EXPECT_TRUE(modifiers & WebInputEvent::IsRight); 80 EXPECT_TRUE(modifiers & WebInputEvent::IsRight);
81 EXPECT_FALSE(modifiers & WebInputEvent::IsKeyPad || modifiers & WebInputEven t::IsLeft); 81 EXPECT_FALSE(modifiers & WebInputEvent::IsKeyPad || modifiers & WebInputEven t::IsLeft);
82 82
83 modifiers = getModifiersForKeyLocationCode(KeyboardEvent::DOM_KEY_LOCATION_N UMPAD); 83 modifiers = getModifiersForKeyLocationCode(KeyboardEvent::DOM_KEY_LOCATION_N UMPAD);
84 EXPECT_TRUE(modifiers & WebInputEvent::IsKeyPad); 84 EXPECT_TRUE(modifiers & WebInputEvent::IsKeyPad);
85 EXPECT_FALSE(modifiers & WebInputEvent::IsLeft || modifiers & WebInputEvent: :IsRight); 85 EXPECT_FALSE(modifiers & WebInputEvent::IsLeft || modifiers & WebInputEvent: :IsRight);
86 } 86 }
87 87
88 TEST(WebInputEventConversionTest, WebTouchEventBuilder) 88 TEST(WebInputEventConversionTest, WebMouseEventBuilder)
89 { 89 {
90 RefPtrWillBeRawPtr<TouchEvent> event = TouchEvent::create(); 90 RefPtrWillBeRawPtr<TouchEvent> event = TouchEvent::create();
91 WebMouseEventBuilder mouse(0, 0, *event); 91 WebMouseEventBuilder mouse(0, 0, *event);
92 EXPECT_EQ(WebInputEvent::Undefined, mouse.type); 92 EXPECT_EQ(WebInputEvent::Undefined, mouse.type);
93 } 93 }
94 94
95 TEST(WebInputEventConversionTest, WebTouchEventBuilder)
96 {
97 const std::string baseURL("http://www.test0.com/");
98 const std::string fileName("fixed_layout.html");
99
100 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_s tr()), WebString::fromUTF8("fixed_layout.html"));
101 FrameTestHelpers::WebViewHelper webViewHelper;
102 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(baseURL + fileNam e, true);
103 int pageWidth = 640;
104 int pageHeight = 480;
105 webViewImpl->resize(WebSize(pageWidth, pageHeight));
106 webViewImpl->layout();
107
108 FrameView* view = toLocalFrame(webViewImpl->page()->mainFrame())->view();
109 RefPtrWillBeRawPtr<Document> document = toLocalFrame(webViewImpl->page()->ma inFrame())->document();
110 LocalDOMWindow* domWindow = document->domWindow();
111 RenderView* documentRenderView = document->renderView();
112
113 WebTouchPoint p0, p1;
114 p0.id = 1;
115 p1.id = 2;
116 p0.screenPosition = WebFloatPoint(100.f, 50.f);
117 p1.screenPosition = WebFloatPoint(150.f, 25.f);
118 p0.position = WebFloatPoint(10.f, 10.f);
119 p1.position = WebFloatPoint(5.f, 5.f);
120 p0.radiusX = p1.radiusY = 10.f;
121 p0.radiusY = p1.radiusX = 5.f;
122 p0.rotationAngle = p1.rotationAngle = 1.f;
123 p0.force = p1.force = 25.f;
124
125 RefPtrWillBeRawPtr<Touch> touch0 = Touch::create(toLocalFrame(webViewImpl->p age()->mainFrame()), document.get(), p0.id, p0.screenPosition, p0.position, Floa tSize(p0.radiusX, p0.radiusY), p0.rotationAngle, p0.force);
126 RefPtrWillBeRawPtr<Touch> touch1 = Touch::create(toLocalFrame(webViewImpl->p age()->mainFrame()), document.get(), p1.id, p1.screenPosition, p1.position, Floa tSize(p1.radiusX, p1.radiusY), p1.rotationAngle, p1.force);
127
128 // Test touchstart.
129 {
130 RefPtrWillBeRawPtr<TouchList> touchList = TouchList::create();
131 touchList->append(touch0);
132 RefPtrWillBeRawPtr<TouchEvent> touchEvent = TouchEvent::create(touchList .get(), touchList.get(), touchList.get(), EventTypeNames::touchstart, domWindow, false, false, false, false, false);
133
134 WebTouchEventBuilder webTouchBuilder(view, documentRenderView, *touchEve nt);
135 ASSERT_EQ(1u, webTouchBuilder.touchesLength);
136 ASSERT_EQ(0u, webTouchBuilder.changedTouchesLength);
137 EXPECT_EQ(WebInputEvent::TouchStart, webTouchBuilder.type);
138 EXPECT_EQ(WebTouchPoint::StatePressed, webTouchBuilder.touches[0].state) ;
139 EXPECT_FLOAT_EQ(p0.screenPosition.x, webTouchBuilder.touches[0].screenPo sition.x);
140 EXPECT_FLOAT_EQ(p0.screenPosition.y, webTouchBuilder.touches[0].screenPo sition.y);
141 EXPECT_FLOAT_EQ(p0.position.x, webTouchBuilder.touches[0].position.x);
142 EXPECT_FLOAT_EQ(p0.position.y, webTouchBuilder.touches[0].position.y);
143 EXPECT_FLOAT_EQ(p0.radiusX, webTouchBuilder.touches[0].radiusX);
144 EXPECT_FLOAT_EQ(p0.radiusY, webTouchBuilder.touches[0].radiusY);
145 EXPECT_FLOAT_EQ(p0.rotationAngle, webTouchBuilder.touches[0].rotationAng le);
146 EXPECT_FLOAT_EQ(p0.force, webTouchBuilder.touches[0].force);
147 }
148
149 // Test touchmove.
150 {
151 RefPtrWillBeRawPtr<TouchList> activeTouchList = TouchList::create();
152 RefPtrWillBeRawPtr<TouchList> movedTouchList = TouchList::create();
153 activeTouchList->append(touch0);
154 activeTouchList->append(touch1);
155 movedTouchList->append(touch0);
156 RefPtrWillBeRawPtr<TouchEvent> touchEvent = TouchEvent::create(activeTou chList.get(), activeTouchList.get(), movedTouchList.get(), EventTypeNames::touch move, domWindow, false, false, false, false, false);
157
158 WebTouchEventBuilder webTouchBuilder(view, documentRenderView, *touchEve nt);
159 ASSERT_EQ(2u, webTouchBuilder.touchesLength);
160 ASSERT_EQ(0u, webTouchBuilder.changedTouchesLength);
161 EXPECT_EQ(WebInputEvent::TouchMove, webTouchBuilder.type);
162 EXPECT_EQ(WebTouchPoint::StateMoved, webTouchBuilder.touches[0].state);
163 EXPECT_EQ(WebTouchPoint::StateStationary, webTouchBuilder.touches[1].sta te);
164 EXPECT_EQ(p0.id, webTouchBuilder.touches[0].id);
165 EXPECT_EQ(p1.id, webTouchBuilder.touches[1].id);
166 }
167
168 // Test touchend.
169 {
170 RefPtrWillBeRawPtr<TouchList> activeTouchList = TouchList::create();
171 RefPtrWillBeRawPtr<TouchList> releasedTouchList = TouchList::create();
172 activeTouchList->append(touch0);
173 releasedTouchList->append(touch1);
174 RefPtrWillBeRawPtr<TouchEvent> touchEvent = TouchEvent::create(activeTou chList.get(), activeTouchList.get(), releasedTouchList.get(), EventTypeNames::to uchend, domWindow, false, false, false, false, false);
175
176 WebTouchEventBuilder webTouchBuilder(view, documentRenderView, *touchEve nt);
177 ASSERT_EQ(2u, webTouchBuilder.touchesLength);
178 ASSERT_EQ(0u, webTouchBuilder.changedTouchesLength);
179 EXPECT_EQ(WebInputEvent::TouchEnd, webTouchBuilder.type);
180 EXPECT_EQ(WebTouchPoint::StateReleased, webTouchBuilder.touches[0].state );
181 EXPECT_EQ(WebTouchPoint::StateStationary, webTouchBuilder.touches[1].sta te);
182 EXPECT_EQ(p1.id, webTouchBuilder.touches[0].id);
183 EXPECT_EQ(p0.id, webTouchBuilder.touches[1].id);
184 }
185
186 // Test touchcancel.
187 {
188 RefPtrWillBeRawPtr<TouchList> activeTouchList = TouchList::create();
189 RefPtrWillBeRawPtr<TouchList> cancelledTouchList = TouchList::create();
190 cancelledTouchList->append(touch0);
191 cancelledTouchList->append(touch1);
192 RefPtrWillBeRawPtr<TouchEvent> touchEvent = TouchEvent::create(activeTou chList.get(), activeTouchList.get(), cancelledTouchList.get(), EventTypeNames::t ouchcancel, domWindow, false, false, false, false, false);
193
194 WebTouchEventBuilder webTouchBuilder(view, documentRenderView, *touchEve nt);
195 ASSERT_EQ(2u, webTouchBuilder.touchesLength);
196 ASSERT_EQ(0u, webTouchBuilder.changedTouchesLength);
197 EXPECT_EQ(WebInputEvent::TouchCancel, webTouchBuilder.type);
198 EXPECT_EQ(WebTouchPoint::StateCancelled, webTouchBuilder.touches[0].stat e);
199 EXPECT_EQ(WebTouchPoint::StateCancelled, webTouchBuilder.touches[1].stat e);
200 EXPECT_EQ(p0.id, webTouchBuilder.touches[0].id);
201 EXPECT_EQ(p1.id, webTouchBuilder.touches[1].id);
202 }
203
204 // Test max point limit.
205 {
206 RefPtrWillBeRawPtr<TouchList> touchList = TouchList::create();
207 RefPtrWillBeRawPtr<TouchList> changedTouchList = TouchList::create();
208 for (unsigned i = 0; i <= static_cast<unsigned>(WebTouchEvent::touchesLe ngthCap) * 2; ++i) {
209 RefPtrWillBeRawPtr<Touch> touch = Touch::create(toLocalFrame(webView Impl->page()->mainFrame()), document.get(), i, p0.screenPosition, p0.position, F loatSize(p0.radiusX, p0.radiusY), p0.rotationAngle, p0.force);
210 touchList->append(touch);
211 changedTouchList->append(touch);
212 }
213 RefPtrWillBeRawPtr<TouchEvent> touchEvent = TouchEvent::create(touchList .get(), touchList.get(), touchList.get(), EventTypeNames::touchstart, domWindow, false, false, false, false, false);
214
215 WebTouchEventBuilder webTouchBuilder(view, documentRenderView, *touchEve nt);
216 ASSERT_EQ(static_cast<unsigned>(WebTouchEvent::touchesLengthCap), webTou chBuilder.touchesLength);
217 ASSERT_EQ(0u, webTouchBuilder.changedTouchesLength);
218 }
219 }
220
95 TEST(WebInputEventConversionTest, InputEventsScaling) 221 TEST(WebInputEventConversionTest, InputEventsScaling)
96 { 222 {
97 const std::string baseURL("http://www.test.com/"); 223 const std::string baseURL("http://www.test.com/");
98 const std::string fileName("fixed_layout.html"); 224 const std::string fileName("fixed_layout.html");
99 225
100 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_s tr()), WebString::fromUTF8("fixed_layout.html")); 226 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_s tr()), WebString::fromUTF8("fixed_layout.html"));
101 FrameTestHelpers::WebViewHelper webViewHelper; 227 FrameTestHelpers::WebViewHelper webViewHelper;
102 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(baseURL + fileNam e, true); 228 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(baseURL + fileNam e, true);
103 webViewImpl->settings()->setViewportEnabled(true); 229 webViewImpl->settings()->setViewportEnabled(true);
104 int pageWidth = 640; 230 int pageWidth = 640;
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 712
587 PlatformTouchEventBuilder platformTouchBuilder(view, webTouchEvent); 713 PlatformTouchEventBuilder platformTouchBuilder(view, webTouchEvent);
588 EXPECT_FLOAT_EQ(10.6f, platformTouchBuilder.touchPoints()[0].screenPos() .x()); 714 EXPECT_FLOAT_EQ(10.6f, platformTouchBuilder.touchPoints()[0].screenPos() .x());
589 EXPECT_FLOAT_EQ(10.4f, platformTouchBuilder.touchPoints()[0].screenPos() .y()); 715 EXPECT_FLOAT_EQ(10.4f, platformTouchBuilder.touchPoints()[0].screenPos() .y());
590 EXPECT_FLOAT_EQ(5.3f + pinchOffset.x(), platformTouchBuilder.touchPoints ()[0].pos().x()); 716 EXPECT_FLOAT_EQ(5.3f + pinchOffset.x(), platformTouchBuilder.touchPoints ()[0].pos().x());
591 EXPECT_FLOAT_EQ(5.2f + pinchOffset.y(), platformTouchBuilder.touchPoints ()[0].pos().y()); 717 EXPECT_FLOAT_EQ(5.2f + pinchOffset.y(), platformTouchBuilder.touchPoints ()[0].pos().y());
592 } 718 }
593 } 719 }
594 720
595 } // anonymous namespace 721 } // anonymous namespace
OLDNEW
« no previous file with comments | « Source/web/WebInputEventConversion.cpp ('k') | public/web/WebInputEvent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698