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

Side by Side Diff: third_party/WebKit/Source/web/tests/TouchActionTest.cpp

Issue 1498923004: Don't reset touch-action zoom state at scrollers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 20 matching lines...) Expand all
31 #include "config.h" 31 #include "config.h"
32 32
33 #include "core/dom/ClientRect.h" 33 #include "core/dom/ClientRect.h"
34 #include "core/dom/ClientRectList.h" 34 #include "core/dom/ClientRectList.h"
35 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
36 #include "core/dom/Element.h" 36 #include "core/dom/Element.h"
37 #include "core/dom/StaticNodeList.h" 37 #include "core/dom/StaticNodeList.h"
38 #include "core/dom/shadow/ShadowRoot.h" 38 #include "core/dom/shadow/ShadowRoot.h"
39 #include "core/frame/FrameView.h" 39 #include "core/frame/FrameView.h"
40 #include "core/frame/LocalFrame.h" 40 #include "core/frame/LocalFrame.h"
41 #include "core/html/HTMLIFrameElement.h"
41 #include "core/input/EventHandler.h" 42 #include "core/input/EventHandler.h"
42 #include "core/layout/HitTestResult.h" 43 #include "core/layout/HitTestResult.h"
43 #include "core/layout/LayoutTreeAsText.h" 44 #include "core/layout/LayoutTreeAsText.h"
44 #include "platform/testing/URLTestHelpers.h" 45 #include "platform/testing/URLTestHelpers.h"
45 #include "platform/testing/UnitTestHelpers.h" 46 #include "platform/testing/UnitTestHelpers.h"
46 #include "public/platform/Platform.h" 47 #include "public/platform/Platform.h"
47 #include "public/platform/WebUnitTestSupport.h" 48 #include "public/platform/WebUnitTestSupport.h"
48 #include "public/web/WebDocument.h" 49 #include "public/web/WebDocument.h"
49 #include "public/web/WebFrame.h" 50 #include "public/web/WebFrame.h"
50 #include "public/web/WebHitTestResult.h" 51 #include "public/web/WebHitTestResult.h"
51 #include "public/web/WebInputEvent.h" 52 #include "public/web/WebInputEvent.h"
52 #include "public/web/WebTouchAction.h" 53 #include "public/web/WebTouchAction.h"
53 #include "public/web/WebView.h" 54 #include "public/web/WebView.h"
54 #include "public/web/WebViewClient.h" 55 #include "public/web/WebViewClient.h"
55 #include "public/web/WebWidgetClient.h" 56 #include "public/web/WebWidgetClient.h"
56 #include "testing/gtest/include/gtest/gtest.h" 57 #include "testing/gtest/include/gtest/gtest.h"
58 #include "web/WebFrameImplBase.h"
57 #include "web/WebViewImpl.h" 59 #include "web/WebViewImpl.h"
58 #include "web/tests/FrameTestHelpers.h" 60 #include "web/tests/FrameTestHelpers.h"
59 61
60 using blink::testing::runPendingTasks; 62 using blink::testing::runPendingTasks;
61 63
62 namespace blink { 64 namespace blink {
63 65
64 class TouchActionTrackingWebViewClient : public FrameTestHelpers::TestWebViewCli ent { 66 class TouchActionTrackingWebViewClient : public FrameTestHelpers::TestWebViewCli ent {
65 public: 67 public:
66 TouchActionTrackingWebViewClient() : 68 TouchActionTrackingWebViewClient() :
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 113 }
112 114
113 void TearDown() override 115 void TearDown() override
114 { 116 {
115 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); 117 Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
116 } 118 }
117 119
118 protected: 120 protected:
119 void runTouchActionTest(std::string file); 121 void runTouchActionTest(std::string file);
120 void runShadowDOMTest(std::string file); 122 void runShadowDOMTest(std::string file);
123 void runIFrameTest(std::string file);
121 void sendTouchEvent(WebView*, WebInputEvent::Type, IntPoint clientPoint); 124 void sendTouchEvent(WebView*, WebInputEvent::Type, IntPoint clientPoint);
122 WebView* setupTest(std::string file, TouchActionTrackingWebViewClient&); 125 WebView* setupTest(std::string file, TouchActionTrackingWebViewClient&);
123 void runTestOnTree(ContainerNode* root, WebView*, TouchActionTrackingWebView Client&); 126 void runTestOnTree(ContainerNode* root, WebView*, TouchActionTrackingWebView Client&);
124 127
125 std::string m_baseURL; 128 std::string m_baseURL;
126 FrameTestHelpers::WebViewHelper m_webViewHelper; 129 FrameTestHelpers::WebViewHelper m_webViewHelper;
127 }; 130 };
128 131
129 void TouchActionTest::runTouchActionTest(std::string file) 132 void TouchActionTest::runTouchActionTest(std::string file)
130 { 133 {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 ShadowRoot* shadowRoot = hostNodes->item(index)->openShadowRoot(); 169 ShadowRoot* shadowRoot = hostNodes->item(index)->openShadowRoot();
167 runTestOnTree(shadowRoot, webView, client); 170 runTestOnTree(shadowRoot, webView, client);
168 } 171 }
169 172
170 // Projections show up in the main document. 173 // Projections show up in the main document.
171 runTestOnTree(document.get(), webView, client); 174 runTestOnTree(document.get(), webView, client);
172 175
173 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally scoped client. 176 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally scoped client.
174 } 177 }
175 178
179 void TouchActionTest::runIFrameTest(std::string file)
180 {
181 TouchActionTrackingWebViewClient client;
182
183 WebView* webView = setupTest(file, client);
184 WebFrame* curFrame = webView->mainFrame()->firstChild();
185 ASSERT_TRUE(curFrame);
186
187 for (; curFrame; curFrame = curFrame->nextSibling()) {
188 // Oilpan: see runTouchActionTest() comment why these are persistent ref erences.
189 RefPtrWillBePersistent<Document> contentDoc = static_cast<PassRefPtrWill BeRawPtr<Document>>(curFrame->document());
190 runTestOnTree(contentDoc.get(), webView, client);
191 }
192
193 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally scoped client.
194 }
195
176 WebView* TouchActionTest::setupTest(std::string file, TouchActionTrackingWebView Client& client) 196 WebView* TouchActionTest::setupTest(std::string file, TouchActionTrackingWebView Client& client)
177 { 197 {
178 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), WebString::fromUTF8(file)); 198 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), WebString::fromUTF8(file));
179 // Note that JavaScript must be enabled for shadow DOM tests. 199 // Note that JavaScript must be enabled for shadow DOM tests.
180 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + file, true, 0, &client); 200 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + file, true, 0, &client);
181 201
182 // Set size to enable hit testing, and avoid line wrapping for consistency w ith browser. 202 // Set size to enable hit testing, and avoid line wrapping for consistency w ith browser.
183 webView->resize(WebSize(800, 1200)); 203 webView->resize(WebSize(800, 1200));
184 204
185 // Scroll to verify the code properly transforms windows to client co-ords. 205 // Scroll to verify the code properly transforms windows to client co-ords.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // Run each test three times at different positions in the element. 237 // Run each test three times at different positions in the element.
218 // Note that we don't want the bounding box because our tests sometimes have elements with 238 // Note that we don't want the bounding box because our tests sometimes have elements with
219 // multiple border boxes with other elements in between. Use the first b order box (which 239 // multiple border boxes with other elements in between. Use the first b order box (which
220 // we can easily visualize in a browser for debugging). 240 // we can easily visualize in a browser for debugging).
221 Persistent<ClientRectList> rects = element->getClientRects(); 241 Persistent<ClientRectList> rects = element->getClientRects();
222 ASSERT_GE(rects->length(), 0u) << failureContext; 242 ASSERT_GE(rects->length(), 0u) << failureContext;
223 Persistent<ClientRect> r = rects->item(0); 243 Persistent<ClientRect> r = rects->item(0);
224 FloatRect clientFloatRect = FloatRect(r->left(), r->top(), r->width(), r ->height()); 244 FloatRect clientFloatRect = FloatRect(r->left(), r->top(), r->width(), r ->height());
225 IntRect clientRect = enclosedIntRect(clientFloatRect); 245 IntRect clientRect = enclosedIntRect(clientFloatRect);
226 for (int locIdx = 0; locIdx < 3; locIdx++) { 246 for (int locIdx = 0; locIdx < 3; locIdx++) {
227 IntPoint clientPoint; 247 IntPoint framePoint;
228 std::stringstream contextStream; 248 std::stringstream contextStream;
229 contextStream << failureContext << " ("; 249 contextStream << failureContext << " (";
230 switch (locIdx) { 250 switch (locIdx) {
231 case 0: 251 case 0:
232 clientPoint = clientRect.center(); 252 framePoint = clientRect.center();
233 contextStream << "center"; 253 contextStream << "center";
234 break; 254 break;
235 case 1: 255 case 1:
236 clientPoint = clientRect.location(); 256 framePoint = clientRect.location();
237 contextStream << "top-left"; 257 contextStream << "top-left";
238 break; 258 break;
239 case 2: 259 case 2:
240 clientPoint = clientRect.maxXMaxYCorner(); 260 framePoint = clientRect.maxXMaxYCorner();
241 clientPoint.move(-1, -1); 261 framePoint.move(-1, -1);
242 contextStream << "bottom-right"; 262 contextStream << "bottom-right";
243 break; 263 break;
244 default: 264 default:
245 FAIL() << "Invalid location index."; 265 FAIL() << "Invalid location index.";
246 } 266 }
247 contextStream << "=" << clientPoint.x() << "," << clientPoint.y() << ")."; 267
268 IntPoint windowPoint = root->document().frame()->view()->convertToRo otFrame(framePoint);
269 contextStream << "=" << windowPoint.x() << "," << windowPoint.y() << ").";
248 std::string failureContextPos = contextStream.str(); 270 std::string failureContextPos = contextStream.str();
249 271
250 LocalFrame* frame = root->document().frame(); 272 LocalFrame* mainFrame = static_cast<LocalFrame*>(webView->mainFrame( )->toImplBase()->frame());
251 FrameView* frameView = frame->view(); 273 FrameView* mainFrameView = mainFrame->view();
252 IntRect visibleRect = frameView->windowClipRect(); 274 IntRect visibleRect = mainFrameView->windowClipRect();
253 ASSERT_TRUE(visibleRect.contains(clientPoint)) << failureContextPos 275 ASSERT_TRUE(visibleRect.contains(windowPoint)) << failureContextPos
254 << " Test point not contained in visible area: " << visibleRect. x() << "," << visibleRect.y() 276 << " Test point not contained in visible area: " << visibleRect. x() << "," << visibleRect.y()
255 << "-" << visibleRect.maxX() << "," << visibleRect.maxY(); 277 << "-" << visibleRect.maxX() << "," << visibleRect.maxY();
256 278
257 // First validate that a hit test at this point will really hit the element 279 // First validate that a hit test at this point will really hit the element
258 // we intended. This is the easiest way for a test to be broken, but has nothing really 280 // we intended. This is the easiest way for a test to be broken, but has nothing really
259 // to do with touch action. 281 // to do with touch action.
260 // Note that we can't use WebView's hit test API because it doesn't look into shadow DOM. 282 // Note that we can't use WebView's hit test API because it doesn't look into shadow DOM.
261 IntPoint docPoint(frameView->rootFrameToContents(clientPoint)); 283 IntPoint docPoint(mainFrameView->frameToContents(windowPoint));
262 HitTestResult result = frame->eventHandler().hitTestResultAtPoint(do cPoint, HitTestRequest::ReadOnly | HitTestRequest::Active); 284 HitTestResult result = mainFrame->eventHandler().hitTestResultAtPoin t(docPoint, HitTestRequest::ReadOnly | HitTestRequest::Active);
263 ASSERT_EQ(element, result.innerElement()) << "Unexpected hit test re sult " << failureContextPos 285 ASSERT_EQ(element, result.innerElement()) << "Unexpected hit test re sult " << failureContextPos
264 << " Got element: \"" << result.innerElement()->outerHTML().str ipWhiteSpace().left(80).ascii().data() << "\"" 286 << " Got element: \"" << result.innerElement()->outerHTML().str ipWhiteSpace().left(80).ascii().data() << "\""
265 << std::endl << "Document render tree:" << std::endl << external Representation(root->document().frame()).utf8().data(); 287 << std::endl << "Document render tree:" << std::endl << external Representation(root->document().frame()).utf8().data();
266 288
267 // Now send the touch event and check any touch action result. 289 // Now send the touch event and check any touch action result.
268 sendTouchEvent(webView, WebInputEvent::TouchStart, clientPoint); 290 sendTouchEvent(webView, WebInputEvent::TouchStart, windowPoint);
269 291
270 AtomicString expectedAction = element->getAttribute("expected-action "); 292 AtomicString expectedAction = element->getAttribute("expected-action ");
271 if (expectedAction == "auto") { 293 if (expectedAction == "auto") {
272 // Auto is the default - no action set. 294 // Auto is the default - no action set.
273 EXPECT_EQ(0, client.touchActionSetCount()) << failureContextPos; 295 EXPECT_EQ(0, client.touchActionSetCount()) << failureContextPos;
274 EXPECT_EQ(WebTouchActionAuto, client.lastTouchAction()) << failu reContextPos; 296 EXPECT_EQ(WebTouchActionAuto, client.lastTouchAction()) << failu reContextPos;
275 } else { 297 } else {
276 // Should have received exactly one touch action. 298 // Should have received exactly one touch action.
277 EXPECT_EQ(1, client.touchActionSetCount()) << failureContextPos; 299 EXPECT_EQ(1, client.touchActionSetCount()) << failureContextPos;
278 if (client.touchActionSetCount()) { 300 if (client.touchActionSetCount()) {
279 if (expectedAction == "none") { 301 if (expectedAction == "none") {
280 EXPECT_EQ(WebTouchActionNone, client.lastTouchAction()) << failureContextPos; 302 EXPECT_EQ(WebTouchActionNone, client.lastTouchAction()) << failureContextPos;
281 } else if (expectedAction == "pan-x") { 303 } else if (expectedAction == "pan-x") {
282 EXPECT_EQ(WebTouchActionPanX, client.lastTouchAction()) << failureContextPos; 304 EXPECT_EQ(WebTouchActionPanX, client.lastTouchAction()) << failureContextPos;
283 } else if (expectedAction == "pan-y") { 305 } else if (expectedAction == "pan-y") {
284 EXPECT_EQ(WebTouchActionPanY, client.lastTouchAction()) << failureContextPos; 306 EXPECT_EQ(WebTouchActionPanY, client.lastTouchAction()) << failureContextPos;
285 } else if (expectedAction == "pan-x-y") { 307 } else if (expectedAction == "pan-x-y") {
286 EXPECT_EQ((WebTouchActionPanX | WebTouchActionPanY), cli ent.lastTouchAction()) << failureContextPos; 308 EXPECT_EQ((WebTouchActionPan), client.lastTouchAction()) << failureContextPos;
287 } else if (expectedAction == "manipulation") { 309 } else if (expectedAction == "manipulation") {
288 EXPECT_EQ((WebTouchActionPanX | WebTouchActionPanY | Web TouchActionPinchZoom), client.lastTouchAction()) << failureContextPos; 310 EXPECT_EQ((WebTouchActionManipulation), client.lastTouch Action()) << failureContextPos;
289 } else { 311 } else {
290 FAIL() << "Unrecognized expected-action \"" << expectedA ction.ascii().data() 312 FAIL() << "Unrecognized expected-action \"" << expectedA ction.ascii().data()
291 << "\" " << failureContextPos; 313 << "\" " << failureContextPos;
292 } 314 }
293 } 315 }
294 } 316 }
295 317
296 // Reset webview touch state. 318 // Reset webview touch state.
297 client.reset(); 319 client.reset();
298 sendTouchEvent(webView, WebInputEvent::TouchCancel, clientPoint); 320 sendTouchEvent(webView, WebInputEvent::TouchCancel, windowPoint);
299 EXPECT_EQ(0, client.touchActionSetCount()); 321 EXPECT_EQ(0, client.touchActionSetCount());
300 } 322 }
301 } 323 }
302 } 324 }
303 void TouchActionTest::sendTouchEvent(WebView* webView, WebInputEvent::Type type, IntPoint clientPoint) 325 void TouchActionTest::sendTouchEvent(WebView* webView, WebInputEvent::Type type, IntPoint clientPoint)
304 { 326 {
305 ASSERT_TRUE(type == WebInputEvent::TouchStart || type == WebInputEvent::Touc hCancel); 327 ASSERT_TRUE(type == WebInputEvent::TouchStart || type == WebInputEvent::Touc hCancel);
306 328
307 WebTouchEvent webTouchEvent; 329 WebTouchEvent webTouchEvent;
308 webTouchEvent.type = type; 330 webTouchEvent.type = type;
(...skipping 19 matching lines...) Expand all
328 TEST_F(TouchActionTest, Simple) 350 TEST_F(TouchActionTest, Simple)
329 { 351 {
330 runTouchActionTest("touch-action-simple.html"); 352 runTouchActionTest("touch-action-simple.html");
331 } 353 }
332 354
333 TEST_F(TouchActionTest, Overflow) 355 TEST_F(TouchActionTest, Overflow)
334 { 356 {
335 runTouchActionTest("touch-action-overflow.html"); 357 runTouchActionTest("touch-action-overflow.html");
336 } 358 }
337 359
360 TEST_F(TouchActionTest, IFrame)
361 {
362 runIFrameTest("touch-action-iframe.html");
363 }
364
338 TEST_F(TouchActionTest, ShadowDOM) 365 TEST_F(TouchActionTest, ShadowDOM)
339 { 366 {
340 runShadowDOMTest("touch-action-shadow-dom.html"); 367 runShadowDOMTest("touch-action-shadow-dom.html");
341 } 368 }
342 369
343 TEST_F(TouchActionTest, Pan) 370 TEST_F(TouchActionTest, Pan)
344 { 371 {
345 runTouchActionTest("touch-action-pan.html"); 372 runTouchActionTest("touch-action-pan.html");
346 } 373 }
347 374
348 } // namespace blink 375 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698